forked from OctaForge/libcubescript
trigger actual errors from parser
parent
879737ce83
commit
323c84c3d6
|
@ -8,6 +8,15 @@
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
|
||||||
|
template<typename ...A>
|
||||||
|
static void cs_error_line(
|
||||||
|
CsState &cs, ostd::ConstCharRange p, ostd::ConstCharRange fmt, A &&...args
|
||||||
|
) {
|
||||||
|
ostd::Array<char, 256> buf;
|
||||||
|
auto rfmt = cs_debug_line(p, fmt, ostd::CharRange(buf.data(), buf.size()));
|
||||||
|
cs.error(rfmt, ostd::forward<A>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
char *cs_dup_ostr(ostd::ConstCharRange s) {
|
char *cs_dup_ostr(ostd::ConstCharRange s) {
|
||||||
char *r = new char[s.size() + 1];
|
char *r = new char[s.size() + 1];
|
||||||
if (s.data()) {
|
if (s.data()) {
|
||||||
|
@ -788,9 +797,8 @@ static void compileblockmain(GenState &gs, int wordtype, int prevargs) {
|
||||||
char c = gs.next_char();
|
char c = gs.next_char();
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\0':
|
case '\0':
|
||||||
cs_debug_code_line(gs.cs, line, "missing \"]\"");
|
cs_error_line(gs.cs, line, "missing \"]\"");
|
||||||
gs.source--;
|
return;
|
||||||
goto done;
|
|
||||||
case '\"':
|
case '\"':
|
||||||
gs.source = parsestring(gs.source);
|
gs.source = parsestring(gs.source);
|
||||||
if (gs.current() == '\"') {
|
if (gs.current() == '\"') {
|
||||||
|
@ -817,7 +825,8 @@ static void compileblockmain(GenState &gs, int wordtype, int prevargs) {
|
||||||
if (brak > level) {
|
if (brak > level) {
|
||||||
continue;
|
continue;
|
||||||
} else if (brak < level) {
|
} else if (brak < level) {
|
||||||
cs_debug_code_line(gs.cs, line, "too many @s");
|
cs_error_line(gs.cs, line, "too many @s");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (!concs && prevargs >= MaxResults) {
|
if (!concs && prevargs >= MaxResults) {
|
||||||
gs.code.push(CsCodeEnter);
|
gs.code.push(CsCodeEnter);
|
||||||
|
@ -843,7 +852,6 @@ static void compileblockmain(GenState &gs, int wordtype, int prevargs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
done:
|
|
||||||
if (gs.source - 1 > start) {
|
if (gs.source - 1 > start) {
|
||||||
if (!concs) {
|
if (!concs) {
|
||||||
switch (wordtype) {
|
switch (wordtype) {
|
||||||
|
@ -1679,9 +1687,10 @@ endstatement:
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '\0':
|
case '\0':
|
||||||
if (c != brak) {
|
if (c != brak) {
|
||||||
cs_debug_code_line(
|
cs_error_line(
|
||||||
gs.cs, line, "missing \"%c\"", char(brak)
|
gs.cs, line, "missing \"%c\"", char(brak)
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
gs.source--;
|
gs.source--;
|
||||||
return;
|
return;
|
||||||
|
@ -1690,8 +1699,8 @@ endstatement:
|
||||||
if (c == brak) {
|
if (c == brak) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cs_debug_code_line(gs.cs, line, "unexpected \"%c\"", c);
|
cs_error_line(gs.cs, line, "unexpected \"%c\"", c);
|
||||||
break;
|
return;
|
||||||
case '/':
|
case '/':
|
||||||
if (gs.current() == '/') {
|
if (gs.current() == '/') {
|
||||||
gs.source += strcspn(gs.source, "\n\0");
|
gs.source += strcspn(gs.source, "\n\0");
|
||||||
|
|
|
@ -108,6 +108,9 @@ CsStackState cs_save_stack(CsState &cs) {
|
||||||
for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) {
|
for (CsIdentLink *l = cs.p_callstack; l != &cs.noalias; l = l->next) {
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
if (!total) {
|
||||||
|
return CsStackState(nullptr, true);
|
||||||
|
}
|
||||||
CsStackStateNode *st =
|
CsStackStateNode *st =
|
||||||
new CsStackStateNode[ostd::min(total, dalias->get_value())];
|
new CsStackStateNode[ostd::min(total, dalias->get_value())];
|
||||||
CsStackStateNode *ret = st, *nd = st;
|
CsStackStateNode *ret = st, *nd = st;
|
||||||
|
|
16
src/cs_vm.hh
16
src/cs_vm.hh
|
@ -115,22 +115,6 @@ void cs_debug_code(CsState &cs, ostd::ConstCharRange fmt, A &&...args) {
|
||||||
cscript::util::print_stack(cs.get_err().iter(), st);
|
cscript::util::print_stack(cs.get_err().iter(), st);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ...A>
|
|
||||||
void cs_debug_code_line(
|
|
||||||
CsState &cs, ostd::ConstCharRange p, ostd::ConstCharRange fmt, A &&...args
|
|
||||||
) {
|
|
||||||
if (cs.nodebug) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ostd::Array<char, 256> buf;
|
|
||||||
cs.get_err().writefln(
|
|
||||||
cs_debug_line(p, fmt, ostd::CharRange(buf.data(), buf.size())),
|
|
||||||
ostd::forward<A>(args)...
|
|
||||||
);
|
|
||||||
auto st = cs_save_stack(cs);
|
|
||||||
cscript::util::print_stack(cs.get_err().iter(), st);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct GenState {
|
struct GenState {
|
||||||
CsState &cs;
|
CsState &cs;
|
||||||
CsVector<ostd::Uint32> code;
|
CsVector<ostd::Uint32> code;
|
||||||
|
|
Loading…
Reference in New Issue