p[] instead of p^
This commit is contained in:
parent
3d696c3da5
commit
46c41e4369
32 changed files with 242 additions and 346 deletions
|
|
@ -22,7 +22,7 @@ p.s[1] = "xyz"
|
|||
p.e = en6
|
||||
|
||||
new(q)
|
||||
q^ = p
|
||||
q[] = p
|
||||
|
||||
s = @[q, q, q, q]
|
||||
|
||||
|
|
|
|||
|
|
@ -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.}
|
||||
|
|
|
|||
11
tests/accept/run/tnewderef.nim
Normal file
11
tests/accept/run/tnewderef.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
discard """
|
||||
output: 3
|
||||
|
||||
"""
|
||||
|
||||
var x: ref int
|
||||
new(x)
|
||||
x[] = 3
|
||||
|
||||
echo x[]
|
||||
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue