Skip to content

Commit 3a79d86

Browse files
committed
Make more fields public
1 parent b12b7e9 commit 3a79d86

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

src/dynval.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ pub type Result<T> = std::result::Result<T, ConversionError>;
88
#[derive(Debug, thiserror::Error)]
99
#[error("Failed to turn {value} into a {target_type}")]
1010
pub struct ConversionError {
11-
value: DynVal,
12-
target_type: &'static str,
13-
source: Option<Box<dyn std::error::Error>>,
11+
pub value: DynVal,
12+
pub target_type: &'static str,
13+
pub source: Option<Box<dyn std::error::Error>>,
1414
}
1515

1616
impl ConversionError {

src/error.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
use crate::{ast::Span, dynval, parser::lexer};
1+
use crate::{
2+
ast::Span,
3+
dynval,
4+
parser::lexer::{self, LexicalError},
5+
};
26
use codespan_reporting::diagnostic;
37

48
pub type Result<T> = std::result::Result<T, Error>;
@@ -25,6 +29,10 @@ impl Error {
2529
Error::ParseError { source: err }
2630
}
2731

32+
pub fn at(self, span: Span) -> Self {
33+
Self::Spanned(span, Box::new(self))
34+
}
35+
2836
pub fn get_span(&self) -> Option<Span> {
2937
match self {
3038
Self::ParseError { source } => get_parse_error_span(source),
@@ -68,7 +76,7 @@ fn get_parse_error_span(err: &lalrpop_util::ParseError<usize, lexer::Token, lexe
6876
lalrpop_util::ParseError::UnrecognizedEOF { location, expected: _ } => Some(Span(*location, *location)),
6977
lalrpop_util::ParseError::UnrecognizedToken { token, expected: _ } => Some(Span(token.0, token.2)),
7078
lalrpop_util::ParseError::ExtraToken { token } => Some(Span(token.0, token.2)),
71-
lalrpop_util::ParseError::User { error: _ } => None,
79+
lalrpop_util::ParseError::User { error: LexicalError(l, r) } => Some(Span(*l, *r)),
7280
}
7381
}
7482

src/parser/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum Token {
4444
}
4545

4646
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
47-
pub struct LexicalError(usize, usize);
47+
pub struct LexicalError(pub usize, pub usize);
4848

4949
impl std::fmt::Display for LexicalError {
5050
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {

src/simplexpr_parser.lalrpop

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::ast::{SimplExpr::{self, *}, Span, BinOp::*, UnaryOp::*};
22
use crate::parser::lexer::{Token, LexicalError};
33
use crate::parser::lalrpop_helpers::*;
4+
use lalrpop_util::ParseError;
45

56

67
grammar;
@@ -42,6 +43,8 @@ extern {
4243
"number" => Token::NumLit(<String>),
4344
"string" => Token::StrLit(<String>),
4445

46+
"lexer_error" => Token::Error,
47+
4548
}
4649
}
4750

@@ -56,7 +59,12 @@ Comma<T>: Vec<T> = {
5659
};
5760

5861
pub Expr: SimplExpr = {
62+
5963
#[precedence(level="0")]
64+
<l:@L> "lexer_error" <r:@R> =>? {
65+
Err(ParseError::User { error: LexicalError(l, r) })
66+
},
67+
6068
<Literal>,
6169
<l:@L> <ident:"identifier"> <r:@R> => VarRef(Span(l, r), ident.to_string()),
6270
"(" <ExprReset> ")",

0 commit comments

Comments
 (0)