Module schema_parser

Source
Expand description

XML Schema 解析器模块

该模块提供从XML格式解析Schema定义的功能,支持将XML schema定义 转换为ModuForge的SchemaSpec结构。

§核心功能

  • 单文件XML Schema解析
  • 多文件XML Schema解析(支持import/include)
  • 自动类型转换(布尔值、数字、字符串)
  • 循环引用检测
  • 全局属性支持

§XML Schema 格式

§基础格式

<?xml version="1.0" encoding="UTF-8"?>
<schema top_node="doc">
  <nodes>
    <node name="doc" group="block">
      <desc>文档根节点</desc>
      <content>paragraph+</content>
      <marks>_</marks>
      <attrs>
        <attr name="title" default="Untitled Document"/>
        <attr name="version" default="1.0"/>
      </attrs>
    </node>
  </nodes>
</schema>

§多文件引用格式

<?xml version="1.0" encoding="UTF-8"?>
<schema top_node="doc">
  <!-- 导入其他schema文件 -->
  <imports>
    <import src="./base-nodes.xml"/>
    <import src="./formatting-marks.xml"/>
    <import src="../common/table-nodes.xml"/>
  </imports>

  <!-- 包含其他schema内容(内联合并) -->
  <includes>
    <include src="./extensions.xml"/>
  </includes>

  <!-- 全局属性定义 -->
  <global_attributes>
    <global_attribute types="paragraph heading">
      <attr name="id"/>
      <attr name="class"/>
      <attr name="style"/>
    </global_attribute>
    <global_attribute types="*">
      <attr name="data-custom"/>
    </global_attribute>
  </global_attributes>

  <!-- 本文件定义的节点和标记 -->
  <nodes>
    <node name="custom_node">
      <desc>自定义节点</desc>
    </node>
  </nodes>
</schema>

Structs§

MultiFileParseContext
多文件解析上下文
XmlSchemaParser
XML Schema 解析器

Enums§

XmlSchemaError
XML Schema 解析错误类型

Type Aliases§

XmlSchemaResult
XML Schema 解析结果类型