diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-06-18 16:40:00 +0300 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-06-19 11:27:32 +0200 |
commit | 112a83c346a537f1a5eac6fc17ee2ce3143d625b (patch) | |
tree | 11ed26fb72a571299eba7e02a225eaf07e527c58 /libbuild2/lexer.hxx | |
parent | 78ac6aee6dff1b608bc312fe7ada442ba83710e8 (diff) |
Fix lexer to fail on invalid UTF-8 sequences
Diffstat (limited to 'libbuild2/lexer.hxx')
-rw-r--r-- | libbuild2/lexer.hxx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libbuild2/lexer.hxx b/libbuild2/lexer.hxx index 6c2b90b..cc42219 100644 --- a/libbuild2/lexer.hxx +++ b/libbuild2/lexer.hxx @@ -187,6 +187,23 @@ namespace build2 pair<pair<char, char>, bool> peek_chars (); + // As base::get() but in case of an invalid character issue diagnostics + // and throw failed. + // + xchar + get (); + + // Get previously peeked character (faster). + // + void + get (const xchar&); + + // As base::peek() but in case of an invalid character issue diagnostics + // and throw failed. + // + xchar + peek (); + protected: struct state { @@ -243,6 +260,9 @@ namespace build2 protected: fail_mark fail; + [[noreturn]] void + fail_char (const xchar&); + // Lexer state. // protected: @@ -266,6 +286,13 @@ namespace build2 std::stack<state> state_; bool sep_; // True if we skipped spaces in peek(). + + private: + using base = char_scanner<butl::utf8_validator, 2>; + + // Buffer for a get()/peek() potential error. + // + string ebuf_; }; } @@ -284,4 +311,6 @@ namespace butl // ADL } } +#include <libbuild2/lexer.ixx> + #endif // LIBBUILD2_LEXER_HXX |