diff options
author | Adam Strzelecki <ono@java.pl> | 2015-06-02 21:56:44 +0200 |
---|---|---|
committer | Adam Strzelecki <ono@java.pl> | 2015-06-02 21:58:14 +0200 |
commit | b0db8126a52fd48352b0b2ce8c7d99e0c98083ef (patch) | |
tree | 0fadc191680eff794b70befbf7d002a7ab11e9cf | |
parent | 2f5ed17cfe21011dfba30dc10ea7f478c0d67d21 (diff) | |
download | Nim-b0db8126a52fd48352b0b2ce8c7d99e0c98083ef.tar.gz |
Parser: Inline expr pragmas with parenthesis
Previously pragmas could be attached only to whole statements, this change allows attaching pragmas to inline statements, eg.: template rewriteAdd{a + b}(a: expr, b: expr): expr = ({.noRewrite.}: a + b) + 1 Code above will cause a + b to be rewritten once, because rewriteAdd attaches {.noRewrite.} to resulting a + b expr.
-rw-r--r-- | compiler/parser.nim | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index 18ef06e64..05b4df13d 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -64,6 +64,7 @@ proc setBaseFlags*(n: PNode, base: TNumericalBase) proc parseSymbol*(p: var TParser, allowNil = false): PNode proc parseTry(p: var TParser; isExpr: bool): PNode proc parseCase(p: var TParser): PNode +proc parseStmtPragma(p: var TParser): PNode # implementation proc getTok(p: var TParser) = @@ -502,6 +503,7 @@ proc parsePar(p: var TParser): PNode = #| par = '(' optInd #| ( &parKeyw complexOrSimpleStmt ^+ ';' #| | ';' complexOrSimpleStmt ^+ ';' + #| | pragmaStmt #| | simpleExpr ( ('=' expr (';' complexOrSimpleStmt ^+ ';' )? ) #| | (':' expr (',' exprColonEqExpr ^+ ',' )? ) ) ) #| optPar ')' @@ -523,6 +525,8 @@ proc parsePar(p: var TParser): PNode = getTok(p) optInd(p, result) semiStmtList(p, result) + elif p.tok.tokType == tkCurlyDotLe: + result.add(parseStmtPragma(p)) elif p.tok.tokType != tkParRi: var a = simpleExpr(p) if p.tok.tokType == tkEquals: |