Further progress on schema parser.
This commit is contained in:
@@ -16,6 +16,7 @@ export async function parse(lines, schema) {
|
||||
const object = {}
|
||||
for (let [key, child] of Object.entries(definition.values)) {
|
||||
child = lookup(child)
|
||||
if (key === 'any') key = null
|
||||
addHandler(handlers, level, key, child, (key, value) => {
|
||||
if (child.collate === 'array') {
|
||||
if (!object[key]) object[key] = []
|
||||
@@ -39,7 +40,7 @@ export async function parse(lines, schema) {
|
||||
|
||||
if (definition.text) {
|
||||
const textKey = definition.text
|
||||
const textType = definition.values[textKey]
|
||||
const textType = 'string'
|
||||
object[textKey] = ''
|
||||
addHandler(handlers, level, '', textType, (key, value) => {
|
||||
object[textKey] += object[textKey] ? `\n${doc.line()}` : doc.line()
|
||||
@@ -149,7 +150,8 @@ export async function parse(lines, schema) {
|
||||
const unmatchedHandler = handlers[level]?.find(h => h.key === '')
|
||||
let matched = false
|
||||
for (const { key, definition, resolve, handler } of handlers[level] || []) {
|
||||
if (doc.head() !== key) continue;
|
||||
if (key && doc.head() !== key) continue;
|
||||
if (!doc.line()) continue;
|
||||
resolve(doc.head(), handler(doc, handlers, definition))
|
||||
matched = true
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user