Fix parser to handle shortform equations (fix bad operator parsing). Add back lines to prelude for line numbers

This commit is contained in:
Jonathan Turner
2009-09-09 14:11:03 +00:00
parent daee00da95
commit f23f0edc70
4 changed files with 258 additions and 251 deletions

View File

@@ -591,7 +591,7 @@ namespace chaiscript
/**
* Reads (and potentially captures) a symbol group from input if it matches the parameter
*/
bool Symbol(const char *s, bool capture = false) {
bool Symbol(const char *s, bool capture = false, bool disallow_prevention=false) {
SkipWS();
if (!capture) {
@@ -601,7 +601,7 @@ namespace chaiscript
bool retval = Symbol_(s);
if (retval) {
//todo: fix this. Hacky workaround for preventing substring matches
if ((input_pos != input_end) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') || (*input_pos == '=') || (*input_pos == '.'))) {
if ((input_pos != input_end) && (disallow_prevention == false) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') || (*input_pos == '=') || (*input_pos == '.'))) {
input_pos = start;
col = prev_col;
line = prev_line;
@@ -619,7 +619,7 @@ namespace chaiscript
int prev_line = line;
if (Symbol_(s)) {
//todo: fix this. Hacky workaround for preventing substring matches
if ((input_pos != input_end) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') || (*input_pos == '=') || (*input_pos == '.'))) {
if ((input_pos != input_end) && (disallow_prevention == false) && ((*input_pos == '+') || (*input_pos == '-') || (*input_pos == '*') || (*input_pos == '/') || (*input_pos == '=') || (*input_pos == '.'))) {
input_pos = start;
col = prev_col;
line = prev_line;
@@ -1185,24 +1185,6 @@ namespace chaiscript
int prev_stack_top = match_stack.size();
if (Symbol("-")) {
retval = true;
if (!Dot_Access()) {
throw Eval_Error("Incomplete negation expression", File_Position(line, col), filename);
}
build_match(Token_Type::Negate, prev_stack_top);
}
else if (Symbol("!")) {
retval = true;
if (!Dot_Access()) {
throw Eval_Error("Incomplete '!' expression", File_Position(line, col), filename);
}
build_match(Token_Type::Not, prev_stack_top);
}
if (Symbol("++", true)) {
retval = true;
@@ -1221,6 +1203,24 @@ namespace chaiscript
build_match(Token_Type::Prefix, prev_stack_top);
}
else if (Char('-')) {
retval = true;
if (!Dot_Access()) {
throw Eval_Error("Incomplete negation expression", File_Position(line, col), filename);
}
build_match(Token_Type::Negate, prev_stack_top);
}
else if (Char('!')) {
retval = true;
if (!Dot_Access()) {
throw Eval_Error("Incomplete '!' expression", File_Position(line, col), filename);
}
build_match(Token_Type::Not, prev_stack_top);
}
return retval;
}
@@ -1423,7 +1423,8 @@ namespace chaiscript
if (Expression()) {
retval = true;
if (Symbol("=", true) || Symbol(":=", true) || Symbol("+=", true) || Symbol("-=", true) || Symbol("*=", true) || Symbol("/=", true)) {
if (Symbol("=", true, true) || Symbol(":=", true, true) || Symbol("+=", true, true) ||
Symbol("-=", true, true) || Symbol("*=", true, true) || Symbol("/=", true, true)) {
if (!Equation()) {
throw Eval_Error("Incomplete equation", match_stack.back());
}