-
Notifications
You must be signed in to change notification settings - Fork 13
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
Open
ALIPHATICHYD
wants to merge
5
commits into
Inferara:main
Choose a base branch
from
ALIPHATICHYD:62-feature-custom-parser
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ffcd57c
This PR adds inline documentation for complex logic in the type-check…
ALIPHATICHYD 78294e4
feat: implement custom parser for Inference language
ALIPHATICHYD 30b061d
fix: address review comments on parser implementation
ALIPHATICHYD 7426029
WIP: Simplify parser grammar modules and add public API methods
ALIPHATICHYD 6df4c10
Refactor parser: Complete parser implementation with grammar modules
ALIPHATICHYD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| [package] | ||
| name = "inference-parser" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| license = "Apache-2.0 OR MIT" | ||
| description = "Custom parser for the Inference language with resilient error recovery" | ||
|
|
||
| [dependencies] | ||
| inference-ast = { path = "../ast" } | ||
| thiserror = "1.0" | ||
| winnow = "0.7" | ||
| tracing = { version = "0.1", optional = true } | ||
| drop_bomb = "0.1" | ||
|
|
||
| [dev-dependencies] | ||
| expect-test = "1.4" | ||
|
|
||
| [features] | ||
| default = [] | ||
| tracing = ["dep:tracing"] | ||
|
|
||
| [[test]] | ||
| name = "parser_tests" | ||
| path = "tests/parser_tests.rs" | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| use std::fmt; | ||
| use thiserror::Error; | ||
|
|
||
| /// Parser error types with location information | ||
| #[derive(Debug, Clone, Error)] | ||
| pub enum ParseError { | ||
| #[error("Unexpected token at position {pos}: expected {expected}, found {found}")] | ||
| UnexpectedToken { | ||
| pos: usize, | ||
| expected: String, | ||
| found: String, | ||
| }, | ||
|
|
||
| #[error("Unexpected end of file while parsing {context}")] | ||
| UnexpectedEof { context: String }, | ||
|
|
||
| #[error("Invalid syntax at position {pos}: {reason}")] | ||
| InvalidSyntax { pos: usize, reason: String }, | ||
|
|
||
| #[error("Failed to parse {context} at position {pos}")] | ||
| FailedToParse { pos: usize, context: String }, | ||
|
|
||
| #[error("Duplicate definition: {name}")] | ||
| DuplicateName { name: String }, | ||
|
|
||
| #[error("Invalid type annotation: {reason}")] | ||
| InvalidTypeAnnotation { reason: String }, | ||
|
|
||
| #[error("Invalid generic parameters: {reason}")] | ||
| InvalidGenerics { reason: String }, | ||
| } | ||
|
|
||
| /// Error recovery mode allows the parser to continue after errors | ||
| #[derive(Debug, Clone)] | ||
| pub struct ParseErrorWithRecovery { | ||
| pub error: ParseError, | ||
| pub recovered: bool, | ||
| } | ||
|
|
||
| impl fmt::Display for ParseErrorWithRecovery { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| if self.recovered { | ||
| write!(f, "{} (recovered)", self.error) | ||
| } else { | ||
| write!(f, "{}", self.error) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Collects multiple errors during parsing for batch reporting | ||
| #[derive(Debug, Default, Clone)] | ||
| pub struct ParseErrorCollector { | ||
| errors: Vec<ParseError>, | ||
| } | ||
|
|
||
| impl ParseErrorCollector { | ||
| pub fn new() -> Self { | ||
| Self { errors: Vec::new() } | ||
| } | ||
|
|
||
| pub fn add_error(&mut self, error: ParseError) { | ||
| self.errors.push(error); | ||
| } | ||
|
|
||
| pub fn has_errors(&self) -> bool { | ||
| !self.errors.is_empty() | ||
| } | ||
|
|
||
| pub fn errors(&self) -> &[ParseError] { | ||
| &self.errors | ||
| } | ||
|
|
||
| pub fn take_errors(self) -> Vec<ParseError> { | ||
| self.errors | ||
| } | ||
| } |
Oops, something went wrong.
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.
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, anddrop_bombare 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.