#line 17 "/home/travis/build/felix-lang/felix/src/packages/flx_doc.fdoc"
  var ishtml = System::argv 1 == "--html";
  var dir =  Filename::join ("src", "lib", "grammar");
  var fregex = ".*\\.flxh";
  
  open Regdef;
  regdef anychar = perl (".");
  
  regdef letter = charset "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  regdef digit = charset "0123456789";
  regdef id1 = letter | "_";
  regdef id2 = id1 | digit | "-" | "'";
  regdef id = id1 id2*;
  
  regdef spaces = " "*;
  regdef prio =  "[" id "]";
  
  regdef production = group(spaces? id prio? spaces? ":=" spaces? anychar*) "=>#" anychar*;
  regdef dssl = spaces group ("syntax" spaces id) anychar*;
  
  var lregex = (regexp (dssl | production)) . render;
  var lgrep = RE2 lregex;
  
  var n = NumberOfCapturingGroups(lgrep)+1;
  var v = varray[StringPiece] (n.size,StringPiece "");
  
  var scomment = RE2 " *//[$] (.*)";
  var vcomment = varray[StringPiece] (2.size, StringPiece "");
  
  if ishtml do
    println$ "<html><body>";
    println$ "<h1>Felix Syntax</h1>";
    println$ "<pre>";
  done
  
  for file in FileSystem::regfilesin (dir, fregex) do
    var href = "/share/lib/grammar/"+file; // URL always uses Unix filenames
    if ishtml do
      println$ '<hr/><a href="'+href+'">'+file+'</a>';
    else
      println$ "-" * 20;
      println$ file;
    done
    var lines = load (Filename::join dir file);
    var count = 0;
    var comments = Empty[string];
    for line in split (lines,char "\n") do
      ++count;
      var commentry = Match (scomment, StringPiece line, 0, ANCHOR_BOTH, vcomment.stl_begin, 2);
      if commentry do
         comments = Cons (vcomment . 1 . string.strip, comments);
      else
  
        var m = Match (lgrep, StringPiece line, 0, ANCHOR_BOTH, v.stl_begin,n);
        if m do
          var syn = v.1.string.strip;
          var prod = v.2.string.strip;
          if ishtml do
            if syn != "" do
              println$ "";
              println$  f"%04d" count + ":  " + '<a href="'+href+'#'+f"%04d" count+'">'+syn+'</a>';
              for cline in rev comments do println$ "           "+cline; done
              comments = Empty[string];
            else
              println$ f"%04d" count + ":    " + '<a href="'+href+'#'+f"%04d" count+'">'+ prod +'</a>';
              for cline in rev comments do println$ "           "+ cline; done
              comments = Empty[string];
            done
          else
            if syn != "" do
              println$ "";
              println$ f"%04d" count + ":  " + syn;
              for cline in rev comments do println$ "           "+cline; done
              comments = Empty[string];
            else
              println$ f"%04d" count + ":    " + prod;
              for cline in rev comments do println$ "           "+ cline; done
              comments = Empty[string];
            done
          done // html
        done
      done
    done
  done
  
  if ishtml do
    println$ "</pre></body></html>";
  done