summaryrefslogtreecommitdiffstats
path: root/parser.l
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-11-15 14:29:34 -0800
committerKaz Kylheku <kaz@kylheku.com>2011-11-15 14:29:34 -0800
commitb6551fda77163f74983688409aaf0c13c8186bec (patch)
tree690b7abd40236f6ef5e168e84a0a4c6eeeb2d2c2 /parser.l
parent9ae8fe9b48cd8e56816225e467f8882c8313d876 (diff)
downloadtxr-b6551fda77163f74983688409aaf0c13c8186bec.tar.gz
txr-b6551fda77163f74983688409aaf0c13c8186bec.tar.bz2
txr-b6551fda77163f74983688409aaf0c13c8186bec.zip
Changing read syntax for character literals, because we are going to
need the single quote in the Lisp way for suppressing evaluation, eventually. I'm going with a Scheme-compatible syntax for character literals. It has a richer repertoire of standard character names than Common Lisp, and has a x convention for coding characters in hex. * lib.c (obj_print): Print characters in a Scheme-like way. * parser.h (end_of_char): New function declared. * parser.l (grammar): Implement rules for #\ syntax, with involving new HASH_BACKSLASH token. (end_of_regex): Enhancement: added check that end_of_regex is called in correct state, like the one in end_of_char. (end_of_char): New function. * parser.y (repeat_rep_helper, o_elems_transform, define_transform, lit_char_helper): Functions changed to static. (rl): Function moved down, past the grammar section. (HASH_BACKSLASH): New terminal symbol. (chrlit): Grammar redesigned. (char_from_name): New function. * txr.1: Character syntax documented.
Diffstat (limited to 'parser.l')
-rw-r--r--parser.l42
1 files changed, 27 insertions, 15 deletions
diff --git a/parser.l b/parser.l
index 1d1e0643..6514a39b 100644
--- a/parser.l
+++ b/parser.l
@@ -386,9 +386,9 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return '"';
}
-<SPECIAL,NESTED>\' {
+<SPECIAL,NESTED>#\\ {
yy_push_state(CHRLIT);
- return '\'';
+ return HASH_BACKSLASH;
}
<SPECIAL,NESTED>` {
@@ -550,29 +550,30 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
return yytext[0];
}
-<CHRLIT>\' {
- yy_pop_state();
- return yytext[0];
- }
-
<QSILIT>` {
yy_pop_state();
return yytext[0];
}
-<STRLIT,CHRLIT,QSILIT>[\\][abtnvfre"`'\\] {
- yylval.chr = char_esc(yytext[1]);
- return LITCHAR;
- }
+<STRLIT,QSILIT>[\\][abtnvfre"`'\\] {
+ yylval.chr = char_esc(yytext[1]);
+ return LITCHAR;
+ }
<STRLIT,QSILIT>{WS}[\\]\n{WS} {
lineno++;
}
-<STRLIT,CHRLIT>[\\](x{HEX}+|{OCT}+) {
- yylval.chr = num_esc(yytext + 1);
- return LITCHAR;
- }
+<CHRLIT>(x{HEX}+|o{OCT}+) {
+ yylval.chr = num_esc(yytext);
+ return LITCHAR;
+ }
+
+<CHRLIT>{SYM} {
+ yylval.lexeme = utf8_dup_from(yytext);
+ return IDENT;
+ }
+
<STRLIT>\n {
yyerrprepf(lit("newline in string literal"), nao);
lineno++;
@@ -615,12 +616,23 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
void end_of_regex(void)
{
+ if (YYSTATE != REGEX)
+ internal_error("end_of_regex called in wrong scanner state");
+
yy_pop_state();
if (yy_top_state() == INITIAL
|| yy_top_state() == QSILIT)
yy_pop_state();
}
+void end_of_char(void)
+{
+ if (YYSTATE != CHRLIT)
+ internal_error("end_of_char called in wrong scanner state");
+
+ yy_pop_state();
+}
+
val source_loc(val form)
{
return gethash(form_to_ln_hash, form);