#include "phpdbg_parser.h"
#include <stdio.h>
#include <string.h>
-
-static inline void phpdbg_param_append(phpdbg_param_t *param, const char *next, size_t nlen) {
- if (param->len + nlen > param->addr) {
- param->str = realloc(
- param->str, param->len + 1024);
- param->addr += 1024;
- }
- memcpy(¶m->str[param->len], next, nlen);
- param->len += nlen;
- param->str[param->len] = 0;
-}
%}
%s RAW
-%s STRING
%option outfile="phpdbg_lexer.c" header-file="phpdbg_lexer.h"
%option warn nodefault
C_NO "no"
C_OFF "off"
C_DISABLED "disabled"
-
C_EVAL "eval"
C_SHELL "shell"
METHOD {ID}::{ID}
FILE [^ :0-9]{1,}:[0-9]+
OPLINE 0x[a-fA-F0-9]+
+LITERAL \"(\\.|[^\\"])*\"
WS [ \r\n\t]+
INPUT [^\n]+
%%
}
{C_EVAL} {
BEGIN(RAW);
- return C_EVAL;
+ return C_EVAL;
}
{C_SHELL} {
BEGIN(RAW);
- return C_SHELL;
+ return C_SHELL;
}
{DIGITS} {
yylval->type = NUMERIC_PARAM;
yylval->addr = strtoul(yytext, NULL, 10);
return T_OPLINE;
}
- {ID} {
+ {LITERAL} {
yylval->type = STR_PARAM;
yylval->str = strndup(yytext, yyleng);
yylval->len = yyleng;
- return T_ID;
+ return T_LITERAL;
}
- \" {
- BEGIN(STRING);
+ {ID} {
yylval->type = STR_PARAM;
- yylval->str = (char*) malloc(28);
- yylval->len = 0;
- yylval->addr = 28;
- }
- <STRING>[^\\"\n]* { phpdbg_param_append(yylval, yytext); }
- <STRING>\\n { phpdbg_param_append(yylval, "\n"); }
- <STRING>\\t { phpdbg_param_append(yylval, "\t"); }
- <STRING>\\[\\"] { phpdbg_param_append(yylval, "\\"); }
- <STRING>\" {
- BEGIN(INITIAL);
- return T_STRING;
+ yylval->str = strndup(yytext, yyleng);
+ yylval->len = yyleng;
+ return T_ID;
}
}
<RAW>{INPUT} {
%token C_SHELL "shell"
%token T_DIGITS "digits (numbers)"
-%token T_STRING "literal (T_LITERAL)"
+%token T_LITERAL "literal (T_LITERAL)"
%token T_METHOD "method (T_METHOD)"
%token T_OPLINE "opline (T_OPLINE)"
%token T_FILE "file (T_FILE)"
| T_METHOD { $$ = $1; }
| T_OPLINE { $$ = $1; }
| T_ID { $$ = $1; }
- | T_STRING { $$ = $1; }
+ | T_LITERAL { $$ = $1; }
| C_TRUTHY { $$ = $1; }
| C_FALSY { $$ = $1; }
;