diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-10-14 21:24:31 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-10-14 21:24:31 -0700 |
commit | 8807a16fe3115e19ce4d65f1c8beb476494ccaec (patch) | |
tree | f61b0adc3c66f76415553c4d114fe784f97c5e70 /parser.y | |
parent | 68e4d78cf9f153871d9a3c07c8ce3e43eb517c3b (diff) | |
download | txr-8807a16fe3115e19ce4d65f1c8beb476494ccaec.tar.gz txr-8807a16fe3115e19ce4d65f1c8beb476494ccaec.tar.bz2 txr-8807a16fe3115e19ce4d65f1c8beb476494ccaec.zip |
More type safety, with help from C++ compiler.
* parser.h (scanner_t): New typedef. Cleverly, we use
yyguts_t as the basis for this, which pays off in
a few places, getting rid of conversions.
(parser_t): scanner member redeclared to scanner_t *.
(yyerror, yyerr, yyerrof, end_of_regex, end_of_char):
Declarations updated.
* parser.l (yyerror, yyerrorf, num_esc): scanner argument becomes
scanner_t * instead of void *.
(yyscanner): Occurrences replaced by yyg: why should we
refer to the type-unsafe void *yyscanner, when we know that
in the middle of the yylex function we have the properly
typed yyguts_t *yyg.
(end_of_regex, end_of_char): Argument changes to scanner_t * and name
strategically changes to yyg, eliminating the local variable and cast.
* parser.y (sym_helper): scanner argument becomes
scanner_t * instead of void *.
(%parse-param}: void *scnr becomes scanner_t *scnr.
(define-transform, yybadtoken): Use scanner_t * instead of void *.
(parse): Since yylex_init takes a void **, we use it to initialize
a local void *, and then assign it to the structure member.
Diffstat (limited to 'parser.y')
-rw-r--r-- | parser.y | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -47,7 +47,7 @@ #include "stream.h" #include "parser.h" -static val sym_helper(void *scnr, wchar_t *lexeme, val meta_allowed); +static val sym_helper(scanner_t *scnr, wchar_t *lexeme, val meta_allowed); static val repeat_rep_helper(val sym, val args, val main, val parts); static val define_transform(parser_t *parser, val define_form); static val lit_char_helper(val litchars); @@ -72,7 +72,7 @@ int yylex(union YYSTYPE *, void *scanner); %} %pure-parser -%parse-param{void *scnr} +%parse-param{scanner_t *scnr} %parse-param{parser_t *parser} %lex-param{void *scnr} @@ -986,7 +986,7 @@ int yylex(YYSTYPE *, void *scanner); val rlcp(val to, val from); #endif -static val sym_helper(void *scnr, wchar_t *lexeme, val meta_allowed) +static val sym_helper(scanner_t *scnr, wchar_t *lexeme, val meta_allowed) { int leading_at = *lexeme == L'@'; wchar_t *tokfree = lexeme; @@ -1081,7 +1081,7 @@ static val repeat_rep_helper(val sym, val args, val main, val parts) static val define_transform(parser_t *parser, val define_form) { - void *scnr = parser->scanner; + scanner_t *scnr = parser->scanner; val sym = first(define_form); val args = second(define_form); @@ -1280,7 +1280,7 @@ static val make_expr(parser_t *parser, val sym, val rest, val lineno) void yybadtoken(parser_t *parser, int tok, val context) { val problem = nil; - void *scnr = parser->scanner; + scanner_t *scnr = parser->scanner; switch (tok) { case ERRTOK: @@ -1354,6 +1354,7 @@ void yybadtoken(parser_t *parser, int tok, val context) int parse(val stream, val name, parser_t *parser) { int res; + void *scanner; parser->lineno = 1; parser->errors = 0; @@ -1361,7 +1362,8 @@ int parse(val stream, val name, parser_t *parser) parser->name = name; parser->prepared_msg = nil; parser->syntax_tree = nil; - yylex_init(&parser->scanner); + yylex_init(&scanner); + parser->scanner = (scanner_t *) scanner; yyset_extra(parser, parser->scanner); |