diff options
author | Araq <rumpf_a@web.de> | 2011-09-20 12:13:24 -0700 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2011-09-20 12:13:24 -0700 |
commit | 57f184cf48a0b522001ab20e2c742d4d6436e14d (patch) | |
tree | 6799fff3c4f1676548b93b537c8d814acec8eded /compiler/parser.nim | |
parent | bf386374020663452bfdbe3169845970d948cba6 (diff) | |
parent | 9acfc43119d42d7265497fd6ae60eda3903d9938 (diff) | |
download | Nim-57f184cf48a0b522001ab20e2c742d4d6436e14d.tar.gz |
Merge pull request #54 from zah/pretty-print-ast
String interpolation implemented in terms of macros
Diffstat (limited to 'compiler/parser.nim')
-rwxr-xr-x | compiler/parser.nim | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index 003bd9219..df21c9916 100755 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -30,6 +30,11 @@ proc closeParser*(p: var TParser) proc parseTopLevelStmt*(p: var TParser): PNode # implements an iterator. Returns the next top-level statement or # emtyNode if end of stream. + +proc parseString*(s: string, filename: string = "", line: int = 0): PNode + # filename and line could be set optionally, when the string originates + # from a certain source file. This way, the compiler could generate + # correct error messages referring to the original source. # helpers for the other parsers proc getPrecedence*(tok: TToken): int @@ -1369,3 +1374,14 @@ proc parseTopLevelStmt(p: var TParser): PNode = result = complexOrSimpleStmt(p) if result.kind == nkEmpty: parMessage(p, errExprExpected, p.tok) break + +proc parseString(s: string, filename: string = "", line: int = 0): PNode = + var stream = LLStreamOpen(s) + stream.lineOffset = line + + var parser : TParser + OpenParser(parser, filename, stream) + + result = parser.parseAll + CloseParser(parser) + |