/src/pigeonhole/src/lib-sieve/sieve-lexer.h
Line | Count | Source |
1 | | #ifndef SIEVE_LEXER_H |
2 | | #define SIEVE_LEXER_H |
3 | | |
4 | | #include "lib.h" |
5 | | #include "str.h" |
6 | | |
7 | | #include "sieve-common.h" |
8 | | |
9 | | enum sieve_token_type { |
10 | | STT_NONE, |
11 | | STT_WHITESPACE, |
12 | | STT_EOF, |
13 | | |
14 | | STT_NUMBER, |
15 | | STT_IDENTIFIER, |
16 | | STT_TAG, |
17 | | STT_STRING, |
18 | | |
19 | | STT_RBRACKET, |
20 | | STT_LBRACKET, |
21 | | STT_RCURLY, |
22 | | STT_LCURLY, |
23 | | STT_RSQUARE, |
24 | | STT_LSQUARE, |
25 | | STT_SEMICOLON, |
26 | | STT_COMMA, |
27 | | |
28 | | /* These are currently not used in the lexical specification, but a |
29 | | token is assigned to these to generate proper error messages (these |
30 | | are technically not garbage and possibly part of mistyped but |
31 | | otherwise valid tokens). |
32 | | */ |
33 | | STT_SLASH, |
34 | | STT_COLON, |
35 | | |
36 | | /* Error tokens */ |
37 | | STT_GARBAGE, /* Error reporting deferred to parser */ |
38 | | STT_ERROR /* Lexer is responsible for error, parser won't report |
39 | | additional errors */ |
40 | | }; |
41 | | |
42 | | /* |
43 | | * Lexer object |
44 | | */ |
45 | | |
46 | | struct sieve_lexical_scanner; |
47 | | |
48 | | struct sieve_lexer { |
49 | | struct sieve_lexical_scanner *scanner; |
50 | | |
51 | | enum sieve_token_type token_type; |
52 | | string_t *token_str_value; |
53 | | sieve_number_t token_int_value; |
54 | | |
55 | | int token_line; |
56 | | }; |
57 | | |
58 | | const struct sieve_lexer * |
59 | | sieve_lexer_create(struct sieve_script *script, |
60 | | struct sieve_error_handler *ehandler, |
61 | | enum sieve_error *error_code_r); |
62 | | void sieve_lexer_free(const struct sieve_lexer **lexer); |
63 | | |
64 | | /* |
65 | | * Scanning |
66 | | */ |
67 | | |
68 | | void sieve_lexer_skip_token(const struct sieve_lexer *lexer); |
69 | | |
70 | | /* |
71 | | * Token access |
72 | | */ |
73 | | |
74 | | static inline enum sieve_token_type |
75 | | sieve_lexer_token_type(const struct sieve_lexer *lexer) |
76 | 0 | { |
77 | 0 | return lexer->token_type; |
78 | 0 | } Unexecuted instantiation: sieve-parser.c:sieve_lexer_token_type Unexecuted instantiation: sieve-lexer.c:sieve_lexer_token_type |
79 | | |
80 | | static inline const string_t * |
81 | | sieve_lexer_token_str(const struct sieve_lexer *lexer) |
82 | 0 | { |
83 | 0 | i_assert(lexer->token_type == STT_STRING); |
84 | | |
85 | 0 | return lexer->token_str_value; |
86 | 0 | } Unexecuted instantiation: sieve-parser.c:sieve_lexer_token_str Unexecuted instantiation: sieve-lexer.c:sieve_lexer_token_str |
87 | | |
88 | | static inline const char * |
89 | | sieve_lexer_token_ident(const struct sieve_lexer *lexer) |
90 | 0 | { |
91 | 0 | i_assert(lexer->token_type == STT_TAG || |
92 | 0 | lexer->token_type == STT_IDENTIFIER); |
93 | | |
94 | 0 | return str_c(lexer->token_str_value); |
95 | 0 | } Unexecuted instantiation: sieve-parser.c:sieve_lexer_token_ident Unexecuted instantiation: sieve-lexer.c:sieve_lexer_token_ident |
96 | | |
97 | | static inline sieve_number_t |
98 | | sieve_lexer_token_int(const struct sieve_lexer *lexer) |
99 | 0 | { |
100 | 0 | i_assert(lexer->token_type == STT_NUMBER); |
101 | | |
102 | 0 | return lexer->token_int_value; |
103 | 0 | } Unexecuted instantiation: sieve-parser.c:sieve_lexer_token_int Unexecuted instantiation: sieve-lexer.c:sieve_lexer_token_int |
104 | | |
105 | | static inline bool sieve_lexer_eof(const struct sieve_lexer *lexer) |
106 | 0 | { |
107 | 0 | return lexer->token_type == STT_EOF; |
108 | 0 | } Unexecuted instantiation: sieve-parser.c:sieve_lexer_eof Unexecuted instantiation: sieve-lexer.c:sieve_lexer_eof |
109 | | |
110 | | static inline int sieve_lexer_token_line(const struct sieve_lexer *lexer) |
111 | 0 | { |
112 | 0 | return lexer->token_line; |
113 | 0 | } Unexecuted instantiation: sieve-parser.c:sieve_lexer_token_line Unexecuted instantiation: sieve-lexer.c:sieve_lexer_token_line |
114 | | |
115 | | const char *sieve_lexer_token_description(const struct sieve_lexer *lexer); |
116 | | |
117 | | void sieve_lexer_token_print(const struct sieve_lexer *lexer); |
118 | | |
119 | | #endif |