aboutsummaryrefslogtreecommitdiff
path: root/src/lj_lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_lex.c')
-rw-r--r--src/lj_lex.c40
1 files changed, 28 insertions, 12 deletions
diff --git a/src/lj_lex.c b/src/lj_lex.c
index d3544e8e..fde7d9ca 100644
--- a/src/lj_lex.c
+++ b/src/lj_lex.c
@@ -154,7 +154,7 @@ static void read_string(LexState *ls, int delim, TValue *tv)
154 continue; 154 continue;
155 case '\\': { 155 case '\\': {
156 int c; 156 int c;
157 next(ls); /* do not save the `\' */ 157 next(ls); /* Skip the '\\'. */
158 switch (ls->current) { 158 switch (ls->current) {
159 case 'a': c = '\a'; break; 159 case 'a': c = '\a'; break;
160 case 'b': c = '\b'; break; 160 case 'b': c = '\b'; break;
@@ -163,20 +163,36 @@ static void read_string(LexState *ls, int delim, TValue *tv)
163 case 'r': c = '\r'; break; 163 case 'r': c = '\r'; break;
164 case 't': c = '\t'; break; 164 case 't': c = '\t'; break;
165 case 'v': c = '\v'; break; 165 case 'v': c = '\v'; break;
166 case 'x': /* Hexadecimal escape '\xXX'. */
167 c = (next(ls) & 15u) << 4;
168 if (!lj_char_isdigit(ls->current)) {
169 if (!lj_char_isxdigit(ls->current)) goto err_xesc;
170 c += 9 << 4;
171 }
172 c += (next(ls) & 15u);
173 if (!lj_char_isdigit(ls->current)) {
174 if (!lj_char_isxdigit(ls->current)) goto err_xesc;
175 c += 9;
176 }
177 break;
166 case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue; 178 case '\n': case '\r': save(ls, '\n'); inclinenumber(ls); continue;
167 case END_OF_STREAM: continue; /* will raise an error next loop */ 179 case END_OF_STREAM: continue;
168 default: 180 default:
169 if (!lj_char_isdigit(ls->current)) { 181 if (!lj_char_isdigit(ls->current)) {
170 save_and_next(ls); /* handles \\, \", \', and \? */ 182 save_and_next(ls); /* Handles '\\', '\"' and "\'". */
171 } else { /* \xxx */ 183 } else { /* Decimal escape '\ddd'. */
172 int i = 0; 184 c = (ls->current - '0');
173 c = 0; 185 if (lj_char_isdigit(next(ls))) {
174 do { 186 c = c*10 + (ls->current - '0');
175 c = 10*c + (ls->current-'0'); 187 if (lj_char_isdigit(next(ls))) {
176 next(ls); 188 c = c*10 + (ls->current - '0');
177 } while (++i<3 && lj_char_isdigit(ls->current)); 189 if (c > 255) {
178 if (c > 255) 190 err_xesc:
179 lj_lex_error(ls, TK_string, LJ_ERR_XESC); 191 lj_lex_error(ls, TK_string, LJ_ERR_XESC);
192 }
193 next(ls);
194 }
195 }
180 save(ls, c); 196 save(ls, c);
181 } 197 }
182 continue; 198 continue;