Merge pull request #2019 from MasonMcGill/devel

Added a few AST-construction shortcuts.
This commit is contained in:
Dominik Picheta 2015-01-27 23:32:29 +00:00
commit 85ae439bb8

View file

@ -466,6 +466,10 @@ proc newStmtList*(stmts: varargs[PNimrodNode]): PNimrodNode {.compileTime.}=
## Create a new statement list ## Create a new statement list
result = newNimNode(nnkStmtList).add(stmts) 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.} = proc newBlockStmt*(label, body: PNimrodNode): PNimrodNode {.compileTime.} =
## Create a new block statement with label ## Create a new block statement with label
return newNimNode(nnkBlockStmt).add(label, body) return newNimNode(nnkBlockStmt).add(label, body)
@ -484,6 +488,11 @@ proc newLetStmt*(name, value: PNimrodNode): PNimrodNode {.compiletime.} =
return newNimNode(nnkLetSection).add( return newNimNode(nnkLetSection).add(
newNimNode(nnkIdentDefs).add(name, newNimNode(nnkEmpty), value)) 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.} = proc newAssignment*(lhs, rhs: PNimrodNode): PNimrodNode {.compileTime.} =
return newNimNode(nnkAsgn).add(lhs, rhs) return newNimNode(nnkAsgn).add(lhs, rhs)
@ -492,6 +501,11 @@ proc newDotExpr*(a, b: PNimrodNode): PNimrodNode {.compileTime.} =
## a.dot(b) -> `a.b` ## a.dot(b) -> `a.b`
return newNimNode(nnkDotExpr).add(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; proc newIdentDefs*(name, kind: PNimrodNode;
default = newEmptyNode()): PNimrodNode {.compileTime.} = default = newEmptyNode()): PNimrodNode {.compileTime.} =
## Creates a new ``nnkIdentDefs`` node of a specific kind and value. ## Creates a new ``nnkIdentDefs`` node of a specific kind and value.