Improve parser diagnostics for missing ':' in equation units#1798
Improve parser diagnostics for missing ':' in equation units#1798bluemoon-o2 wants to merge 2 commits intobrian-team:masterfrom
Conversation
Improve parse errors for model equation strings by generating more specific diagnostics when unit separators are missing.\n\n- recover non-degraded line-level parse errors from ZeroOrMore fallthroughs\n- add explicit hint for missing ':' before unit declarations\n- reduce fragile string matching by using ParseException parser metadata\n- avoid false positives for dt typos and malformed RHS expressions\n- add regression tests for missing-colon hints and non-hint error paths\n\nRefs brian-team#1461
|
For context, this PR overlaps with #1787 on improving missing-unit diagnostics, but intentionally keeps a narrower scope. Compared to #1787, this PR focuses on a minimal fix path for #1461:
It does not include broader parser refactors or new equation metadata/features. If preferred, I can follow up with separate PRs for additional diagnostics after this lands. |
|
Hi @bluemoon-o2. Could you please use the pre-commit tool to fix the formatting of the file (as described here: https://brian2.readthedocs.io/en/stable/developer/guidelines/style.html#code-style) so that our linter is happy and the test suite can run? Thanks! |
|
Thanks for the reminder! I ran pre-commit on all files and pushed the formatting fix in commit a2d6a41. I also re-ran the relevant tests (...............s [100%] -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html |
Summary
Improve equation parse diagnostics for model descriptions that miss
:before unit declarations.What Changed
parse_string_equationsto provide clearer line-level diagnostics.ZeroOrMore(EQUATION)yields a degraded top-level error, re-parse the relevant line withEQUATIONto recover specific expectations.Equation syntax error: expected ':' before unit declaration.dv/dt = -v / tau : 1).ParseException.parser_elementmetadata instead of relying on raw exception strings.Edge-Case Handling
dv/d = ...still reportsExpected 'dt').:hints for malformed RHS expression cases (e.g.x = ().tau second).Tests
Added
test_parse_error_messagescoverage for::in equation definitions.:in multiline/comment inputs.dttypo should not be masked by missing-unit hints.:in parameter declarations.... foobaz) should still surface missing-unit hint.Validation run:
pytest -q brian2/tests/test_equations.py15 passed, 1 skippedRefs #1461