schemas: improve "include" parsing

This commit is contained in:
Emery Hemingway 2022-11-20 14:12:23 -06:00
parent e1ab43578a
commit 65195a5eb7
3 changed files with 9 additions and 8 deletions

View File

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

View File

@ -23,7 +23,7 @@ proc joinWhitespace(s: string): string =
for token, isSep in tokenize(s, Whitespace + {','}):
if not isSep: add(result, token)
template unescape(buf: var string; capture: string) =
template unescape*(buf: var string; capture: string) =
var i: int
while i < len(capture):
if capture[i] == '\\':

View File

@ -75,14 +75,15 @@ const parser = peg("Schema", p: ParseState):
EmbeddedTypeName <- "embeddedType" * S * >("#f" | Ref)
Include <- "include" * +Space * (>(+Alnum) | >('"' * @'"')):
var
path = absolutePath(strip($1, true, true, {'"'}), p.directory)
ip = ParseState(
Include <- "include" * S * '"' * >(+Preserves.char) * '"':
var path: string
unescape(path, $1)
path = absolutePath(path, p.directory)
var state = ParseState(
schema: move p.schema,
directory: parentDir path)
match(readFile path, ip)
p.schema = move ip.schema
match(readFile path, state)
p.schema = move state.schema
Definition <- >id * S * '=' * S * (OrPattern | AndPattern | Pattern):
if p.schema.definitions.hasKey(Symbol $1):