{ v1b Render an ixml grammar as html, from the ixml specification.
  Extended with the xmq ixml extensions: renaming name>alias, rule costs =< and
  =<<, the controlled ambiguity mark *rule and negative lookahead !factor.
  The characters < and & are escaped. }
{version 2022-06-07}
         ixml:  +"<HTML>", HEADER, +"<BODY><PRE>", s, prolog?, rule++RS, s, +"</PRE></BODY></HTML>".

           -s: (whitespace; comment)*. {Optional spacing}
          -RS: (whitespace; comment)+. {Required spacing}
  -whitespace: [Zs]; tab; lf; cr.
         -tab: #9.
          -lf: #a.
          -cr: #d.
     -comment: +'<SPAN CLASS="comment">', "{", (cchar; comment)*, "}", +'</SPAN>'.
       -cchar: ~["{}<&"]; lt; amp.
          -lt: -"<", +"&lt;".
         -amp: -"&", +"&amp;".

      -prolog: version, s.
     -version: "ixml", RS, "version", RS, string, s, -'.' .

        -rule: (rmark, s)?, +'<SPAN CLASS="rule">', name, +"</SPAN>", s, alias?, ["=:"], cost, s, -alts, ".".
        -mark: +'<SPAN CLASS="mark">', ["@^-"], +'</SPAN>'.
       -rmark: +'<SPAN CLASS="mark">', ["@^-*"], +'</SPAN>'.
       -alias: ">", s, +'<SPAN CLASS="rule">', name, +"</SPAN>", s.
        -cost: (+'<SPAN CLASS="mark">', lt+, +'</SPAN>')?.
        -alts: alt++([";|"], s).
         -alt: term**(",", s).
        -term: factor;
               option;
               repeat0;
               repeat1.
      -factor: terminal;
               nonterminal;
               insertion;
               "(", s, alts, ")", s;
               +'<SPAN CLASS="mark">', "!", +'</SPAN>', s, factor.
     -repeat0: factor, ("*", s; "**", s, sep).
     -repeat1: factor, ("+", s; "++", s, sep).
      -option: factor, "?", s.
         -sep: factor.
 -nonterminal: (mark, s)?, +'<SPAN CLASS="ref">', name, +'</SPAN>', s,
               (">", s, +'<SPAN CLASS="ref">', name, +'</SPAN>', s)?.

        -name: namestart, namefollower*.
   -namestart: ["_"; L].
-namefollower: namestart; ["-.·‿⁀"; Nd; Mn].

    -terminal: literal;
               +'<SPAN CLASS="charset">', charset, +'</SPAN>'.
     -literal: quoted;
               encoded.
      -quoted: (tmark, s)?, +'<SPAN CLASS="string">', string, +'</SPAN>', s.

       -tmark: +'<SPAN CLASS="mark">', ["^-"], +'</SPAN>'.
      -string: '"', dchar+, '"';
               "'", schar+, "'".
       -dchar: ~['"'; #a; #d; "<&"]; lt; amp;
               '"', -'"'. {all characters except line breaks; quotes must be doubled}
       -schar: ~["'"; #a; #d; "<&"]; lt; amp;
               "'", "'". {all characters except line breaks; quotes must be doubled}
     -encoded: (tmark, s)?, "#", hex, s.
         -hex: ["0"-"9"; "a"-"f"; "A"-"F"]+.

     -charset: inclusion;
               exclusion.
   -inclusion: (tmark, s)?,          set.
   -exclusion: (tmark, s)?, "~", s, set.
         -set: "[", s,  (member, s)**([";|"], s), "]", s.
      -member: string;
               "#", hex;
               range;
               class.
       -range: from, s, "-", s, to.
        -from: character.
          -to: character.
   -character: '"', dchar, '"';
               "'", schar, "'";
               "#", hex.
       -class: code.
        -code: capital, letter?.
     -capital: ["A"-"Z"].
      -letter: ["a"-"z"].
   -insertion: +'<SPAN CLASS="insert">', "+", s, (string; "#", hex), +'</SPAN>', s.

-HEADER: +'<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="color-scheme" content="light dark">',
+"<style>:root {",
+"--bg: #fffcf2;",
+"--fg: #000000;",
+"--rule: #CC6921;",
+"--ref: #5555AA;",
+"--string: #118811;",
+"--insert: #955900;",
+"--charset: #C33682;",
+"--mark: #ff4444;",
+"--comment: #586e75;",
+".ref { font-weight: bold; }",
+"}@media (prefers-color-scheme: dark) {  :root {",
+"--bg: #002b36;",
+"--fg: #ffffff;",
+"--rule: #EE6931;",
+"--ref: #7777ff;",
+"--string: #77ff77;",
+"--insert: #b58900;",
+"--charset: #F356A2;",
+"--mark: #ff4444;",
+"--comment: #788e95;",
+".ref { font-weight: normal; }",
+"}}html,body {  background-color: var(--bg);  color: var(--fg);  margin: 0;  padding: 1em;  min-height: 100vh;  font-size: 16px;}.comment { color: var(--comment); }.rule { font-weight: bold; color: var(--rule); }.ref { color: var(--ref); }.string { color: var(--string); }.charset { color: var(--charset); }.insert { color: var(--insert); }.mark{ color: var(--mark); }</style>".