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
version = "20230228"
version = "20230301"
author = "Emery Hemingway"
description = "data model and serialization format"
license = "Unlicense"

View File

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

View File

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