Problem
Currently, pest parsing errors are displayed directly to users, which can be cryptic and unhelpful. For example:
ParseError { variant: Expected(keyword), positives: [keyword], negatives: [] }
This tells the user almost nothing about what went wrong or how to fix it.
Current State
ParseError struct in core/parse_result.rs captures pest errors
error_codes.rs defines error code constants (P001-P007) but they are not used for parser errors
- The LSP displays
parse_error.variant directly as the message (see syntax/sysml/parser.rs:63)
Proposed Solution
1. Error Code Integration
Map pest error patterns to our defined error codes:
P001 (PARSER_SYNTAX_ERROR) - General syntax errors
P002 (PARSER_UNEXPECTED_TOKEN) - When pest reports unexpected input
P003 (PARSER_EXPECTED_TOKEN) - When pest reports expected tokens
P006 (PARSER_UNTERMINATED) - Unterminated strings/comments
2. Human-Readable Error Messages
Create a PestErrorTranslator that:
- Analyzes pest positives and negatives lists
- Maps grammar rule names to user-friendly terms
- Provides context-aware suggestions based on error location
3. Example Transformations
| Pest Error |
Current Display |
Improved Display |
| Expected([keyword]) |
Expected(keyword) |
P003: Expected a keyword |
| Expected([identifier]) |
Expected(identifier) |
P003: Expected an identifier |
| Expected([;]) |
Expected(;) |
P003: Missing semicolon at end of statement |
4. Contextual Help
For common errors, provide hints:
- Missing semicolon: Did you forget a semicolon at the end?
- Unmatched brace: Check for missing closing brace
- Reserved word as identifier: keyword cannot be used as a name
5. Implementation Plan
- Phase 1: Create parser/error_translator.rs module
- Phase 2: Integrate with ParseError (add code and hint fields)
- Phase 3: Context-aware improvements
Related
- Error codes defined in core/error_codes.rs
- Current parsing: syntax/sysml/parser.rs, syntax/kerml/parser.rs
- LSP diagnostics: syster-lsp/src/server/diagnostics.rs
Problem
Currently, pest parsing errors are displayed directly to users, which can be cryptic and unhelpful. For example:
This tells the user almost nothing about what went wrong or how to fix it.
Current State
ParseErrorstruct incore/parse_result.rscaptures pest errorserror_codes.rsdefines error code constants (P001-P007) but they are not used for parser errorsparse_error.variantdirectly as the message (seesyntax/sysml/parser.rs:63)Proposed Solution
1. Error Code Integration
Map pest error patterns to our defined error codes:
P001(PARSER_SYNTAX_ERROR) - General syntax errorsP002(PARSER_UNEXPECTED_TOKEN) - When pest reports unexpected inputP003(PARSER_EXPECTED_TOKEN) - When pest reports expected tokensP006(PARSER_UNTERMINATED) - Unterminated strings/comments2. Human-Readable Error Messages
Create a
PestErrorTranslatorthat:3. Example Transformations
4. Contextual Help
For common errors, provide hints:
5. Implementation Plan
Related