first steps to make templates hygienic

This commit is contained in:
Araq 2012-08-20 01:13:13 +02:00
commit 5e15dec175
23 changed files with 486 additions and 187 deletions

View file

@ -218,6 +218,9 @@ proc findAll*(s: string, pattern: TRegEx, start = 0): seq[string] =
## If it does not match, @[] is returned.
accumulateResult(findAll(s, pattern, start))
when not defined(nimhygiene):
{.pragma: inject.}
template `=~` *(s: string, pattern: TRegEx): expr =
## This calls ``match`` with an implicit declared ``matches`` array that
## can be used in the scope of the ``=~`` call:
@ -237,7 +240,7 @@ template `=~` *(s: string, pattern: TRegEx): expr =
## echo("syntax error")
##
when not definedInScope(matches):
var matches: array[0..re.maxSubPatterns-1, string]
var matches {.inject.}: array[0..re.maxSubPatterns-1, string]
match(s, pattern, matches)
# ------------------------- more string handling ------------------------------