diff --git a/docs/experiments/parsers/core.js b/docs/experiments/parsers/core.js index 7406024..9f103a6 100644 --- a/docs/experiments/parsers/core.js +++ b/docs/experiments/parsers/core.js @@ -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 diff --git a/docs/experiments/parsers/schema.js b/docs/experiments/parsers/schema.js index b83652d..b14aa6f 100644 --- a/docs/experiments/parsers/schema.js +++ b/docs/experiments/parsers/schema.js @@ -1,4 +1,6 @@ -const schemaSchemaTCE = ` +import { parse } from './core.js' + +const schemaTCE = ` types primitive object, tail as type any primitive @@ -11,7 +13,7 @@ root object any primitive ` -const schemaSchemaJSON = { +const schema = { types: { primitive: { type: 'object', @@ -41,3 +43,9 @@ const schemaSchemaJSON = { }, } } + +async function main() { + console.dir(await parse(schemaTCE.split('\n'), schema), { depth: null }) +} + +main() \ No newline at end of file