Work on error messages
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
7f7bf5c98d
commit
42698bb219
13 changed files with 333 additions and 160 deletions
|
|
@ -7,11 +7,13 @@ fn check_files() {
|
|||
for file in files {
|
||||
let input = std::fs::read_to_string(file.unwrap().path()).unwrap();
|
||||
|
||||
let Ok(parsed) = nomo::lexer::parse(input.into()) else {
|
||||
let input = nomo::input::NomoInput::from(input);
|
||||
|
||||
let Ok(parsed) = nomo::lexer::parse(input.clone()) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
let Ok(ast) = nomo::parser::parse(parsed.tokens()) else {
|
||||
let Ok(ast) = nomo::parser::parse(input, parsed.tokens()) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
source: tests/file_tests.rs
|
||||
expression: parsed
|
||||
info:
|
||||
input: "{{ if }} {{ end }}\n{{ if if }} {{ end }}\n{{ if if }} {{ for foo in bar }} {{ end }} {{ end }}\n{{ for in bar }} {{ end }}\n{{ for blah bar }} {{ end }}\n{{ else }}"
|
||||
input: "{{ if }} {{ end }}\n{{ if if }} {{ end }}\n{{ if if }} {{ for foo in bar }} {{ end }} {{ end }}\n{{ for in bar }} {{ end }}\n{{ for blah bar }} {{ end }}\n{{ for blah}} {{ end }}\n{{ else }}"
|
||||
context: {}
|
||||
---
|
||||
ParsedTemplate {
|
||||
|
|
@ -99,8 +99,21 @@ ParsedTemplate {
|
|||
[Whitespace]"\n" (149..150),
|
||||
[LeftDelim]"{{" (150..152),
|
||||
[Whitespace]" " (152..153),
|
||||
[ConditionalElse]"else" (153..157),
|
||||
[Whitespace]" " (157..158),
|
||||
[RightDelim]"}}" (158..160),
|
||||
[For]"for" (153..156),
|
||||
[Whitespace]" " (156..157),
|
||||
[Ident]"blah" (157..161),
|
||||
[RightDelim]"}}" (161..163),
|
||||
[Whitespace]" " (163..164),
|
||||
[LeftDelim]"{{" (164..166),
|
||||
[Whitespace]" " (166..167),
|
||||
[End]"end" (167..170),
|
||||
[Whitespace]" " (170..171),
|
||||
[RightDelim]"}}" (171..173),
|
||||
[Whitespace]"\n" (173..174),
|
||||
[LeftDelim]"{{" (174..176),
|
||||
[Whitespace]" " (176..177),
|
||||
[ConditionalElse]"else" (177..181),
|
||||
[Whitespace]" " (181..182),
|
||||
[RightDelim]"}}" (182..184),
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,31 +2,50 @@
|
|||
source: tests/file_tests.rs
|
||||
expression: ast
|
||||
info:
|
||||
input: "{{ if }} {{ end }}\n{{ if if }} {{ end }}\n{{ if if }} {{ for foo in bar }} {{ end }} {{ end }}\n{{ for in bar }} {{ end }}\n{{ for blah bar }} {{ end }}\n{{ else }}"
|
||||
input: "{{ if }} {{ end }}\n{{ if if }} {{ end }}\n{{ if if }} {{ for foo in bar }} {{ end }} {{ end }}\n{{ for in bar }} {{ end }}\n{{ for blah bar }} {{ end }}\n{{ for blah}} {{ end }}\n{{ else }}"
|
||||
context: {}
|
||||
---
|
||||
[1m[91merror[0m[1m: Expected an expression after 'if'[0m
|
||||
[1m[94m ╭▸ [0m
|
||||
[1m[94m1[0m [1m[94m│[0m {{ if }} {{ end }}
|
||||
[1m[94m│[0m [1m[91m━━[0m
|
||||
[1m[94m╰╴[0m
|
||||
[1m[94m╰╴[0m [1m[91m━━[0m
|
||||
|
||||
[1m[91merror[0m[1m: Expected an expression after 'if'[0m
|
||||
[1m[94m ╭▸ [0m
|
||||
[1m[94m2[0m [1m[94m│[0m {{ if if }} {{ end }}
|
||||
[1m[94m╰╴[0m [1m[91m━━[0m
|
||||
|
||||
[1m[91merror[0m[1m: Expected an expression after 'if'[0m
|
||||
[1m[94m ╭▸ [0m
|
||||
[1m[94m3[0m [1m[94m│[0m {{ if if }} {{ for foo in bar }} {{ end }} {{ end }}
|
||||
[1m[94m╰╴[0m [1m[91m━━[0m
|
||||
[1m[91merror[0m[1m: Expected identifier here[0m
|
||||
|
||||
[1m[91merror[0m[1m: Missing ident here[0m
|
||||
[1m[94m ╭▸ [0m
|
||||
[1m[94m4[0m [1m[94m│[0m {{ for in bar }} {{ end }}
|
||||
[1m[94m╰╴[0m [1m[91m━━━━━━[0m
|
||||
[1m[91merror[0m[1m: Missing `in` in `for _ in <expr>`[0m
|
||||
|
||||
[1m[91merror[0m[1m: Missing `in` in `for .. in ` loop[0m
|
||||
[1m[94m ╭▸ [0m
|
||||
[1m[94m5[0m [1m[94m│[0m {{ for blah bar }} {{ end }}
|
||||
[1m[94m╰╴[0m [1m[91m━━━━━━━━[0m
|
||||
[1m[91merror[0m[1m: An error occurred while producing an Ast[0m
|
||||
[1m[94m│[0m [1m[91m━━━━━━━━[0m
|
||||
[1m[94m╰╴[0m
|
||||
[1m[92mnote[0m: Try adding it
|
||||
[1m[94m╭╴[0m
|
||||
[1m[94m5[0m [1m[94m│ [0m{{ for blah[92m in[0m bar }} {{ end }}
|
||||
[1m[94m╰╴[0m [92m++[0m
|
||||
|
||||
[1m[91merror[0m[1m: Missing `in` in `for .. in ` loop[0m
|
||||
[1m[94m ╭▸ [0m
|
||||
[1m[94m6[0m [1m[94m│[0m {{ else }}
|
||||
[1m[94m╰╴[0m [1m[91m━━━━━━━[0m
|
||||
[1m[94m6[0m [1m[94m│[0m {{ for blah}} {{ end }}
|
||||
[1m[94m│[0m [1m[91m━━━━[0m
|
||||
[1m[94m╰╴[0m
|
||||
[1m[92mnote[0m: Try adding it
|
||||
[1m[94m╭╴[0m
|
||||
[1m[94m6[0m [1m[94m│ [0m{{ for blah[92m in[0m}} {{ end }}
|
||||
[1m[94m╰╴[0m [92m++[0m
|
||||
|
||||
[1m[91merror[0m[1m: Unexpected keyword[0m
|
||||
[1m[94m ╭▸ [0m
|
||||
[1m[94m7[0m [1m[94m│[0m {{ else }}
|
||||
[1m[94m╰╴[0m [1m[91m━━━━[0m
|
||||
|
|
|
|||
|
|
@ -5,4 +5,5 @@
|
|||
{{ if if }} {{ for foo in bar }} {{ end }} {{ end }}
|
||||
{{ for in bar }} {{ end }}
|
||||
{{ for blah bar }} {{ end }}
|
||||
{{ for blah}} {{ end }}
|
||||
{{ else }}
|
||||
|
|
@ -5,6 +5,7 @@ use std::path::Path;
|
|||
|
||||
use nomo::Context;
|
||||
use nomo::functions::FunctionMap;
|
||||
use nomo::input::NomoInput;
|
||||
|
||||
test_each_file::test_each_path! { for ["nomo"] in "./tests/cases/" as cases => check_for_input }
|
||||
|
||||
|
|
@ -43,16 +44,18 @@ fn check_for_input([path]: [&Path; 1]) {
|
|||
context.try_insert(k, v).unwrap();
|
||||
}
|
||||
|
||||
let parsed = nomo::lexer::parse(input.into()).unwrap();
|
||||
let input = NomoInput::from(input);
|
||||
|
||||
let parsed = nomo::lexer::parse(input.clone()).unwrap();
|
||||
|
||||
let _guard = settings.bind_to_scope();
|
||||
|
||||
insta::assert_debug_snapshot!(format!("{basename}.1-parsed"), parsed);
|
||||
|
||||
let ast = match nomo::parser::parse(parsed.tokens()) {
|
||||
let ast = match nomo::parser::parse(input, parsed.tokens()) {
|
||||
Ok(ast) => ast,
|
||||
Err(err) => {
|
||||
eprintln!("{}", err.to_report(input));
|
||||
eprintln!("{}", err);
|
||||
panic!("Could not evaluate ast");
|
||||
}
|
||||
};
|
||||
|
|
@ -97,7 +100,9 @@ fn check_errors([path]: [&Path; 1]) {
|
|||
|
||||
let _guard = settings.bind_to_scope();
|
||||
|
||||
let parsed = nomo::lexer::parse(input.into()).map_err(|err| err.to_report());
|
||||
let input = NomoInput::from(input);
|
||||
|
||||
let parsed = nomo::lexer::parse(input.clone()).map_err(|err| err.to_report());
|
||||
|
||||
match &parsed {
|
||||
Ok(parsed) => insta::assert_debug_snapshot!(format!("{basename}.1-parsed"), parsed),
|
||||
|
|
@ -108,7 +113,7 @@ fn check_errors([path]: [&Path; 1]) {
|
|||
return;
|
||||
};
|
||||
|
||||
let ast = nomo::parser::parse(parsed.tokens()).map_err(|err| err.to_report(input));
|
||||
let ast = nomo::parser::parse(input, parsed.tokens()).map_err(|err| err.to_string());
|
||||
|
||||
match &ast {
|
||||
Ok(ast) => insta::assert_debug_snapshot!(format!("{basename}.2-ast"), ast),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue