From bcf46ee83b7a62d571a8fcd93854b32f54d4348e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 6 Jul 1995 14:47:08 -0300 Subject: [PATCH] new syntax for strings: [[ ... ]]. Still in tests, since the code does not check buffer overflow. --- lex.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/lex.c b/lex.c index 7906ed6e..7fd0ee79 100644 --- a/lex.c +++ b/lex.c @@ -1,4 +1,4 @@ -char *rcs_lex = "$Id: lex.c,v 2.13 1994/12/20 21:20:36 roberto Exp celes $"; +char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; #include @@ -21,7 +21,7 @@ char *rcs_lex = "$Id: lex.c,v 2.13 1994/12/20 21:20:36 roberto Exp celes $"; #define save_and_next() { save(current); next(); } static int current; -static char yytext[256]; +static char yytext[3000]; static char *yytextLast; static Input input; @@ -85,6 +85,40 @@ static int findReserved (char *name) } +static int read_long_string (void) +{ + int cont = 0; + while (1) + { + switch (current) + { + case EOF: + case 0: + return WRONGTOKEN; + case '[': + save_and_next(); + if (current == '[') + { + cont++; + save_and_next(); + } + continue; + case ']': + save_and_next(); + if (current == ']') + { + if (cont == 0) return STRING; + cont--; + save_and_next(); + } + continue; + default: + save_and_next(); + } + } +} + + int yylex (void) { float a; @@ -128,6 +162,20 @@ int yylex (void) do { next(); } while (current != '\n' && current != 0); continue; + case '[': + save_and_next(); + if (current != '[') return '['; + else + { + save_and_next(); /* pass the second '[' */ + if (read_long_string() == WRONGTOKEN) + return WRONGTOKEN; + save_and_next(); /* pass the second ']' */ + *(yytextLast-2) = 0; /* erases ']]' */ + yylval.vWord = luaI_findconstant(lua_constcreate(yytext+2)); + return STRING; + } + case '=': save_and_next(); if (current != '=') return '=';