]> git.wincent.com - wikitext.git/blob - ext/token.h
Remove repetition of ID2SYM() and rb_intern()
[wikitext.git] / ext / token.h
1 // Copyright 2008-2009 Wincent Colaiuta. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // 1. Redistributions of source code must retain the above copyright notice,
7 //    this list of conditions and the following disclaimer.
8 // 2. Redistributions in binary form must reproduce the above copyright notice,
9 //    this list of conditions and the following disclaimer in the documentation
10 //    and/or other materials provided with the distribution.
11 //
12 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22 // POSSIBILITY OF SUCH DAMAGE.
23
24 #include "ruby_compat.h"
25 #include <stdint.h>     /* uint32_t */
26
27 #define TOKEN_LEN(token)    (token->stop - token->start)
28 #define TOKEN_TEXT(token)   rb_str_new((const char *)token->start, TOKEN_LEN(token))
29
30 typedef struct
31 {
32     char        *start;
33     char        *stop;
34     size_t      line_start;
35     size_t      line_stop;
36     size_t      column_start;
37     size_t      column_stop;
38     uint32_t    code_point;
39     int         type;
40 } token_t;
41
42 enum token_types {
43     NO_TOKEN,
44     P,              // imaginary token (never explicitly marked up)
45     LI,             // imaginary token (never explicitly marked up)
46     NESTED_LIST,    // imaginary token (never explicitly marked up)
47     PRE,
48     PRE_START,
49     PRE_END,
50     NO_WIKI_START,
51     NO_WIKI_END,
52     BLOCKQUOTE,
53     BLOCKQUOTE_START,
54     BLOCKQUOTE_END,
55     STRONG_EM,
56     STRONG_START,
57     STRONG_END,
58     STRONG,
59     EM_START,
60     EM_END,
61     EM,
62     TT_START,
63     TT_END,
64     TT,
65     OL,
66     UL,
67
68     // keep these consecutive, and in ascending order
69     // (the arithmetic for the base_heading_level feature assumes this)
70     H1_START,
71     H2_START,
72     H3_START,
73     H4_START,
74     H5_START,
75     H6_START,
76
77     // likewise for the H*_END tokens
78     H1_END,
79     H2_END,
80     H3_END,
81     H4_END,
82     H5_END,
83     H6_END,
84
85     URI,
86     MAIL,
87     PATH,
88     LINK_START,
89     LINK_END,
90     EXT_LINK_START,
91     EXT_LINK_END,
92     SEPARATOR,
93     SPACE,
94     QUOT_ENTITY,
95     AMP_ENTITY,
96     NAMED_ENTITY,
97     HEX_ENTITY,
98     DECIMAL_ENTITY,
99     QUOT,
100     AMP,
101     LESS,
102     GREATER,
103     IMG_START,
104     IMG_END,
105     LEFT_CURLY,
106     RIGHT_CURLY,
107     CRLF,
108     SPECIAL_URI_CHARS,
109     PRINTABLE,
110     ALNUM,
111     DEFAULT,
112     END_OF_FILE
113 };
114
115 VALUE Wikitext_parser_token_types(VALUE self);
116
117 VALUE wiki_token(token_t *token);