don't expose lexical error and provide location
This commit is contained in:
@@ -461,7 +461,7 @@ pub enum ParserErrorKind {
|
|||||||
IncompleteReduction,
|
IncompleteReduction,
|
||||||
InfiniteFloat,
|
InfiniteFloat,
|
||||||
InvalidSingleQuotedCharacter(char),
|
InvalidSingleQuotedCharacter(char),
|
||||||
LexicalError(lexical::Error),
|
ParseFloat,
|
||||||
MissingQuote,
|
MissingQuote,
|
||||||
NonPrologChar,
|
NonPrologChar,
|
||||||
ParseBigInt,
|
ParseBigInt,
|
||||||
@@ -492,7 +492,7 @@ impl ParserError {
|
|||||||
atom!("invalid_data")
|
atom!("invalid_data")
|
||||||
}
|
}
|
||||||
ParserErrorKind::IO(_) => atom!("input_output_error"),
|
ParserErrorKind::IO(_) => atom!("input_output_error"),
|
||||||
ParserErrorKind::LexicalError(_) => atom!("lexical_error"),
|
ParserErrorKind::ParseFloat => atom!("parse_float"),
|
||||||
ParserErrorKind::MissingQuote => atom!("missing_quote"),
|
ParserErrorKind::MissingQuote => atom!("missing_quote"),
|
||||||
ParserErrorKind::NonPrologChar => atom!("non_prolog_character"),
|
ParserErrorKind::NonPrologChar => atom!("non_prolog_character"),
|
||||||
ParserErrorKind::ParseBigInt => atom!("cannot_parse_big_int"),
|
ParserErrorKind::ParseBigInt => atom!("cannot_parse_big_int"),
|
||||||
@@ -519,15 +519,6 @@ impl ParserError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<lexical::Error> for ParserError {
|
|
||||||
fn from(e: lexical::Error) -> ParserError {
|
|
||||||
ParserError {
|
|
||||||
location: None,
|
|
||||||
kind: ParserErrorKind::LexicalError(e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<IOError> for ParserError {
|
impl From<IOError> for ParserError {
|
||||||
fn from(e: IOError) -> ParserError {
|
fn from(e: IOError) -> ParserError {
|
||||||
ParserError {
|
ParserError {
|
||||||
|
|||||||
@@ -684,7 +684,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
) -> Result<(F64Offset, OrderedFloat<f64>), ParserError> {
|
) -> Result<(F64Offset, OrderedFloat<f64>), ParserError> {
|
||||||
self.return_char(token.pop().unwrap());
|
self.return_char(token.pop().unwrap());
|
||||||
|
|
||||||
let n = parse_float_lossy(&token)?;
|
let n = self.parse_float_lossy(&token)?;
|
||||||
let offset = float_alloc!(n, self.machine_st.arena);
|
let offset = float_alloc!(n, self.machine_st.arena);
|
||||||
|
|
||||||
Ok((offset, OrderedFloat(n)))
|
Ok((offset, OrderedFloat(n)))
|
||||||
@@ -821,7 +821,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let n = parse_float_lossy(&token)?;
|
let n = self.parse_float_lossy(&token)?;
|
||||||
let offset = float_alloc!(n, self.machine_st.arena);
|
let offset = float_alloc!(n, self.machine_st.arena);
|
||||||
|
|
||||||
Ok(NumberToken::Float(offset, OrderedFloat(n)))
|
Ok(NumberToken::Float(offset, OrderedFloat(n)))
|
||||||
@@ -830,7 +830,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
.map(|(offset, fl)| NumberToken::Float(offset, fl))
|
.map(|(offset, fl)| NumberToken::Float(offset, fl))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let n = parse_float_lossy(&token)?;
|
let n = self.parse_float_lossy(&token)?;
|
||||||
let offset = float_alloc!(n, self.machine_st.arena);
|
let offset = float_alloc!(n, self.machine_st.arena);
|
||||||
Ok(NumberToken::Float(offset, OrderedFloat(n)))
|
Ok(NumberToken::Float(offset, OrderedFloat(n)))
|
||||||
}
|
}
|
||||||
@@ -969,7 +969,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
Ok(NumberToken::Partial(token_string)) => match self.parse_integer(&token_string) {
|
Ok(NumberToken::Partial(token_string)) => match self.parse_integer(&token_string) {
|
||||||
Ok(n) => Ok(Token::Literal(n.to_literal())),
|
Ok(n) => Ok(Token::Literal(n.to_literal())),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
let n = parse_float_lossy(&token_string)?;
|
let n = self.parse_float_lossy(&token_string)?;
|
||||||
let offset = float_alloc!(n, self.machine_st.arena);
|
let offset = float_alloc!(n, self.machine_st.arena);
|
||||||
Ok(Token::Literal(Literal::F64(offset, OrderedFloat(n))))
|
Ok(Token::Literal(Literal::F64(offset, OrderedFloat(n))))
|
||||||
}
|
}
|
||||||
@@ -1083,14 +1083,17 @@ impl<'a, R: CharRead> Lexer<'a, R> {
|
|||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_float_lossy(token: &str) -> Result<f64, ParserError> {
|
fn parse_float_lossy(&self, token: &str) -> Result<f64, ParserError> {
|
||||||
const FORMAT: u128 = lexical::format::STANDARD;
|
const FORMAT: u128 = lexical::format::STANDARD;
|
||||||
let options = lexical::ParseFloatOptions::builder()
|
let Ok(options) = lexical::ParseFloatOptions::builder().lossy(true).build() else {
|
||||||
.lossy(true)
|
return Err(self.located_error(ParserErrorKind::ParseFloat));
|
||||||
.build()
|
};
|
||||||
.unwrap();
|
|
||||||
let n = lexical::parse_with_options::<f64, _, FORMAT>(token.as_bytes(), &options)?;
|
let Ok(n) = lexical::parse_with_options::<f64, _, FORMAT>(token.as_bytes(), &options)
|
||||||
Ok(n)
|
else {
|
||||||
|
return Err(self.located_error(ParserErrorKind::ParseFloat));
|
||||||
|
};
|
||||||
|
Ok(n)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user