verb-sql.mkii / last modification: 2020-01-30 14:15
%D \module
%D   [       file=verb-sql,
%D        version=2000.05.09,
%D          title=\CONTEXT\ Verbatim Macros,
%D       subtitle=Pretty \SQL\ Verbatim,
%D         author={Berend de Boer \& Hans Hagen},
%D           date=\currentdate,
%D      copyright={Berend de Boer \& Hans Hagen}]
%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 SQL Verbatim}

%D \quotation {He, I want pretty pretting too!}, Berend cried out
%D one day, \quotation {But now for \SQL.}. This query language
%D shows code like:
%D \startbuffer
%D \startSQL
%D select *       -- some comment
%D   from tableA
%D   where 1 = 2
%D \stopSQL
%D \stopbuffer
%D \typebuffer
%D and this should become something pretty like:
%D \getbuffer
%D or, with Berend's preferences:
%D \startbuffer[setup]
%D \setuptyping
%D   [SQL]
%D   [text=yes,palet=,icommand=\bf,vcommand=,ccommand=\it]
%D \stopbuffer
%D \getbuffer[setup]
%D \getbuffer
%D This kind of pretty printing is accomplished by:
%D \typebuffer

%D Like we did with the \JAVASCRIPT\ driver, we will borrow
%D most of the macros from the \PERL\ driver.

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


%D \SQL\ has the one line comment sequence \type{--} and the
%D multi line comment delimiters \type{/*} and \type{*/}. The
%D next counter keeps track of multi line comment nesting.


%D We need to handle \type{%}, \type{#} and \type{-} a bit
%D different than in the \PERL\ driver. Compared to the
%D \JAVASCRIPT\ driver |<|we copied most of the code from
%D that one|>|, we now also have type~45.

   \setpretty`\-=45 }

%D We need three additional handlers:

   \installprettyhandler 43 \SQLtypefourthree
   \installprettyhandler 44 \SQLtypefourfour
   \installprettyhandler 45 \SQLtypefourfive }

%D Next we have to do some general housekeeping.


   \global\SQLcommentlevel=0 }


%D We have to look upto four characters ahead. If you don't
%D grab the picture, just skip reading these macros.


     \global\advance\SQLcommentlevel by 1


\gdef\dodoSQLtypefourthree% #1%




     \global\advance\SQLcommentlevel by -1

%D Much of the indirect calls (\type {dodo..}) is due to
%D looking ahead as well as midway pretty print changing.



\gdef\dodoSQLtypefourfive% #1%



%D We need a different list of reserved words. This list
%D replaces the \PERL\ one.

\useprettyidentifiers \SQLidentifiers \SQLsetspecials
  add all alter and any as asc avg begin between break
  browse bulk by cascade case check close clustered coalesce
  column commit constraint contains count create cross
  cursor database default delete desc distinct drop else end
  exec execute exists exit fetch for foreign from grant
  group having if in index inner insert into is join key
  left like max min nocheck nonclustered not null of on open
  or order outer over plan prepare proc procedure public
  references return revoce right rollback rule select set
  sum table then to tran transaction trigger truncate
  uncommited union unique update use values varying view
  when where while with work primary

\useprettyidentifiers \SQLvariables \SQLsetspecials

\protect \endinput