Merge pull request #2019 from MasonMcGill/devel
Added a few AST-construction shortcuts.
This commit is contained in:
commit
85ae439bb8
1 changed files with 51 additions and 37 deletions
|
|
@ -466,6 +466,10 @@ proc newStmtList*(stmts: varargs[PNimrodNode]): PNimrodNode {.compileTime.}=
|
|||
## Create a new statement list
|
||||
result = newNimNode(nnkStmtList).add(stmts)
|
||||
|
||||
proc newPar*(exprs: varargs[PNimrodNode]): PNimrodNode {.compileTime.}=
|
||||
## Create a new parentheses-enclosed expression
|
||||
newNimNode(nnkPar).add(exprs)
|
||||
|
||||
proc newBlockStmt*(label, body: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||
## Create a new block statement with label
|
||||
return newNimNode(nnkBlockStmt).add(label, body)
|
||||
|
|
@ -484,6 +488,11 @@ proc newLetStmt*(name, value: PNimrodNode): PNimrodNode {.compiletime.} =
|
|||
return newNimNode(nnkLetSection).add(
|
||||
newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value))
|
||||
|
||||
proc newConstStmt*(name, value: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||
## Create a new const stmt
|
||||
newNimNode(nnkConstSection).add(
|
||||
newNimNode(nnkConstDef).add(name, newNimNode(nnkEmpty), value))
|
||||
|
||||
proc newAssignment*(lhs, rhs: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||
return newNimNode(nnkAsgn).add(lhs, rhs)
|
||||
|
||||
|
|
@ -492,6 +501,11 @@ proc newDotExpr*(a, b: PNimrodNode): PNimrodNode {.compileTime.} =
|
|||
## a.dot(b) -> `a.b`
|
||||
return newNimNode(nnkDotExpr).add(a, b)
|
||||
|
||||
proc newColonExpr*(a, b: PNimrodNode): PNimrodNode {.compileTime.} =
|
||||
## Create new colon expression
|
||||
## newColonExpr(a, b) -> `a: b`
|
||||
newNimNode(nnkExprColonExpr).add(a, b)
|
||||
|
||||
proc newIdentDefs*(name, kind: PNimrodNode;
|
||||
default = newEmptyNode()): PNimrodNode {.compileTime.} =
|
||||
## Creates a new ``nnkIdentDefs`` node of a specific kind and value.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue