Schemas: fix embedded pattern

This commit is contained in:
Emery Hemingway 2021-08-15 13:17:19 +02:00
parent 16c8ce62ff
commit 50b71b8651
1 changed files with 7 additions and 3 deletions

View File

@ -47,6 +47,8 @@ type
of snkAny: discard
of snkAtom:
atom*: AtomKind
of snkEmbedded:
embed*: SchemaNode
of snkLiteral:
value*: Preserve
of snkNamed:
@ -90,7 +92,7 @@ proc `$`*(n: SchemaNode): string =
of snkAny: result.add "any"
of snkAtom: result.add $n.atom
of snkEmbedded:
result.add "#!" & $n.nodes[0]
result.add "#!" & $n.embed
of snkLiteral:
case n.value.kind
of pkBoolean, pkFloat, pkDouble, pkSignedInteger, pkString, pkByteString, pkSymbol:
@ -221,6 +223,8 @@ const parser = peg("Schema", p: ParseState):
match(readFile $1, p)
Definition <- >id * S * '=' * S * (OrPattern | AndPattern | Pattern):
if p.schema.definitions.hasKey $1:
raise newException(ValueError, "duplicate definition of " & $1)
p.schema.definitions[$1] = popStack()
p.stack.setLen(0)
@ -304,8 +308,8 @@ const parser = peg("Schema", p: ParseState):
of "symbol": n.atom = akSymbol
pushStack n
EmbeddedPattern <- "embedded":
let n = newSchemaNode(snkEmbedded)
EmbeddedPattern <- "#!" * SimplePattern:
let n = SchemaNode(kind: snkEmbedded, embed: popStack())
pushStack n
LiteralPattern <- ('=' * >symbol) | ("<<lit>" * >Preserves.Value * ">") | >nonSymbolAtom: