You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've noticed an incorrect span for error when compiler looks something like this:
fnident<'a>(ident_name:String) -> ... {any().try_map(move |token:Token, span| {let word = token.to_string();letmut chars = word.chars();let first_char = chars.next().unwrap();if !first_char.is_ascii_alphabetic() && first_char != '_'{returnErr(Rich::custom(
span,"identifier must start with a letter or an underscore",));}for char in chars {if !char.is_ascii_alphanumeric() && char != '_'{returnErr(Rich::custom(
span,"identifier must contain only alphanumeric characters or underscores",));}}ifKEYWORDS.contains(&word.as_str()){returnErr(Rich::custom(
span,format!("keyword used as {ident_name} name"),));}Ok(word)})}let int = any().try_map(|token:Token,span:SimpleSpan| {let word = token.to_string();for char in word.chars(){if !char.is_ascii_digit(){returnErr(Rich::custom(span,"int must contain only digits"));}}Ok(word)});let number = int
.then(just(T!['.']).ignore_then(int).or_not()).map(|(int, float)| {let float = float.unwrap_or('0'.to_string());format!("{}.{}", int, float)}).from_str::<f32>().unwrapped().map_with(|num, e| (Expression::Number((num, e.span())), e.span())).boxed();let parser = number
.then(just(T!["as"]).ignore_then(ident("type".to_string()).map_with(|txt, e| (txt, e.span())).recover_with(via_parser(any().or(end().map(|_| T![""])).map_with(|_, e| ("ERROR".to_string(), e.span())),)),).boxed(),).map_with(|(exp, ty), e| (Expression::Cast(Box::new(exp), ty), e.span())).boxed();let spanned_tokens = tokens.spanned(SimpleSpan::new(eoi, eoi));
parser.parse(spanned_tokens)
Parsing results in:
output: Some((
Cast(
(Number((2.0, 0..1)), 0..1),
("ERROR", 0..4),
), 0..4))
errors: "found end of input at 0..4 expected something else"
Error has a span of 0..4 but It should have 4..4
The text was updated successfully, but these errors were encountered:
I'm using my own lexer that returns vector of spanned tokens like this:
For input like this:
I've noticed an incorrect span for error when compiler looks something like this:
Parsing results in:
Error has a span of
0..4
but It should have 4..4The text was updated successfully, but these errors were encountered: