commit 367139c6d952272cff1f114e7323299478681ffd
parent 457bac94ce770682c140c971a4d1ec1638ca59cc
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 15 Sep 1995 17:48:07 -0300
buffer for literals now grows dynamically, allowing big programs between [[ and ]].
Diffstat:
M | lex.c | | | 47 | ++++++++++++++++++++++++++++++++++++++++------- |
1 file changed, 40 insertions(+), 7 deletions(-)
diff --git 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 <ctype.h>
@@ -7,6 +7,7 @@ char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $";
#include <stdlib.h>
#include <string.h>
+#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):(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: