Change 'elseif' to 'else if' to better support C++ expectations

This commit is contained in:
Jonathan Turner
2009-07-17 14:16:27 +00:00
parent 689143aba5
commit ac817ff33a
4 changed files with 25 additions and 22 deletions

View File

@@ -525,13 +525,13 @@ namespace chaiscript
retval = eval_token(ss, node->children[i+1]); retval = eval_token(ss, node->children[i+1]);
cond = true; cond = true;
} }
else if (node->children[i]->text == "elseif") { else if (node->children[i]->text == "else if") {
retval = eval_token(ss, node->children[i+1]); retval = eval_token(ss, node->children[i+1]);
try { try {
cond = dispatchkit::boxed_cast<bool &>(retval); cond = dispatchkit::boxed_cast<bool &>(retval);
} }
catch (const dispatchkit::bad_boxed_cast &) { catch (const dispatchkit::bad_boxed_cast &) {
throw Eval_Error("Elseif condition not boolean", node->children[i+1]); throw Eval_Error("'else if' condition not boolean", node->children[i+1]);
} }
if (cond) { if (cond) {
retval = eval_token(ss, node->children[i+2]); retval = eval_token(ss, node->children[i+2]);

View File

@@ -846,29 +846,32 @@ namespace chaiscript
while (has_matches) { while (has_matches) {
while (Eol()); while (Eol());
has_matches = false; has_matches = false;
if (Keyword("elseif", true)) { if (Keyword("else", true)) {
if (!Char('(')) { if (Keyword("if")) {
throw Eval_Error("Incomplete 'elseif' expression", File_Position(line, col), filename); match_stack.back()->text = "else if";
} if (!Char('(')) {
throw Eval_Error("Incomplete 'else if' expression", File_Position(line, col), filename);
}
if (!(Expression() && Char(')'))) { if (!(Expression() && Char(')'))) {
throw Eval_Error("Incomplete 'elseif' expression", File_Position(line, col), filename); throw Eval_Error("Incomplete 'else if' expression", File_Position(line, col), filename);
} }
while (Eol()); while (Eol());
if (!Block()) { if (!Block()) {
throw Eval_Error("Incomplete 'elseif' block", File_Position(line, col), filename); throw Eval_Error("Incomplete 'else if' block", File_Position(line, col), filename);
}
has_matches = true;
} }
has_matches = true; else {
} while (Eol());
else if (Keyword("else", true)) {
while (Eol());
if (!Block()) { if (!Block()) {
throw Eval_Error("Incomplete 'else' block", File_Position(line, col), filename); throw Eval_Error("Incomplete 'else' block", File_Position(line, col), filename);
}
has_matches = true;
} }
has_matches = true;
} }
} }

View File

@@ -2,10 +2,10 @@ var i = 3
if (i == 2) { if (i == 2) {
print("2") print("2")
} }
elseif (i == 4) { else if (i == 4) {
print("4") print("4")
} }
elseif (i == 3) { else if (i == 3) {
print("3") print("3")
} }

View File

@@ -2,7 +2,7 @@ var i = 3
if (i == 2) { if (i == 2) {
print("2") print("2")
} }
elseif (i == 4) { else if (i == 4) {
print("4") print("4")
} }
else { else {