mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-10-12 06:08:57 +03:00
error messages and test regen
This commit is contained in:
parent
7f21855312
commit
c0b0e28ee2
@ -16,7 +16,7 @@
|
||||
|
||||
use crate::create_errors;
|
||||
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
create_errors!(
|
||||
/// ParserError enum that represents all the errors for the `leo-parser` crate.
|
||||
@ -228,55 +228,47 @@ create_errors!(
|
||||
@backtraced
|
||||
lexer_empty_input_tendril {
|
||||
args: (),
|
||||
msg: "",
|
||||
msg: "Expected more characters to lex but found none.",
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When an integer is started with a leading zero.
|
||||
@backtraced
|
||||
lexer_eat_integer_leading_zero {
|
||||
args: (),
|
||||
msg: "",
|
||||
args: (input: impl Display),
|
||||
msg: format!("Tried to eat integer but found a leading zero on {}.", input),
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When an integer is started with a leading zero.
|
||||
@backtraced
|
||||
lexer_expected_valid_escaped_char {
|
||||
args: (),
|
||||
msg: "",
|
||||
args: (input: impl Display),
|
||||
msg: format!("Expected a valid escape character but found {}.", input),
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When a string is not properly closed.
|
||||
@backtraced
|
||||
lexer_string_not_closed {
|
||||
args: (),
|
||||
msg: "",
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When an illegal escaped character is provided.
|
||||
@backtraced
|
||||
lexer_invalid_escaped_char {
|
||||
args: (),
|
||||
msg: "",
|
||||
args: (input: impl Display),
|
||||
msg: format!("Expected a closed string but found {}.", input),
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When a string is not properly closed.
|
||||
@backtraced
|
||||
lexer_char_not_closed {
|
||||
args: (),
|
||||
msg: "",
|
||||
args: (input: impl Display),
|
||||
msg: format!("Expected a closed char but found {}.", input),
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When a string is not properly closed.
|
||||
@backtraced
|
||||
lexer_invalid_char {
|
||||
args: (),
|
||||
msg: "",
|
||||
args: (input: impl Display),
|
||||
msg: format!("Expected valid character but found {}.", input),
|
||||
help: None,
|
||||
}
|
||||
|
||||
@ -284,23 +276,23 @@ create_errors!(
|
||||
@backtraced
|
||||
lexer_empty_block_comment {
|
||||
args: (),
|
||||
msg: "",
|
||||
msg: "Empty block comment.",
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When a block comment is not closed before end of file.
|
||||
@backtraced
|
||||
lexer_block_comment_does_not_close_before_eof {
|
||||
args: (),
|
||||
msg: "",
|
||||
args: (input: impl Display),
|
||||
msg: format!("Block comment does not close with content: {}.", input),
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// When the lexer could not lex some text.
|
||||
@backtraced
|
||||
could_not_lex {
|
||||
args: (),
|
||||
msg: "",
|
||||
args: (input: impl Display),
|
||||
msg: format!("Could not lex the following content: {}.", input),
|
||||
help: None,
|
||||
}
|
||||
);
|
||||
|
@ -154,7 +154,7 @@ impl Token {
|
||||
}
|
||||
let input = input_tendril[..].as_bytes();
|
||||
if !input[0].is_ascii_digit() {
|
||||
return Err(ParserError::lexer_eat_integer_leading_zero().into());
|
||||
return Err(ParserError::lexer_eat_integer_leading_zero(String::from_utf8_lossy(input)).into());
|
||||
}
|
||||
let mut i = 1;
|
||||
let mut is_hex = false;
|
||||
@ -271,7 +271,7 @@ impl Token {
|
||||
unicode = false;
|
||||
string.push(character.into());
|
||||
}
|
||||
None => return Err(ParserError::lexer_expected_valid_escaped_char().into()),
|
||||
None => return Err(ParserError::lexer_expected_valid_escaped_char(input_tendril.subtendril(start as u32, len as u32)).into()),
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,7 +283,7 @@ impl Token {
|
||||
}
|
||||
|
||||
if i == input.len() || !end {
|
||||
return Err(ParserError::lexer_string_not_closed().into());
|
||||
return Err(ParserError::lexer_string_not_closed(String::from_utf8_lossy(&input[0..i])).into());
|
||||
}
|
||||
|
||||
return Ok((i + 1, Token::StringLit(string)));
|
||||
@ -311,7 +311,7 @@ impl Token {
|
||||
if input[i + 1] == b'{' {
|
||||
unicode = true;
|
||||
} else {
|
||||
return Err(ParserError::lexer_invalid_escaped_char().into());
|
||||
return Err(ParserError::lexer_expected_valid_escaped_char(input[i]).into());
|
||||
}
|
||||
} else {
|
||||
escaped = true;
|
||||
@ -324,12 +324,12 @@ impl Token {
|
||||
}
|
||||
|
||||
if !end {
|
||||
return Err(ParserError::lexer_string_not_closed().into());
|
||||
return Err(ParserError::lexer_char_not_closed(String::from_utf8_lossy(&input[0..i])).into());
|
||||
}
|
||||
|
||||
return match Self::eat_char(input_tendril.subtendril(1, (i - 1) as u32), escaped, hex, unicode) {
|
||||
Some(character) => Ok((i + 1, Token::CharLit(character))),
|
||||
None => Err(ParserError::lexer_invalid_char().into()),
|
||||
None => Err(ParserError::lexer_invalid_char(String::from_utf8_lossy(&input[0..i-1])).into()),
|
||||
};
|
||||
}
|
||||
x if x.is_ascii_digit() => {
|
||||
@ -400,7 +400,7 @@ impl Token {
|
||||
let len = if let Some(eol) = eol {
|
||||
eol + 4
|
||||
} else {
|
||||
return Err(ParserError::lexer_block_comment_does_not_close_before_eof().into());
|
||||
return Err(ParserError::lexer_block_comment_does_not_close_before_eof(String::from_utf8_lossy(&input[0..])).into());
|
||||
};
|
||||
return Ok((len, Token::CommentBlock(input_tendril.subtendril(0, len as u32))));
|
||||
} else if let Some(len) = eat(input, "/=") {
|
||||
@ -491,7 +491,7 @@ impl Token {
|
||||
));
|
||||
}
|
||||
|
||||
Err(ParserError::could_not_lex().into())
|
||||
Err(ParserError::could_not_lex(String::from_utf8_lossy(&input[0..])).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,7 +214,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let mut output = String::new();
|
||||
for SpannedToken { token, .. } in tokens.iter() {
|
||||
output += &format!("{} ", token.to_string());
|
||||
output += &format!("{} ", token);
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
|
@ -2,38 +2,38 @@
|
||||
namespace: Token
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370027]: "
|
||||
- "Error [EPAR0370027]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370028]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370028]: "
|
||||
- "Error [EPAR0370028]: "
|
||||
- "Error [EPAR0370028]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370028]: "
|
||||
- "Error [EPAR0370028]: "
|
||||
- "Error [EPAR0370028]: "
|
||||
- "Error [EPAR0370030]: "
|
||||
- "Error [EPAR0370028]: Expected a closed char but found '\\'."
|
||||
- "Error [EPAR0370028]: Expected a closed char but found 'a."
|
||||
- "Error [EPAR0370029]: Expected valid character but found ."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\x9."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\x."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\x7."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\x."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\x8."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\xc."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\xc."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\xD."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\xC."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\xe."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\x9."
|
||||
- "Error [EPAR0370029]: Expected valid character but found 'abcdef."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\t\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found 117."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\u{bbbbb}\\u{aaaa."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found 117."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found 117."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found 117."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\u{2764."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '\\u{276g."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found 117."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found 117."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found 117."
|
||||
- "Error [EPAR0370029]: Expected valid character but found '😭😂<F09F98AD>."
|
||||
|
@ -2,10 +2,10 @@
|
||||
namespace: Token
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [EPAR0370027]: "
|
||||
- "Error [EPAR0370027]: "
|
||||
- "Error [EPAR0370026]: "
|
||||
- "Error [EPAR0370027]: "
|
||||
- "Error [EPAR0370027]: "
|
||||
- "Error [EPAR0370026]: "
|
||||
- "Error [EPAR0370027]: "
|
||||
- "Error [EPAR0370027]: Expected a closed string but found \"Hello world!."
|
||||
- "Error [EPAR0370027]: Expected a closed string but found \"\\\"."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found \\l."
|
||||
- "Error [EPAR0370027]: Expected a closed string but found \"\\uaaa\"."
|
||||
- "Error [EPAR0370027]: Expected a closed string but found \"\\u\"."
|
||||
- "Error [EPAR0370026]: Expected a valid escape character but found \\xFF."
|
||||
- "Error [EPAR0370027]: Expected a closed string but found \"\\x\"."
|
||||
|
Loading…
Reference in New Issue
Block a user