Files
Nim/tests/macros/ttryparseexpr.nim
Jake Leahy 0bd4d80238 Allow parseAll to parse statements separated by semicolons (#23088)
Fixes the second issue listed in #9918.

Fixed by replacing the logic used in `parseAll` with just a continious
loop to `complexOrSimpleStmt` like what the [normal parser
does](https://github.com/nim-lang/Nim/blob/devel/compiler/passes.nim#L143-L146).
`complexOrSimpleStmt` [guarantees
progress](https://github.com/nim-lang/Nim/blob/devel/compiler/parser.nim#L2541)
so we don't need to check progress ourselves.

Also allows `nimpretty` to parse more valid Nim code such as 
```nim
proc foo(); # Would complain about indention here
# ...
proc foo() = 
  # ...
```
2023-12-17 09:01:00 +01:00

25 lines
433 B
Nim

discard """
outputsub: '''Error: expression expected, but found '[EOF]' 45'''
"""
# feature request #1473
import macros
macro test(text: string): untyped =
try:
result = parseExpr(text.strVal)
except ValueError:
result = newLit getCurrentExceptionMsg()
const
valid = 45
a = test("foo&&")
b = test("valid")
c = test("\"") # bug #2504
echo a, " ", b
static:
# Issue #9918
discard parseStmt("echo(1+1);")