Further progress on schema parser.
This commit is contained in:
parent
172f9d5ca1
commit
4405f4857d
@ -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
|
||||
|
@ -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()
|
Loading…
x
Reference in New Issue
Block a user