pegs/re =~ warns about scope rule change; improved docs

This commit is contained in:
Araq 2013-05-08 15:49:04 +02:00
commit 44c4b945eb
4 changed files with 19 additions and 9 deletions

View file

@ -242,6 +242,7 @@ template `=~` *(s: string, pattern: TRegEx): expr =
bind maxSubPatterns
when not definedInScope(matches):
var matches {.inject.}: array[0..maxSubPatterns-1, string]
{.warning: "injected 'matches' might be affected by new scoping rules in 0.9.4".}
match(s, pattern, matches)
# ------------------------- more string handling ------------------------------

View file

@ -870,6 +870,7 @@ template `=~`*(s: string, pattern: TPeg): bool =
bind maxSubpatterns
when not definedInScope(matches):
var matches {.inject.}: array[0..maxSubpatterns-1, string]
{.warning: "injected 'matches' might be affected by new scoping rules in 0.9.4".}
match(s, pattern, matches)
# ------------------------- more string handling ------------------------------
@ -1718,6 +1719,7 @@ when isMainModule:
assert match("_______ana", peg"A <- 'ana' / . A")
assert match("abcs%%%", peg"A <- ..A / .A / '%'")
var matches: array[0..maxSubpatterns-1, string]
if "abc" =~ peg"{'a'}'bc' 'xyz' / {\ident}":
assert matches[0] == "abc"
else:
@ -1742,8 +1744,6 @@ when isMainModule:
else:
assert false
when not definedInScope(matches):
var matches: array[0..maxSubpatterns-1, string]
if match("abcdefg", peg"c {d} ef {g}", matches, 2):
assert matches[0] == "d"
assert matches[1] == "g"