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 = {}
|
const object = {}
|
||||||
for (let [key, child] of Object.entries(definition.values)) {
|
for (let [key, child] of Object.entries(definition.values)) {
|
||||||
child = lookup(child)
|
child = lookup(child)
|
||||||
|
if (key === 'any') key = null
|
||||||
addHandler(handlers, level, key, child, (key, value) => {
|
addHandler(handlers, level, key, child, (key, value) => {
|
||||||
if (child.collate === 'array') {
|
if (child.collate === 'array') {
|
||||||
if (!object[key]) object[key] = []
|
if (!object[key]) object[key] = []
|
||||||
@ -39,7 +40,7 @@ export async function parse(lines, schema) {
|
|||||||
|
|
||||||
if (definition.text) {
|
if (definition.text) {
|
||||||
const textKey = definition.text
|
const textKey = definition.text
|
||||||
const textType = definition.values[textKey]
|
const textType = 'string'
|
||||||
object[textKey] = ''
|
object[textKey] = ''
|
||||||
addHandler(handlers, level, '', textType, (key, value) => {
|
addHandler(handlers, level, '', textType, (key, value) => {
|
||||||
object[textKey] += object[textKey] ? `\n${doc.line()}` : doc.line()
|
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 === '')
|
const unmatchedHandler = handlers[level]?.find(h => h.key === '')
|
||||||
let matched = false
|
let matched = false
|
||||||
for (const { key, definition, resolve, handler } of handlers[level] || []) {
|
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))
|
resolve(doc.head(), handler(doc, handlers, definition))
|
||||||
matched = true
|
matched = true
|
||||||
break
|
break
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
const schemaSchemaTCE = `
|
import { parse } from './core.js'
|
||||||
|
|
||||||
|
const schemaTCE = `
|
||||||
types
|
types
|
||||||
primitive object, tail as type
|
primitive object, tail as type
|
||||||
any primitive
|
any primitive
|
||||||
@ -11,7 +13,7 @@ root object
|
|||||||
any primitive
|
any primitive
|
||||||
`
|
`
|
||||||
|
|
||||||
const schemaSchemaJSON = {
|
const schema = {
|
||||||
types: {
|
types: {
|
||||||
primitive: {
|
primitive: {
|
||||||
type: 'object',
|
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