diff --git a/arbitrile.cpp b/arbitrile.cpp index 3c4b0b03..ab7af344 100644 --- a/arbitrile.cpp +++ b/arbitrile.cpp @@ -78,7 +78,7 @@ void shape::build_from_angles_edges() { bool correct_index(int index, int size) { return index >= 0 && index < size; } template bool correct_index(int index, const T& v) { return correct_index(index, isize(v)); } -template void verify_index(int index, const T& v) { if(!correct_index(index, v)) throw hr_parse_exception("bad index"); } +template void verify_index(int index, const T& v, exp_parser& ep) { if(!correct_index(index, v)) throw hr_parse_exception("bad index: " + its(index) + " at " + ep.where()); } string unnamed = "unnamed"; @@ -102,7 +102,7 @@ EX void load(const string& fname) { int ai; if(ep.next() == ')') ai = isize(c.shapes)-1; else ai = ep.iparse(); - verify_index(ai, c.shapes); + verify_index(ai, c.shapes, ep); c.shapes[ai].flags |= f; ep.force_eat(")"); }; @@ -171,7 +171,12 @@ EX void load(const string& fname) { else if(ep.eat(")")) break; else throw hr_parse_exception("expecting , or )"); } - cc.build_from_angles_edges(); + try { + cc.build_from_angles_edges(); + } + catch(hr_parse_exception& ex) { + throw hr_parse_exception(ex.s + ep.where()); + } cc.connections.resize(cc.size()); for(int i=0; i extra_params; @@ -168,14 +174,21 @@ struct exp_parser { void force_eat(const char *c) { skip_white(); - if(!eat(c)) throw hr_parse_exception("expected: " + string(c)); + if(!eat(c)) throw hr_parse_exception("expected: " + string(c) + " at " + where()); } }; #endif void exp_parser::skip_white() { - while(next() == ' ' || next() == '\n' || next() == '\r' || next() == '\t') at++; + while(next() == ' ' || next() == '\n' || next() == '\r' || next() == '\t') { + if(next() == '\r') last_line++; + if(next() == '\n') { + println(hlog, "new line at ", at); + line_number++, last_line = at; + } + at++; + } } string exp_parser::next_token() {