FEATURE: Use offsets for errors when parsing an assert.

This commit is contained in:
Jeremy Wall 2018-08-30 19:20:17 -05:00
parent d288924fbb
commit fb5247e98f
2 changed files with 15 additions and 4 deletions

View File

@ -0,0 +1,2 @@
assert |macro |;
assert |{ foo = hello world}|;

View File

@ -243,9 +243,8 @@ impl<'a> Builder<'a> {
Ok(())
}
/// Evaluate an input string as UCG.
pub fn eval_string(&mut self, input: &str) -> Result<Rc<Val>, Box<Error>> {
match parse(Span::new(input)) {
fn eval_span(&mut self, input: Span) -> Result<Rc<Val>, Box<Error>> {
match parse(input) {
Ok(stmts) => {
//panic!("Successfully parsed {}", input);
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.
pub fn build_file(&mut self, name: &'a str) -> BuildResult {
self.curr_file = Some(name);
@ -988,7 +992,12 @@ impl<'a> Builder<'a> {
let expr = &tok.fragment;
expr_as_stmt.push_str(expr);
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,
Err(e) => {
// failure!