preserves_schema_nim: recursively search dicts for embedding

This commit is contained in:
Emery Hemingway 2023-03-01 11:12:47 -06:00
parent a130079162
commit 075627709f
3 changed files with 9 additions and 6 deletions

View File

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

View File

@ -211,7 +211,8 @@ proc attrs(loc: Location; cp: CompoundPattern; seen: RefSet): Attributes =
for p in cp.tupleprefix.fixed: for p in cp.tupleprefix.fixed:
result = result + attrs(loc, p, seen) result = result + attrs(loc, p, seen)
of CompoundPatternKind.dict: of CompoundPatternKind.dict:
discard for nsp in cp.dict.entries.values:
result = result + attrs(loc, nsp, seen)
proc attrs(loc: Location; pat: Pattern; seen: RefSet): Attributes = proc attrs(loc: Location; pat: Pattern; seen: RefSet): Attributes =
case pat.orKind case pat.orKind
@ -914,6 +915,7 @@ when isMainModule:
for inputPath in inputs: for inputPath in inputs:
var bundle: Bundle var bundle: Bundle
if dirExists inputPath: if dirExists inputPath:
new bundle
for filePath in walkDirRec(inputPath, relative = true): for filePath in walkDirRec(inputPath, relative = true):
var (dirPath, fileName, fileExt) = splitFile(filePath) var (dirPath, fileName, fileExt) = splitFile(filePath)
if fileExt == ".prs": if fileExt == ".prs":
@ -934,9 +936,10 @@ when isMainModule:
if fromPreserve(schema, pr): if fromPreserve(schema, pr):
bundle.modules[@[Symbol fileName]] = schema bundle.modules[@[Symbol fileName]] = schema
else: else:
new bundle
var scm = parsePreservesSchema(readFile(inputPath), dirPath) var scm = parsePreservesSchema(readFile(inputPath), dirPath)
bundle.modules[@[Symbol fileName]] = scm bundle.modules[@[Symbol fileName]] = scm
if bundle.modules.len == 0: if bundle.isNil or bundle.modules.len == 0:
quit "Failed to recognize " & inputPath quit "Failed to recognize " & inputPath
else: else:
writeModules(bundle) writeModules(bundle)

View File

@ -7,7 +7,7 @@ type
`name`*: Symbol `name`*: Symbol
ModulePath* = seq[Symbol] ModulePath* = seq[Symbol]
Bundle* {.preservesRecord: "bundle".} = object Bundle* {.preservesRecord: "bundle".} = ref object
`modules`*: Modules `modules`*: Modules
CompoundPatternKind* {.pure.} = enum CompoundPatternKind* {.pure.} = enum
@ -162,12 +162,12 @@ type
`variantLabel`*: string `variantLabel`*: string
`pattern`*: Pattern `pattern`*: Pattern
SchemaData* {.preservesDictionary.} = object SchemaData* {.preservesDictionary.} = ref object
`version`* {.preservesLiteral: "1".}: bool `version`* {.preservesLiteral: "1".}: bool
`embeddedType`*: EmbeddedTypeName `embeddedType`*: EmbeddedTypeName
`definitions`*: Definitions `definitions`*: Definitions
Schema* {.preservesRecord: "schema".} = object Schema* {.preservesRecord: "schema".} = ref object
`data`*: SchemaData `data`*: SchemaData
PatternKind* {.pure.} = enum PatternKind* {.pure.} = enum