-
Notifications
You must be signed in to change notification settings - Fork 12
feat: implement custom parser for Inference language #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements a custom parser for the Inference language, featuring resilient error recovery and advance tracking to prevent infinite loops. The parser converts source code into a token stream and validates syntax according to the language grammar, collecting errors for batch reporting.
Changes:
- Added new
inference-parsercrate with lexer, parser, and error handling modules - Implemented advance tracking mechanism to ensure forward progress during parsing
- Created comprehensive test suite covering core language constructs
- Updated type-checker documentation for clarity and consistency
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| core/parser/Cargo.toml | Added parser crate dependencies and test configuration |
| core/parser/src/lib.rs | Public API exports with module organization and usage example |
| core/parser/src/lexer.rs | Lexer implementation for tokenizing Inference language source code |
| core/parser/src/parser.rs | Core parser with resilient error recovery and advance tracking |
| core/parser/src/error.rs | Error types with location tracking and batch error collection |
| core/parser/tests/parser_tests.rs | Integration tests covering major language constructs |
| core/type-checker/src/type_checker.rs | Documentation improvements for type checking phases |
| core/type-checker/src/symbol_table.rs | Documentation clarifications for scope management |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
core/parser/Cargo.toml
Outdated
| inference-ast = { path = "../ast" } | ||
| thiserror = "1.0" | ||
| winnow = "0.7" | ||
| tracing = { version = "0.1", optional = true } | ||
| drop_bomb = "0.1" |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dependencies inference-ast, winnow, and drop_bomb are declared but not used in any of the parser implementation files (lexer.rs, parser.rs, error.rs, lib.rs). These unused dependencies should be removed to reduce build times and avoid confusion.
| inference-ast = { path = "../ast" } | |
| thiserror = "1.0" | |
| winnow = "0.7" | |
| tracing = { version = "0.1", optional = true } | |
| drop_bomb = "0.1" | |
| thiserror = "1.0" | |
| tracing = { version = "0.1", optional = true } |
core/parser/src/parser.rs
Outdated
| #[allow(dead_code)] | ||
| #[inline] | ||
| fn advance_drop(&mut self) { | ||
| self.advance_stack.pop(); | ||
| } | ||
|
|
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advance_drop() method is marked with #[allow(dead_code)] because it's never used. According to the documentation in lib.rs, this method is supposed to be part of the advance tracking mechanism. Either implement its usage or remove it to reduce code complexity.
| #[allow(dead_code)] | |
| #[inline] | |
| fn advance_drop(&mut self) { | |
| self.advance_stack.pop(); | |
| } |
core/parser/tests/parser_tests.rs
Outdated
| match parser.parse_module() { | ||
| Ok(()) | Err(_) => { | ||
| // Accept both success and error for now | ||
| } | ||
| } |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test accepts both success and error outcomes without verification. This doesn't actually test the parser's behavior for variable declarations. Either assert that it succeeds with assert!(parser.parse_module().is_ok()), or assert specific error behavior if variable declarations at module level are invalid.
core/parser/tests/parser_tests.rs
Outdated
| match parser.parse_module() { | ||
| Ok(()) | Err(_) => { | ||
| // Accept both | ||
| } | ||
| } |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test accepts both success and error outcomes without verification. This doesn't effectively test if statement parsing. Either assert that it succeeds with assert!(parser.parse_module().is_ok()), or assert specific error behavior if the syntax is invalid.
core/parser/tests/parser_tests.rs
Outdated
| match parser.parse_module() { | ||
| Ok(()) | Err(_) => { | ||
| // Accept both | ||
| } | ||
| } |
Copilot
AI
Jan 22, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test accepts both success and error outcomes without verification. This doesn't effectively test expression parsing. Either assert that it succeeds with assert!(parser.parse_module().is_ok()), or assert specific error behavior if the syntax is invalid.
- Remove unused dependencies (inference-ast, winnow, drop_bomb) - Add proper assertions to parser tests (variable_declaration, if_statement, simple_expression) - Remove unused advance_drop() method marked with #[allow(dead_code)] Resolves feedback from PR review
|
The parser project scale can be observed here: https://github.com/rust-lang/rust-analyzer/tree/master/crates/parser/src |
Closes #62
Description
Implemented a custom parser for the Inference language with resilient error recovery and advance tracking mechanism. The parser converts source code into a token stream and validates syntax according to the language grammar. It includes comprehensive error handling that allows parsing to continue despite errors, collecting them for batch reporting.
Specific Changes
core/parser/Cargo.toml: Added new parser crate with dependencies
core/parser/src/lib.rs: Public API exports and module organization
core/parser/src/lexer.rs: Full tokenization support for Inference language syntax
core/parser/src/parser.rs: Resilient LL parser with tracking pattern, error recovery, and grammar rules
core/parser/src/error.rs: Error types with location tracking and error collection for batch reporting
core/parser/tests/parser_tests.rs: 10 integration tests covering major language constructs (all passing)
Type
Testing
Added 10 integration tests covering:
All tests pass. Parser compiles without errors.
AI-Generated Code
No AI-generated code in this PR (all were code written from reference implementations and design patterns).
Files Modified
core/parser/Cargo.toml
core/parser/src/lib.rs
core/parser/src/lexer.rs
core/parser/src/parser.rs
core/parser/src/error.rs
core/parser/tests/parser_tests.rs