#line 110 "/home/travis/build/felix-lang/felix/src/packages/flx_doc.fdoc"
  var ishtml = System::argv 1 == "--html";
  var dir =  Filename::join ("src", "lib", "std");
  
  include "plugins/fdoc-interface";
  var  xlat_fdoc = Dynlink::load-plugin-func2 [fdoc_t, string, string] (
      dll-name="fdoc2html", setup-str="", entry-point="fdoc2html"
    );
  
  
  var fregex = ".*\\.(flx|fdoc)";
  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 tex = "\\" letter*;
  regdef symbol1 = "+-*/%^";
  regdef symbol = symbol1 | symbol1 symbol1 | symbol1 symbol1 symbol1;
  regdef name = id | symbol;
  regdef spaces = " "*;
  regdef vlist =  "[" spaces id (spaces "," spaces id)* spaces "]";
  
  regdef adjective = "pure" | "inline" | "noinline" | "pod" | "open" | "virtual";
  regdef binder = "fun" | "proc" | "gen" | "class" | "union" | "struct" | "type" | "typedef" | "ctor" (spaces vlist)?;
  
  regdef indent2 = "  ";
  
  regdef classbind= group ("class" | "open class");
  regdef otherbind= indent2? group (adjective* spaces binder);
  
  // Group 1 = class
  // Group 2 = other
  // group 3 = identifier
  regdef decl = (classbind | otherbind) spaces group (name) anychar*;
  
  var emptystring = "";
  var emptystringpiece = StringPiece emptystring;
  
  var lregex = decl . render;
  var lgrep = RE2 lregex;
  var n = NumberOfCapturingGroups(lgrep)+1;
  var v = varray[StringPiece] (n.size,emptystringpiece);
  
  var extract = RE2 " *([^={]*) *(=|{|;).*";
  var n2 = NumberOfCapturingGroups(extract)+1;
  var v2 = varray[StringPiece] (n2.size,emptystringpiece);
  
  var scomment = RE2 " *//[$](.*)";
  var vcomment = varray[StringPiece] (2.size, emptystringpiece);
  
  if ishtml do
    println$ "<html><body>";
    println$ "<h1>Felix Library Contents</h1>";
  done
  
  var files = FileSystem::regfilesin (dir, fregex);
  files = files.sort;
  
  for file in files do
    var href = "/share/lib/std/"+file; // URL always uses Unix filenames
    if ishtml do
      println$ '<hr/><a href="'+href+'">'+file+'</a>';
    else
      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 spl = StringPiece line;
      var commentry = Match (scomment, spl, 0, ANCHOR_BOTH, vcomment.stl_begin, 2);
      if commentry do
         comments = Cons (vcomment . 1 . string, comments);
      else
  
        match lgrep line with
        | Some v =>
          var sym = v.3;
          var dfn = "";
          var m2 = Match (extract, spl, 0, ANCHOR_BOTH, v2.stl_begin, n2);
          if m2 do
            dfn = v2 . 1 . string . strip;
          else
            dfn = line . strip;
          done
          if ishtml do
            if prefix (dfn, "class") or prefix (dfn, "open class") do
              println$ "";
              println$  "<pre>"+ f"%04d" count + ":  " + '<a href="'+href+'#'+f"%04d" count+'">'+dfn +'</a></pre>';
              //for cline in rev comments do println$ "           "+cline; done
              var txt = "";
              for cline in rev comments do txt += cline+"\n"; done
              var result = xlat_fdoc (txt, "dummy");
              var html = #(result.html_raw);
              if txt != "" do
                println$ "<div style='font-family:sans-serif; font-size:12pt; "+
                "margin-left:100; margin-right:100; top:5; color:#406040'>" + html + "</div>";
              done
              comments = Empty[string];
            else
              println$ "<pre>"+f"%04d" count + ":    " + '<a href="'+href+'#'+f"%04d" count+'">'+ dfn +'</a></pre>';
              //for cline in rev comments do println$ "           "+ cline; done
              txt = "";
              for cline in rev comments do txt += cline+"\n"; done
              result = xlat_fdoc (txt, "dummy");
              html = #(result.html_raw);
              if txt != "" do
                println$ "<div style='font-family:sans-serif; font-size:10pt; " +
                "margin-left:100; margin-right:100; top:2; color:#404040; '>" + html + "</div>";
              done
              comments = Empty[string];
            done
          else
            if prefix (dfn, "class") or prefix (dfn, "open class") do
              println$ "";
              println$ f"%04d" count + ":  " + dfn;
              for cline in rev comments do println$ "           "+cline; done
              comments = Empty[string];
            else
              println$ f"%04d" count + ":    " + dfn;
              for cline in rev comments do println$ "           "+ cline; done
              comments = Empty[string];
            done
          done
        | #None => ;
        endmatch; //d grexp
      done
    done
  done
  
  if ishtml do
    println$ "</body></html>";
  done