Skip to content

Commit

Permalink
internal: reorder ParsedNodeKind for range checks (#907)
Browse files Browse the repository at this point in the history
## Summary

Reorder `ParsedNodeKind` for range checks, and added named sets to
support querying parsed node kinds.

## Details

Reorder `ParsedNodeKind` in order to support ranges over similar kinds.
This is considered experimental as the motivation for the reodering came
from usage in `suggest` (a consumer). The ordering should be determined
by the `parser` (the producer). Creating these seemingly convenient
consumer/read side ranges end up quietly coupling the producer and
consumer(s). Which results in refactorings to a small collection of
parser modules spilling out to changes in various consumer locations. In
this case these might coincide with the parser's needs, as well.

Additionally, added `pnkDeclarativeDefs` and `pnkRoutineDefs` similar to
`PNode`'s kind, `TNodeKind`.

---------

Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
  • Loading branch information
bung87 and saem authored Sep 21, 2023
1 parent 8beb528 commit 37263e3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compiler/ast/ast_parsed_types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ type
pnkPostfix
pnkExprEqExpr
pnkExprColonExpr
pnkIdentDefs
pnkConstDef
pnkVarTuple
pnkPar
pnkSqrBracket
pnkCurly
Expand Down Expand Up @@ -174,6 +171,7 @@ type
pnkIncludeStmt
pnkExportStmt
pnkExportExceptStmt
pnkTypeSection
pnkConstSection
pnkLetSection
pnkVarSection
Expand All @@ -184,8 +182,10 @@ type
pnkIteratorDef
pnkMacroDef
pnkTemplateDef
pnkTypeSection
pnkIdentDefs
pnkConstDef
pnkTypeDef
pnkVarTuple
pnkEnumTy
pnkEnumFieldDef
pnkObjectTy
Expand Down Expand Up @@ -265,6 +265,8 @@ const
pnkFloatKinds* = {pnkFloatLit..pnkFloat128Lit}
pnkIntKinds* = {pnkCharLit..pnkUInt64Lit}
pnkStrKinds* = {pnkStrLit..pnkTripleStrLit}
pnkDeclarativeDefs* = {pnkProcDef, pnkFuncDef, pnkMethodDef, pnkIteratorDef, pnkConverterDef}
pnkRoutineDefs* = pnkDeclarativeDefs + {pnkMacroDef, pnkTemplateDef}

func len*(node: ParsedNode): int =
## Number of sons of the parsed node
Expand Down

0 comments on commit 37263e3

Please sign in to comment.