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 # Package
version = "20230514" version = "20230516"
author = "Emery Hemingway" author = "Emery Hemingway"
description = "data model and serialization format" description = "data model and serialization format"
license = "Unlicense" license = "Unlicense"

View File

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

View File

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

View File

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