summaryrefslogtreecommitdiff
path: root/mesonbuild/mparser.py
AgeCommit message (Collapse)Author
2025-12-08interpreterbase: make ArithmeticNode and MesonOperator both use operator namesPaolo Bonzini
This avoids creating a dictionary every time an arithmetic operator is evaluated. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08mparser: move dictionaries to toplevelPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08mparser: tweak typing of accept_any, use it for comparisons.Paolo Bonzini
Tuples are inefficient, require the ability to use hash table lookup via either a frozenset or a dictionary. This also allows using accept_any with COMPARISON_MAP.
2025-12-08mparser: make comparison_map global uppercsaePaolo Bonzini
2025-12-08mparser: use a literal for arithmetic operatorsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08make ctype the same as the printed ASTPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08mparser: lexer: check early against common tokensPaolo Bonzini
Identifiers are more common than strings, check against 'id' first. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08mparser: lexer: reduce regular expression usagePaolo Bonzini
Match single-character tokens a separate dictionary lookup. As pointed out by dcbaker, this is even faster than str.index and gives the syntax error check for free (via KeyError). It also enables splitting the special-case "if" in two parts, one for long tokens and one for short tokens, thus providing further speedup. This shaves about 2/3rds of the time spent in lex(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-09-24format: Fix indentation with parenthesesCharles Brunet
- Split long expressions in () according to max line length - Partly revert d028502 . Fixes #14935. - Fixes #15032.
2025-05-29rewriter: Rewrite how we add/remove source filesVolker Weißmann
Change the semantics of IntrospectionBuildTarget.source_nodes and IntrospectionBuildTarget.extra_files . The rewriter and the static introspection tool used to be very broken, now it is *less* broken, hence we add some tests in this commit. Fixes #11763
2025-05-29parser: Fix colno after multiline stringsVolker Weißmann
Without this commit, meson thinks that the `var` token in the code below starts at a different column number than it actually starts, because the old author forgot to account for the length of the triple quotes. ``` ''' some multiline strings abc''' + var ```
2025-05-29parser: Simplify precedence levelsVolker Weißmann
The parser should behave exactly as before, but the code is a bit easier to understand now.
2025-05-05parser: update position when reporting lexer errors for unrecognized tokenEli Schwartz
By default we point to the start of the most recent token we parsed. This is used when erroring out on parser issues, to print the line that caused the error, with a pointer to where we were when we got the error. In this particular case, the pointer pointed to the start of the last token we successfully parsed (col), but was not updated if we hit a token we didn't understand at all. Instead use a pointer to the unrecognized token itself. Fixes: https://github.com/mesonbuild/meson/issues/14415
2025-05-05more explicit error message for unrecognized lexer tokenCharles Brunet
Fixes #14415
2025-03-08Fix typos in commentsco63oc
2025-01-08optimize variable assignmentsPaolo Bonzini
Except for set_variable(), the variable name is certainly an identifier because it comes from the parser; thus, the check is unnecessary. Move the regular expression match to func_set_variable(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-09-06mformat: better handling of continuation linesCharles Brunet
Fixes #13566. Fixes #13567.
2024-08-30update various deprecation notices to call out meson 2.0Eli Schwartz
2024-08-20format: fix indentation of commentsCharles Brunet
Fixes #13508 - Fix indentation of comments in arrays - Fix indentation of comments in dicts - Fix indentation of comments in if clauses - Fix indentation of comments in foreach clauses
2024-06-26format: fix edge case with empty functionsCharles Brunet
format was adding a new empty line each time when trying to split a long line containing a function with no arguments
2024-04-08meson format commandCharles Brunet
2024-04-08parser: revert to single StringNode typeCharles Brunet
this will allow transforming string types in the formater
2024-04-08fix colon wrongly named column in parserCharles Brunet
In #02ff955, I used the word `columns` instead of `colons`, but the meaning really was about the ':' symbol.
2024-02-23Detect utf8 bom from meson build filesCharles Brunet
Some text editors on Windows may use utf8bom encoding by default. Prevent crash and properly report misencoded files. Fixes #12766.
2024-02-12Remove implicit-optional assignment in `__init__` that cannot ever be trueEli Schwartz
IfClauseNode is only ever initialized in such a way that this attribute is immediately set to something valid. And attempting to access its value when the value is None would be a pretty broken error anyway. The assignment served no purpose, but did perform a frivolous runtime op in addition to angering mypy's checks for implicit None.
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-09-11parser: allow whitespaces and comments in cont_eolCharles Brunet
FIXME: another approach would be to consider cont_eol as comment (i.e. add backslash and whitespaces to the comment regex). In both cases it works until we want to parse comments separately. TODO?: handle eol_cont inside a string (to split long string without breaking lines). Probably a bad idea and better to simply join a multiline string.
2023-09-11parser: preserve whitespaces and commentsCharles Brunet
2023-09-11parser: simplify other node constructorsCharles Brunet
2023-09-11parser: simplify by using Unary and Binary Operator NodeCharles Brunet
2023-09-11parser: simplify Assignment and PlusAssignment nodesCharles Brunet
2023-09-11parser: add SymbolNode to preserve operatorsCharles Brunet
2023-09-11parser: add ElseNodeCharles Brunet
2023-09-11parser: remember previous TokenCharles Brunet
2023-09-11parser: preserve value of all tokensCharles Brunet
2023-09-11parser: use IdNode for foreach varnamesCharles Brunet
2023-09-11parser: use IdNode for function name and assignment nameCharles Brunet
2023-09-11parser: preserve escape chars in stringsCharles Brunet
use separate Node for multiline strings
2023-09-11parser: remove useless __str__ methods on nodesCharles Brunet
2023-09-11parser: preserve number baseCharles Brunet
2023-09-11parser: more specific error for float numbersCharles Brunet
2023-09-11Add ParenthesizedNodeJCWasmx86
2023-08-11treewide: automatic rewriting of all comment-style type annotationsEli Schwartz
Performed using https://github.com/ilevkivskyi/com2ann This has no actual effect on the codebase as type checkers (still) support both and negligible effect on runtime performance since __future__ annotations ameliorates that. Technically, the bytecode would be bigger for non function-local annotations, of which we have many either way. So if it doesn't really matter, why do a large-scale refactor? Simple: because people keep wanting to, but it's getting nickle-and-dimed. If we're going to do this we might as well do it consistently in one shot, using tooling that guarantees repeatability and correctness. Repeat with: ``` com2ann mesonbuild/ ```
2023-08-11remove useless type annotationsEli Schwartz
These annotations all had a default initializer of the correct type, or a parent class annotation.
2023-06-01mparser: Further cleanup node definitionsXavier Claessens
- Include BaseNode position in hash methods, integer is the most straightforward way of differentiating nodes. - Exclude non hashable fields from hash method. - Avoid using default values in BaseNode that way subclasses can have fields wihtout default value without repeating init=False. - Nodes that does not add fields does not need `@dataclass`. - Make all node types hashable because they can be used for feature_key in FeatureCheckBase.use(). - Remove unused type annotations
2023-06-01mparser: add equality operators to nodesDylan Baker
This makes use of dataclasses, but without a dataclass generated initializer. This means that we get nice `__repr__` and `__eq__` methods without having to type them by hand. Pylance understands `dataclass(init=False)`, but mypy doesn't. https://github.com/microsoft/pyright/issues/1753 https://github.com/python/mypy/issues/10309
2023-03-01mparser: Add partial AST to exceptionsEli Schwartz
Surprisingly enough we need to do this twice. In some cases (failing-meson/72 triggers this) we can error out after parsing the codeblock, but without getting the expected eof. We need to catch both exceptions as either one can interrupt the built codeblock object. Co-authored-by: Xavier Claessens <xavier.claessens@collabora.com>
2023-03-01mparser: use an inherited ParseException everywhereEli Schwartz
2023-03-01Revert "Exit meson with an error if an invalid escape sequence is found in a"Eli Schwartz
This reverts commit 348248f0a19bdc80e8a184befb2faaa1d5e66f40. The rules were relaxed in commit ccc4ce28cc9077d77a0bc9e72b1177eba1be7186 to permit this, so it's never possible to raise this exception anymore. But that commit was incomplete, and didn't remove the now-useless infrastructure for exception handling. The test needed to test this was always broken, and then removed in commit 465ef856ac9b978f13414db4aff649c66f2e6be5, and still this useless try/except persisted.
2023-03-01interpreter: Add testcase..endtestcase clause supportXavier Claessens
This is currently only enabled when running unit tests to facilitate writing failing unit tests. Fixes: #11394