Created
September 18, 2022 16:28
-
-
Save gimsieke/efae6906458e4be8d26d62c5241269f1 to your computer and use it in GitHub Desktop.
REx EBNF for a parsing problem presented by Martynas Jusevičius on the xml.com slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Go to https://bottlecaps.de/rex/ and use this command line on nested-parentheses.ebnf: -xslt -main -tree -ll 3 -backtrack | |
# Assumption: A Saxon front-end script called 'saxon' is on the path | |
saxon -o:out.xml -it:main -xsl:nested-parentheses.xslt input='{(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))}' '!indent=yes' | |
# Looking at the main template of the generated XSLT, you need to surround the input string with curly braces; otherweise it will be interpreted as a file name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nested_parentheses ::= '(' ( nested_parentheses (',' S* nested_parentheses)* | tuple_sequence ) ')' S* | |
tuple_sequence ::= ( tuple (',' S* tuple)* ) | |
tuple ::= digits S+ digits | |
<?TOKENS?> | |
digits ::= [0-9]+ | |
S ::= [ #x0009#x000D#x000A#x000C]+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<nested_parentheses> | |
<TOKEN>(</TOKEN> | |
<nested_parentheses> | |
<TOKEN>(</TOKEN> | |
<nested_parentheses> | |
<TOKEN>(</TOKEN> | |
<tuple_sequence> | |
<tuple> | |
<digits>40</digits> | |
<S> </S> | |
<digits>40</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>20</digits> | |
<S> </S> | |
<digits>45</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>45</digits> | |
<S> </S> | |
<digits>30</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>40</digits> | |
<S> </S> | |
<digits>40</digits> | |
</tuple> | |
</tuple_sequence> | |
<TOKEN>)</TOKEN> | |
</nested_parentheses> | |
<TOKEN>)</TOKEN> | |
</nested_parentheses> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<nested_parentheses> | |
<TOKEN>(</TOKEN> | |
<nested_parentheses> | |
<TOKEN>(</TOKEN> | |
<tuple_sequence> | |
<tuple> | |
<digits>20</digits> | |
<S> </S> | |
<digits>35</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>10</digits> | |
<S> </S> | |
<digits>30</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>10</digits> | |
<S> </S> | |
<digits>10</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>30</digits> | |
<S> </S> | |
<digits>5</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>45</digits> | |
<S> </S> | |
<digits>20</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>20</digits> | |
<S> </S> | |
<digits>35</digits> | |
</tuple> | |
</tuple_sequence> | |
<TOKEN>)</TOKEN> | |
</nested_parentheses> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<nested_parentheses> | |
<TOKEN>(</TOKEN> | |
<tuple_sequence> | |
<tuple> | |
<digits>30</digits> | |
<S> </S> | |
<digits>20</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>20</digits> | |
<S> </S> | |
<digits>15</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>20</digits> | |
<S> </S> | |
<digits>25</digits> | |
</tuple> | |
<TOKEN>,</TOKEN> | |
<S> </S> | |
<tuple> | |
<digits>30</digits> | |
<S> </S> | |
<digits>20</digits> | |
</tuple> | |
</tuple_sequence> | |
<TOKEN>)</TOKEN> | |
</nested_parentheses> | |
<TOKEN>)</TOKEN> | |
</nested_parentheses> | |
<TOKEN>)</TOKEN> | |
</nested_parentheses> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment