Browse Source

new ForStatement parsing test and small grammar fix

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
e934aa0bef
  1. 1
      libsolidity/Parser.cpp
  2. 2
      libsolidity/grammar.txt
  3. 16
      test/solidityParser.cpp

1
libsolidity/Parser.cpp

@ -381,7 +381,6 @@ ASTPointer<ForStatement> Parser::parseForStatement()
ASTPointer<Expression> conditionExpression = parseExpression();
expectToken(Token::SEMICOLON);
ASTPointer<ExpressionStatement> loopExpression = parseExpressionStatement();
expectToken(Token::SEMICOLON);
expectToken(Token::RPAREN);
ASTPointer<Statement> body = parseStatement();
nodeFactory.setEndPositionFromNode(body);

2
libsolidity/grammar.txt

@ -20,7 +20,7 @@ Statement = IfStatement | WhileStatement | Block |
IfStatement = 'if' '(' Expression ')' Statement ( 'else' Statement )?
WhileStatement = 'while' '(' Expression ')' Statement
ForStatement = 'for' '(' Expressionstatement Expression Expressionstatement ')' Statement
ForStatement = 'for' '(' VardefOrExpressionstatement ';' Expression ';' Expressionstatement ')' Statement
Continue = 'continue' ';'
Break = 'break' ';'
Return = 'return' Expression? ';'

16
test/solidityParser.cpp

@ -374,11 +374,23 @@ BOOST_AUTO_TEST_CASE(while_loop)
BOOST_CHECK_NO_THROW(parseText(text));
}
BOOST_AUTO_TEST_CASE(for_loop)
BOOST_AUTO_TEST_CASE(for_loop_vardef_initexpr)
{
char const* text = "contract test {\n"
" function fun(uint256 a) {\n"
" for (uint256 i = 0; i < 10; i++;)\n"
" for (uint256 i = 0; i < 10; i++)\n"
" { uint256 x = i; break; continue; }\n"
" }\n"
"}\n";
BOOST_CHECK_NO_THROW(parseTextExplainError(text));
}
BOOST_AUTO_TEST_CASE(for_loop_simple_initexpr)
{
char const* text = "contract test {\n"
" function fun(uint256 a) {\n"
" uint256 i =0;\n"
" for (i = 0; i < 10; i++)\n"
" { uint256 x = i; break; continue; }\n"
" }\n"
"}\n";

Loading…
Cancel
Save