Move projectPath into Preserves library
This commit is contained in:
parent
00609f3b6f
commit
090b4d77ef
|
@ -364,16 +364,10 @@ func analyse*(p: Pattern): Analysis =
|
||||||
var path: Path
|
var path: Path
|
||||||
walk(result, path, p)
|
walk(result, path, p)
|
||||||
|
|
||||||
func projectPath*(v: Value; path: Path): Option[Value] =
|
|
||||||
result = some(v)
|
|
||||||
for index in path:
|
|
||||||
result = preserves.step(result.get, index)
|
|
||||||
if result.isNone: break
|
|
||||||
|
|
||||||
func projectPaths*(v: Value; paths: Paths): Option[Captures] =
|
func projectPaths*(v: Value; paths: Paths): Option[Captures] =
|
||||||
var res = newSeq[Value](paths.len)
|
var res = newSeq[Value](paths.len)
|
||||||
for i, path in paths:
|
for i, path in paths:
|
||||||
var vv = projectPath(v, path)
|
var vv = step(v, path)
|
||||||
if vv.isSome: res[i] = get(vv)
|
if vv.isSome: res[i] = get(vv)
|
||||||
else: return
|
else: return
|
||||||
some res
|
some res
|
||||||
|
@ -382,22 +376,22 @@ func matches*(pat: Pattern; pr: Value): bool =
|
||||||
let analysis = analyse(pat)
|
let analysis = analyse(pat)
|
||||||
assert analysis.constPaths.len == analysis.constValues.len
|
assert analysis.constPaths.len == analysis.constValues.len
|
||||||
for i, path in analysis.constPaths:
|
for i, path in analysis.constPaths:
|
||||||
let v = projectPath(pr, path)
|
let v = step(pr, path)
|
||||||
if v.isNone : return false
|
if v.isNone : return false
|
||||||
if analysis.constValues[i] != v.get: return false
|
if analysis.constValues[i] != v.get: return false
|
||||||
for path in analysis.capturePaths:
|
for path in analysis.capturePaths:
|
||||||
if isNone projectPath(pr, path): return false
|
if isNone step(pr, path): return false
|
||||||
true
|
true
|
||||||
|
|
||||||
func capture*(pat: Pattern; pr: Value): seq[Value] =
|
func capture*(pat: Pattern; pr: Value): seq[Value] =
|
||||||
let analysis = analyse(pat)
|
let analysis = analyse(pat)
|
||||||
assert analysis.constPaths.len == analysis.constValues.len
|
assert analysis.constPaths.len == analysis.constValues.len
|
||||||
for i, path in analysis.constPaths:
|
for i, path in analysis.constPaths:
|
||||||
let v = projectPath(pr, path)
|
let v = step(pr, path)
|
||||||
if v.isNone : return @[]
|
if v.isNone : return @[]
|
||||||
if analysis.constValues[i] != v.get: return @[]
|
if analysis.constValues[i] != v.get: return @[]
|
||||||
for path in analysis.capturePaths:
|
for path in analysis.capturePaths:
|
||||||
let v = projectPath(pr, path)
|
let v = step(pr, path)
|
||||||
if v.isNone: return @[]
|
if v.isNone: return @[]
|
||||||
result.add(get v)
|
result.add(get v)
|
||||||
|
|
||||||
|
|
|
@ -215,7 +215,7 @@ proc extendWalk(node: Node; popCount: Natural; stepIndex: Value; pat: Pattern; p
|
||||||
table[class] = result.nextNode
|
table[class] = result.nextNode
|
||||||
new result.nextNode.continuation
|
new result.nextNode.continuation
|
||||||
for a in node.continuation.cache:
|
for a in node.continuation.cache:
|
||||||
var v = projectPath(a, path)
|
var v = step(a, path)
|
||||||
if v.isSome and class == classOf(get v):
|
if v.isSome and class == classOf(get v):
|
||||||
result.nextNode.continuation.cache.incl a
|
result.nextNode.continuation.cache.incl a
|
||||||
result.popCount = 0
|
result.popCount = 0
|
||||||
|
|
|
@ -9,4 +9,4 @@ srcDir = "src"
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
requires "https://github.com/khchen/hashlib.git#84e0247555e4488594975900401baaf5bbbfb531", "nim >= 2.0.0", "https://git.syndicate-lang.org/ehmry/preserves-nim.git >= 20231019"
|
requires "https://github.com/khchen/hashlib.git#84e0247555e4488594975900401baaf5bbbfb531", "nim >= 2.0.0", "https://git.syndicate-lang.org/ehmry/preserves-nim.git >= 20231028"
|
||||||
|
|
Loading…
Reference in New Issue