1 /*
2 * phpdbg_lexer.l
3 */
4
5 #include "phpdbg.h"
6 #include "phpdbg_cmd.h"
7
8 #include "phpdbg_parser.h"
9
10 #define LEX(v) (PHPDBG_G(lexer).v)
11
12 #define YYCTYPE unsigned char
13 #define YYSETCONDITION(x) LEX(state) = x;
14 #define YYGETCONDITION() LEX(state)
15 #define YYCURSOR LEX(cursor)
16 #define YYMARKER LEX(marker)
17 #define yyleng LEX(len)
18 #define yytext ((char*) LEX(text))
19 #undef YYDEBUG
20 #define YYDEBUG(a, b)
21 #define YYFILL(n)
22
23 #define NORMAL 0
24 #define RAW 1
25 #define INITIAL 2
26
27 ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
28
phpdbg_init_lexer(phpdbg_param_t * stack,char * input TSRMLS_DC)29 void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) {
30 PHPDBG_G(parser_stack) = stack;
31
32 YYSETCONDITION(INITIAL);
33
34 LEX(text) = YYCURSOR = (unsigned char *) input;
35 LEX(len) = strlen(input);
36 }
37
phpdbg_lex(phpdbg_param_t * yylval)38 int phpdbg_lex (phpdbg_param_t* yylval) {
39 TSRMLS_FETCH(); /* Slow, but this is not a major problem here. TODO: Use TSRMLS_DC */
40
41 restart:
42 LEX(text) = YYCURSOR;
43
44 /*!re2c
45 re2c:yyfill:check = 0;
46 T_TRUE 'true'
47 T_YES 'yes'
48 T_ON 'on'
49 T_ENABLED 'enabled'
50 T_FALSE 'false'
51 T_NO 'no'
52 T_OFF 'off'
53 T_DISABLED 'disabled'
54 T_EVAL 'ev'
55 T_SHELL 'sh'
56 T_IF 'if'
57 T_RUN 'run'
58 T_RUN_SHORT "r"
59 WS [ \r\n\t]+
60 DIGITS [-]?[0-9\.]+
61 ID [^ \r\n\t:#\000]+
62 ADDR [0][x][a-fA-F0-9]+
63 OPCODE (ZEND_|zend_)([A-Za-z])+
64 INPUT [^\n\000]+
65
66 <!*> := yyleng = (size_t) YYCURSOR - (size_t) yytext;
67
68 <*>[\n\000] {
69 return 0;
70 }
71
72 <NORMAL>{T_IF}{WS} {
73 YYSETCONDITION(RAW);
74 phpdbg_init_param(yylval, EMPTY_PARAM);
75 return T_IF;
76 }
77
78 <NORMAL>{ID}[:]{1}[//]{2} {
79 phpdbg_init_param(yylval, STR_PARAM);
80 yylval->str = zend_strndup(yytext, yyleng);
81 yylval->len = yyleng;
82 return T_PROTO;
83 }
84 <NORMAL>[#]{1} {
85 return T_POUND;
86 }
87 <NORMAL>[:]{2} {
88 return T_DCOLON;
89 }
90 <NORMAL>[:]{1} {
91 return T_COLON;
92 }
93
94 <NORMAL>({T_YES}|{T_ON}|{T_ENABLED}|{T_TRUE}){WS} {
95 phpdbg_init_param(yylval, NUMERIC_PARAM);
96 yylval->num = 1;
97 return T_TRUTHY;
98 }
99
100 <NORMAL>({T_NO}|{T_OFF}|{T_DISABLED}|{T_FALSE}){WS} {
101 phpdbg_init_param(yylval, NUMERIC_PARAM);
102 yylval->num = 0;
103 return T_FALSY;
104 }
105
106 <NORMAL>{DIGITS} {
107 phpdbg_init_param(yylval, NUMERIC_PARAM);
108 yylval->num = atoi(yytext);
109 return T_DIGITS;
110 }
111
112 <NORMAL>{ADDR} {
113 phpdbg_init_param(yylval, ADDR_PARAM);
114 yylval->addr = strtoul(yytext, 0, 16);
115 return T_ADDR;
116 }
117
118 <NORMAL>{OPCODE} {
119 phpdbg_init_param(yylval, OP_PARAM);
120 yylval->str = zend_strndup(yytext, yyleng);
121 yylval->len = yyleng;
122 return T_OPCODE;
123 }
124
125 <NORMAL>{ID} {
126 phpdbg_init_param(yylval, STR_PARAM);
127 yylval->str = zend_strndup(yytext, yyleng);
128 yylval->len = yyleng;
129 return T_ID;
130 }
131
132 <RAW>{INPUT} {
133 phpdbg_init_param(yylval, STR_PARAM);
134 yylval->str = zend_strndup(yytext, yyleng);
135 yylval->len = yyleng;
136 return T_INPUT;
137 }
138
139 <*>{WS} {
140 /* ignore whitespace */
141
142 goto restart;
143 }
144
145 <INITIAL>{T_EVAL}{WS} {
146 YYSETCONDITION(RAW);
147 phpdbg_init_param(yylval, EMPTY_PARAM);
148 return T_EVAL;
149 }
150 <INITIAL>{T_SHELL}{WS} {
151 YYSETCONDITION(RAW);
152 phpdbg_init_param(yylval, EMPTY_PARAM);
153 return T_SHELL;
154 }
155 <INITIAL>({T_RUN}|{T_RUN_SHORT}){WS} {
156 YYSETCONDITION(RAW);
157 phpdbg_init_param(yylval, EMPTY_PARAM);
158 return T_RUN;
159 }
160
161 <INITIAL>. {
162 YYSETCONDITION(NORMAL);
163
164 YYCURSOR = LEX(text);
165 goto restart;
166 }
167
168 */
169 }
170