projects
/
henge
/
webcc.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
removed olinks, updated lexer_lex to handle errors
[henge/webcc.git]
/
src
/
apc
/
lexer_lex.rl
diff --git
a/src/apc/lexer_lex.rl
b/src/apc/lexer_lex.rl
index
4c9aeea
..
234e941
100644
(file)
--- a/
src/apc/lexer_lex.rl
+++ b/
src/apc/lexer_lex.rl
@@
-33,6
+33,7
@@
char* ttos(const char* str, int);
action set_val { PUSHTOK(NUM, ttov, val); }
action set_name { PUSHTOK(NAME, ttos, str); }
action set_ts { ts = p; }
action set_val { PUSHTOK(NUM, ttov, val); }
action set_name { PUSHTOK(NAME, ttos, str); }
action set_ts { ts = p; }
+ action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);}
# instantiate machines for each possible token
ref = '0x' xdigit+ %set_ref;
# instantiate machines for each possible token
ref = '0x' xdigit+ %set_ref;
@@
-41,7
+42,7
@@
char* ttos(const char* str, int);
tok = ref | val | name;
segment = (tok . '_') %set_ts;
tok = ref | val | name;
segment = (tok . '_') %set_ts;
-
main := segment* . tok
;
+
main := segment* . tok $lerr(lex_error)
;
}%%
}%%
@@
-55,7
+56,7
@@
int lexer_lex (const char* str)
int cs, tok_t, ntok = 0;
printf ("Lexing: %s\n",str);
p = ts = str;
int cs, tok_t, ntok = 0;
printf ("Lexing: %s\n",str);
p = ts = str;
- pe = p + strlen(str)
+ 1
;
+ pe = p + strlen(str);
%%write init;
%%write exec;
printf ("Lexed %i tokens\n",ntok);
%%write init;
%%write exec;
printf ("Lexed %i tokens\n",ntok);