diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-10-17 10:44:25 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-12-08 10:08:10 -0800 |
| commit | 18f3abb6e662b5a3d6ec2c13992f87b3f690cae5 (patch) | |
| tree | b6212bffb08d6f7a8696b93e7efe0359b8e05c24 | |
| parent | 4ef1866dba127a9c12f4c475d3bbb6aaac97a243 (diff) | |
| download | meson-18f3abb6e662b5a3d6ec2c13992f87b3f690cae5.tar.gz | |
mparser: lexer: check early against common tokens
Identifiers are more common than strings, check against 'id'
first.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | mesonbuild/mparser.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py index 5a9494606..b9bc22213 100644 --- a/mesonbuild/mparser.py +++ b/mesonbuild/mparser.py @@ -201,7 +201,14 @@ class Lexer: if par_count > 0 or bracket_count > 0 or curl_count > 0: tid = 'whitespace' - if tid in {'string', 'fstring'}: + if tid == 'id': + if value in self.keywords: + tid = value + else: + if value in self.future_keywords: + mlog.warning(f"Identifier '{value}' will become a reserved keyword in a future release. Please rename it.", + location=BaseNode(lineno, col, filename)) + elif tid in {'string', 'fstring'}: if value.find("\n") != -1: msg = ("Newline character in a string detected, use ''' (three single quotes) " "for multiline strings instead.\n" @@ -218,13 +225,6 @@ class Lexer: lineno += 1 line_start = loc tid = 'whitespace' - elif tid == 'id': - if value in self.keywords: - tid = value - else: - if value in self.future_keywords: - mlog.warning(f"Identifier '{value}' will become a reserved keyword in a future release. Please rename it.", - location=BaseNode(lineno, col, filename)) bytespan = (span_start, loc) yield Token(tid, filename, curline_start, curline, col, bytespan, value) |
