p[] instead of p^

This commit is contained in:
Araq 2011-04-11 23:28:53 +02:00
commit 46c41e4369
32 changed files with 242 additions and 346 deletions

View file

@ -22,7 +22,7 @@ p.s[1] = "xyz"
p.e = en6
new(q)
q^ = p
q[] = p
s = @[q, q, q, q]

View file

@ -8,7 +8,7 @@ proc recTest(i: int) =
recTest(i+1)
else: # should printStackTrace()
var p: ptr int = nil
p^ = 12
p[] = 12
# leave
{.pop.}

View file

@ -0,0 +1,11 @@
discard """
output: 3
"""
var x: ref int
new(x)
x[] = 3
echo x[]

View file

@ -115,7 +115,7 @@ proc charSet*(s: set[char]): TPeg {.rtl, extern: "npegs$1".} =
assert '\0' notin s
result.kind = pkCharChoice
new(result.charChoice)
result.charChoice^ = s
result.charChoice[] = s
proc len(a: TPeg): int {.inline.} = return a.sons.len
proc add(d: var TPeg, s: TPeg) {.inline.} = add(d.sons, s)
@ -130,7 +130,7 @@ proc copyPeg(a: TPeg): TPeg =
result.ch = a.ch
of pkCharChoice, pkGreedyRepSet:
new(result.charChoice)
result.charChoice^ = a.charChoice^
result.charChoice[] = a.charChoice[]
of pkNonTerminal: result.nt = a.nt
of pkBackRef..pkBackRefIgnoreStyle:
result.index = a.index
@ -143,9 +143,9 @@ proc addChoice(dest: var TPeg, elem: TPeg) =
# caution! Do not introduce false aliasing here!
case elem.kind
of pkCharChoice:
dest.sons[L] = charSet(dest.sons[L].charChoice^ + elem.charChoice^)
dest.sons[L] = charSet(dest.sons[L].charChoice[] + elem.charChoice[])
of pkChar:
dest.sons[L] = charSet(dest.sons[L].charChoice^ + {elem.ch})
dest.sons[L] = charSet(dest.sons[L].charChoice[] + {elem.ch})
else: add(dest, elem)
else: add(dest, elem)
@ -447,7 +447,7 @@ proc toStrAux(r: TPeg, res: var string) =
add(res, 'y')
add(res, singleQuoteEsc(r.term))
of pkChar: add(res, singleQuoteEsc(r.ch))
of pkCharChoice: add(res, charSetEsc(r.charChoice^))
of pkCharChoice: add(res, charSetEsc(r.charChoice[]))
of pkNonTerminal: add(res, r.nt.name)
of pkSequence:
add(res, '(')
@ -470,7 +470,7 @@ proc toStrAux(r: TPeg, res: var string) =
add(res, singleQuoteEsc(r.ch))
add(res, '*')
of pkGreedyRepSet:
add(res, charSetEsc(r.charChoice^))
add(res, charSetEsc(r.charChoice[]))
add(res, '*')
of pkGreedyAny:
add(res, ".*")
@ -652,7 +652,7 @@ proc rawMatch*(s: string, p: TPeg, start: int, c: var TCaptures): int {.
if p.ch == s[start]: result = 1
else: result = -1
of pkCharChoice:
if contains(p.charChoice^, s[start]): result = 1
if contains(p.charChoice[], s[start]): result = 1
else: result = -1
of pkNonTerminal:
var oldMl = c.ml
@ -719,7 +719,7 @@ proc rawMatch*(s: string, p: TPeg, start: int, c: var TCaptures): int {.
while ch == s[start+result]: inc(result)
of pkGreedyRepSet:
result = 0
while contains(p.charChoice^, s[start+result]): inc(result)
while contains(p.charChoice[], s[start+result]): inc(result)
of pkOption:
result = max(0, rawMatch(s, p.sons[0], start, c))
of pkAndPredicate: