From b3ac785f95950791ae342d8973864684c78cc09b Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 3 Jun 2013 08:05:32 +0200 Subject: [PATCH] fixes semicolon parsing issue --- compiler/parser.nim | 14 +++++++++----- doc/grammar.txt | 2 +- tests/run/tstmtexprs.nim | 5 +++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/compiler/parser.nim b/compiler/parser.nim index 7cfd35a414..46294925d4 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1748,7 +1748,7 @@ proc complexOrSimpleStmt(p: var TParser): PNode = proc parseStmt(p: var TParser): PNode = #| stmt = (IND{>} complexOrSimpleStmt^+(IND{=} / ';') DED) - #| / simpleStmt + #| / simpleStmt ^+ ';' if p.tok.indent > p.currInd: result = newNodeP(nkStmtList, p) withInd(p): @@ -1779,10 +1779,14 @@ proc parseStmt(p: var TParser): PNode = parMessage(p, errComplexStmtRequiresInd) result = ast.emptyNode else: - if p.tok.indent >= 0: parMessage(p, errInvalidIndentation) - result = simpleStmt(p) - if result.kind == nkEmpty: parMessage(p, errExprExpected, p.tok) - #while p.tok.tokType == tkSemicolon: getTok(p) + result = newNodeP(nkStmtList, p) + while true: + if p.tok.indent >= 0: parMessage(p, errInvalidIndentation) + let a = simpleStmt(p) + if a.kind == nkEmpty: parMessage(p, errExprExpected, p.tok) + result.add(a) + if p.tok.tokType != tkSemicolon: break + getTok(p) proc parseAll(p: var TParser): PNode = result = newNodeP(nkStmtList, p) diff --git a/doc/grammar.txt b/doc/grammar.txt index 3aa556ce3d..741e9b9071 100644 --- a/doc/grammar.txt +++ b/doc/grammar.txt @@ -186,4 +186,4 @@ complexOrSimpleStmt = (ifStmt | whenStmt | whileStmt | bindStmt | mixinStmt) / simpleStmt stmt = (IND{>} complexOrSimpleStmt^+(IND{=} / ';') DED) - / simpleStmt + / simpleStmt ^+ ';' diff --git a/tests/run/tstmtexprs.nim b/tests/run/tstmtexprs.nim index a69acd98bf..497a2f6d05 100644 --- a/tests/run/tstmtexprs.nim +++ b/tests/run/tstmtexprs.nim @@ -64,3 +64,8 @@ proc p2(a: int): int = q() echo p(), " ", p2(2) + +proc semiProblem() = + if false: echo "aye"; echo "indeed" + +semiProblem()