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/cmCommandArgumentParserHelper.cxx | |
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/cmCommandArgumentParserHelper.cxx')
-rw-r--r-- | Source/cmCommandArgumentParserHelper.cxx | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index e07f7f1..e3d014e 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -205,23 +205,24 @@ bool cmCommandArgumentParserHelper::HandleEscapeSymbol( void cmCommandArgument_SetupEscapes(yyscan_t yyscanner, bool noEscapes); -int cmCommandArgumentParserHelper::ParseString(const char* str, int verb) +int cmCommandArgumentParserHelper::ParseString(std::string const& str, + int verb) { - if (!str) { + if (str.empty()) { return 0; } + this->InputSize = str.size(); this->Verbose = verb; - this->InputBuffer = str; - this->InputBufferPos = 0; - this->CurrentLine = 0; this->Result.clear(); yyscan_t yyscanner; cmCommandArgument_yylex_init(&yyscanner); + auto scanBuf = cmCommandArgument_yy_scan_string(str.c_str(), yyscanner); cmCommandArgument_yyset_extra(this, yyscanner); cmCommandArgument_SetupEscapes(yyscanner, this->NoEscapeMode); int res = cmCommandArgument_yyparse(yyscanner); + cmCommandArgument_yy_delete_buffer(scanBuf, yyscanner); cmCommandArgument_yylex_destroy(yyscanner); if (res != 0) { return 0; @@ -241,25 +242,14 @@ void cmCommandArgumentParserHelper::CleanupParser() this->Variables.clear(); } -int cmCommandArgumentParserHelper::LexInput(char* buf, int maxlen) +void cmCommandArgumentParserHelper::Error(const char* str) { - if (maxlen < 1) { - return 0; + auto pos = this->InputBufferPos; + auto const isEof = (this->InputSize < this->InputBufferPos); + if (!isEof) { + pos -= this->LastTokenLength; } - if (this->InputBufferPos < this->InputBuffer.size()) { - buf[0] = this->InputBuffer[this->InputBufferPos++]; - if (buf[0] == '\n') { - this->CurrentLine++; - } - return (1); - } - buf[0] = '\n'; - return (0); -} -void cmCommandArgumentParserHelper::Error(const char* str) -{ - unsigned long pos = static_cast<unsigned long>(this->InputBufferPos); std::ostringstream ostr; ostr << str << " (" << pos << ")"; this->SetError(ostr.str()); @@ -286,3 +276,9 @@ void cmCommandArgumentParserHelper::SetError(std::string const& msg) this->ErrorString = msg; } } + +void cmCommandArgumentParserHelper::UpdateInputPosition(int const tokenLength) +{ + this->InputBufferPos += tokenLength; + this->LastTokenLength = tokenLength; +} |