put the new for loop macros under an experimental switch named 'forLoopMacros'

This commit is contained in:
Andreas Rumpf 2018-08-15 17:45:57 +02:00
commit da41fc1801
4 changed files with 13 additions and 5 deletions

View file

@ -111,14 +111,16 @@ type
ideNone, ideSug, ideCon, ideDef, ideUse, ideDus, ideChk, ideMod, ideNone, ideSug, ideCon, ideDef, ideUse, ideDus, ideChk, ideMod,
ideHighlight, ideOutline, ideKnown, ideMsg ideHighlight, ideOutline, ideKnown, ideMsg
Feature* = enum ## experimental features Feature* = enum ## experimental features; DO NOT RENAME THESE!
implicitDeref, implicitDeref,
dotOperators, dotOperators,
callOperator, callOperator,
parallel, parallel,
destructor, destructor,
notnil, notnil,
dynamicBindSym dynamicBindSym,
forLoopMacros
#caseStmtMacros
SymbolFilesOption* = enum SymbolFilesOption* = enum
disabledSf, writeOnlySf, readOnlySf, v2Sf disabledSf, writeOnlySf, readOnlySf, v2Sf

View file

@ -720,6 +720,7 @@ proc handleForLoopMacro(c: PContext; n: PNode): PNode =
proc semFor(c: PContext, n: PNode): PNode = proc semFor(c: PContext, n: PNode): PNode =
checkMinSonsLen(n, 3, c.config) checkMinSonsLen(n, 3, c.config)
var length = sonsLen(n) var length = sonsLen(n)
if forLoopMacros in c.features:
result = handleForLoopMacro(c, n) result = handleForLoopMacro(c, n)
if result != nil: return result if result != nil: return result
openScope(c) openScope(c)

View file

@ -5380,6 +5380,7 @@ type ``system.ForLoopStmt`` can rewrite the entirety of a ``for`` loop:
:test: "nim c $1" :test: "nim c $1"
import macros import macros
{.experimental: "forLoopMacros".}
macro enumerate(x: ForLoopStmt): untyped = macro enumerate(x: ForLoopStmt): untyped =
expectKind x, nnkForStmt expectKind x, nnkForStmt
@ -5406,6 +5407,10 @@ type ``system.ForLoopStmt`` can rewrite the entirety of a ``for`` loop:
echo a2, " ", b2 echo a2, " ", b2
Currently for loop macros must be enabled explicitly
via ``{.experimental: "forLoopMacros".}``.
Special Types Special Types
============= =============

View file

@ -12,7 +12,7 @@ discard """
""" """
import macros import macros
{.experimental: "forLoopMacros".}
macro mymacro(): untyped = macro mymacro(): untyped =
result = newLit([1, 2, 3]) result = newLit([1, 2, 3])