Added for loop
This commit is contained in:
parent
bb174b37a6
commit
3214f427ff
@ -356,8 +356,7 @@ namespace chaiscript
|
|||||||
retval = dispatchkit::Boxed_Value();
|
retval = dispatchkit::Boxed_Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/*
|
case(Token_Type::For) : {
|
||||||
case(TokenType::For_Block) : {
|
|
||||||
dispatchkit::Boxed_Value condition;
|
dispatchkit::Boxed_Value condition;
|
||||||
bool cond;
|
bool cond;
|
||||||
|
|
||||||
@ -399,7 +398,6 @@ namespace chaiscript
|
|||||||
retval = dispatchkit::Boxed_Value();
|
retval = dispatchkit::Boxed_Value();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
*/
|
|
||||||
case (Token_Type::Def) : {
|
case (Token_Type::Def) : {
|
||||||
std::vector<std::string> param_names;
|
std::vector<std::string> param_names;
|
||||||
|
|
||||||
@ -463,22 +461,6 @@ namespace chaiscript
|
|||||||
throw BreakLoop(node);
|
throw BreakLoop(node);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case (TokenType::Statement) :
|
|
||||||
case (TokenType::Carriage_Return) :
|
|
||||||
case (TokenType::Semicolon) :
|
|
||||||
case (TokenType::Comment) :
|
|
||||||
case (TokenType::Operator) :
|
|
||||||
case (TokenType::Whitespace) :
|
|
||||||
case (TokenType::Parens_Open) :
|
|
||||||
case (TokenType::Parens_Close) :
|
|
||||||
case (TokenType::Square_Open) :
|
|
||||||
case (TokenType::Square_Close) :
|
|
||||||
case (TokenType::Curly_Open) :
|
|
||||||
case (TokenType::Curly_Close) :
|
|
||||||
case (TokenType::Comma) :
|
|
||||||
break;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -701,17 +701,17 @@ namespace chaiscript
|
|||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Char('(')) {
|
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(')'))) {
|
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());
|
while (Eol());
|
||||||
|
|
||||||
if (!Block()) {
|
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);
|
build_match(Token_Type::If, prev_stack_top);
|
||||||
@ -729,17 +729,17 @@ namespace chaiscript
|
|||||||
retval = true;
|
retval = true;
|
||||||
|
|
||||||
if (!Char('(')) {
|
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(')'))) {
|
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());
|
while (Eol());
|
||||||
|
|
||||||
if (!Block()) {
|
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);
|
build_match(Token_Type::While, prev_stack_top);
|
||||||
@ -748,6 +748,44 @@ namespace chaiscript
|
|||||||
return retval;
|
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 Block() {
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
@ -1196,6 +1234,14 @@ namespace chaiscript
|
|||||||
retval = true;
|
retval = true;
|
||||||
saw_eol = false;
|
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()) {
|
else if (Statement()) {
|
||||||
if (!saw_eol) {
|
if (!saw_eol) {
|
||||||
throw Parse_Error("Two expressions missing line separator", match_stack.back());
|
throw Parse_Error("Two expressions missing line separator", match_stack.back());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user