diff options
author | Araq <rumpf_a@web.de> | 2014-11-12 02:36:59 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-11-12 02:36:59 +0100 |
commit | b2f577df23d5daae873df18ff345965f8dc7e47b (patch) | |
tree | 2307ab50c5aa1c3cd2f7d56dfda817bcf05a3da1 /lib/core/macros.nim | |
parent | 2d43fcafe0cedd4f78611dddccc31e1bef432aab (diff) | |
download | Nim-b2f577df23d5daae873df18ff345965f8dc7e47b.tar.gz |
fixes #1473
Diffstat (limited to 'lib/core/macros.nim')
-rw-r--r-- | lib/core/macros.nim | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim index db2bfa9a6..b61fe1d17 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -249,13 +249,29 @@ proc lineinfo*(n: PNimrodNode): string {.magic: "NLineInfo", noSideEffect.} ## returns the position the node appears in the original source file ## in the form filename(line, col) -proc parseExpr*(s: string): PNimrodNode {.magic: "ParseExprToAst", noSideEffect.} +proc internalParseExpr(s: string): PNimrodNode {. + magic: "ParseExprToAst", noSideEffect.} + +proc internalParseStmt(s: string): PNimrodNode {. + magic: "ParseStmtToAst", noSideEffect.} + +proc internalErrorFlag*(): string {.magic: "NError", noSideEffect.} + ## Some builtins set an error flag. This is then turned into a proper + ## exception. **Note**: Ordinary application code should not call this. + +proc parseExpr*(s: string): PNimrodNode {.noSideEffect, compileTime.} = ## Compiles the passed string to its AST representation. - ## Expects a single expression. + ## Expects a single expression. Raises ``ValueError`` for parsing errors. + result = internalParseExpr(s) + let x = internalErrorFlag() + if x.len > 0: raise newException(ValueError, x) -proc parseStmt*(s: string): PNimrodNode {.magic: "ParseStmtToAst", noSideEffect.} +proc parseStmt*(s: string): PNimrodNode {.noSideEffect, compileTime.} = ## Compiles the passed string to its AST representation. - ## Expects one or more statements. + ## Expects one or more statements. Raises ``ValueError`` for parsing errors. + result = internalParseStmt(s) + let x = internalErrorFlag() + if x.len > 0: raise newException(ValueError, x) proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst", noSideEffect.} ## Obtains the AST nodes returned from a macro or template invocation. |