fixes #19662; Indent level errored for first line (#19718)

This commit is contained in:
flywind 2022-04-25 18:00:23 +08:00 • committed by GitHub
commit 42ac50e988
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

View file

@ -2393,6 +2393,10 @@ proc parseAll(p: var Parser): PNode =
if p.tok.indent != 0:
parMessage(p, errInvalidIndentation)
proc checkFirstLineIndentation*(p: var Parser) =
if p.tok.indent != 0 and p.tok.strongSpaceA > 0:
parMessage(p, errInvalidIndentation)
proc parseTopLevelStmt(p: var Parser): PNode =
## Implements an iterator which, when called repeatedly, returns the next
## top-level statement or emptyNode if end of stream.

View file

@ -150,6 +150,7 @@ proc processModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator;
processImplicits graph, graph.config.implicitImports, nkImportStmt, a, module
processImplicits graph, graph.config.implicitIncludes, nkIncludeStmt, a, module
checkFirstLineIndentation(p)
while true:
if graph.stopCompile(): break
var n = parseTopLevelStmt(p)

View file

@ -16,7 +16,7 @@ import
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
export Parser, parseAll, parseTopLevelStmt, closeParser
export Parser, parseAll, parseTopLevelStmt, checkFirstLineIndentation, closeParser
type
FilterKind = enum

6
tests/parser/t19662.nim Normal file
View file

@ -0,0 +1,6 @@
var i: int # bug #19662
echo i
discard """
errormsg: "invalid indentation"
"""