mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-09-11 03:45:29 +03:00
Add missing error message
This commit is contained in:
parent
65065e9038
commit
842891cbf4
@ -495,27 +495,26 @@ impl<'a> TermParser<'a> {
|
|||||||
self.skip_trivia();
|
self.skip_trivia();
|
||||||
let (cur_name, rule) = self.parse_rule()?;
|
let (cur_name, rule) = self.parse_rule()?;
|
||||||
let mut rules = vec![rule];
|
let mut rules = vec![rule];
|
||||||
let mut cur_idx = *self.index();
|
let mut nxt_term = *self.index();
|
||||||
loop {
|
loop {
|
||||||
self.skip_trivia();
|
self.skip_trivia();
|
||||||
let back_term = *self.index();
|
let nxt_def = *self.index();
|
||||||
match self.parse_rule() {
|
match self.parse_rule() {
|
||||||
Ok((name, rule)) => {
|
Ok((name, rule)) => {
|
||||||
if name == "def" {
|
if name == "def" {
|
||||||
self.index = back_term;
|
self.index = nxt_def;
|
||||||
return Ok(Term::Def { nam: cur_name, rules, nxt: Box::new(self.parse_term()?) });
|
return Ok(Term::Def { nam: cur_name, rules, nxt: Box::new(self.parse_term()?) });
|
||||||
}
|
}
|
||||||
if name == cur_name {
|
if name == cur_name {
|
||||||
rules.push(rule);
|
rules.push(rule);
|
||||||
cur_idx = *self.index();
|
nxt_term = *self.index();
|
||||||
} else {
|
} else {
|
||||||
panic!()
|
let cur = *self.index();
|
||||||
|
let msg = format!("Expected a rule with name '{cur_name}'.");
|
||||||
|
return self.with_ctx(Err(msg), nxt_def..cur);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => break self.index = nxt_term,
|
||||||
self.index = cur_idx;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let nxt = self.parse_term()?;
|
let nxt = self.parse_term()?;
|
||||||
|
@ -77,13 +77,13 @@ fn gen_use(
|
|||||||
fvs.iter().cloned().map(|nam| Term::Var { nam }).collect::<Vec<_>>(),
|
fvs.iter().cloned().map(|nam| Term::Var { nam }).collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let r#use = Term::Use { nam: Some(nam.clone()), val: Box::new(call.clone()), nxt: std::mem::take(nxt) };
|
|
||||||
|
|
||||||
for rule in rules.iter_mut() {
|
for rule in rules.iter_mut() {
|
||||||
let slf = std::mem::take(&mut rule.body);
|
let slf = std::mem::take(&mut rule.body);
|
||||||
rule.body = Term::Use { nam: Some(nam.clone()), val: Box::new(call.clone()), nxt: Box::new(slf) };
|
rule.body = Term::Use { nam: Some(nam.clone()), val: Box::new(call.clone()), nxt: Box::new(slf) };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let r#use = Term::Use { nam: Some(nam.clone()), val: Box::new(call.clone()), nxt: std::mem::take(nxt) };
|
||||||
|
|
||||||
(r#use, fvs, rules)
|
(r#use, fvs, rules)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
tests/golden_tests/parse_file/fun_def.bend
Normal file
5
tests/golden_tests/parse_file/fun_def.bend
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
main =
|
||||||
|
let base = 0
|
||||||
|
def aux [] = base
|
||||||
|
aux (List/Cons head tail) = (+ head (aux tail))
|
||||||
|
(aux [1, 2, 3])
|
5
tests/golden_tests/parse_file/fun_def_name.bend
Normal file
5
tests/golden_tests/parse_file/fun_def_name.bend
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
main =
|
||||||
|
let base = 0
|
||||||
|
def aux [] = base
|
||||||
|
aux2 (List/Cons head tail) = (+ head (aux tail))
|
||||||
|
(aux [1, 2, 3])
|
5
tests/snapshots/parse_file__fun_def.bend.snap
Normal file
5
tests/snapshots/parse_file__fun_def.bend.snap
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
source: tests/golden_tests.rs
|
||||||
|
input_file: tests/golden_tests/parse_file/fun_def.bend
|
||||||
|
---
|
||||||
|
(main) = let base = 0; def (aux []) = base(aux (List/Cons head tail)) = (+ head (aux tail))(aux [1, 2, 3])
|
8
tests/snapshots/parse_file__fun_def_name.bend.snap
Normal file
8
tests/snapshots/parse_file__fun_def_name.bend.snap
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
source: tests/golden_tests.rs
|
||||||
|
input_file: tests/golden_tests/parse_file/fun_def_name.bend
|
||||||
|
---
|
||||||
|
[4m[1m[31mErrors:[0m
|
||||||
|
In tests/golden_tests/parse_file/fun_def_name.bend :
|
||||||
|
Expected a rule with name 'aux'.
|
||||||
|
[0m 4 | [4m[31maux2 (List/Cons head tail) = (+ head (aux tail))[0m
|
Loading…
Reference in New Issue
Block a user