diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-08-02 18:31:31 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-08-02 18:31:31 -0700 |
commit | 894c655f0214531ad7eff3d68d72792ae18d40cd (patch) | |
tree | c7da31229ce40626fa937de8e688ac645ace2309 /parser.h | |
parent | 73a7ae605d364be49dc5bd1cc15c1116fe47a446 (diff) | |
download | txr-894c655f0214531ad7eff3d68d72792ae18d40cd.tar.gz txr-894c655f0214531ad7eff3d68d72792ae18d40cd.tar.bz2 txr-894c655f0214531ad7eff3d68d72792ae18d40cd.zip |
Big switch to reentrant lexing and parsing.
* parser.l (YY_INPUT): Stop relying on removed yyin_stream;
refer to stream via yyextra.
(yyin_stream, lineno, errors, spec_file_str,
prepared_error_message): Global variables removed.
(yyget_column, yyset_column): Missing prototypes not generated by flex
in bison bridge mode have to be added by us to avoid
warning.
(yyerror): Takes parser and scanner as parameters. Prepared error
message is now in the parser context. Calls to other error handling
functions receive scanner context.
(yyerr): New function.
(yyerrorf, yyerrprepf): Takes scanner argument, chases extra data to
get to parser, and refers to parser variables instead of globals.
(num_esc): Scanner argument added.
(%option reentrant, %option bison-bridge, %option extra-type): New
flex options.
(grammar): yyscanner added everywhere.
(end_of_char): Takes scanner argument.
(parse_init): Removed references to yyin_stream and
prepared_error_message.
(parse_reset): Function renamed to open_txr_file. Returns
results via pointers instead of setting global variables.
(regex_parse, lisp_parse): Use reentrant parser interface.
* parser.y (yyerror): Prototype removed.
(yylex): Prototype moved after grammar, with new arguments.
(sym_helper, define_transform): Take scanner argument.
(make_expr): Takes parser argument.
(rlrec): New static function.
(rl): Function turned into macro.
(mkexp, symhlpr): New macros.
(%purse-parser, %parse-param, %lex-param): New Yacc options.
(grammar): Actions re-worked for reentrance. Parser and scanner
contexts are passed down to helper functions, in some cases
via the three new macros. The result of the parse is stored
in the syntax_tree member of the parser_t structure instead
of a global. The yylex function receives the scanner instance.
(get_spec): Function removed.
(parse): New function.
* parser.h (lineno, errors, yyin_stream, spec_file_str):
Declarations removed.
(parser_t): New struct.
(yyerr): New function declared.
(yyparse, yyerror, yyerrorf, end_of_regex, end_of_char,
yylex, yylex_destroy): Declarations updated.
Diffstat (limited to 'parser.h')
-rw-r--r-- | parser.h | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -24,26 +24,34 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -extern cnum lineno; -extern int errors; -extern val yyin_stream; +typedef struct { + cnum lineno; + int errors; + val stream; + val name; + val prepared_msg; + val syntax_tree; + void *scanner; +} parser_t; + extern const wchar_t *spec_file; -extern val spec_file_str; extern val form_to_ln_hash; -int yyparse(void); -val get_spec(void); -void yyerror(const char *s); -void yyerrorf(val s, ...); +int yyparse(parser_t *, void *scanner); +void yyerror(parser_t *, void *scanner, const char *s); +void yyerr(void *scanner, const char *s); +void yyerrorf(void *scanner, val s, ...); void yybadtoken(int tok, val context); -void end_of_regex(void); -void end_of_char(void); -int yylex(void); -int yylex_destroy(void); +void end_of_regex(void *scanner); +void end_of_char(void *scanner); +int yylex_init(void **pscanner); +int yylex_destroy(void *scanner); +parser_t *yyget_extra(void *scanner); +void yyset_extra(parser_t *, void *scanner); void parse_init(void); -void parse_reset(val spec_file); +void open_txr_file(val spec_file, val *name, val *stream); +int parse(val stream, val name, parser_t *parser); val source_loc(val form); val source_loc_str(val form); -val rl(val form, val lineno); val rlset(val form, val info); INLINE val rlcp(val to, val from) { |