Skip to content

Instantly share code, notes, and snippets.

@hoehrmann
Created May 26, 2024 22:54
Show Gist options
  • Save hoehrmann/f234c1156ee5ef7b24cb589c14aaefda to your computer and use it in GitHub Desktop.
Save hoehrmann/f234c1156ee5ef7b24cb589c14aaefda to your computer and use it in GitHub Desktop.
Using LLMs to convert old RFC .txt files to modern xml2rfc XML files (and turn them into modern .html files)

Frameworks like llama.cpp support context-free grammars to restrict the output of a large language model to a specific format.

The specification for the xml2rfc format comes with a RELAX NG schema that describes this particular format.

The RELAX NG specification defines its semantics based on a simpler format called the simple syntax. Some more advanced constructs are basically just syntactic sugar in this sense.

There are tools that convert the full format into the simple syntax.

The simple syntax is very easy to work for for all kinds of purposes.

We can make a formal grammar for a concrete XML format easily

html        = start-html  (head body) final-html
head        = start-head  (title)     final-head
title       = start-title ""          final-title
body        = start-body  *(div / p)  final-body
div         = start-div   *(div / p)  final-div 
p           = start-p     ""          final-p

Throw in attributes and such as appropriate.

So, take the RNC schema from the xml2rfc RFC. Convert it from compact syntax to XML-based simple syntax. Transform that into a context-free grammar in the form as above. Write a system prompt for the large language model tasking it with the conversion. Priorities would be to preserve the wording exactly and the formatting of ascii art diagrams and similar constructs exactly.

Constrain its output with the CFG for the XML format. If the grammar mechanism works properly, the result should be a valid xml2rfc file which (modulo some issues like that there might not be an ID for each IDREF or whatever internal linking mechanism exists in xml2rfc). That can then be put through the converter to generate plain text files again.

Diff the results, possibly with re-wrapping tolerant settings.

@hoehrmann
Copy link
Author

