Schema: do not overload `$` or encode for Preserve types

This commit is contained in:
Emery Hemingway 2021-10-20 13:59:48 +02:00
parent 5250707f0e
commit b6275a241b
1 changed files with 12 additions and 2 deletions

View File

@ -197,7 +197,7 @@ proc isEmbeddable(scm: Schema; orDef: DefinitionOr; seen: RefSet): bool =
isEmbeddable(scm, na.pattern, seen)
isEmbeddable(orDef.data.pattern0) or
isEmbeddable(orDef.data.pattern1) or
any(orDef.data.patternN, isEmbeddable)
sequtils.any(orDef.data.patternN, isEmbeddable)
proc isEmbeddable(scm: Schema; def: Definition; seen: RefSet): bool =
case def.orKind
@ -266,6 +266,16 @@ proc isSymbolEnum(scm: Schema; def: Definition): bool =
result = isSymbolEnum(scm, def.or)
else: discard
proc isAny(scm: Schema; def: Definition): bool =
if def.orKind == DefinitionKind.Pattern:
if def.pattern.orKind == PatternKind.SimplePattern:
case def.pattern.simplePattern.orKind
of SimplePatternKind.Ref:
result = isAny(scm, deref(scm, def.pattern.simplePattern.`ref`))
of SimplePatternKind.any:
result = true
else: discard
proc typeIdent(atom: AtomKind): PNode =
case atom
of AtomKind.`Boolean`: ident"bool"
@ -705,7 +715,7 @@ proc renderNimModule*(scm: Schema): string =
var name = name
name[0] = name[0].toUpperAscii
var defIdent = parameterize(ident(name), isEmbeddable(scm, def))
if not isSymbolEnum(scm, def):
if not isSymbolEnum(scm, def) and not isAny(scm, def):
if isEmbeddable(scm, def):
mergeType(embeddableType, defIdent)
else: