diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-07-06 14:47:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-07-06 14:47:08 -0300 |
commit | bcf46ee83b7a62d571a8fcd93854b32f54d4348e (patch) | |
tree | c92177a540e3681b37990fe7e31877faa0e689b5 /lex.c | |
parent | 97b2fd1ba1685137dd1933a9e7e70fdc010760d3 (diff) | |
download | lua-bcf46ee83b7a62d571a8fcd93854b32f54d4348e.tar.gz lua-bcf46ee83b7a62d571a8fcd93854b32f54d4348e.tar.bz2 lua-bcf46ee83b7a62d571a8fcd93854b32f54d4348e.zip |
new syntax for strings: [[ ... ]]. Still in tests,
since the code does not check buffer overflow.
Diffstat (limited to 'lex.c')
-rw-r--r-- | lex.c | 52 |
1 files changed, 50 insertions, 2 deletions
@@ -1,4 +1,4 @@ | |||
1 | char *rcs_lex = "$Id: lex.c,v 2.13 1994/12/20 21:20:36 roberto Exp celes $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.14 1994/12/27 20:50:38 celes Exp $"; |
2 | 2 | ||
3 | 3 | ||
4 | #include <ctype.h> | 4 | #include <ctype.h> |
@@ -21,7 +21,7 @@ char *rcs_lex = "$Id: lex.c,v 2.13 1994/12/20 21:20:36 roberto Exp celes $"; | |||
21 | #define save_and_next() { save(current); next(); } | 21 | #define save_and_next() { save(current); next(); } |
22 | 22 | ||
23 | static int current; | 23 | static int current; |
24 | static char yytext[256]; | 24 | static char yytext[3000]; |
25 | static char *yytextLast; | 25 | static char *yytextLast; |
26 | 26 | ||
27 | static Input input; | 27 | static Input input; |
@@ -85,6 +85,40 @@ static int findReserved (char *name) | |||
85 | } | 85 | } |
86 | 86 | ||
87 | 87 | ||
88 | static int read_long_string (void) | ||
89 | { | ||
90 | int cont = 0; | ||
91 | while (1) | ||
92 | { | ||
93 | switch (current) | ||
94 | { | ||
95 | case EOF: | ||
96 | case 0: | ||
97 | return WRONGTOKEN; | ||
98 | case '[': | ||
99 | save_and_next(); | ||
100 | if (current == '[') | ||
101 | { | ||
102 | cont++; | ||
103 | save_and_next(); | ||
104 | } | ||
105 | continue; | ||
106 | case ']': | ||
107 | save_and_next(); | ||
108 | if (current == ']') | ||
109 | { | ||
110 | if (cont == 0) return STRING; | ||
111 | cont--; | ||
112 | save_and_next(); | ||
113 | } | ||
114 | continue; | ||
115 | default: | ||
116 | save_and_next(); | ||
117 | } | ||
118 | } | ||
119 | } | ||
120 | |||
121 | |||
88 | int yylex (void) | 122 | int yylex (void) |
89 | { | 123 | { |
90 | float a; | 124 | float a; |
@@ -128,6 +162,20 @@ int yylex (void) | |||
128 | do { next(); } while (current != '\n' && current != 0); | 162 | do { next(); } while (current != '\n' && current != 0); |
129 | continue; | 163 | continue; |
130 | 164 | ||
165 | case '[': | ||
166 | save_and_next(); | ||
167 | if (current != '[') return '['; | ||
168 | else | ||
169 | { | ||
170 | save_and_next(); /* pass the second '[' */ | ||
171 | if (read_long_string() == WRONGTOKEN) | ||
172 | return WRONGTOKEN; | ||
173 | save_and_next(); /* pass the second ']' */ | ||
174 | *(yytextLast-2) = 0; /* erases ']]' */ | ||
175 | yylval.vWord = luaI_findconstant(lua_constcreate(yytext+2)); | ||
176 | return STRING; | ||
177 | } | ||
178 | |||
131 | case '=': | 179 | case '=': |
132 | save_and_next(); | 180 | save_and_next(); |
133 | if (current != '=') return '='; | 181 | if (current != '=') return '='; |