verb-js.mkii / last modification: 2020-01-30 14:15
%D \module
%D   [       file=verb-js,
%D        version=1998.02.07,
%D          title=\CONTEXT\ Verbatim Macros,
%D       subtitle=Pretty \JAVASCRIPT\ Verbatim,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Verbatim Macros / Pretty JavaScript Verbatim}

%D In \CONTEXT\ we support \JAVASCRIPT\ inclusion in \PDF\
%D documents and thereby enter the field of authoring. Of
%D course we also want to pretty print such scripts, that look
%D like:
%D \startJS
%D alfa = beta*2 ;       // both alfa and beta are numbers // indeed
%D if (odd(alfa))
%D   { do_something() }
%D else
%D   { do_nothing() }    /* As we can see /* in this example */ there
%D how_about(alfa) ;        is no fi needed. Also no semicolons are
%D or_about(beta) ;         needed after a right brace. */
%D \stopJS
%D Because \JAVASCRIPT\ looks much like \PERL, we will use
%D a slightly adapted \PERL\ visualization. First we load the
%D \PERL\ module:

\ifdefined\setupprettyPLtype \else \loadmarkfile{verb-pl} \fi


%D The main difference between the \JAVASCRIPT\ and \PERL\
%D interpreters concern comments. Where \TEX, \METAPOST\ and
%D \PERL\ have one comment symbol (\type{%}, \type{%} and
%D \type{#}), \JAVA\ has the one line comment sequence
%D \type{//} and the multi line comment delimiters \type{/*}
%D and \type{*/}.
%D We need a counter to keep track of multi line comment
%D nesting.


%D We handle both \type{%} and \type{#} a bit different:

   \setpretty`\*=44 }

%D We also need a few more handlers: one for \type{//} and
%D \type{/*} and one for \type{*/}.

   \installprettyhandler 43 \JStypefourthree
   \installprettyhandler 44 \JStypefourfour }

%D We can inherit most of the settings:

      \ifcase\JScommentlevel \inPLcommentfalse \fi

   \global\JScommentlevel=0 }


%D The main complication is that we have to look upto four
%D characters ahead. Such macros are hard to understand but
%D they do work!


     \global\advance\JScommentlevel by 1


\gdef\dodoJStypefourthree% #1%




     \global\advance\JScommentlevel by -1
     \ifcase\JScommentlevel \global\inPLcommentfalse \fi

%D We need different (less) reserved words. This list replaces
%D the \PERL\ one.

\useprettyidentifiers \JSidentifiers \JSsetspecials
  abstract boolean break byte case catch char class const
  continue default delete do double else extends false final
  finally float for function goto if implements import in
  instanceof int interface long native new null package
  private protected public return short static super switch
  synchronized this throw throws transient true try var void
  while with

\useprettyidentifiers \JSvariables \JSsetspecials

\protect \endinput