mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-23 18:29:50 -04:00
FEATURE: Use offsets for errors when parsing an assert.
This commit is contained in:
parent
d288924fbb
commit
fb5247e98f
2
example_errors/tuple_errors_test.ucg
Normal file
2
example_errors/tuple_errors_test.ucg
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
assert |macro |;
|
||||||
|
assert |{ foo = hello world}|;
|
@ -243,9 +243,8 @@ impl<'a> Builder<'a> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Evaluate an input string as UCG.
|
fn eval_span(&mut self, input: Span) -> Result<Rc<Val>, Box<Error>> {
|
||||||
pub fn eval_string(&mut self, input: &str) -> Result<Rc<Val>, Box<Error>> {
|
match parse(input) {
|
||||||
match parse(Span::new(input)) {
|
|
||||||
Ok(stmts) => {
|
Ok(stmts) => {
|
||||||
//panic!("Successfully parsed {}", input);
|
//panic!("Successfully parsed {}", input);
|
||||||
let mut out: Option<Rc<Val>> = None;
|
let mut out: Option<Rc<Val>> = None;
|
||||||
@ -268,6 +267,11 @@ impl<'a> Builder<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Evaluate an input string as UCG.
|
||||||
|
pub fn eval_string(&mut self, input: &str) -> Result<Rc<Val>, Box<Error>> {
|
||||||
|
self.eval_span(Span::new(input))
|
||||||
|
}
|
||||||
|
|
||||||
/// Builds a ucg file at the named path.
|
/// Builds a ucg file at the named path.
|
||||||
pub fn build_file(&mut self, name: &'a str) -> BuildResult {
|
pub fn build_file(&mut self, name: &'a str) -> BuildResult {
|
||||||
self.curr_file = Some(name);
|
self.curr_file = Some(name);
|
||||||
@ -988,7 +992,12 @@ impl<'a> Builder<'a> {
|
|||||||
let expr = &tok.fragment;
|
let expr = &tok.fragment;
|
||||||
expr_as_stmt.push_str(expr);
|
expr_as_stmt.push_str(expr);
|
||||||
expr_as_stmt.push_str(";");
|
expr_as_stmt.push_str(";");
|
||||||
let ok = match self.eval_string(&expr_as_stmt) {
|
let assert_input = Span {
|
||||||
|
fragment: &expr_as_stmt,
|
||||||
|
line: tok.pos.line as u32,
|
||||||
|
offset: tok.pos.column,
|
||||||
|
};
|
||||||
|
let ok = match self.eval_span(assert_input) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// failure!
|
// failure!
|
||||||
|
Loading…
x
Reference in New Issue
Block a user