mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 03:45:29 +03:00
Improve error messages of branching cases
This commit is contained in:
parent
2232a708e3
commit
676d4ca732
@ -575,7 +575,9 @@ impl<'a> PyParser<'a> {
|
||||
indent.exit_level();
|
||||
|
||||
if nxt_indent != *indent {
|
||||
return self.expected_indent(*indent, nxt_indent);
|
||||
return self
|
||||
.expected_indent(*indent, nxt_indent)
|
||||
.or(self.expected_spanned("else or elif", self.index..self.index + 1));
|
||||
}
|
||||
let mut elifs = Vec::new();
|
||||
while self.try_parse_keyword("elif") {
|
||||
@ -588,7 +590,9 @@ impl<'a> PyParser<'a> {
|
||||
indent.exit_level();
|
||||
|
||||
if nxt_indent != *indent {
|
||||
return self.expected_indent(*indent, nxt_indent);
|
||||
return self
|
||||
.expected_indent(*indent, nxt_indent)
|
||||
.or(self.expected_spanned("else or elif", self.index..self.index + 1));
|
||||
}
|
||||
elifs.push((cond, then));
|
||||
}
|
||||
@ -630,7 +634,7 @@ impl<'a> PyParser<'a> {
|
||||
self.consume_new_line()?;
|
||||
indent.enter_level();
|
||||
|
||||
self.consume_indent_exactly(*indent)?;
|
||||
self.consume_indent_exactly(*indent).or(self.expected_spanned("case", self.index..self.index + 1))?;
|
||||
let (case, mut nxt_indent) = self.parse_match_case(indent)?;
|
||||
let mut arms = vec![case];
|
||||
while nxt_indent == *indent {
|
||||
@ -728,7 +732,9 @@ impl<'a> PyParser<'a> {
|
||||
let mut expected_num = 1;
|
||||
while should_continue {
|
||||
if nxt_indent != *indent {
|
||||
return self.expected_indent(*indent, nxt_indent);
|
||||
return self
|
||||
.expected_indent(*indent, nxt_indent)
|
||||
.or(self.expected_spanned("case", self.index..self.index + 1));
|
||||
}
|
||||
let (case, stmt, nxt_indent_) = self.parse_switch_case(indent)?;
|
||||
nxt_indent = nxt_indent_;
|
||||
@ -793,7 +799,7 @@ impl<'a> PyParser<'a> {
|
||||
self.consume_new_line()?;
|
||||
indent.enter_level();
|
||||
|
||||
self.consume_indent_exactly(*indent)?;
|
||||
self.consume_indent_exactly(*indent).or(self.expected_spanned("case", self.index..self.index + 1))?;
|
||||
let (case, mut nxt_indent) = self.parse_match_case(indent)?;
|
||||
let mut arms = vec![case];
|
||||
while nxt_indent == *indent {
|
||||
@ -824,7 +830,7 @@ impl<'a> PyParser<'a> {
|
||||
self.consume_new_line()?;
|
||||
indent.enter_level();
|
||||
|
||||
self.consume_indent_exactly(*indent)?;
|
||||
self.consume_indent_exactly(*indent).or(self.expected_spanned("when", self.index..self.index + 1))?;
|
||||
self.parse_keyword("when")?;
|
||||
let cond = self.parse_expr(true, false)?;
|
||||
self.skip_trivia_inline()?;
|
||||
@ -837,7 +843,9 @@ impl<'a> PyParser<'a> {
|
||||
indent.exit_level();
|
||||
|
||||
if nxt_indent != *indent {
|
||||
return self.expected_indent(*indent, nxt_indent);
|
||||
return self
|
||||
.expected_indent(*indent, nxt_indent)
|
||||
.or(self.expected_spanned("else", self.index..self.index + 1));
|
||||
}
|
||||
self.parse_keyword("else")?;
|
||||
self.skip_trivia_inline()?;
|
||||
|
15
tests/golden_tests/parse_file/bend_missing_else.bend
Normal file
15
tests/golden_tests/parse_file/bend_missing_else.bend
Normal file
@ -0,0 +1,15 @@
|
||||
def is_even(n):
|
||||
if n % 2 == 0:
|
||||
return 1
|
||||
else:
|
||||
return 0
|
||||
|
||||
def get_even_sum_under_if(this_number):
|
||||
bend current = 0:
|
||||
when current < this_number:
|
||||
new_num = fork(current + is_even(current))
|
||||
|
||||
return new_num
|
||||
|
||||
def main():
|
||||
return get_even_sum_under_if(1000)
|
3
tests/golden_tests/parse_file/fold_missing_case.bend
Normal file
3
tests/golden_tests/parse_file/fold_missing_case.bend
Normal file
@ -0,0 +1,3 @@
|
||||
def main:
|
||||
fold [] with x = 1:
|
||||
|
4
tests/golden_tests/parse_file/if_missing_else.bend
Normal file
4
tests/golden_tests/parse_file/if_missing_else.bend
Normal file
@ -0,0 +1,4 @@
|
||||
def main:
|
||||
if 1 == 1:
|
||||
return "true"
|
||||
|
3
tests/golden_tests/parse_file/match_missing_case.bend
Normal file
3
tests/golden_tests/parse_file/match_missing_case.bend
Normal file
@ -0,0 +1,3 @@
|
||||
def main:
|
||||
match []:
|
||||
|
@ -4,5 +4,6 @@ input_file: tests/golden_tests/compile_file/elif_no_else.bend
|
||||
---
|
||||
[4m[1m[31mErrors:[0m
|
||||
In tests/golden_tests/compile_file/elif_no_else.bend :
|
||||
Indentation error. Expected 2 spaces, got end-of-input.
|
||||
[1m- expected:[0m else or elif
|
||||
[1m- detected:[0m end of input
|
||||
[0m 6 | [4m[31m [0m
|
||||
|
9
tests/snapshots/parse_file__bend_missing_else.bend.snap
Normal file
9
tests/snapshots/parse_file__bend_missing_else.bend.snap
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/parse_file/bend_missing_else.bend
|
||||
---
|
||||
[4m[1m[31mErrors:[0m
|
||||
In tests/golden_tests/parse_file/bend_missing_else.bend :
|
||||
[1m- expected:[0m else
|
||||
[1m- detected:[0m
|
||||
[0m 14 | [4m[31md[0mef main():[0m
|
9
tests/snapshots/parse_file__fold_missing_case.bend.snap
Normal file
9
tests/snapshots/parse_file__fold_missing_case.bend.snap
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/parse_file/fold_missing_case.bend
|
||||
---
|
||||
[4m[1m[31mErrors:[0m
|
||||
In tests/golden_tests/parse_file/fold_missing_case.bend :
|
||||
[1m- expected:[0m case
|
||||
[1m- detected:[0m end of input
|
||||
[0m 4 | [4m[31m [0m
|
9
tests/snapshots/parse_file__if_missing_else.bend.snap
Normal file
9
tests/snapshots/parse_file__if_missing_else.bend.snap
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/parse_file/if_missing_else.bend
|
||||
---
|
||||
[4m[1m[31mErrors:[0m
|
||||
In tests/golden_tests/parse_file/if_missing_else.bend :
|
||||
[1m- expected:[0m else or elif
|
||||
[1m- detected:[0m end of input
|
||||
[0m 5 | [4m[31m [0m
|
9
tests/snapshots/parse_file__match_missing_case.bend.snap
Normal file
9
tests/snapshots/parse_file__match_missing_case.bend.snap
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/parse_file/match_missing_case.bend
|
||||
---
|
||||
[4m[1m[31mErrors:[0m
|
||||
In tests/golden_tests/parse_file/match_missing_case.bend :
|
||||
[1m- expected:[0m case
|
||||
[1m- detected:[0m end of input
|
||||
[0m 4 | [4m[31m [0m
|
Loading…
Reference in New Issue
Block a user