diff options
author | Araq <rumpf_a@web.de> | 2014-12-23 23:08:37 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-12-23 23:08:37 +0100 |
commit | 59e279ba9cd0cedb8021c9f8cd425cb38e128224 (patch) | |
tree | 58b39db0b5e51918236cb242fa8d207b5d791b7e | |
parent | ea4160b23ff154000b79b554c40565875c59a216 (diff) | |
download | Nim-59e279ba9cd0cedb8021c9f8cd425cb38e128224.tar.gz |
fixes a small bug concerning semicolons for top level statements
-rw-r--r-- | compiler/parser.nim | 6 | ||||
-rw-r--r-- | tests/parser/tprecedence.nim | 8 |
2 files changed, 10 insertions, 4 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index a91760e15..87565ae3a 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -1980,15 +1980,17 @@ proc parseTopLevelStmt(p: var TParser): PNode = ## top-level statement or emptyNode if end of stream. result = ast.emptyNode while true: - if p.tok.indent != 0: + if p.tok.indent != 0: if p.firstTok and p.tok.indent < 0: discard - else: parMessage(p, errInvalidIndentation) + elif p.tok.tokType != tkSemiColon: + parMessage(p, errInvalidIndentation) p.firstTok = false case p.tok.tokType of tkSemiColon: getTok(p) if p.tok.indent <= 0: discard else: parMessage(p, errInvalidIndentation) + p.firstTok = true of tkEof: break else: result = complexOrSimpleStmt(p) diff --git a/tests/parser/tprecedence.nim b/tests/parser/tprecedence.nim index 6b1b250a2..d2c6d0b30 100644 --- a/tests/parser/tprecedence.nim +++ b/tests/parser/tprecedence.nim @@ -1,11 +1,15 @@ discard """ - output: "true" + output: '''holla +true''' """ +# Test top level semicolon works properly: +import os; echo "holla" + # Test the new predence rules proc `\+` (x, y: int): int = result = x + y proc `\*` (x, y: int): int = result = x * y -echo 5 \+ 1 \* 9 == 14 +echo 5 \+ 1 \* 9 == 6*9 |