From 8d93e6473e93f6393d2771a5a8058f503ed1c28d Mon Sep 17 00:00:00 2001 From: LordBaryhobal Date: Sun, 19 May 2024 17:29:16 +0200 Subject: [PATCH] added XML parser --- src/schema.typ | 20 +++++++++++++++++++- src/xml-loader.typ | 8 ++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/schema.typ b/src/schema.typ index 335b887..112540c 100644 --- a/src/schema.typ +++ b/src/schema.typ @@ -23,7 +23,25 @@ } } -#let load(path-or-schema, config: auto) = { +#let parse-raw(schema) = { + let lang = schema.lang + let content = schema.text + if not lang in valid-extensions { + let fmts = valid-extensions.map(fmt => "." + fmt).join(", ") + fmts = "(" + fmts + ")" + panic("Unsupported format '" + lang + "'. Valid formats: " + fmts) + } + + if lang == "yaml" { + return yaml.decode(content) + } else if lang == "json" { + return json.decode(content) + } else if lang == "xml" { + return xml-loader.parse(xml.decode(content).first()) + } +} + +#let load(path-or-schema) = { let schema = if type(path-or-schema) == str { parse-file(path-or-schema) } else { diff --git a/src/xml-loader.typ b/src/xml-loader.typ index ca7213a..1f00c42 100644 --- a/src/xml-loader.typ +++ b/src/xml-loader.typ @@ -81,8 +81,7 @@ ) } -#let load(path) = { - let content = xml(path).first() +#let parse(content) = { let struct-elmts = content.children.filter(e => "tag" in e and e.tag == "structure") let structures = (:) @@ -97,4 +96,9 @@ return ( structures: structures ) +} + +#let load(path) = { + let content = xml(path).first() + return parse(content) } \ No newline at end of file