\defineregister[function][functions]
\defineregister[variable][variables]

\definehead[source][subject]
\definehead[extra] [subsubject]
\definehead[topic] [subsubsubject]

\setuphead[source][style=\bfb]
\setuphead[extra] [style=\bfa]
\setuphead[topic] [style=\bf]

\def\LDXkey     #1{\bold{#1}}
\def\LDXfunction#1{\LDXkey{function} #1\function{#1}}
\def\LDXvariable#1{#1\variable{#1}}
\def\LDXcomment #1{{\tt--#1}}
\def\LDXsource  #1{\source{#1}}

\defineXMLenvironment
    [ldx:document]
    {\page}
    {\determineregistercharacteristics[function]
     \startmode[*register]
        \extra{Functions}
        \placeregister[function]
     \stopmode
     \determineregistercharacteristics[variable]
     \startmode[*register]
        \extra{Variables}
        \placeregister[variable]
     \stopmode}

\defineXMLargument [ldx:source]   \LDXsource
\defineXMLargument [ldx:key]      \LDXkey
\defineXMLargument [ldx:variable] \LDXvariable
\defineXMLargument [ldx:function] \LDXfunction
\defineXMLargument [ldx:com]      \LDXcomment

\newcounter\CommentCounter

\defineXMLenvironment[ldx:comment]
  {\endgraf
   \blank
   \doglobal\increment\CommentCounter
   \margintitle{\bf\CommentCounter}}
  {\blank
   \endgraf}

\defineXMLenvironment[ldx:dqs]
  {\bgroup\tt"}
  {"\egroup}

\defineXMLenvironment[ldx:sqs]
  {\bgroup\tt'}
  {'\egroup}

\defineXMLenvironment[ldx:code]
  {\startpacked}
  {\stoppacked}

\defineXMLenvironment[ldx:line][n=0,comment=] % maybe hangindent or leftskip
  {\dontleavehmode
   \hbox to \hsize\bgroup
   \strut\hskip\dimexpr\XMLop{n}em/4\relax\relax
   \doif {\XMLop{comment}} {yes} {\tt}}
  {\hss
   \egroup
   \endgraf}

\defineXMLsingular[ldx:line]
  {\crlf}

\defineXMLargument [source] \LDXsource
\defineXMLargument [key]    \LDXkey

\defineXMLsingular[logo][label=,name=]
  {\uppercasestring\XMLop{label}\XMLop{label}\to\ascii
   \getvalue{\ascii}}

\defineXMLsingular[l][l=,n=]
  {\uppercasestring\XMLop{l}\XMLop{l}\to\ascii
   \getvalue{\ascii}}

\defineXMLenvironment
  [typing]
  {\blank
   \startpacked \tt
   \obeyspaces}
  {\stoppacked
   \blank}

\defineXMLentity[amp]{\&}
\defineXMLentity[lt] {<}
\defineXMLentity[gt] {>}

\usemodule[abr-02]

\startnotmode[atpragma]
    \definetypeface[mainfacenormal]  [ss][sans] [iwona]       [default]
    \definetypeface[mainfacenormal]  [rm][serif][palatino]    [default]
    \definetypeface[mainfacenormal]  [tt][mono] [modern]      [default][rscale=1.1]
    \definetypeface[mainfacenormal]  [mm][math] [iwona]       [default][encoding=default]

    \definetypeface[mainfacemedium]  [ss][sans] [iwona-medium][default]
    \definetypeface[mainfacenormal]  [rm][serif][palatino]    [default]
    \definetypeface[mainfacemedium]  [tt][mono] [modern]      [default][rscale=1.1]
    \definetypeface[mainfacemedium]  [mm][math] [iwona-medium][default][encoding=default]

    \definetypeface[mainfacenarrowtt][tt][mono] [modern-cond] [default][rscale=1.1]
\stopnotmode

\startmode[atpragma]
    \usetypescriptfile[type-ghz]

    \definetypeface[mainfacenormal]  [ss][sans] [optima-nova] [default]
    \definetypeface[mainfacenormal]  [rm][serif][palatino]    [default]
    \definetypeface[mainfacenormal]  [tt][mono] [modern]      [default][rscale=1.1]
    \definetypeface[mainfacenormal]  [mm][math] [palatino]    [default][encoding=default]

    \definetypeface[mainfacemedium]  [ss][sans] [optima-nova] [default]
    \definetypeface[mainfacenormal]  [rm][serif][palatino]    [default]
    \definetypeface[mainfacemedium]  [tt][mono] [modern]      [default][rscale=1.1]
    \definetypeface[mainfacemedium]  [mm][math] [palatino]    [default][encoding=default]

    \definetypeface[mainfacenarrowtt][tt][mono] [modern-cond] [default][rscale=1.1]
\stopmode

\setupbodyfont[mainfacenormal,11pt]

\setupwhitespace[big]

% \starttext
%     \processXMLfilegrouped{\inputfilename}
% \stoptext
