fixes a small bug concerning semicolons for top level statements
This commit is contained in:
parent
ea4160b23f
commit
59e279ba9c
2 changed files with 10 additions and 4 deletions
|
|
@ -1980,15 +1980,17 @@ proc parseTopLevelStmt(p: var TParser): PNode =
|
||||||
## top-level statement or emptyNode if end of stream.
|
## top-level statement or emptyNode if end of stream.
|
||||||
result = ast.emptyNode
|
result = ast.emptyNode
|
||||||
while true:
|
while true:
|
||||||
if p.tok.indent != 0:
|
if p.tok.indent != 0:
|
||||||
if p.firstTok and p.tok.indent < 0: discard
|
if p.firstTok and p.tok.indent < 0: discard
|
||||||
else: parMessage(p, errInvalidIndentation)
|
elif p.tok.tokType != tkSemiColon:
|
||||||
|
parMessage(p, errInvalidIndentation)
|
||||||
p.firstTok = false
|
p.firstTok = false
|
||||||
case p.tok.tokType
|
case p.tok.tokType
|
||||||
of tkSemiColon:
|
of tkSemiColon:
|
||||||
getTok(p)
|
getTok(p)
|
||||||
if p.tok.indent <= 0: discard
|
if p.tok.indent <= 0: discard
|
||||||
else: parMessage(p, errInvalidIndentation)
|
else: parMessage(p, errInvalidIndentation)
|
||||||
|
p.firstTok = true
|
||||||
of tkEof: break
|
of tkEof: break
|
||||||
else:
|
else:
|
||||||
result = complexOrSimpleStmt(p)
|
result = complexOrSimpleStmt(p)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
discard """
|
discard """
|
||||||
output: "true"
|
output: '''holla
|
||||||
|
true'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Test top level semicolon works properly:
|
||||||
|
import os; echo "holla"
|
||||||
|
|
||||||
# Test the new predence rules
|
# Test the new predence rules
|
||||||
|
|
||||||
proc `\+` (x, y: int): int = result = x + y
|
proc `\+` (x, y: int): int = result = x + y
|
||||||
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
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue