summaryrefslogtreecommitdiffstats
path: root/parser.l
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-03-25 06:57:25 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-03-25 06:57:25 -0700
commitc60f5a54deed7064cb8aa32fb91c684ad049d2d3 (patch)
tree7f49a16663477c67910e53aae3475e97613e2274 /parser.l
parent8707c5ecbfc4ceeb1ceb2eb3015ce492bf99636a (diff)
downloadtxr-c60f5a54deed7064cb8aa32fb91c684ad049d2d3.tar.gz
txr-c60f5a54deed7064cb8aa32fb91c684ad049d2d3.tar.bz2
txr-c60f5a54deed7064cb8aa32fb91c684ad049d2d3.zip
Introducing word list literals.
* parser.l (WLIT): New exclusive start state. Extend lexical grammar to transition to WLIT state upon the #" or #*" sequence which kicks off a word literal, and in that state, piecewise lexically analyze the literal, mostly by borrowing rules from other literals. * parser.y (WORDS, WSPLICE): New tokens. (n_exprs): Integrate splicing form of word list literal syntax. (n_expr): Integrate non-splicit for of word list literal syntax. (litchars): Propagate line number info. (wordslit): New grammar rule. * txr.1: Updated.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l35
1 files changed, 27 insertions, 8 deletions
diff --git a/parser.l b/parser.l
index d678100a..3bd3436a 100644
--- a/parser.l
+++ b/parser.l
@@ -190,7 +190,7 @@ 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 STRLIT CHRLIT QSILIT QSPECIAL
+%x SPECIAL BRACED NESTED REGEX STRLIT CHRLIT QSILIT QSPECIAL WLIT
%%
@@ -574,6 +574,16 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return '`';
}
+<SPECIAL,QSPECIAL,NESTED,BRACED>#\" {
+ yy_push_state(WLIT);
+ return WORDS;
+}
+
+<SPECIAL,QSPECIAL,NESTED,BRACED>#\*\" {
+ yy_push_state(WLIT);
+ return WSPLICE;
+}
+
<NESTED,BRACED># {
return '#';
}
@@ -761,7 +771,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
/* comment to end of line */
}
-<STRLIT>\" {
+<STRLIT,WLIT>\" {
yy_pop_state();
return yytext[0];
}
@@ -771,21 +781,21 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return yytext[0];
}
-<STRLIT,QSILIT>[\\][abtnvfre "`'\\ ] {
+<STRLIT,QSILIT,WLIT>[\\][abtnvfre "`'\\ ] {
yylval.chr = char_esc(yytext[1]);
return LITCHAR;
}
-<STRLIT,QSILIT>{WS}[\\]\n{WS} {
+<STRLIT,QSILIT,WLIT>{WS}[\\]\n{WS} {
lineno++;
}
-<STRLIT,QSILIT>[\\](x{HEX}+|{OCT}+);? {
+<STRLIT,QSILIT,WLIT>[\\](x{HEX}+|{OCT}+);? {
yylval.chr = num_esc(yytext+1);
return LITCHAR;
}
-<STRLIT,QSILIT>[\\]. {
+<STRLIT,QSILIT,WLIT>[\\]. {
yyerrorf(lit("unrecognized escape: \\~a"), chr(yytext[1]), nao);
}
@@ -825,18 +835,27 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return ERRTOK;
}
+<WLIT>\n {
+ lineno++;
+ return '\n';
+}
+
<QSILIT>@ {
yy_push_state(QSPECIAL);
}
-<STRLIT,CHRLIT,QSILIT>{UANYN} {
+<WLIT>{WS} {
+ return ' ';
+}
+
+<STRLIT,CHRLIT,QSILIT,WLIT>{UANYN} {
wchar_t buf[8];
utf8_from(buf, yytext);
yylval.chr = buf[0];
return LITCHAR;
}
-<STRLIT,CHRLIT,QSILIT>. {
+<STRLIT,CHRLIT,QSILIT,WLIT>. {
yyerrprepf(lit("non-UTF-8 byte in literal: '\\x~02x'"),
num((unsigned char) yytext[0]), nao);
return ERRTOK;