From 80023f287c52876b82af43027dd4605ab939d006 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 12 Aug 2015 20:35:04 -0700 Subject: Use new pushback token priming for single regex parse. * parser.h (enum prime_parser): New enum. (prime_parser, prime_scanner, parse): Declarations updated with new argument. * parser.c (prime_parser): New argument of enum prime_parser type Select appropriate secret token for regex and Lisp case. Pass prime selector down to prime_scanner. (regex_parse): Do not prepend secret escape to string. Do not use parse_once function; instead do the parser init and cleanup here and use the parse function. (lisp_parse): Pass new argument to parse, configuring the parser to be primed for Lisp parsing. * parser.l (grammar): Rule producing SECRET_ESCAPE_R removed. (prime_scanner): New argument. Pop the scanner state down to INITIAL. Then unconditionally switch to appopriate state based on priming configuration. * parser.y (parse): New argument for priming selection, passed down to prime parser. --- parser.l | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'parser.l') diff --git a/parser.l b/parser.l index 92bad198..2610a921 100644 --- a/parser.l +++ b/parser.l @@ -858,11 +858,6 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U} yy_push_state(SPECIAL, yyscanner); } -@\x01R { - yy_push_state(REGEX, yyscanner); - return SECRET_ESCAPE_R; -} - ^@[#;].*\n { /* eat whole line comment */ yyextra->lineno++; @@ -1043,12 +1038,20 @@ int yylex(YYSTYPE *yylval_param, yyscan_t yyscanner) return yy_char; } -void prime_scanner(scanner_t *yyg) +void prime_scanner(scanner_t *yyg, enum prime_parser prim) { - if (YYSTATE == INITIAL) { + while (YYSTATE != INITIAL) + yy_pop_state(yyg); + + switch (prim) { + case prime_lisp: yy_push_state(SPECIAL, yyg); yy_push_state(NESTED, yyg); yy_push_state(NESTED, yyg); + break; + case prime_regex: + yy_push_state(REGEX, yyg); + break; } } -- cgit v1.2.3