From 367139c6d952272cff1f114e7323299478681ffd Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 15 Sep 1995 17:48:26 -0300 Subject: buffer for literals now grows dynamically, allowing big programs between [[ and ]]. --- lex.c | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/lex.c b/lex.c index 7fd0ee79..9a1d3635 100644 --- a/lex.c +++ b/lex.c @@ -1,4 +1,4 @@ -char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; +char *rcs_lex = "$Id: lex.c,v 2.15 1995/07/06 17:47:08 roberto Exp roberto $"; #include @@ -7,6 +7,7 @@ char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; #include #include +#include "mem.h" #include "tree.h" #include "table.h" #include "opcode.h" @@ -14,6 +15,8 @@ char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; #include "parser.h" #include "ugly.h" +#define MINBUFF 260 + #define lua_strcmp(a,b) (a[0]b[0]?(1):strcmp(a,b))) #define next() { current = input(); } @@ -21,7 +24,8 @@ char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; #define save_and_next() { save(current); next(); } static int current; -static char yytext[3000]; +static char *yytext = NULL; +static int textsize = 0; static char *yytextLast; static Input input; @@ -30,6 +34,11 @@ void lua_setinput (Input fn) { current = ' '; input = fn; + if (yytext == NULL) + { + textsize = MINBUFF; + yytext = newvector(textsize, char); + } } char *lua_lasttext (void) @@ -85,35 +94,52 @@ static int findReserved (char *name) } +static void growtext (void) +{ + int size = yytextLast - yytext; + textsize *= 2; + yytext = growvector(yytext, textsize, char); + yytextLast = yytext + size; +} + + static int read_long_string (void) { int cont = 0; + int spaceleft = textsize - (yytextLast - yytext); while (1) { + if (spaceleft <= 2) /* may read more than 1 char in one cicle */ + { + growtext(); + spaceleft = textsize - (yytextLast - yytext); + } switch (current) { case EOF: case 0: return WRONGTOKEN; case '[': - save_and_next(); + save_and_next(); spaceleft--; if (current == '[') { cont++; - save_and_next(); + save_and_next(); spaceleft--; } continue; case ']': - save_and_next(); + save_and_next(); spaceleft--; if (current == ']') { if (cont == 0) return STRING; cont--; - save_and_next(); + save_and_next(); spaceleft--; } continue; + case '\n': + lua_linenumber++; /* goes through */ default: - save_and_next(); + save_and_next(); spaceleft--; } } } @@ -200,9 +226,16 @@ int yylex (void) case '\'': { int del = current; + int spaceleft = textsize - (yytextLast - yytext); next(); /* skip the delimiter */ while (current != del) { + if (spaceleft <= 2) /* may read more than 1 char in one cicle */ + { + growtext(); + spaceleft = textsize - (yytextLast - yytext); + } + spaceleft--; switch (current) { case EOF: -- cgit v1.2.3-55-g6feb