nl ::= "\n"?
text ::= ([^>"<&]| "&amp;"| "&lt;"| "&gt;"| "&quot;"| "&apos;"| "&#x" [0-9a-fA-F]+ ";"| "&#" [0-9]+ ";")*
root ::=  element1 
element1 ::= "<rfc" ( "FIXME"  | (" number=\x22"  text  "\x22") | (" obsoletes=\x22"  text  "\x22") | (" updates=\x22"  text  "\x22") | (" category=\x22"  text  "\x22") | (" mode=\x22"  text  "\x22") | (" consensus=\x22"  "\x22") | (" seriesNo=\x22"  text  "\x22") | (" ipr=\x22"  text  "\x22") | (" iprExtract=\x22"  text  "\x22") | (" submissionType=\x22"  "\x22") | (" docName=\x22"  text  "\x22") | (" sortRefs=\x22"  "\x22") | (" symRefs=\x22"  "\x22") | (" tocInclude=\x22"  "\x22") | (" tocDepth=\x22"  text  "\x22") | (" prepTime=\x22"  text  "\x22") | (" indexInclude=\x22"  "\x22") | (" version=\x22"  text  "\x22") | (" scripts=\x22"  text  "\x22") | (" expiresDate=\x22"  text  "\x22"))*  ">" nl  (  (  (  (   (  ""  |  (  element2  )+  )  )   element3  )   element4  )   (  ""  |  element5  )  )  "</rfc>" nl
element2 ::= "<link" ( "FIXME"  | (" href=\x22"  text  "\x22") | (" rel=\x22"  text  "\x22"))*  ">" nl  "</link>" nl
element3 ::= "<front" ( "FIXME" )*  ">" nl  (  (  (  (  (  (  (  (  (  (   element6  )   (  ""  |  (  element7  )+  )  )   (  element8  )+  )   (  ""  |  element9  )  )   (  ""  |  (  element10  )+  )  )   (  ""  |  (  element11  )+  )  )   (  ""  |  (  element12  )+  )  )   (  ""  |  element13  )  )   (  ""  |  (  element14  )+  )  )   (  ""  |  element15  )  )  "</front>" nl
element4 ::= "<middle" ( "FIXME" )*  ">" nl  (   (  element16  )+  )  "</middle>" nl
element5 ::= "<back" ( "FIXME" )*  ">" nl  (  (  (   (  ""  |  (  element17  )+  )  )   (  ""  |  (  element18  )+  )  )   (  ""  |  (  element16  )+  )  )  "</back>" nl
element6 ::= "<title" ( "FIXME"  | (" abbrev=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</title>" nl
element7 ::= "<seriesInfo" ( "FIXME"  | (" name=\x22"  text  "\x22") | (" value=\x22"  text  "\x22") | (" status=\x22"  text  "\x22") | (" stream=\x22"  "\x22"))*  ">" nl  "</seriesInfo>" nl
element8 ::= "<author" ( "FIXME"  | (" initials=\x22"  text  "\x22") | (" surname=\x22"  text  "\x22") | (" fullname=\x22"  text  "\x22") | (" role=\x22" "editor" "\x22"))*  ">" nl  (  (   (  ""  |  element19  )  )   (  ""  |  element20  )  )  "</author>" nl
element9 ::= "<date" ( "FIXME"  | (" day=\x22"  text  "\x22") | (" month=\x22"  text  "\x22") | (" year=\x22"  text  "\x22"))*  ">" nl  "</date>" nl
element10 ::= "<area" ( "FIXME" )*  ">" nl  (   text  )  "</area>" nl
element11 ::= "<workgroup" ( "FIXME" )*  ">" nl  (   text  )  "</workgroup>" nl
element12 ::= "<keyword" ( "FIXME" )*  ">" nl  (   text  )  "</keyword>" nl
element13 ::= "<abstract" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  element21  |  element22  )  |  element23  )  |  element24  )  )+  )  "</abstract>" nl
element14 ::= "<note" ( "FIXME"  | (" title=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" removeInRFC=\x22"  "\x22"))*  ">" nl  (  (   (  ""  |  element25  )  )   (  (  (  (  element21  |  element22  )  |  element23  )  |  element24  )  )+  )  "</note>" nl
element15 ::= "<boilerplate" ( "FIXME" )*  ">" nl  (   (  element16  )+  )  "</boilerplate>" nl
element16 ::= "<section" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" title=\x22"  text  "\x22") | (" numbered=\x22"  "\x22") | (" toc=\x22"  "\x22") | (" removeInRFC=\x22"  "\x22"))*  ">" nl  (  (  (   (  ""  |  element25  )  )   (  ""  |  (  (  (  (  (  (  (  (  (  (  (  (  element26  |  element27  )  |  element28  )  |  element21  )  |  element29  )  |  element30  )  |  element22  )  |  element31  )  |  element23  )  |  element32  )  |  element33  )  |  element24  )  )+  )  )   (  ""  |  (  element16  )+  )  )  "</section>" nl
element17 ::= "<displayreference" ( "FIXME"  | (" target=\x22"  text  "\x22") | (" to=\x22"  text  "\x22"))*  ">" nl  "</displayreference>" nl
element18 ::= "<references" ( "FIXME"  | (" pn=\x22"  text  "\x22") | (" anchor=\x22"  text  "\x22") | (" title=\x22"  text  "\x22"))*  ">" nl  (  (   (  ""  |  element25  )  )   (  ""  |  (  (  element34  |  element35  )  )+  )  )  "</references>" nl
element19 ::= "<organization" ( "FIXME"  | (" abbrev=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</organization>" nl
element20 ::= "<address" ( "FIXME" )*  ">" nl  (  (  (  (  (   (  ""  |  element36  )  )   (  ""  |  element37  )  )   (  ""  |  element38  )  )   (  ""  |  element39  )  )   (  ""  |  element40  )  )  "</address>" nl
element21 ::= "<dl" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" spacing=\x22"  "\x22") | (" hanging=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  element41   element42  )  )+  )  "</dl>" nl
element22 ::= "<ol" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" start=\x22"  text  "\x22") | (" group=\x22"  text  "\x22") | (" spacing=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  element43  )+  )  "</ol>" nl
element23 ::= "<t" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" hangText=\x22"  text  "\x22") | (" keepWithNext=\x22"  "\x22") | (" keepWithPrevious=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element48  )  |  element49  )  |  element50  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element55  )  |  element56  )  )+  )  "</t>" nl
element24 ::= "<ul" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" spacing=\x22"  "\x22") | (" empty=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  element43  )+  )  "</ul>" nl
element25 ::= "<name" ( "FIXME"  | (" slugifiedName=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  text  |  element45  )  |  element47  )  |  element49  )  |  element54  )  |  element56  )  )+  )  "</name>" nl
element26 ::= "<artwork" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" name=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" src=\x22"  text  "\x22") | (" align=\x22"  "\x22") | (" alt=\x22"  text  "\x22") | (" width=\x22"  text  "\x22") | (" height=\x22"  text  "\x22") | (" originalSrc=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</artwork>" nl
element27 ::= "<aside" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  ""  |  (  (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element30  )  |  element48  )  |  element22  )  |  element23  )  |  element32  )  |  element24  )  )+  )  )  "</aside>" nl
element28 ::= "<blockquote" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" cite=\x22"  text  "\x22") | (" quotedFrom=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</blockquote>" nl
element29 ::= "<figure" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" title=\x22"  text  "\x22") | (" suppress-title=\x22"  "\x22") | (" src=\x22"  text  "\x22") | (" originalSrc=\x22"  text  "\x22") | (" align=\x22"  "\x22") | (" alt=\x22"  text  "\x22") | (" width=\x22"  text  "\x22") | (" height=\x22"  text  "\x22"))*  ">" nl  (  (  (  (  (   (  ""  |  element25  )  )   (  ""  |  (  element30  )+  )  )   (  ""  |  element57  )  )   (  (  element26  |  element31  )  )+  )   (  ""  |  element58  )  )  "</figure>" nl
element30 ::= "<iref" ( "FIXME"  | (" item=\x22"  text  "\x22") | (" subitem=\x22"  text  "\x22") | (" primary=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  "</iref>" nl
element31 ::= "<sourcecode" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" name=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" src=\x22"  text  "\x22") | (" originalSrc=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</sourcecode>" nl
element32 ::= "<table" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (  (  (  (  (   (  ""  |  element25  )  )   (  ""  |  (  element30  )+  )  )   (  ""  |  element59  )  )   (  element60  )+  )   (  ""  |  element61  )  )  "</table>" nl
element33 ::= "<texttable" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" title=\x22"  text  "\x22") | (" suppress-title=\x22"  "\x22") | (" align=\x22"  "\x22") | (" style=\x22"  "\x22"))*  ">" nl  (  (  (  (  (   (  ""  |  element25  )  )   (  ""  |  element57  )  )   (  element62  )+  )   (  ""  |  (  element63  )+  )  )   (  ""  |  element58  )  )  "</texttable>" nl
element34 ::= "<reference" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" target=\x22"  text  "\x22") | (" quoteTitle=\x22"  "\x22"))*  ">" nl  (  (   element3  )   (  ""  |  (  (  (  (  element64  |  element65  )  |  element66  )  |  element7  )  )+  )  )  "</reference>" nl
element35 ::= "<referencegroup" ( "FIXME"  | (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element34  )+  )  "</referencegroup>" nl
element36 ::= "<postal" ( "FIXME" )*  ">" nl  (   (  (  ""  |  (  (  (  (  (  element67  |  element68  )  |  element69  )  |  element70  )  |  element71  )  )+  )  |  (  element72  )+  )  )  "</postal>" nl
element37 ::= "<phone" ( "FIXME" )*  ">" nl  (   text  )  "</phone>" nl
element38 ::= "<facsimile" ( "FIXME" )*  ">" nl  (   text  )  "</facsimile>" nl
element39 ::= "<email" ( "FIXME" )*  ">" nl  (   text  )  "</email>" nl
element40 ::= "<uri" ( "FIXME" )*  ">" nl  (   text  )  "</uri>" nl
element41 ::= "<dt" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</dt>" nl
element42 ::= "<dd" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</dd>" nl
element43 ::= "<li" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</li>" nl
element44 ::= "<bcp14" ( "FIXME" )*  ">" nl  (   text  )  "</bcp14>" nl
element45 ::= "<cref" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" source=\x22"  text  "\x22") | (" display=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  (  text  |  element46  )  |  element47  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</cref>" nl
element46 ::= "<em" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</em>" nl
element47 ::= "<eref" ( "FIXME"  | (" target=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</eref>" nl
element48 ::= "<list" ( "FIXME"  | (" style=\x22"  text  "\x22") | (" hangIndent=\x22"  text  "\x22") | (" counter=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  element23  )+  )  "</list>" nl
element49 ::= "<relref" ( "FIXME"  | (" target=\x22"  text  "\x22") | (" displayFormat=\x22"  "\x22") | (" section=\x22"  text  "\x22") | (" relative=\x22"  text  "\x22") | (" derivedLink=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</relref>" nl
element50 ::= "<spanx" ( "FIXME"  | (" style=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</spanx>" nl
element51 ::= "<strong" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</strong>" nl
element52 ::= "<sub" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element54  )  |  element56  )  )+  )  "</sub>" nl
element53 ::= "<sup" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element54  )  |  element56  )  )+  )  "</sup>" nl
element54 ::= "<tt" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element56  )  )+  )  "</tt>" nl
element55 ::= "<vspace" ( "FIXME"  | (" blankLines=\x22"  text  "\x22"))*  ">" nl  "</vspace>" nl
element56 ::= "<xref" ( "FIXME"  | (" target=\x22"  text  "\x22") | (" pageno=\x22"  "\x22") | (" format=\x22"  "\x22") | (" derivedContent=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</xref>" nl
element57 ::= "<preamble" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element50  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</preamble>" nl
element58 ::= "<postamble" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  text  |  element45  )  |  element47  )  |  element30  )  |  element50  )  |  element56  )  )+  )  "</postamble>" nl
element59 ::= "<thead" ( "FIXME"  | (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element73  )+  )  "</thead>" nl
element60 ::= "<tbody" ( "FIXME"  | (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element73  )+  )  "</tbody>" nl
element61 ::= "<tfoot" ( "FIXME"  | (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element73  )+  )  "</tfoot>" nl
element62 ::= "<ttcol" ( "FIXME"  | (" width=\x22"  text  "\x22") | (" align=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  element45  |  element47  )  |  element30  )  |  element56  )  |  text  )  )+  )  "</ttcol>" nl
element63 ::= "<c" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  text  |  element45  )  |  element47  )  |  element30  )  |  element50  )  |  element56  )  )+  )  "</c>" nl
element64 ::= "<annotation" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element50  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</annotation>" nl
element65 ::= "<format" ( "FIXME"  | (" target=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" octets=\x22"  text  "\x22"))*  ">" nl  "</format>" nl
element66 ::= "<refcontent" ( "FIXME" )*  ">" nl  (   (  (  (  (  (  (  (  text  |  element44  )  |  element46  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  )+  )  "</refcontent>" nl
element67 ::= "<city" ( "FIXME" )*  ">" nl  (   text  )  "</city>" nl
element68 ::= "<code" ( "FIXME" )*  ">" nl  (   text  )  "</code>" nl
element69 ::= "<country" ( "FIXME" )*  ">" nl  (   text  )  "</country>" nl
element70 ::= "<region" ( "FIXME" )*  ">" nl  (   text  )  "</region>" nl
element71 ::= "<street" ( "FIXME" )*  ">" nl  (   text  )  "</street>" nl
element72 ::= "<postalLine" ( "FIXME" )*  ">" nl  (   text  )  "</postalLine>" nl
element73 ::= "<tr" ( "FIXME"  | (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  (  element74  |  element75  )  )+  )  "</tr>" nl
element74 ::= "<td" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" colspan=\x22"  text  "\x22") | (" rowspan=\x22"  text  "\x22") | (" align=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element76  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</td>" nl
element75 ::= "<th" ( "FIXME"  | (" anchor=\x22"  text  "\x22") | (" colspan=\x22"  text  "\x22") | (" rowspan=\x22"  text  "\x22") | (" align=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element76  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</th>" nl
element76 ::= "<br" ( "FIXME" )*  ">" nl  "</br>" nl

@hoehrmann
Copy link
Author

With this, llama.cpp runs out of stack space after generating a couple of lines of text, resulting in a SIGSEGV;

nl ::= "\n"?
text ::= ([^>"<&]| "&amp;"| "&lt;"| "&gt;"| "&quot;"| "&apos;"| "&#x" [0-9a-fA-F]+ ";"| "&#" [0-9]+ ";")*
root ::=  element1 
element1 ::= "<rfc" (  (" number=\x22"  text  "\x22") | (" obsoletes=\x22"  text  "\x22") | (" updates=\x22"  text  "\x22") | (" category=\x22"  text  "\x22") | (" mode=\x22"  text  "\x22") | (" consensus=\x22"  "\x22") | (" seriesNo=\x22"  text  "\x22") | (" ipr=\x22"  text  "\x22") | (" iprExtract=\x22"  text  "\x22") | (" submissionType=\x22"  "\x22") | (" docName=\x22"  text  "\x22") | (" sortRefs=\x22"  "\x22") | (" symRefs=\x22"  "\x22") | (" tocInclude=\x22"  "\x22") | (" tocDepth=\x22"  text  "\x22") | (" prepTime=\x22"  text  "\x22") | (" indexInclude=\x22"  "\x22") | (" version=\x22"  text  "\x22") | (" scripts=\x22"  text  "\x22") | (" expiresDate=\x22"  text  "\x22"))*  ">" nl  (  (  (  (   (  ""  |  (  element2  )+  )  )   element3  )   element4  )   (  ""  |  element5  )  )  "</rfc>" nl
element2 ::= "<link" (  (" href=\x22"  text  "\x22") | (" rel=\x22"  text  "\x22"))*  ">" nl  "</link>" nl
element3 ::= "<front"   ">" nl  (  (  (  (  (  (  (  (  (  (   element6  )   (  ""  |  (  element7  )+  )  )   (  element8  )+  )   (  ""  |  element9  )  )   (  ""  |  (  element10  )+  )  )   (  ""  |  (  element11  )+  )  )   (  ""  |  (  element12  )+  )  )   (  ""  |  element13  )  )   (  ""  |  (  element14  )+  )  )   (  ""  |  element15  )  )  "</front>" nl
element4 ::= "<middle"   ">" nl  (   (  element16  )+  )  "</middle>" nl
element5 ::= "<back"   ">" nl  (  (  (   (  ""  |  (  element17  )+  )  )   (  ""  |  (  element18  )+  )  )   (  ""  |  (  element16  )+  )  )  "</back>" nl
element6 ::= "<title" (  (" abbrev=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</title>" nl
element7 ::= "<seriesInfo" (  (" name=\x22"  text  "\x22") | (" value=\x22"  text  "\x22") | (" status=\x22"  text  "\x22") | (" stream=\x22"  "\x22"))*  ">" nl  "</seriesInfo>" nl
element8 ::= "<author" (  (" initials=\x22"  text  "\x22") | (" surname=\x22"  text  "\x22") | (" fullname=\x22"  text  "\x22") | (" role=\x22" "editor" "\x22"))*  ">" nl  (  (   (  ""  |  element19  )  )   (  ""  |  element20  )  )  "</author>" nl
element9 ::= "<date" (  (" day=\x22"  text  "\x22") | (" month=\x22"  text  "\x22") | (" year=\x22"  text  "\x22"))*  ">" nl  "</date>" nl
element10 ::= "<area"   ">" nl  (   text  )  "</area>" nl
element11 ::= "<workgroup"   ">" nl  (   text  )  "</workgroup>" nl
element12 ::= "<keyword"   ">" nl  (   text  )  "</keyword>" nl
element13 ::= "<abstract" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  element21  |  element22  )  |  element23  )  |  element24  )  )+  )  "</abstract>" nl
element14 ::= "<note" (  (" title=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" removeInRFC=\x22"  "\x22"))*  ">" nl  (  (   (  ""  |  element25  )  )   (  (  (  (  element21  |  element22  )  |  element23  )  |  element24  )  )+  )  "</note>" nl
element15 ::= "<boilerplate"   ">" nl  (   (  element16  )+  )  "</boilerplate>" nl
element16 ::= "<section" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" title=\x22"  text  "\x22") | (" numbered=\x22"  "\x22") | (" toc=\x22"  "\x22") | (" removeInRFC=\x22"  "\x22"))*  ">" nl  (  (  (   (  ""  |  element25  )  )   (  ""  |  (  (  (  (  (  (  (  (  (  (  (  (  element26  |  element27  )  |  element28  )  |  element21  )  |  element29  )  |  element30  )  |  element22  )  |  element31  )  |  element23  )  |  element32  )  |  element33  )  |  element24  )  )+  )  )   (  ""  |  (  element16  )+  )  )  "</section>" nl
element17 ::= "<displayreference" (  (" target=\x22"  text  "\x22") | (" to=\x22"  text  "\x22"))*  ">" nl  "</displayreference>" nl
element18 ::= "<references" (  (" pn=\x22"  text  "\x22") | (" anchor=\x22"  text  "\x22") | (" title=\x22"  text  "\x22"))*  ">" nl  (  (   (  ""  |  element25  )  )   (  ""  |  (  (  element34  |  element35  )  )+  )  )  "</references>" nl
element19 ::= "<organization" (  (" abbrev=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</organization>" nl
element20 ::= "<address"   ">" nl  (  (  (  (  (   (  ""  |  element36  )  )   (  ""  |  element37  )  )   (  ""  |  element38  )  )   (  ""  |  element39  )  )   (  ""  |  element40  )  )  "</address>" nl
element21 ::= "<dl" (  (" anchor=\x22"  text  "\x22") | (" spacing=\x22"  "\x22") | (" hanging=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  element41   element42  )  )+  )  "</dl>" nl
element22 ::= "<ol" (  (" anchor=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" start=\x22"  text  "\x22") | (" group=\x22"  text  "\x22") | (" spacing=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  element43  )+  )  "</ol>" nl
element23 ::= "<t" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" hangText=\x22"  text  "\x22") | (" keepWithNext=\x22"  "\x22") | (" keepWithPrevious=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element48  )  |  element49  )  |  element50  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element55  )  |  element56  )  )+  )  "</t>" nl
element24 ::= "<ul" (  (" anchor=\x22"  text  "\x22") | (" spacing=\x22"  "\x22") | (" empty=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  element43  )+  )  "</ul>" nl
element25 ::= "<name" (  (" slugifiedName=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  text  |  element45  )  |  element47  )  |  element49  )  |  element54  )  |  element56  )  )+  )  "</name>" nl
element26 ::= "<artwork" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" name=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" src=\x22"  text  "\x22") | (" align=\x22"  "\x22") | (" alt=\x22"  text  "\x22") | (" width=\x22"  text  "\x22") | (" height=\x22"  text  "\x22") | (" originalSrc=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</artwork>" nl
element27 ::= "<aside" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  ""  |  (  (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element30  )  |  element48  )  |  element22  )  |  element23  )  |  element32  )  |  element24  )  )+  )  )  "</aside>" nl
element28 ::= "<blockquote" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" cite=\x22"  text  "\x22") | (" quotedFrom=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</blockquote>" nl
element29 ::= "<figure" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" title=\x22"  text  "\x22") | (" suppress-title=\x22"  "\x22") | (" src=\x22"  text  "\x22") | (" originalSrc=\x22"  text  "\x22") | (" align=\x22"  "\x22") | (" alt=\x22"  text  "\x22") | (" width=\x22"  text  "\x22") | (" height=\x22"  text  "\x22"))*  ">" nl  (  (  (  (  (   (  ""  |  element25  )  )   (  ""  |  (  element30  )+  )  )   (  ""  |  element57  )  )   (  (  element26  |  element31  )  )+  )   (  ""  |  element58  )  )  "</figure>" nl
element30 ::= "<iref" (  (" item=\x22"  text  "\x22") | (" subitem=\x22"  text  "\x22") | (" primary=\x22"  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  "</iref>" nl
element31 ::= "<sourcecode" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22") | (" name=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" src=\x22"  text  "\x22") | (" originalSrc=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</sourcecode>" nl
element32 ::= "<table" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (  (  (  (  (   (  ""  |  element25  )  )   (  ""  |  (  element30  )+  )  )   (  ""  |  element59  )  )   (  element60  )+  )   (  ""  |  element61  )  )  "</table>" nl
element33 ::= "<texttable" (  (" anchor=\x22"  text  "\x22") | (" title=\x22"  text  "\x22") | (" suppress-title=\x22"  "\x22") | (" align=\x22"  "\x22") | (" style=\x22"  "\x22"))*  ">" nl  (  (  (  (  (   (  ""  |  element25  )  )   (  ""  |  element57  )  )   (  element62  )+  )   (  ""  |  (  element63  )+  )  )   (  ""  |  element58  )  )  "</texttable>" nl
element34 ::= "<reference" (  (" anchor=\x22"  text  "\x22") | (" target=\x22"  text  "\x22") | (" quoteTitle=\x22"  "\x22"))*  ">" nl  (  (   element3  )   (  ""  |  (  (  (  (  element64  |  element65  )  |  element66  )  |  element7  )  )+  )  )  "</reference>" nl
element35 ::= "<referencegroup" (  (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element34  )+  )  "</referencegroup>" nl
element36 ::= "<postal"   ">" nl  (   (  (  ""  |  (  (  (  (  (  element67  |  element68  )  |  element69  )  |  element70  )  |  element71  )  )+  )  |  (  element72  )+  )  )  "</postal>" nl
element37 ::= "<phone"   ">" nl  (   text  )  "</phone>" nl
element38 ::= "<facsimile"   ">" nl  (   text  )  "</facsimile>" nl
element39 ::= "<email"   ">" nl  (   text  )  "</email>" nl
element40 ::= "<uri"   ">" nl  (   text  )  "</uri>" nl
element41 ::= "<dt" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</dt>" nl
element42 ::= "<dd" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</dd>" nl
element43 ::= "<li" (  (" anchor=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</li>" nl
element44 ::= "<bcp14"   ">" nl  (   text  )  "</bcp14>" nl
element45 ::= "<cref" (  (" anchor=\x22"  text  "\x22") | (" source=\x22"  text  "\x22") | (" display=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  (  text  |  element46  )  |  element47  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</cref>" nl
element46 ::= "<em"   ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</em>" nl
element47 ::= "<eref" (  (" target=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</eref>" nl
element48 ::= "<list" (  (" style=\x22"  text  "\x22") | (" hangIndent=\x22"  text  "\x22") | (" counter=\x22"  text  "\x22") | (" pn=\x22"  text  "\x22"))*  ">" nl  (   (  element23  )+  )  "</list>" nl
element49 ::= "<relref" (  (" target=\x22"  text  "\x22") | (" displayFormat=\x22"  "\x22") | (" section=\x22"  text  "\x22") | (" relative=\x22"  text  "\x22") | (" derivedLink=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</relref>" nl
element50 ::= "<spanx" (  (" style=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</spanx>" nl
element51 ::= "<strong"   ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</strong>" nl
element52 ::= "<sub"   ">" nl  (   (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element54  )  |  element56  )  )+  )  "</sub>" nl
element53 ::= "<sup"   ">" nl  (   (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element54  )  |  element56  )  )+  )  "</sup>" nl
element54 ::= "<tt"   ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element56  )  )+  )  "</tt>" nl
element55 ::= "<vspace" (  (" blankLines=\x22"  text  "\x22"))*  ">" nl  "</vspace>" nl
element56 ::= "<xref" (  (" target=\x22"  text  "\x22") | (" pageno=\x22"  "\x22") | (" format=\x22"  "\x22") | (" derivedContent=\x22"  text  "\x22"))*  ">" nl  (   text  )  "</xref>" nl
element57 ::= "<preamble"   ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element50  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</preamble>" nl
element58 ::= "<postamble"   ">" nl  (   (  (  (  (  (  (  text  |  element45  )  |  element47  )  |  element30  )  |  element50  )  |  element56  )  )+  )  "</postamble>" nl
element59 ::= "<thead" (  (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element73  )+  )  "</thead>" nl
element60 ::= "<tbody" (  (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element73  )+  )  "</tbody>" nl
element61 ::= "<tfoot" (  (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  element73  )+  )  "</tfoot>" nl
element62 ::= "<ttcol" (  (" width=\x22"  text  "\x22") | (" align=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  element45  |  element47  )  |  element30  )  |  element56  )  |  text  )  )+  )  "</ttcol>" nl
element63 ::= "<c"   ">" nl  (   (  (  (  (  (  (  text  |  element45  )  |  element47  )  |  element30  )  |  element50  )  |  element56  )  )+  )  "</c>" nl
element64 ::= "<annotation"   ">" nl  (   (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element50  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  "</annotation>" nl
element65 ::= "<format" (  (" target=\x22"  text  "\x22") | (" type=\x22"  text  "\x22") | (" octets=\x22"  text  "\x22"))*  ">" nl  "</format>" nl
element66 ::= "<refcontent"   ">" nl  (   (  (  (  (  (  (  (  text  |  element44  )  |  element46  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  )+  )  "</refcontent>" nl
element67 ::= "<city"   ">" nl  (   text  )  "</city>" nl
element68 ::= "<code"   ">" nl  (   text  )  "</code>" nl
element69 ::= "<country"   ">" nl  (   text  )  "</country>" nl
element70 ::= "<region"   ">" nl  (   text  )  "</region>" nl
element71 ::= "<street"   ">" nl  (   text  )  "</street>" nl
element72 ::= "<postalLine"   ">" nl  (   text  )  "</postalLine>" nl
element73 ::= "<tr" (  (" anchor=\x22"  text  "\x22"))*  ">" nl  (   (  (  element74  |  element75  )  )+  )  "</tr>" nl
element74 ::= "<td" (  (" anchor=\x22"  text  "\x22") | (" colspan=\x22"  text  "\x22") | (" rowspan=\x22"  text  "\x22") | (" align=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element76  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</td>" nl
element75 ::= "<th" (  (" anchor=\x22"  text  "\x22") | (" colspan=\x22"  text  "\x22") | (" rowspan=\x22"  text  "\x22") | (" align=\x22"  "\x22"))*  ">" nl  (   (  (  (  (  (  (  (  (  element26  |  element21  )  |  element29  )  |  element22  )  |  element31  )  |  element23  )  |  element24  )  )+  |  (  (  (  (  (  (  (  (  (  (  (  (  (  text  |  element44  )  |  element76  )  |  element45  )  |  element46  )  |  element47  )  |  element30  )  |  element49  )  |  element51  )  |  element52  )  |  element53  )  |  element54  )  |  element56  )  )+  )  )  "</th>" nl
element76 ::= "<br"   ">" nl  "</br>" nl

@hoehrmann
Copy link
Author

XSLT to generate the above (modulo some search and replace to remove the FIXME strings):

<xsl:transform
    version='1.0'
    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
    xmlns:rng='http://relaxng.org/ns/structure/1.0'
>

    <xsl:output method='text'></xsl:output>

    <xsl:template match='rng:attribute[rng:name/@ns = "http://www.w3.org/XML/1998/namespace"]'/>
    <xsl:template match='rng:attribute[starts-with(rng:name, "ascii")]'/>

    <xsl:template match='rng:attribute'>
        <xsl:text> | (" </xsl:text>
        <xsl:value-of select='rng:name'/>
        <xsl:text>=\x22" </xsl:text>
        <xsl:apply-templates></xsl:apply-templates>
        <xsl:text> "\x22")</xsl:text>
    </xsl:template>

    <xsl:template match='rng:choice[descendant::*[descendant-or-self::*[(self::rng:value or self::rng:data or self::rng:ref or self::rng:text) and not(ancestor-or-self::rng:attribute)]]]'>
        <xsl:text> ( </xsl:text>
        <xsl:apply-templates select='*[1]'/>
        <xsl:text> | </xsl:text>
        <xsl:apply-templates select='*[2]'/>
        <xsl:text> ) </xsl:text>
    </xsl:template>

    <xsl:template match='rng:choice'/>

    <xsl:template match='rng:data'>
        <xsl:text> text </xsl:text>
    </xsl:template>

    <xsl:template match='rng:define'>
        <xsl:value-of select='@name'></xsl:value-of><xsl:text> ::= </xsl:text>
        <xsl:apply-templates/>
        <xsl:text>&#xa;</xsl:text>
    </xsl:template>

    <xsl:template match='rng:element'>
        <xsl:text>&quot;</xsl:text>
        <xsl:value-of select='concat("&lt;", rng:name)'></xsl:value-of>
        <xsl:text>&quot;</xsl:text>

        <xsl:text> ( "FIXME" </xsl:text>
        <xsl:apply-templates select='.//rng:attribute'></xsl:apply-templates>
        <xsl:text>)* </xsl:text>

        <xsl:text> &quot;&gt;&quot; nl</xsl:text>
        <xsl:text> </xsl:text>
        <xsl:apply-templates/>
        <xsl:text> </xsl:text>
        <xsl:text>&quot;</xsl:text>
        <xsl:value-of select='concat("&lt;/", rng:name)'></xsl:value-of>
        <xsl:text>&gt;&quot;</xsl:text>
        <xsl:text> nl</xsl:text>
    </xsl:template>

    <xsl:template match='rng:empty'>
        <xsl:text> "" </xsl:text>
    </xsl:template>

    <xsl:template match='rng:grammar'>
        <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match='rng:group[descendant::*[descendant-or-self::*[(self::rng:value or self::rng:data or self::rng:ref or self::rng:text) and not(ancestor-or-self::rng:attribute)]]]'>
        <xsl:text> ( </xsl:text>
        <xsl:apply-templates select='*[1]'/>
        <xsl:text> </xsl:text>
        <xsl:apply-templates select='*[2]'/>
        <xsl:text> ) </xsl:text>
    </xsl:template>
    <xsl:template match='rng:group'/>

    <xsl:template match='rng:oneOrMore'>
        <xsl:text> ( </xsl:text>
        <xsl:apply-templates/>
        <xsl:text> )+ </xsl:text>
    </xsl:template>

    <xsl:template match='rng:ref'>
        <xsl:text> </xsl:text>
        <xsl:value-of select='@name'></xsl:value-of>
        <xsl:text> </xsl:text>
    </xsl:template>

    <xsl:template match='rng:start'>
        <xsl:text>&#xa;nl ::= "\n"?</xsl:text>
        <xsl:text>&#xa;text ::= </xsl:text>
        <xsl:text>([^&gt;&quot;&lt;&amp;]</xsl:text>
        <xsl:text>| "<![CDATA[&amp;]]>"</xsl:text>
        <xsl:text>| "<![CDATA[&lt;]]>"</xsl:text>
        <xsl:text>| "<![CDATA[&gt;]]>"</xsl:text>
        <xsl:text>| "<![CDATA[&quot;]]>"</xsl:text>
        <xsl:text>| "<![CDATA[&apos;]]>"</xsl:text>
        <xsl:text>| "&amp;#x" [0-9a-fA-F]+ ";"</xsl:text>
        <xsl:text>| "&amp;#" [0-9]+ ";"</xsl:text>
        <xsl:text>)*</xsl:text>
        <xsl:text>&#xa;</xsl:text>
        <xsl:text> root ::= </xsl:text>
        <xsl:apply-templates/>
        <xsl:text>&#xa;</xsl:text>
    </xsl:template>

    <xsl:template match='rng:text'>
        <xsl:text> text </xsl:text>
    </xsl:template>

    <xsl:template match='rng:value'>
        <!-- TODO: escaping -->
        <xsl:text>"</xsl:text>
        <xsl:value-of select='.'></xsl:value-of>
        <xsl:text>"</xsl:text>
    </xsl:template>

    <xsl:template match='rng:name'/>
    <xsl:template match='text()'/>

</xsl:transform>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment