Fixes to for loops. Added elseif and else
This commit is contained in:
parent
27f6ec7b70
commit
042df442a1
@ -714,6 +714,36 @@ namespace chaiscript
|
|||||||
throw Parse_Error("Incomplete 'if' block", File_Position(line, col), filename);
|
throw Parse_Error("Incomplete 'if' block", File_Position(line, col), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_matches = true;
|
||||||
|
while (has_matches) {
|
||||||
|
while (Eol());
|
||||||
|
has_matches = false;
|
||||||
|
if (Keyword("elseif", true)) {
|
||||||
|
if (!Char('(')) {
|
||||||
|
throw Parse_Error("Incomplete 'elseif' expression", File_Position(line, col), filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(Expression() && Char(')'))) {
|
||||||
|
throw Parse_Error("Incomplete 'elseif' expression", File_Position(line, col), filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (Eol());
|
||||||
|
|
||||||
|
if (!Block()) {
|
||||||
|
throw Parse_Error("Incomplete 'elseif' block", File_Position(line, col), filename);
|
||||||
|
}
|
||||||
|
has_matches = true;
|
||||||
|
}
|
||||||
|
else if (Keyword("else", true)) {
|
||||||
|
while (Eol());
|
||||||
|
|
||||||
|
if (!Block()) {
|
||||||
|
throw Parse_Error("Incomplete 'else' block", File_Position(line, col), filename);
|
||||||
|
}
|
||||||
|
has_matches = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
build_match(Token_Type::If, prev_stack_top);
|
build_match(Token_Type::If, prev_stack_top);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -751,7 +781,7 @@ namespace chaiscript
|
|||||||
bool For_Guards() {
|
bool For_Guards() {
|
||||||
Equation();
|
Equation();
|
||||||
|
|
||||||
if (Char(';') && Expression() && Char(';') && Expression()) {
|
if (Char(';') && Expression() && Char(';') && Equation()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -1216,7 +1246,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
has_more = true;
|
has_more = true;
|
||||||
retval = true;
|
retval = true;
|
||||||
saw_eol = false;
|
saw_eol = true;
|
||||||
}
|
}
|
||||||
else if (If()) {
|
else if (If()) {
|
||||||
if (!saw_eol) {
|
if (!saw_eol) {
|
||||||
@ -1224,7 +1254,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
has_more = true;
|
has_more = true;
|
||||||
retval = true;
|
retval = true;
|
||||||
saw_eol = false;
|
saw_eol = true;
|
||||||
}
|
}
|
||||||
else if (While()) {
|
else if (While()) {
|
||||||
if (!saw_eol) {
|
if (!saw_eol) {
|
||||||
@ -1232,7 +1262,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
has_more = true;
|
has_more = true;
|
||||||
retval = true;
|
retval = true;
|
||||||
saw_eol = false;
|
saw_eol = true;
|
||||||
}
|
}
|
||||||
else if (For()) {
|
else if (For()) {
|
||||||
if (!saw_eol) {
|
if (!saw_eol) {
|
||||||
@ -1240,7 +1270,7 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
has_more = true;
|
has_more = true;
|
||||||
retval = true;
|
retval = true;
|
||||||
saw_eol = false;
|
saw_eol = true;
|
||||||
}
|
}
|
||||||
else if (Statement()) {
|
else if (Statement()) {
|
||||||
if (!saw_eol) {
|
if (!saw_eol) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
var add2 = function(x, y) { x + y }
|
var add2 = fun(x, y) { x + y }
|
||||||
var add1 = function(x, f) { f(3,x) }
|
var add1 = fun(x, f) { f(3,x) }
|
||||||
print(add2(3, 4))
|
print(add2(3, 4))
|
||||||
|
|
||||||
print(add1(2, add2))
|
print(add1(2, add2))
|
||||||
|
@ -11,5 +11,5 @@ def for_each(container, function)
|
|||||||
|
|
||||||
var vec = [1,2,3,4,5,6,7,8,9, "hi", 4.5]
|
var vec = [1,2,3,4,5,6,7,8,9, "hi", 4.5]
|
||||||
|
|
||||||
for_each(vec, function(x) { print(x); } );
|
for_each(vec, fun(x) { print(x); } );
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ var x = 4
|
|||||||
def do_it() {
|
def do_it() {
|
||||||
var x = 1
|
var x = 1
|
||||||
print(x)
|
print(x)
|
||||||
var y = function(x) { x + 1 }
|
var y = fun(x) { x + 1 }
|
||||||
print(y(9))
|
print(y(9))
|
||||||
}
|
}
|
||||||
do_it()
|
do_it()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user