Improve interface parser diagnostics - #190
Open
dellaert wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves wrapper interface (.i) parser diagnostics by introducing a structured InterfaceParseError, capturing the most relevant nested pyparsing failures during backtracking, and surfacing clean, source-located errors (including semantic validations) through the CLI wrappers.
Changes:
- Add
InterfaceParseErrorplus a diagnostics collector to preserve the deepest credible parser failure and render source excerpts/carets. - Thread
source_namethrough parsing entrypoints and wrapper scripts, and print parse errors without Python tracebacks (exit status 1). - Replace constructor/operator parse-time assertions with located semantic errors and add comprehensive diagnostic regression tests.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_parser_diagnostics.py | Adds regression tests validating structured, source-aware syntax/semantic diagnostics and clean CLI stderr. |
| scripts/pybind_wrap.py | Catches InterfaceParseError, prints clean diagnostic to stderr, and exits with status 1 (no traceback). |
| scripts/matlab_wrap.py | Catches InterfaceParseError and exits with status 1 after printing the diagnostic. |
| gtwrap/pybind_wrapper.py | Plumbs source_name into parsing so diagnostics report the correct filename. |
| gtwrap/matlab_wrapper/wrapper.py | Plumbs a composed source_name into parsing for single/multi-file wraps. |
| gtwrap/interface_parser/module.py | Wraps pyparsing failures into InterfaceParseError using the diagnostic context. |
| gtwrap/interface_parser/function.py | Improves argument-name failure messaging by naming the IDENT subexpression. |
| gtwrap/interface_parser/enum.py | Improves enumerator-name failure messaging by naming the IDENT subexpression. |
| gtwrap/interface_parser/diagnostics.py | New diagnostic machinery (failure tracking, best-failure selection, source rendering, semantic errors). |
| gtwrap/interface_parser/classes.py | Converts constructor/operator semantic checks into located semantic_error exceptions. |
| gtwrap/interface_parser/init.py | Exports InterfaceParseError and registers tracked rules for better backtracked-failure selection. |
Comments suppressed due to low confidence (2)
gtwrap/interface_parser/diagnostics.py:274
ParserElement's scanning API is typically exposed asscanString(...)(camelCase). Using.scan_string(...)here risks an AttributeError at runtime, and should be aligned with the canonical pyparsing method name (and the updatedcppStyleComment/quotedStringidentifiers).
(cpp_style_comment | quoted_string).scan_string(source))
gtwrap/interface_parser/diagnostics.py:196
ParserElementis used with camelCase APIs throughout this repo (setParseAction,enablePackrat, etc.). Usingset_fail_actionhere may rely on a non-standard alias and can fail at import/runtime if it is unavailable. Prefer the canonical pyparsing API namesetFailActionfor compatibility.
rule.set_fail_action(record_failure)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InterfaceParseErrorwith source filename, line, column, source excerpt, caret, parser context, and optional hintsZeroOrMoreorOptionalbacktracking.isource names through the existing wrapper entrypoints and print clean command-line diagnostics without Python tracebacksRoot cause
The shared
.igrammar uses repeated and optional expressions. When a declaration partially matched and then failed, pyparsing backtracked out of the declaration. The remaining outer rule usually reportedExpected string_endorExpected '}'at the start of the enclosing class or namespace, discarding the useful nested failure.Tested examples
Missing argument name
Missing method semicolon
Malformed template argument list
Additional regression cases
public:,private:, orprotected:labels in wrapper class declarationspython -O)Validation
conda run -n py312 python -m pytest tests— 110 passedgit diff --check