summaryrefslogtreecommitdiffstats
path: root/parser.l
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2009-11-21 11:12:20 -0800
committerKaz Kylheku <kaz@kylheku.com>2009-11-21 11:12:20 -0800
commit4a1556a848c5bfb527cecb2b823a750ba63e6f80 (patch)
treebe9378666222056692e4770a8f0eb79b45ef8993 /parser.l
parent00f823aee439ed8c2cdd71dfbb89385dc68eae7b (diff)
downloadtxr-4a1556a848c5bfb527cecb2b823a750ba63e6f80.tar.gz
txr-4a1556a848c5bfb527cecb2b823a750ba63e6f80.tar.bz2
txr-4a1556a848c5bfb527cecb2b823a750ba63e6f80.zip
Introducing symbol packages. Internal symbols are now in
a system package instead of being hacked with the $ prefix. Keyword symbols are provided. In the matcher, evaluation is tightened up. Keywords, nil and t are not bindeable, and errors are thrown if attempts are made to bind them. Destructuring in dest_bind is strict in the number of items. String streams are exploited to print bindings to objects that are not strings or characters. Numerous bugfixes.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l15
1 files changed, 11 insertions, 4 deletions
diff --git a/parser.l b/parser.l
index 9fd779f5..564f9730 100644
--- a/parser.l
+++ b/parser.l
@@ -91,6 +91,7 @@ void yybadtoken(int tok, const char *context)
switch (tok) {
case TEXT: problem = lit("text"); break;
case IDENT: problem = lit("identifier"); break;
+ case KEYWORD: problem = lit("keyword"); break;
case ALL: problem = lit("\"all\""); break;
case SOME: problem = lit("\"some\""); break;
case NONE: problem = lit("\"none\""); break;
@@ -166,7 +167,7 @@ static wchar_t num_esc(char *num)
%option stack
-TOK [a-zA-Z_][a-zA-Z0-9_]*|[+-]?[0-9]+
+TOK :?[a-zA-Z_][a-zA-Z0-9_]*|[+-]?[0-9]+
ID_END [^a-zA-Z0-9_]
NUM_END [^0-9]
WS [\t ]*
@@ -192,14 +193,20 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
long val;
char *errp;
- errno = 0;
-
- val = strtol(yytext, &errp, 10);
if (yy_top_state() == INITIAL
|| yy_top_state() == QSILIT)
yy_pop_state();
+ if (yytext[0] == ':') {
+ yylval.lexeme = utf8_dup_from(yytext + 1);
+ return KEYWORD;
+ }
+
+ errno = 0;
+
+ val = strtol(yytext, &errp, 10);
+
if (*errp != 0) {
/* not a number */
yylval.lexeme = utf8_dup_from(yytext);