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.
This commit is contained in:
Oleksandr Koval
2020-09-09 15:49:35 +03:00
parent 9a0a5f8420
commit 62d7acc6d4
20 changed files with 50 additions and 62 deletions
+6 -5
View File
@@ -25,7 +25,7 @@ public:
cmCommandArgumentParserHelper& operator=(
cmCommandArgumentParserHelper const&) = delete;
int ParseString(const char* str, int verb);
int ParseString(std::string const& str, int verb);
// For the lexer:
void AllocateParserType(cmCommandArgumentParserHelper::ParserType* pt,
@@ -33,7 +33,6 @@ public:
bool HandleEscapeSymbol(cmCommandArgumentParserHelper::ParserType* pt,
char symbol);
int LexInput(char* buf, int maxlen);
void Error(const char* str);
// For yacc
@@ -46,6 +45,8 @@ public:
void SetMakefile(const cmMakefile* mf);
void UpdateInputPosition(int tokenLength);
std::string& GetResult() { return this->Result; }
void SetLineFile(long line, const char* file);
@@ -57,8 +58,9 @@ public:
const char* GetError() { return this->ErrorString.c_str(); }
private:
std::string::size_type InputBufferPos;
std::string InputBuffer;
std::string::size_type InputBufferPos{ 1 };
std::string::size_type LastTokenLength{};
std::string::size_type InputSize{};
std::vector<char> OutputBuffer;
void Print(const char* place, const char* str);
@@ -75,7 +77,6 @@ private:
std::string ErrorString;
const char* FileName;
long FileLine;
int CurrentLine;
int Verbose;
bool EscapeQuotes;
bool NoEscapeMode;