From 18f3abb6e662b5a3d6ec2c13992f87b3f690cae5 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 17 Oct 2025 10:44:25 +0200 Subject: mparser: lexer: check early against common tokens Identifiers are more common than strings, check against 'id' first. Signed-off-by: Paolo Bonzini --- mesonbuild/mparser.py | 16 ++++++++-------- 1 file 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) -- cgit v1.2.3