diff options
author | Oleksandr Koval <oleksandr.koval.dev@gmail.com> | 2020-09-09 12:49:35 (GMT) |
---|---|---|
committer | Oleksandr Koval <oleksandr.koval.dev@gmail.com> | 2020-09-09 12:49:35 (GMT) |
commit | 62d7acc6d4f2e4563b5a71d6e5c90352bf732c79 (patch) | |
tree | 8da5b452aeb392d31f817a4b1655f671d7534d26 /Source/LexerParser | |
parent | 9a0a5f84208f652d3ce84e141adf7e9b304574cb (diff) | |
download | CMake-62d7acc6d4f2e4563b5a71d6e5c90352bf732c79.zip CMake-62d7acc6d4f2e4563b5a71d6e5c90352bf732c79.tar.gz CMake-62d7acc6d4f2e4563b5a71d6e5c90352bf732c79.tar.bz2 |
cmCommandArgumentParserHelper: rework input handling
Old implementation uses involved Flex input management technique that
requires usage of obsolete YY_INPUT macro. This causes a lot of useless
allocations and byte-by-byte scanning. New implementation avoids those
hacks, it uses yy_scan_string() API to setup Flex input. Also it fixes
reporting of syntax error position and corresponding tests.
Diffstat (limited to 'Source/LexerParser')
-rw-r--r-- | Source/LexerParser/cmCommandArgumentLexer.cxx | 22 | ||||
-rw-r--r-- | Source/LexerParser/cmCommandArgumentLexer.in.l | 7 |
2 files changed, 10 insertions, 19 deletions
diff --git a/Source/LexerParser/cmCommandArgumentLexer.cxx b/Source/LexerParser/cmCommandArgumentLexer.cxx index 5879912..46220ff 100644 --- a/Source/LexerParser/cmCommandArgumentLexer.cxx +++ b/Source/LexerParser/cmCommandArgumentLexer.cxx @@ -653,7 +653,7 @@ This file must be translated to C++ and modified to build everywhere. Run flex >= 2.6 like this: - flex --nounistd -DFLEXINT_H --noline --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l + flex --nounistd --never-interactive --batch -DFLEXINT_H --noline --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l Modify cmCommandArgumentLexer.cxx: - remove trailing whitespace: sed -i 's/\s*$//' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx @@ -668,10 +668,7 @@ Modify cmCommandArgumentLexer.cxx: #include "cmCommandArgumentParserHelper.h" -/* Replace the lexer input function. */ -#undef YY_INPUT -#define YY_INPUT(buf, result, max_size) \ - do { result = yyextra->LexInput(buf, max_size); } while (0) +#define YY_USER_ACTION yyextra->UpdateInputPosition(yyleng); /* Include the set of tokens from the parser. */ #include "cmCommandArgumentParserTokens.h" @@ -967,16 +964,12 @@ yy_match: yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 41 ); + while ( yy_current_state != 29 ); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; yy_find_action: yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = yyg->yy_last_accepting_cpos; - yy_current_state = yyg->yy_last_accepting_state; - yy_act = yy_accept[yy_current_state]; - } YY_DO_BEFORE_ACTION; @@ -1173,7 +1166,8 @@ case YY_STATE_EOF(NOESCAPES): else { - yy_cp = yyg->yy_c_buf_p; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; } } @@ -1661,7 +1655,7 @@ static void yy_load_buffer_state (yyscan_t yyscanner) b->yy_bs_column = 0; } - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + b->yy_is_interactive = 0; errno = oerrno; } diff --git a/Source/LexerParser/cmCommandArgumentLexer.in.l b/Source/LexerParser/cmCommandArgumentLexer.in.l index 010d54b..8ad2335 100644 --- a/Source/LexerParser/cmCommandArgumentLexer.in.l +++ b/Source/LexerParser/cmCommandArgumentLexer.in.l @@ -7,7 +7,7 @@ This file must be translated to C++ and modified to build everywhere. Run flex >= 2.6 like this: - flex --nounistd -DFLEXINT_H --noline --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l + flex --nounistd --never-interactive --batch -DFLEXINT_H --noline --header-file=cmCommandArgumentLexer.h -ocmCommandArgumentLexer.cxx cmCommandArgumentLexer.in.l Modify cmCommandArgumentLexer.cxx: - remove trailing whitespace: sed -i 's/\s*$//' cmCommandArgumentLexer.h cmCommandArgumentLexer.cxx @@ -22,10 +22,7 @@ Modify cmCommandArgumentLexer.cxx: #include "cmCommandArgumentParserHelper.h" -/* Replace the lexer input function. */ -#undef YY_INPUT -#define YY_INPUT(buf, result, max_size) \ - do { result = yyextra->LexInput(buf, max_size); } while (0) +#define YY_USER_ACTION yyextra->UpdateInputPosition(yyleng); /* Include the set of tokens from the parser. */ #include "cmCommandArgumentParserTokens.h" |