Added for loop
This commit is contained in:
@@ -701,17 +701,17 @@ namespace chaiscript
|
||||
retval = true;
|
||||
|
||||
if (!Char('(')) {
|
||||
throw Parse_Error("Incomplete if expression", File_Position(line, col), filename);
|
||||
throw Parse_Error("Incomplete 'if' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
if (!(Expression() && Char(')'))) {
|
||||
throw Parse_Error("Incomplete if expression", File_Position(line, col), filename);
|
||||
throw Parse_Error("Incomplete 'if' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
while (Eol());
|
||||
|
||||
if (!Block()) {
|
||||
throw Parse_Error("Incomplete if block", File_Position(line, col), filename);
|
||||
throw Parse_Error("Incomplete 'if' block", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
build_match(Token_Type::If, prev_stack_top);
|
||||
@@ -729,17 +729,17 @@ namespace chaiscript
|
||||
retval = true;
|
||||
|
||||
if (!Char('(')) {
|
||||
throw Parse_Error("Incomplete while expression", File_Position(line, col), filename);
|
||||
throw Parse_Error("Incomplete 'while' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
if (!(Expression() && Char(')'))) {
|
||||
throw Parse_Error("Incomplete while expression", File_Position(line, col), filename);
|
||||
throw Parse_Error("Incomplete 'while' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
while (Eol());
|
||||
|
||||
if (!Block()) {
|
||||
throw Parse_Error("Incomplete while block", File_Position(line, col), filename);
|
||||
throw Parse_Error("Incomplete 'while' block", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
build_match(Token_Type::While, prev_stack_top);
|
||||
@@ -748,6 +748,44 @@ namespace chaiscript
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool For_Guards() {
|
||||
Equation();
|
||||
|
||||
if (Char(';') && Expression() && Char(';') && Expression()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
throw Parse_Error("Incomplete conditions in 'for' loop", File_Position(line, col), filename);
|
||||
}
|
||||
}
|
||||
bool For() {
|
||||
bool retval = false;
|
||||
|
||||
int prev_stack_top = match_stack.size();
|
||||
|
||||
if (Keyword("for")) {
|
||||
retval = true;
|
||||
|
||||
if (!Char('(')) {
|
||||
throw Parse_Error("Incomplete 'for' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
if (!(For_Guards() && Char(')'))) {
|
||||
throw Parse_Error("Incomplete 'for' expression", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
while (Eol());
|
||||
|
||||
if (!Block()) {
|
||||
throw Parse_Error("Incomplete 'for' block", File_Position(line, col), filename);
|
||||
}
|
||||
|
||||
build_match(Token_Type::For, prev_stack_top);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool Block() {
|
||||
bool retval = false;
|
||||
|
||||
@@ -1196,6 +1234,14 @@ namespace chaiscript
|
||||
retval = true;
|
||||
saw_eol = false;
|
||||
}
|
||||
else if (For()) {
|
||||
if (!saw_eol) {
|
||||
throw Parse_Error("Two function definitions missing line separator", match_stack.back());
|
||||
}
|
||||
has_more = true;
|
||||
retval = true;
|
||||
saw_eol = false;
|
||||
}
|
||||
else if (Statement()) {
|
||||
if (!saw_eol) {
|
||||
throw Parse_Error("Two expressions missing line separator", match_stack.back());
|
||||
|
Reference in New Issue
Block a user