Regenerate schema module

This commit is contained in:
Emery Hemingway 2023-05-16 23:06:52 +01:00
parent ebaa927b55
commit b3f40347e8
4 changed files with 39 additions and 39 deletions

View File

@ -1,6 +1,6 @@
# Package
version = "20230514"
version = "20230516"
author = "Emery Hemingway"
description = "data model and serialization format"
license = "Unlicense"

View File

@ -116,23 +116,23 @@ proc ident(`ref`: Ref): PNode =
proc deref(loc: Location; r: Ref): (Location, Definition) =
result[0] = loc
if r.module == @[]:
result[1] = loc.bundle.modules[loc.schemaPath].data.definitions[r.name]
result[1] = loc.bundle.modules[loc.schemaPath].field0.definitions[r.name]
else:
result[0].schemaPath = r.module
result[1] = loc.bundle.modules[r.module].data.definitions[r.name]
result[1] = loc.bundle.modules[r.module].field0.definitions[r.name]
proc hasEmbeddedType(scm: Schema): bool =
case scm.data.embeddedType.orKind
case scm.field0.embeddedType.orKind
of EmbeddedtypenameKind.false: false
of EmbeddedtypenameKind.Ref: true
proc embeddedIdentString(scm: Schema): string =
case scm.data.embeddedType.orKind
case scm.field0.embeddedType.orKind
of EmbeddedtypenameKind.false:
"E"
of EmbeddedtypenameKind.Ref:
doAssert $scm.data.embeddedType.ref.name != ""
$scm.data.embeddedType.ref.name
doAssert $scm.field0.embeddedType.ref.name != ""
$scm.field0.embeddedType.ref.name
proc embeddedIdent(scm: Schema): PNode =
ident(embeddedIdentString(scm))
@ -213,8 +213,8 @@ proc attrs(loc: Location; pat: Pattern; seen: RefSet): Attributes =
attrs(loc, pat.compoundPattern, seen)
proc attrs(loc: Location; orDef: DefinitionOr; seen: RefSet): Attributes =
result = attrs(loc, orDef.data.pattern0, seen) + attrs(loc, orDef.data.pattern1, seen)
for p in orDef.data.patternN:
result = attrs(loc, orDef.field0.pattern0, seen) + attrs(loc, orDef.field0.pattern1, seen)
for p in orDef.field0.patternN:
result = result + attrs(loc, p, seen)
proc attrs(loc: Location; def: Definition; seen: RefSet): Attributes =
@ -222,9 +222,9 @@ proc attrs(loc: Location; def: Definition; seen: RefSet): Attributes =
of DefinitionKind.or: result = attrs(loc, def.or, seen)
of DefinitionKind.and:
result =
attrs(loc, def.and.data.pattern0, seen) +
attrs(loc, def.and.data.pattern1, seen)
for p in def.and.data.patternN:
attrs(loc, def.and.field0.pattern0, seen) +
attrs(loc, def.and.field0.pattern1, seen)
for p in def.and.field0.patternN:
result = result + attrs(loc, p, seen)
of DefinitionKind.Pattern:
result = attrs(loc, def.pattern, seen)
@ -277,8 +277,8 @@ proc isSimple(pat: Pattern): bool =
proc isLiteral(loc: Location; na: NamedAlternative): bool = isLiteral(loc, na.pattern)
proc isSymbolEnum(loc: Location; orDef: DefinitionOr): bool =
result = isLiteral(loc, orDef.data.pattern0) and isLiteral(loc, orDef.data.pattern1)
for na in orDef.data.patternN:
result = isLiteral(loc, orDef.field0.pattern0) and isLiteral(loc, orDef.field0.pattern1)
for na in orDef.field0.patternN:
if not result: break
result = isLiteral(loc, na)
@ -351,7 +351,7 @@ proc typeIdent(loc: Location; sp: SimplePattern): TypeSpec =
result = TypeSpec(node: ident(sp.ref), attrs: attrs(loc, sp))
result.node = parameterize(scm, result)
of SimplepatternKind.embedded:
case scm.data.embeddedType.orKind
case scm.field0.embeddedType.orKind
of EmbeddedtypenameKind.false:
result = typeIdent(loc, sp.embedded.interface)
of EmbeddedtypenameKind.Ref:
@ -613,9 +613,9 @@ proc nimTypeOf(loc: Location; known: var TypeTable; orDef: DefinitionOr; name: s
let ty = nkEnumTy.newNode.add newEmpty()
proc add (na: NamedAlternative) =
ty.add na.variantLabel.ident.accQuote
add(orDef.data.pattern0)
add(orDef.data.pattern1)
for na in orDef.data.patternN:
add(orDef.field0.pattern0)
add(orDef.field0.pattern1)
for na in orDef.field0.patternN:
add(na)
ty
if isSymbolEnum(loc, orDef):
@ -664,9 +664,9 @@ proc nimTypeOf(loc: Location; known: var TypeTable; orDef: DefinitionOr; name: s
nn(nkDotExpr,
enumIdent, na.variantLabel.ident.accQuote),
branchRecList)
addCase(orDef.data.pattern0)
addCase(orDef.data.pattern1)
for na in orDef.data.patternN: addCase(na)
addCase(orDef.field0.pattern0)
addCase(orDef.field0.pattern1)
for na in orDef.field0.patternN: addCase(na)
result.node = nn(nkObjectTy,
newEmpty(),
newEmpty(),
@ -725,20 +725,20 @@ proc collectRefImports(imports: var StringSet; loc: Location; pat: Pattern) =
proc collectRefImports(imports: var StringSet; loc: Location; def: Definition) =
case def.orKind
of DefinitionKind.or:
collectRefImports(imports, loc, def.or.data.pattern0.pattern)
collectRefImports(imports, loc, def.or.data.pattern1.pattern)
for na in def.or.data.patternN:
collectRefImports(imports, loc, def.or.field0.pattern0.pattern)
collectRefImports(imports, loc, def.or.field0.pattern1.pattern)
for na in def.or.field0.patternN:
collectRefImports(imports, loc, na.pattern)
of DefinitionKind.and:
collectRefImports(imports, loc, def.and.data.pattern0.pattern)
collectRefImports(imports, loc, def.and.data.pattern1.pattern)
for np in def.and.data.patternN:
collectRefImports(imports, loc, def.and.field0.pattern0.pattern)
collectRefImports(imports, loc, def.and.field0.pattern1.pattern)
for np in def.and.field0.patternN:
collectRefImports(imports, loc, np.pattern)
of DefinitionKind.Pattern:
collectRefImports(imports, loc, def.pattern)
proc collectRefImports(imports: var StringSet; loc: Location; scm: Schema) =
for _, def in scm.data.definitions:
for _, def in scm.field0.definitions:
collectRefImports(imports, loc, def)
proc mergeType(x: var PNode; y: PNode) =
@ -760,7 +760,7 @@ proc renderNimBundle*(bundle: Bundle): Table[string, string] =
typeSection = newNode nkTypeSection
procs: seq[PNode]
unembeddableType, embeddableType: PNode
for name, def in scm.data.definitions.pairs:
for name, def in scm.field0.definitions.pairs:
if isLiteral(loc, def):
generateConstProcs(procs, scm, string name, def)
else:

View File

@ -130,21 +130,21 @@ type
DefinitionKind* {.pure.} = enum
`or`, `and`, `Pattern`
DefinitionOrData* {.preservesTuple.} = ref object
DefinitionOrField0* {.preservesTuple.} = ref object
`pattern0`*: NamedAlternative
`pattern1`*: NamedAlternative
`patternN`* {.preservesTupleTail.}: seq[NamedAlternative]
DefinitionOr* {.preservesRecord: "or".} = ref object
`data`*: DefinitionOrData
`field0`*: DefinitionOrField0
DefinitionAndData* {.preservesTuple.} = ref object
DefinitionAndField0* {.preservesTuple.} = ref object
`pattern0`*: NamedPattern
`pattern1`*: NamedPattern
`patternN`* {.preservesTupleTail.}: seq[NamedPattern]
DefinitionAnd* {.preservesRecord: "and".} = ref object
`data`*: DefinitionAndData
`field0`*: DefinitionAndField0
`Definition`* {.preservesOr.} = ref object
case orKind*: DefinitionKind
@ -162,13 +162,13 @@ type
`variantLabel`*: string
`pattern`*: Pattern
SchemaData* {.preservesDictionary.} = ref object
`version`* {.preservesLiteral: "1".}: bool
SchemaField0* {.preservesDictionary.} = ref object
`version`* {.preservesLiteral: "1".}: tuple[]
`embeddedType`*: EmbeddedTypeName
`definitions`*: Definitions
Schema* {.preservesRecord: "schema".} = ref object
`data`*: SchemaData
`field0`*: SchemaField0
PatternKind* {.pure.} = enum
`SimplePattern`, `CompoundPattern`

View File

@ -12,7 +12,7 @@ type
Value = Preserve[void]
Stack = seq[tuple[node: Value, pos: int]]
ParseState = object
schema: SchemaData
schema: SchemaField0
stack: Stack
directory: string
@ -289,9 +289,9 @@ proc parsePreservesSchema*(text: string; directory = getCurrentDir()): Schema =
## Schemas in binary encoding should instead be parsed as Preserves
## and converted to `Schema` with `fromPreserve` or `preserveTo`.
assert directory != ""
var p = ParseState(schema: SchemaData(), directory: directory)
var p = ParseState(schema: SchemaField0(), directory: directory)
match(text, p)
Schema(data: p.schema)
Schema(field0: p.schema)
when isMainModule:
import std/streams