This commit is contained in:
perro tuerto 2023-01-25 19:30:33 -08:00
parent dfbaa98af6
commit f16ecab458
2 changed files with 88 additions and 45 deletions

133
README.md
View File

@ -1,6 +1,4 @@
--- \[TOC\]
warn: This is just a prototype.
---
# YASD, Yet Another Schema Definition # YASD, Yet Another Schema Definition
@ -8,6 +6,36 @@ YASD is a YAML format for human writable XSDs (XML Schema Definition), humans
declare what is indispensable, leaving the machines to do the rest of the declare what is indispensable, leaving the machines to do the rest of the
unreadable `<syntaxis who_can_read_this="?" />`. unreadable `<syntaxis who_can_read_this="?" />`.
## Workflow
The following chart is the YASD CLI flow:
``` mermaid
flowchart LR
direction LR
yasd --- convert
yasd --- check
yasd --- sample
yasd --- document
yasd --- man
convert --- |from| YASD1([YASD])
YASD1 --> |to| XSD([XSD])
check --- |validates| YASD2([YASD])
sample --- |from| YASD3([YASD])
YASD3 --> |to| XML([XML])
document --- |from| YASD4([YASD])
YASD4 --> |to| MD([Markdown])
man --- |prints| README
```
## Example
To better understad what YASD does, see the inputs and outputs:
- Input: human workable schema in [YASD].
- Output: computer processable schema in [XSD].
- Output: human readable documentation in [Markdown].
## Structure ## Structure
General structure: General structure:
@ -77,27 +105,27 @@ Group (GRPS) structure:
## Reference ## Reference
### `elementFormDefault`[^1] ### `elementFormDefault`[^1] {#elementformdefault1}
Indicates that any elements used by the XML instance document which were Indicates that any elements used by the XML instance document which were
declared in this schema must be namespace qualified. declared in this schema must be namespace qualified.
Optional; if not present by default is `unqualified`. Optional; if not present by default is `unqualified`.
### `taget_namespace`[^1] ### `taget_namespace`[^2] {#taget_namespace1}
Indicates that the elements defined by this schema come from the specified URL Indicates that the elements defined by this schema come from the specified URL
namespace. namespace.
Optional. Optional.
### `xmlns`[^1] ### `xmlns`[^3] {#xmlns1}
Indicates that the default namespace is the specified URL. Indicates that the default namespace is the specified URL.
Mandatory. Mandatory.
### `schemaLocation`[^1] ### `schemaLocation`[^4] {#schemalocation1}
Indicates the location of the XML schema to use for that namespace. Indicates the location of the XML schema to use for that namespace.
@ -122,7 +150,8 @@ Naming rules:
- Element names are case-sensitive - Element names are case-sensitive
- Element names must start with a letter or underscore - Element names must start with a letter or underscore
- Element names cannot start with the letters xml (or XML, or Xml, etc) - Element names cannot start with the letters xml (or XML, or Xml, etc)
- Element names can contain letters, digits, hyphens, underscores, and periods - Element names can contain letters, digits, hyphens, underscores, and
periods
- Element names cannot contain spaces - Element names cannot contain spaces
### `description` ### `description`
@ -147,19 +176,19 @@ Allowed types:
Chart: Chart:
|type | children elements | text node | attributes | | type | children elements | text node | attributes |
|------------|:-----------------:|:----------:|:----------:| |------------|:-----------------:|:---------:|:----------:|
|simple | | | | |simple | | | |
|empty | | | | |empty | | | |
|no_text | | | | |no_text | | | |
|no_elements | | | | |no_elements | | | |
|mixed | | | | |mixed | | | |
> **Note**: attributes are never mandatory; they could be zero or more. > **Note**: attributes are never mandatory; they could be zero or more.
### `datatype` ### `datatype`
Indicates element or attribute data types.[^2] Indicates element or attribute data types.[^5]
Only mandatory for 'simple' and 'no_elements' elements, and attributes. Only mandatory for 'simple' and 'no_elements' elements, and attributes.
@ -169,8 +198,8 @@ Allowed String Data Types:
- `ENTITY`.   - `ENTITY`.  
- `ID`. A string that represents the ID attribute in XML (only used with - `ID`. A string that represents the ID attribute in XML (only used with
schema attributes). schema attributes).
- `IDREF`. A string that represents the IDREF attribute in XML (only used with - `IDREF`. A string that represents the IDREF attribute in XML (only used
schema attributes). with schema attributes).
- `IDREFS`. - `IDREFS`.
- `language`. A string that contains a valid language id. - `language`. A string that contains a valid language id.
- `Name`. A string that contains a valid XML name. - `Name`. A string that contains a valid XML name.
@ -247,7 +276,7 @@ Optional.
Only `required` is valid as value. Only `required` is valid as value.
### `restriction`[^3] ### `restriction`[^6] {#restriction3}
Indicates accepted constrained values for element or attribute. Indicates accepted constrained values for element or attribute.
@ -275,8 +304,8 @@ Allowed constrains:
- `minLength`. Specifies the minimum number of characters or list items - `minLength`. Specifies the minimum number of characters or list items
allowed; must be equal to or greater than zero. allowed; must be equal to or greater than zero.
- `pattern`. Defines the exact sequence of characters that are acceptable. - `pattern`. Defines the exact sequence of characters that are acceptable.
- `totalDigits`. Specifies the exact number of digits allowed; must be greater - `totalDigits`. Specifies the exact number of digits allowed; must be
than zero. greater than zero.
- `whiteSpace`. Specifies how white space (line feeds, tabs, spaces, and - `whiteSpace`. Specifies how white space (line feeds, tabs, spaces, and
carriage returns) is handled; accepted values are carriage returns) is handled; accepted values are
`preserve|replace|collapse`. `preserve|replace|collapse`.
@ -340,8 +369,8 @@ Optional; if not present by default is `false`.
Allowed values: Allowed values:
- `true`. - `true`.
- `false`. - `false`.
### `elements` ### `elements`
@ -363,37 +392,51 @@ Mandatory.
## Command-Line Interface ## Command-Line Interface
``` usage: yasd [-h] [-q] [-l] [-n NUM] {convert,check,sample,document,man} [file]
usage: yasd [-h] [-q] [-l] [-n NUM] {convert,check,sample,document,man} [file]
YASD, Yet Another Schema Definition. YASD is a YAML format for human writable YASD, Yet Another Schema Definition. YASD is a YAML format for human writable
XSDs (XML Schema Definition), humans declare what is indispensable, leaving XSDs (XML Schema Definition), humans declare what is indispensable, leaving
the machines to do the rest of the unreadable <syntaxis who_can_read_this="?" the machines to do the rest of the unreadable <syntaxis who_can_read_this="?"
/>. />.
positional arguments: positional arguments:
{convert,check,sample,document,man} {convert,check,sample,document,man}
action to perform action to perform
file file in YAML format file file in YAML format
options: options:
-h, --help show this help message and exit -h, --help show this help message and exit
-q, --quiet enable quiet mode -q, --quiet enable quiet mode
-l, --log write log -l, --log write log
-n NUM, --num NUM number of XML samples; 1 by default -n NUM, --num NUM number of XML samples; 1 by default
(c) 2023 Perro Tuerto <hi@perrotuerto.blog>. Founded by Mexican Academy of (c) 2023 Perro Tuerto <hi@perrotuerto.blog>. Founded by Mexican Academy of
Language <https://academia.org.mx>. Licensed under GPLv3 Language <https://academia.org.mx>. Licensed under GPLv3
<https://www.gnu.org/licenses/gpl-3.0.en.html>. <https://www.gnu.org/licenses/gpl-3.0.en.html>.
```
[^1]: The following explanation is practically a copy-paste from "XSD - The [^1]: The following explanation is practically a copy-paste from "XSD - The
<schema> Element", W3Schools. Cfr. `<schema>`{=html} Element", W3Schools. Cfr.
<https://www.w3schools.com/xml/schema_schema.asp>. <https://www.w3schools.com/xml/schema_schema.asp>.
[^2]: The following explanation is practically a copy-paste from "XSD Data [^2]: The following explanation is practically a copy-paste from "XSD - The
`<schema>`{=html} Element", W3Schools. Cfr.
<https://www.w3schools.com/xml/schema_schema.asp>.
[^3]: The following explanation is practically a copy-paste from "XSD - The
`<schema>`{=html} Element", W3Schools. Cfr.
<https://www.w3schools.com/xml/schema_schema.asp>.
[^4]: The following explanation is practically a copy-paste from "XSD - The
`<schema>`{=html} Element", W3Schools. Cfr.
<https://www.w3schools.com/xml/schema_schema.asp>.
[^5]: The following explanation is practically a copy-paste from "XSD Data
Types", W3Schools. Cfr. <https://www.w3schools.com/xml/schema_intro.asp>. Types", W3Schools. Cfr. <https://www.w3schools.com/xml/schema_intro.asp>.
[^3]: The following explanation is practically a copy-paste from "XSD [^6]: The following explanation is practically a copy-paste from "XSD
Restrictions/Facets", W3Schools. Cfr. Restrictions/Facets", W3Schools. Cfr.
<https://www.w3schools.com/xml/schema_facets.asp>. <https://www.w3schools.com/xml/schema_facets.asp>.
[YASD]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.yaml
[XSD]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.xsd
[Markdown]: https://gitlab.com/amlengua/apal/esquema/-/blob/main/apal.md

0
yasd.py Normal file → Executable file
View File