# Minimal grammar for our documentation files. To compile, run
# > leg create_doc.leg -o create_doc_gen.c

start = group*

group = comments groupopening comments (EOL|function|subgroupopening)*


groupopening = stars blankline sectiontitle blankline content stars
subgroupopening = pluses blankline? subsectiontitle blankline? content pluses

sectiontitle = "    " < linecontent > EOL     {
    fprintf(out, "\\section{%.*s}\n", yyleng, yytext);}

subsectiontitle = "    " < linecontent > EOL     {
    fprintf(out, "\\subsection{%.*s}\n", yyleng, yytext);}

function = (macroheader|functionheader) functionfooter? EOL*

functionheader = < funcnametype '(' funcargs ')' modifiers? ';'?
                      > whitespace? EOL {printfuncheader(yytext, yyleng);}

macroheader = < 'macro' whitespace linecontent > EOL    {
    printfuncheader(yytext, yyleng);}

funcnametype = !('*'|'+') ('operator()' | (! '(' .))*
funcargs = (! ')' .)*
modifiers = whitespace? ("const" | "(macro)")

functionfooter = content


content = < (contentline | blankline)* >       {
    fprintf(out, "%.*s", yyleng, yytext);}

contentline = "    " linecontent EOL

linecontent = (! EOL .) *

comments = (whitespace | EOL | comment)*

comment = '/*' (! "*/" .)* '*/'

blankline = whitespace? EOL

stars = "*******************************************************************************" EOL
pluses = "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" EOL
EOL = ('\r\n' | '\n' | '\r')
whitespace = (' ' | '\t')+
