From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/531 Path: main.gmane.org!not-for-mail From: "Berend de Boer" Newsgroups: gmane.comp.tex.context Subject: Pretty printing for sql Date: Tue, 8 Jun 1999 18:56:06 +0200 Sender: owner-ntg-context@let.uu.nl Message-ID: <017a01beb1cf$cd6d94d0$0321a8c0@bmach.nederware.nl> NNTP-Posting-Host: coloc-standby.netfonds.no Mime-Version: 1.0 Content-Type: multipart/mixed; X-Trace: main.gmane.org 1035391384 24838 80.91.224.250 (23 Oct 2002 16:43:04 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 23 Oct 2002 16:43:04 +0000 (UTC) Original-To: Xref: main.gmane.org gmane.comp.tex.context:531 X-Report-Spam: http://spam.gmane.org/gmane.comp.tex.context:531 This is a multi-part message in MIME format. ------=_NextPart_000_017B_01BEB1E0.90F664D0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hai All, Because SQL is just as close to PERL as JAVASCRIPT is, here the first stab at syntax highlighting for SQL, see the readme for bugs. For Hans, I'm not quite sure what I've done. Maybe it's easy for you to turn off that // is a comment? Also -- is the one line comment in (some dialects of) SQL. This one is hard to do it seems. Could you create a command like \DoAtEndOfThisLine macro which I can set when needed? I like pretty printing more when not only the comment start is different, but the entire comment is well. For one liners I didn't see a way to do this. And thanks again for these great macro's! Groetjes, Berend. (-: ------=_NextPart_000_017B_01BEB1E0.90F664D0 Content-Type: application/octet-stream; name="verb-sql.README" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="verb-sql.README" Created: 1999-06-08 File: verb-sql.tex Author: Berend de Boer WHAT's THIS ----------- This file provides pretty printing for SQL. Currently it's meant to be used within ConTeXt. Use it like: \setupbodyfont[ber,ptm,pcr,11pt] \input verb-sql.tex \starttext \startSQL select * from TableA join TableB on TableB.FK = TableA.PK where TableA.ThisCol is not Null \stopSQL \stoptext INSTALLATION ----------- Place somewhere in $TEXMFLOCAL tree. Your $TEXMFLOCAL tree is something like /usr/local/texmf or /usr/local/share/texmf.local. Put it in a suitable subdirectory of $TEXMFLOCAL like $TEXMFLOCAL/tex/context. BUGS ---- This program is meant to be used with no palet. Comments are displayed in italics and reserved words in bold. That means you need a mono-spaced font that supports this. The standard font-pcr.tex and font-ber.tex are not correct in this respect. Make sure font-pcr.tex looks like this: \definefontsynonym [Mono] [Courier] \definefontsynonym [MonoBold] [Courier-Bold] \definefontsynonym [MonoItalic] [Courier-Oblique] \definefontsynonym [MonoSlanted] [Courier-Oblique] \definefontsynonym [MonoBoldItalic] [Courier-BoldOblique] \definefontsynonym [MonoBoldSlanted] [Courier-BoldOblique] \definefontsynonym [MonoCaps] [Courier] Make sure font-ber.tex thas this Courier entries: \definefontsynonym [Courier] [pcrr] \definefontsynonym [Courier-Bold] [pcrb] \definefontsynonym [Courier-Oblique] [pcrro] \definefontsynonym [Courier-BoldOblique] [pcrbo] Also one line comments starting with -- are not displayed in italics. There should be a switch to use different fonts or to use coloring. Maybe in the future. ------=_NextPart_000_017B_01BEB1E0.90F664D0 Content-Type: application/octet-stream; name="verb-sql.tex" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="verb-sql.tex" %D \module %D [ file=3Dverb-sql, %D version=3D1999.06.08, %D title=3D\CONTEXT\ Verbatim Macros, %D subtitle=3DPretty \SQL\ Verbatim, %D author=3DBerend de Boer, %D date=3D\currentdate, %D copyright=3D{Berend de Boer}] %C \writestatus{loading}{Context Support Macros / Pretty SQL Verbatim} %D He, I want pretty pretting too! %D But this one is for SQL. %D Example: %D=20 %D \startSQL %D select * %D from tableA %D where 1 =3D 2 %D \stopSQL %D=20 %D Because SQL looks much like \PERL (???), we will use %D a slightly adapted \PERL\ visualization. First we load the %D \PERL\ module: \ifx\undefined\setupprettyPLtype \input verb-pl \relax \fi \unprotect %D The main difference between the SQL and \PERL\ %D interpreters concern comments. Where \TEX, \METAPOST\ and %D \PERL\ have one comment symbol (\type{%}, \type{%} and %D \type{#}), SQL has the one line comment sequence %D \type{--} and the multi line comment delimiters \type{/*} %D and \type{*/}. %D %D We need a counter to keep track of multi line comment %D nesting. \newcount\SQLcommentlevel %D We handle both \type{%} and \type{#} a bit different: \gdef\SQLsetspecials% {\PLsetspecials \setpretty`\#=3D32 \setpretty`\%=3D41 \setpretty`\/=3D43 \setpretty`\*=3D44 \setpretty`\-=3D45 } %D We also need a few more handlers: one for \type{--} and %D \type{/*} and one for \type{*/}. \gdef\SQLsethandlers% {\PLsethandlers \installprettyhandler 43 \SQLtypefourthree \installprettyhandler 44 \SQLtypefourfour \installprettyhandler 45 \SQLtypefourfive } %D We can inherit most of the settings: \gdef\SQLsetcontrols% {\PLsetcontrols \def\obeyedline% {\endPLtypesix \ifcase\SQLcommentlevel \inPLcommentfalse \fi \PLverbosefalse \PLverboseskipped=3D0=20 \oldobeyedline}} \gdef\SQLsetvariables {\PLsetvariables \global\SQLcommentlevel=3D0 } \gdef\setupprettySQLtype% {\def\prettyidentifier{SQL}% \let\PLidentifiers=3D\SQLidentifiers \let\PLvariables=3D\SQLvariables \SQLsetvariables \SQLsetcontrols \SQLsethandlers \SQLsetspecials \def\prettyidentifierfont{\SQLidentifierfont} \SQLnormalfont \PLsetdiagnostics} %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! \gdef\SQLtypefourthree% {\handlenextnextpretty\doSQLtypefourthree\PLtypefourtwo} \gdef\doSQLtypefourthree#1#2% {\getprettydata{#2}% \ifnum\prettytype=3D43 \let\next=3D\dodoSQLtypefourthree \else\ifnum\prettytype=3D44 \global\advance\SQLcommentlevel by 1 \global\inPLcommenttrue \SQLcommentfont \PLverbosecorrection \let\next=3D\SQLtogglecomment \else \let\next=3D\PLtypefourtwo \fi\fi \next{#1}#2} \gdef\SQLtogglecomment#1#2% {\ifnum\SQLcommentlevel=3D1 \getpretties{#1}{#2} \else \getpretties{#1}{#2}% \fi} \gdef\dodoSQLtypefourthree% #1% {\endPLtypesix \handlenextnextpretty\dododoSQLtypefourthree\dodododoPLtypefourthree} \gdef\dododoSQLtypefourthree% {\ifnewpretty\expandafter\handlenewpretty\fi\dodododoSQLtypefourthree} \gdef\dodododoSQLtypefourthree#1#2% {\ifinPLcomment \getpretties{#1}{#2}% \else \global\inPLcommenttrue \PLverbosecorrection \beginofpretty[\!!prettyone]\getpretties{#1}{#2}\endofpretty \fi} \gdef\SQLtypefourfour% {\handlenextnextpretty\doSQLtypefourfour\PLtypefourtwo} \gdef\doSQLtypefourfour#1#2% {\getprettydata{#2}% \ifnum\prettytype=3D43 \SQLtogglecomment{#1}#2% \global\advance\SQLcommentlevel by -1 \SQLnormalfont \ifcase\SQLcommentlevel \global\inPLcommentfalse \fi \else \beginofpretty[\!!prettyfour]#1\endofpretty\expandafter#2% \fi} %D Handle -- type comments=20 \gdef\SQLtypefourfive% {\handlenextnextpretty\doSQLtypefourfive\PLtypefourtwo} \gdef\doSQLtypefourfive#1#2% {\ifinPLcomment \getpretties{#1}{#2}% \else \getprettydata{#2}% \ifnum\prettytype=3D45 \global\inPLcommenttrue \PLverbosecorrection %\SQLcommentfont % does not work, how can I turn this of at = end-of-line? \getpretties{#1}{#2}% \def\PLsequence{\SQLnormalfont}% \else \getpretties{#1}{#2}% \fi \fi} %D We need different reserved words. This list replaces %D 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 \useprettyidentifiers \SQLvariables \SQLsetspecials not-yet-defined \protect % I'm not sure if these settings belong here, but they need to go % somewhere. Hacking core-ver.tex is not an option. % I use no color as I produce mainly paper documents, see fonts below \definepalet [SQLcolorpretty] [colorpretty] \definepalet [SQLgraypretty] [graypretty] \definetyping[SQL][optie=3DSQL,palet=3Dnone] %D control which fonts are used for reserved words and comments. %D Reserved words should go in bold, comments in italic \definefont[SQLidentifierfont][MonoBold at \bodyfontsize] \definefont[SQLcommentfont][MonoItalic at \bodyfontsize] \definefont[SQLnormalfont][Mono at \bodyfontsize] % Oops, no hook in \settupprettiesintype, redefine it here so % SQL support works. \def\setupprettiesintype#1% {\edef\prettyidentifier{#1}% \doifinstringelse{\prettyidentifier}{tex,TEX} {\def\prettyidentifier{TEX}} {\doifinstringelse{\prettyidentifier}{perl,pl,pm,PERL,PL,PM} {\def\prettyidentifier{PL}} = {\doifinstringelse{\prettyidentifier}{metapost,mp,metafont,mf,METAPOST,MP= ,METAFONT,MF} {\def\prettyidentifier{MP}} = {\doifinstringelse{\prettyidentifier}{javascript,js,java,jv,JAVASCRIPT,JS= ,JAVA,JV} {\def\prettyidentifier{JV}} {\doifinstringelse{\prettyidentifier}{sql,SQL} {\def\prettyidentifier{SQL}} {\def\prettyidentifier{TEX}}}}}}% \doifundefined{setuppretty\prettyidentifier type}% {\bgroup \setbox0=3D\hbox % get rid of spaces when in-line \newpretty = loading {\restorecatcodes % also needed when loading during \newpretty=20 \startreadingfile % restore < and > if needed \lowercasestring verb-\prettyidentifier.tex\to\filename \readsysfile{\filename}{}{} \stopreadingfile}% \egroup}% \doifdefinedelse{setuppretty\prettyidentifier type}% {\def\setupprettytype{\getvalue{setuppretty\prettyidentifier = type}}} {\let\setupprettytype=3D\relax}} \endinput =20 ------=_NextPart_000_017B_01BEB1E0.90F664D0--