Support '.' in Ref

This commit is contained in:
Emery Hemingway 2021-08-15 17:16:54 +02:00
parent c449d41759
commit 1644736625
1 changed files with 5 additions and 4 deletions

View File

@ -55,7 +55,7 @@ type
name*: string name*: string
pattern*: SchemaNode pattern*: SchemaNode
of snkRef: of snkRef:
def*: string refPath*: seq[string]
else: else:
nodes*: seq[SchemaNode] nodes*: seq[SchemaNode]
@ -139,7 +139,7 @@ proc `$`*(n: SchemaNode): string =
result.add ' ' result.add ' '
result.add $n.pattern result.add $n.pattern
of snkRef: of snkRef:
result.add n.def result.add join(n.refPath, ".")
proc `$`*(scm: Schema): string = proc `$`*(scm: Schema): string =
result.add("version = $1 .\n" % $scm.version) result.add("version = $1 .\n" % $scm.version)
@ -328,8 +328,9 @@ const parser = peg("Schema", p: ParseState):
assert(n.nodes.len == 2, $n.nodes) assert(n.nodes.len == 2, $n.nodes)
pushStack n pushStack n
Ref <- id: Ref <- >(Alpha * *Alnum) * *('.' * >(*Alnum)):
let n = SchemaNode(kind: snkRef, def: $0) let n = SchemaNode(kind: snkRef)
for i in 1..<capture.len: n.refPath.add capture[i].s
pushStack n pushStack n
CompoundPattern <- CompoundPattern <-