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.
This commit is contained in:
Adam Strzelecki
2015-06-02 21:56:44 +02:00
committed by Oscar Campbell
parent 07c40add8f
commit 83369f4bce

View File

@@ -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: