grammar_expression(p);
p_tree = parser_get_tree(p);
} catch(ParseException) {
- fprintf(stderr, "Invalid Syntax\n");
+ /* Do nothing, the tree is bad */
}
return p_tree;
}
break;
default:
- parser_error(p, "Not a valid expression");
+ parser_error(p, "Expected a literal");
}
}
void parser_error(parser_t* p_parser, const char* p_text)
{
(void)p_parser;
+ lex_tok_t* tok = parser_peek(p_parser);
+ fprintf(stderr, "<file>:%zu:%zu:Error: %s\n", tok->line, tok->col, p_text);
throw_msg(ParseException, p_text);
}
end
it "should error on missing semicolon" do
- expect{ast('require "foo"')}.to raise_error /Invalid Syntax/
+ expect{ast('require "foo"')}.to raise_error /Error/
end
it "should error on missing filename" do
- expect{ast('require ;')}.to raise_error /Invalid Syntax/
+ expect{ast('require ;')}.to raise_error /Error/
end
it "should error on invalid filename type" do
- expect{ast('require 123;')}.to raise_error /Invalid Syntax/
+ expect{ast('require 123;')}.to raise_error /Error/
end
it "should error on too many parameters" do
- expect{ast('require foo bar;')}.to raise_error /Invalid Syntax/
+ expect{ast('require foo bar;')}.to raise_error /Error/
end
end
context "corner cases" do
it "an unexpected terminator should error" do
- expect{ast(';')}.to raise_error /Invalid Syntax/
+ expect{ast(';')}.to raise_error /Error/
end
it "an invalid literal should error" do
- expect{ast('\'')}.to raise_error /Invalid Syntax/
+ expect{ast('\'')}.to raise_error /Error/
end
end
end