Initial checkin of Python parser for heckfiles.

This commit is contained in:
2024-01-31 08:30:20 -08:00
parent e1bfcb4815
commit c69778d7e4
7 changed files with 717 additions and 7 deletions

View File

@ -4,7 +4,7 @@
%%% heck
element value value
element value value
element tag=value
element attribute=value
> subelement value
> subelement value
>> sub-subelement value
@ -23,19 +23,23 @@ NUMBER ::= (<BASE10NUMBER|BASE16NUMBER>)
STRING ::= "([^\"]*|(\\)|(\"))"
VALUE ::= (<ATOM>|<STRING>|<NUMBER>)
VALUES ::= <VALUE>(\s+<VALUES>)?
TAGNAME ::= <ATOM>
TAG ::= <TAGNAME>=<VALUE>
TAGS ::= <TAG>(\s+<TAGS>)?
ATTRIBUTENAME ::= <ATOM>
ATTRIBUTE ::= <ATTRIBUTENAME>=<VALUE>
ATTRIBUTES ::= <ATTRIBUTE>(\s+<ATTRIBUTES>)?
SECTIONLABEL ::= <ATOM>
SECTION ::= %%%\s+<SECTIONLABEL>\s+<TAGS>
SECTION ::= %%%\s+<SECTIONLABEL>\s+<ATTRIBUTES>
ELEMENTLABEL ::= [A-Za-z_][A-Za-z0-9!@#$%^&*()_+/\\-]?
ELEMENT ::= <ELEMENTLABEL>\s+(<VALUES>|<TAGS>)
ELEMENT ::= <ELEMENTLABEL>\s+(<VALUES>|<ATTRIBUTES>)
LINE ::= ^(((>)*<ELEMENT>) | <SECTION> | <COMMENT>) (<COMMENT>|$)
```
Heck is composed of a series of elements each with a label and one or more values. Elements may also have several key-value pairs associated with them as tags. Elements may also have sub-elements which then take the place of the value indicated with a > before the value at the current level. The heck document also can have several sections. Sections all start with %%% and a label. If the label is heck, the section is interpreted as more elements for the heck document. Any other label is stored as an element of arbitrary string value under that label name.
Heck is composed of a series of elements each with a label and one or more values. Elements may also have several key-value pairs associated with them as attributes. Elements may also have sub-elements which then take the place of the value indicated with a > before the value at the current level. The heck document also can have several sections. Sections all start with %%% and a label. If the label is heck, the section is interpreted as more elements for the heck document. Any other label is stored as an element of arbitrary string value under that label name.
The data structure represented is an ordered array. Elements may have the same name as previous elmenents in the same containment.
## APIs
Heckformat APIs should provide a way to iterate the elements, to access their attributes as a mapping, to access their values as an array, and collect all elements within the root (or another element) of a specific kind (or set of kinds) as an array.