1 
2 /*
3  +------------------------------------------------------------------------+
4  | Phalcon Framework                                                      |
5  +------------------------------------------------------------------------+
6  | Copyright (c) 2011-2016 Phalcon Team (http://www.phalconphp.com)       |
7  +------------------------------------------------------------------------+
8  | This source file is subject to the New BSD License that is bundled     |
9  | with this package in the file docs/LICENSE.txt.                        |
10  |                                                                        |
11  | If you did not receive a copy of the license and are unable to         |
12  | obtain it through the world-wide-web, please send an email             |
13  | to license@phalconphp.com so we can send you a copy immediately.       |
14  +------------------------------------------------------------------------+
15  | Authors: Andres Gutierrez <andres@phalconphp.com>                      |
16  |          Eduar Carvajal <eduar@phalconphp.com>                         |
17  +------------------------------------------------------------------------+
18 */
19 
20 #ifndef PHALCON_MVC_VIEW_ENGINE_VOLT_SCANNER_H
21 #define PHALCON_MVC_VIEW_ENGINE_VOLT_SCANNER_H
22 
23 #include "php_phalcon.h"
24 
25 #define PHVOLT_RAW_BUFFER_SIZE 256
26 
27 #define PHVOLT_SCANNER_RETCODE_EOF -1
28 #define PHVOLT_SCANNER_RETCODE_ERR -2
29 #define PHVOLT_SCANNER_RETCODE_IMPOSSIBLE -3
30 
31 /** Modes */
32 #define PHVOLT_MODE_RAW 0
33 #define PHVOLT_MODE_CODE 1
34 #define PHVOLT_MODE_COMMENT 2
35 
36 #define PHVOLT_T_IGNORE 257
37 
38 /* Literals & Identifiers */
39 #define PHVOLT_T_INTEGER 258
40 #define PHVOLT_T_DOUBLE 259
41 #define PHVOLT_T_STRING 260
42 #define PHVOLT_T_NULL 261
43 #define PHVOLT_T_FALSE 262
44 #define PHVOLT_T_TRUE 263
45 #define PHVOLT_T_IDENTIFIER 265
46 
47 /* Operators */
48 #define PHVOLT_T_ADD '+'
49 #define PHVOLT_T_SUB '-'
50 #define PHVOLT_T_MUL '*'
51 #define PHVOLT_T_DIV '/'
52 #define PHVOLT_T_MOD '%'
53 #define PHVOLT_T_AND 266
54 #define PHVOLT_T_OR 267
55 #define PHVOLT_T_CONCAT '~'
56 #define PHVOLT_T_PIPE '|'
57 
58 #define PHVOLT_T_DOT '.'
59 #define PHVOLT_T_COMMA 269
60 
61 #define PHVOLT_T_NOT '!'
62 #define PHVOLT_T_LESS '<'
63 #define PHVOLT_T_LESSEQUAL 270
64 #define PHVOLT_T_GREATER '>'
65 #define PHVOLT_T_GREATEREQUAL 271
66 #define PHVOLT_T_EQUALS 272
67 #define PHVOLT_T_NOTEQUALS 273
68 #define PHVOLT_T_IDENTICAL 274
69 #define PHVOLT_T_NOTIDENTICAL 275
70 #define PHVOLT_T_RANGE 276
71 #define PHVOLT_T_ASSIGN '='
72 #define PHVOLT_T_COLON 277
73 #define PHVOLT_T_QUESTION '?'
74 #define PHVOLT_T_POW 278
75 #define PHVOLT_T_INCR 279
76 #define PHVOLT_T_DECR 280
77 #define PHVOLT_T_ADD_ASSIGN 281
78 #define PHVOLT_T_SUB_ASSIGN 282
79 #define PHVOLT_T_MUL_ASSIGN 283
80 #define PHVOLT_T_DIV_ASSIGN 284
81 
82 #define PHVOLT_T_PARENTHESES_OPEN '('
83 #define PHVOLT_T_PARENTHESES_CLOSE ')'
84 #define PHVOLT_T_SBRACKET_OPEN '['
85 #define PHVOLT_T_SBRACKET_CLOSE ']'
86 #define PHVOLT_T_CBRACKET_OPEN '{'
87 #define PHVOLT_T_CBRACKET_CLOSE '}'
88 
89 /** Reserved words */
90 #define PHVOLT_T_IF 300
91 #define PHVOLT_T_ELSE 301
92 #define PHVOLT_T_ELSEIF 302
93 #define PHVOLT_T_ENDIF 303
94 #define PHVOLT_T_FOR 304
95 #define PHVOLT_T_ENDFOR 305
96 #define PHVOLT_T_SET 306
97 #define PHVOLT_T_BLOCK 307
98 #define PHVOLT_T_ENDBLOCK 308
99 #define PHVOLT_T_IN 309
100 #define PHVOLT_T_EXTENDS 310
101 #define PHVOLT_T_IS 311
102 #define PHVOLT_T_DEFINED 312
103 #define PHVOLT_T_INCLUDE 313
104 #define PHVOLT_T_CACHE 314
105 #define PHVOLT_T_ENDCACHE 315
106 #define PHVOLT_T_DO 316
107 #define PHVOLT_T_AUTOESCAPE 317
108 #define PHVOLT_T_ENDAUTOESCAPE 318
109 #define PHVOLT_T_CONTINUE 319
110 #define PHVOLT_T_BREAK 320
111 #define PHVOLT_T_ELSEFOR 321
112 #define PHVOLT_T_MACRO 322
113 #define PHVOLT_T_ENDMACRO 323
114 #define PHVOLT_T_WITH 324
115 #define PHVOLT_T_CALL 325
116 #define PHVOLT_T_ENDCALL 326
117 #define PHVOLT_T_RETURN 327
118 
119 /** Delimiters */
120 #define PHVOLT_T_OPEN_DELIMITER  330
121 #define PHVOLT_T_CLOSE_DELIMITER  331
122 #define PHVOLT_T_OPEN_EDELIMITER  332
123 #define PHVOLT_T_CLOSE_EDELIMITER  333
124 
125 /** Special Tokens */
126 #define PHVOLT_T_FCALL 350
127 #define PHVOLT_T_EXPR 354
128 #define PHVOLT_T_QUALIFIED 355
129 #define PHVOLT_T_ENCLOSED 356
130 #define PHVOLT_T_RAW_FRAGMENT 357
131 #define PHVOLT_T_EMPTY_STATEMENT 358
132 #define PHVOLT_T_ECHO 359
133 #define PHVOLT_T_ARRAY 360
134 #define PHVOLT_T_ARRAYACCESS 361
135 #define PHVOLT_T_NOT_ISSET 362
136 #define PHVOLT_T_ISSET 363
137 #define PHVOLT_T_RESOLVED_EXPR 364
138 #define PHVOLT_T_SLICE 365
139 #define PHVOLT_T_TERNARY 366
140 #define PHVOLT_T_NOT_IN 367
141 
142 #define PHVOLT_T_MINUS 368
143 #define PHVOLT_T_PLUS 369
144 
145 #define PHVOLT_T_EMPTY 380
146 #define PHVOLT_T_EVEN 381
147 #define PHVOLT_T_ODD 382
148 #define PHVOLT_T_NUMERIC 383
149 #define PHVOLT_T_SCALAR 384
150 #define PHVOLT_T_ITERABLE 385
151 
152 #define PHVOLT_T_ISEMPTY 386
153 #define PHVOLT_T_ISEVEN 387
154 #define PHVOLT_T_ISODD 388
155 #define PHVOLT_T_ISNUMERIC 389
156 #define PHVOLT_T_ISSCALAR 390
157 #define PHVOLT_T_ISITERABLE 391
158 
159 #define PHVOLT_T_NOT_ISEMPTY 392
160 #define PHVOLT_T_NOT_ISEVEN 393
161 #define PHVOLT_T_NOT_ISODD 394
162 #define PHVOLT_T_NOT_ISNUMERIC 395
163 #define PHVOLT_T_NOT_ISSCALAR 396
164 #define PHVOLT_T_NOT_ISITERABLE 397
165 
166 #define PHVOLT_T_RAW 400
167 #define PHVOLT_T_ENDRAW 401
168 
169 /* switch-case statement */
170 #define PHVOLT_T_SWITCH 411
171 #define PHVOLT_T_CASE 412
172 #define PHVOLT_T_DEFAULT 413
173 #define PHVOLT_T_ENDSWITCH 414
174 
175 /* List of tokens and their names */
176 typedef struct _phvolt_token_names {
177 	char *name;
178 	int len;
179 	unsigned int code;
180 } phvolt_token_names;
181 
182 /* Active token state */
183 typedef struct _phvolt_scanner_state {
184 	int active_token;
185 	int mode;
186 	char* start;
187 	char* end;
188 	unsigned int start_length;
189 	unsigned int active_line;
190 	zval *active_file;
191 	unsigned int statement_position;
192 	unsigned int extends_mode;
193 	unsigned int block_level;
194 	unsigned int macro_level;
195 	char *raw_buffer;
196 	unsigned int raw_buffer_cursor;
197 	unsigned int raw_buffer_size;
198 	unsigned int old_if_level;
199 	unsigned int if_level;
200 	unsigned int for_level;
201     unsigned int switch_level;
202 	int whitespace_control;
203 	int forced_raw_state;
204 } phvolt_scanner_state;
205 
206 /* Extra information tokens */
207 typedef struct _phvolt_scanner_token {
208 	int opcode;
209 	int len;
210 	char *value;
211 } phvolt_scanner_token;
212 
213 int phvolt_get_token(phvolt_scanner_state *s, phvolt_scanner_token *token);
214 
215 extern const phvolt_token_names phvolt_tokens[];
216 
217 #endif  /* PHALCON_MVC_VIEW_ENGINE_VOLT_SCANNER_H */
218