Skip to content

Commit

Permalink
parser refactor follow-up code style fixes
Browse files Browse the repository at this point in the history
follow-up PR for review comments from the
nim-works#425
  • Loading branch information
haxscramper committed Sep 4, 2022
1 parent 65dd4c2 commit a9ba94d
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
6 changes: 3 additions & 3 deletions compiler/ast/ast_parsed_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import
lexer # For the token type definition
]

# NOTE further refactoring considerations for the parser
# NOTE further refactoring considerations for the parser:
#
# - store everything in tokens, do not require identifier interning for any
# purposes during the parsing stage, it must be done later, during
Expand Down Expand Up @@ -49,7 +49,7 @@ type
# flag in the first place?

func len*(node: ParsedNode): int =
## Number of the sons of a parsed node
## Number of sons of the parsed node
return node.sons.len()

# NOTE added for the sake of API similarity between PNode
Expand All @@ -70,7 +70,7 @@ iterator pairs*(node: ParsedNode): (int, ParsedNode) =
yield (idx, item)

proc add*(node: ParsedNode, other: ParsedNode) =
## Add new element to the sons
## append `other` to `node`'s `sons`
node.sons.add(other)

proc transitionSonsKind*(n: ParsedNode, kind: TNodeKind) =
Expand Down
1 change: 0 additions & 1 deletion compiler/ast/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ proc skipInd*(p: var Parser)
proc optPar*(p: var Parser)
proc optInd*(p: var Parser, n: ParsedNode)
proc indAndComment*(p: var Parser, n: ParsedNode, maybeMissEquals = false)
# proc setBaseFlags*(n: ParsedNode, base: NumericalBase)
proc parseSymbol*(p: var Parser, mode = smNormal): ParsedNode
proc parseTry(p: var Parser; isExpr: bool): ParsedNode
proc parseCase(p: var Parser): ParsedNode
Expand Down
7 changes: 3 additions & 4 deletions compiler/ast/reports.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,12 @@ type

reportInst*: ReportLineInfo ## Information about instantiation location
## of the reports - present for all reports in order to track their
## origins throught the compiler.
## origin withing the compiler.

reportFrom*: ReportLineInfo ## Information about submit location of the
## report. Contains information about the place where report was
## /submitted/ to the system - sometimes report might be created,
## modified to add new information and only them put into the pipeline.

## /submitted/ to the system - sometimes a report is created, modified
## to add new information, and only then put into the pipeline.

type
LexerReport* = object of ReportBase
Expand Down
4 changes: 1 addition & 3 deletions compiler/sem/lookups.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ import
modulegraphs
],
compiler/utils/[
debugutils,
astrepr
debugutils
],
compiler/front/[
msgs,
Expand Down Expand Up @@ -741,7 +740,6 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
result = errorExpectedIdentifier(c, ident, wrongNode, errExprCtx)
elif checkModule in flags:
result = searchInScopes(c, ident, amb).skipAlias(n, c.config)
# debug(result, verboseTReprConf)
# xxx: search in scopes can return an skError -- this happens because
# skError is a const referring to skUnknown, which gets used in resolving
# `result`, which starts off as undeclared/unknown.
Expand Down
12 changes: 4 additions & 8 deletions compiler/sem/passes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import
lineinfos,
],
compiler/utils/[
pathutils,
astrepr
pathutils
]

type
Expand Down Expand Up @@ -90,7 +89,7 @@ proc processTopLevelStmt(
toProcess: PNode,
a: var TPassContextArray): bool =
## Main processing pipeline entry point - accepts a toplevel node,
## collection of pass contexts and main module graph which defines passes
## collection of pass contexts and a main module graph which defines passes
## to use.
# First step works with the base tree as entry point
var processingResult = toProcess
Expand All @@ -100,9 +99,6 @@ proc processTopLevelStmt(
# results each time.
processingResult = graph.passes[i].process(a[i], processingResult)
if isNil(processingResult):
# QUESTION this is an error/fatal diagnostic or some parts of the
# compiler are expected to return `nil` on failure? If the latter
# is true, which ones?
return false

result = true
Expand Down Expand Up @@ -185,7 +181,7 @@ proc processModule*(
if defaultStream.isNil():
let filename = toFullPathConsiderDirty(graph.config, fileIdx)
stream = llStreamOpen(filename, fmRead)
if stream == nil:
if stream.isNil():
localReport(
graph.config,
reportStr(rsemCannotOpenFile, filename.string))
Expand Down Expand Up @@ -280,7 +276,7 @@ proc processModule*(
processingOk = processTopLevelStmt(
graph, toplevelStatements, passesArray)

if rest != nil and processingOk:
if not rest.isNil() and processingOk:
processingOk = processTopLevelStmt(
graph, rest, passesArray)

Expand Down
3 changes: 1 addition & 2 deletions compiler/sem/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import
compiler/utils/[
ropes,
pathutils,
debugUtils,
astrepr
debugutils
],
compiler/sem/[
semdata,
Expand Down

0 comments on commit a9ba94d

Please sign in to comment.