-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c434e61
commit 1339b55
Showing
9 changed files
with
131 additions
and
115 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,88 @@ | ||
use thiserror::Error as ThisError; | ||
use origlang_source_span::{Pointed, SourcePosition as SourcePos, SourcePosition}; | ||
use std::fmt::{Display, Formatter}; | ||
use derive_more::Display; | ||
use std::num::ParseIntError; | ||
use crate::lexer::error::LexerError; | ||
use crate::lexer::token::Token; | ||
use crate::parser::TokenKind; | ||
use crate::parser::recover::{IntermediateStateCandidate, PartiallyParseFixCandidate}; | ||
|
||
#[derive(ThisError, Debug, Eq, PartialEq)] | ||
pub struct ParserError(Pointed<ParserErrorInner>); | ||
|
||
impl Display for ParserError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.write_fmt(format_args!("{} ({})", &self.0.data, &self.0.position)) | ||
} | ||
} | ||
|
||
impl ParserError { | ||
pub fn new(kind: ParserErrorInner, position: SourcePos) -> Self { | ||
Self(Pointed { | ||
data: kind, | ||
position | ||
}) | ||
} | ||
|
||
pub fn kind(&self) -> &ParserErrorInner { | ||
&self.0.data | ||
} | ||
|
||
pub fn position(&self) -> &SourcePosition { | ||
&self.0.position | ||
} | ||
} | ||
|
||
#[derive(ThisError, Debug, Eq, PartialEq)] | ||
#[allow(clippy::module_name_repetitions)] | ||
pub enum ParserErrorInner { | ||
#[error("lexer error: {_0}")] | ||
LexerError(#[from] LexerError), | ||
#[error("unconsumed token found: {token:?}")] | ||
UnconsumedToken { | ||
token: Token | ||
}, | ||
#[error("statement must be terminated by a newline")] | ||
StatementTerminationError, | ||
#[error("EOF Error")] | ||
EndOfFileError, | ||
#[error("Expected {pat}, but got {unmatch:?}")] | ||
UnexpectedToken { | ||
pat: TokenKind, | ||
unmatch: Token, | ||
}, | ||
#[error("Incomplete program snippet. Check hint for fix candidates. hint:{hint:?} state:{intermediate_state:?}")] | ||
PartiallyParsed { | ||
hint: Vec<PartiallyParseFixCandidate>, | ||
intermediate_state: Vec<IntermediateStateCandidate>, | ||
}, | ||
#[error("input sequence cannot be parsed as a int literal: {error}")] | ||
UnParsableIntLiteral { | ||
error: ParseIntError | ||
}, | ||
#[error("int literal type of {tp} must be in range ({min}..={max}), but its value is {value}")] | ||
OverflowedLiteral { | ||
tp: Box<str>, | ||
min: i64, | ||
max: i64, | ||
value: i64, | ||
}, | ||
#[error("if expression requires `else` clause")] | ||
IfExpressionWithoutElseClause, | ||
#[error("if expression requires `then` clause and `else` clause")] | ||
IfExpressionWithoutThenClauseAndElseClause, | ||
#[error("tuple literal requires 2 or more elements, but got {_0}")] | ||
InsufficientElementsForTupleLiteral(UnexpectedTupleLiteralElementCount), | ||
#[error("`_` cannot used as right hand side expression")] | ||
UnderscoreCanNotBeRightHandExpression, | ||
} | ||
|
||
#[repr(u8)] | ||
#[derive(Eq, PartialEq, Copy, Clone, Debug, Display)] | ||
pub enum UnexpectedTupleLiteralElementCount { | ||
#[display(fmt = "no elements")] | ||
Zero = 0, | ||
#[display(fmt = "only one element")] | ||
One = 1, | ||
} |
This file contains 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,22 @@ | ||
use derive_more::Display; | ||
use origlang_ast::after_parse::Expression; | ||
use crate::lexer::token::Token; | ||
|
||
#[derive(Debug, Eq, PartialEq, Clone)] | ||
pub enum IntermediateStateCandidate { | ||
Expression(Expression), | ||
} | ||
|
||
#[derive(Display, Debug, Eq, PartialEq, Clone)] | ||
pub enum PartiallyParseFixCandidate { | ||
#[display(fmt = "No fixes available")] | ||
None, | ||
#[display(fmt = "Insert before")] | ||
InsertBefore { | ||
tokens: Vec<Token>, | ||
}, | ||
#[display(fmt = "Insert after")] | ||
InsertAfter { | ||
tokens: Vec<Token>, | ||
}, | ||
} |
This file contains 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
This file contains 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