summaryrefslogtreecommitdiffstats
path: root/parser.l
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-04-21 06:56:23 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-04-21 06:56:23 -0700
commit4e647f4d27827d2918e519cb3f52583d2bbb2a59 (patch)
tree4de914375260f4ccfdecef3ce64ec1de3adef575 /parser.l
parent0ba765092f20424828a520d6ccda1c313dab08f0 (diff)
downloadtxr-4e647f4d27827d2918e519cb3f52583d2bbb2a59.tar.gz
txr-4e647f4d27827d2918e519cb3f52583d2bbb2a59.tar.bz2
txr-4e647f4d27827d2918e519cb3f52583d2bbb2a59.zip
Continuing implementation of buffers.
* Makefile (OBJS): New objects itypes.o and buf.o. * buf.c, buf.h: New files. * itypes.c, itypes.h: New files. * lib.c (obj_print_impl): Handle BUF via buf_print and buf_pprint. (init): Call itypes_init and buf_init. * parser.h (end_of_buflit): Declared. * parser.l (BUFLIT): New exclusive state. (grammar): New rules for recognizing start of buffer literal and its interior. (end_of_buflit): New function. * parser.y (HASH_B_QUOTE): New token. (buflit, buflit_items, buflit_item): New nonterminals and corresponding grammar rules. (i_expr, n_expr): These symbols now generate a buflit; a buffer literal is a kind of expression. (yybadtoken): Handle HASH_B_QUOTE case.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l37
1 files changed, 36 insertions, 1 deletions
diff --git a/parser.l b/parser.l
index 7d6c0284..fef31835 100644
--- a/parser.l
+++ b/parser.l
@@ -239,7 +239,8 @@ UANY {ASC}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
UANYN {ASCN}|{U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
-%x SPECIAL BRACED NESTED REGEX SREGEX STRLIT CHRLIT QSILIT QSPECIAL WLIT QWLIT
+%x SPECIAL BRACED NESTED REGEX SREGEX STRLIT CHRLIT
+%x QSILIT QSPECIAL WLIT QWLIT BUFLIT
%%
@@ -621,6 +622,11 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return HASH_BACKSLASH;
}
+<SPECIAL,QSPECIAL,NESTED,BRACED>#b' {
+ yy_push_state(BUFLIT, yyscanner);
+ return HASH_B_QUOTE;
+}
+
<SPECIAL,QSPECIAL,NESTED,BRACED>#[/] {
yy_push_state(REGEX, yyscanner);
return HASH_SLASH;
@@ -1011,6 +1017,27 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return LITCHAR;
}
+<BUFLIT>{HEX} {
+ yylval->chr = strtol(yytext, 0, 16);
+ return LITCHAR;
+}
+
+<BUFLIT>' {
+ return '\'';
+}
+
+<BUFLIT>{WS} {
+}
+
+<BUFLIT>{NL} {
+ yyextra->lineno++;
+}
+
+<BUFLIT>. {
+ yyerrorf(yyg, lit("bad character in buffer literal: \\~a"),
+ chr(yytext[0]), nao);
+}
+
<STRLIT,CHRLIT,QSILIT,WLIT,QWLIT>. {
yyerrprepf(yyg, lit("non-UTF-8 byte in literal: '\\x~02x'"),
num(convert(unsigned char, yytext[0])), nao);
@@ -1084,6 +1111,14 @@ void end_of_char(scanner_t *yyg)
yy_pop_state(yyg);
}
+void end_of_buflit(scanner_t *yyg)
+{
+ if (YYSTATE != BUFLIT)
+ internal_error("end_of_buflit called in wrong scanner state");
+
+ yy_pop_state(yyg);
+}
+
val source_loc(val form)
{
return gethash(form_to_ln_hash, form);