[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / glafp-utils / verbatim / verbatim.lex
1
2   /*    This Lex script acts as a filter to pre-process Latex files.
3
4         It surrounds groups of lines beginning with a ">" sign, and
5         preceded and followed by a blank line, with \begin{verbatim} 
6         and \end{verbatim}.  The ">" may be preceded by a digit or digit
7         range (eg 4>, 2-5>, 3->); in this case the digits are removed.  
8         They are meant to be used for filtering out versions.
9
10         It takes words surrounded with @ signs (thus @letrec@) and makes them
11         come out in typewriter font, regardless of the current mode.
12   */
13
14 %START  NORM  VERB  MIRANDA VERBATIM VERBATIMSIM
15 sp                      [ \t]*
16 nl                      {sp}\n{sp}
17 miranda                 ([0-9]+(\-([0-9]+)?)?)?>
18 %{
19 #define PUSH            states[top++] =
20 #define POP             BEGIN states[--top]
21 #define yywrap()        1
22 %}
23 %%
24                         int states[256];
25                         int top;
26                         BEGIN NORM;
27                         top = 0;
28 <NORM>@@                { printf ("@"); }
29 <NORM>@                 { printf ("\\mbox{\\tt "); PUSH NORM;  BEGIN VERB; }
30 <VERB>@                 { printf ("}");  POP; }
31 <VERB>\n                { printf ("}\\\\{}\n\\mbox{\\tt "); }
32 <VERB>" "               { printf ("\\ "); }
33 <VERB>@@                { printf ("@"); }
34 <VERB>\#                { printf ("{\\char'43}"); }
35 <VERB>\$                { printf ("{\\char'44}"); }
36 <VERB>\%                { printf ("{\\char'45}"); }
37 <VERB>\&                { printf ("{\\char'46}"); }
38 <VERB>\~                { printf ("{\\char'176}"); }
39 <VERB>\_                { printf ("{\\char'137}"); }
40 <VERB>\^                { printf ("{\\char'136}"); }
41 <VERB>\\                { printf ("{\\char'134}"); }
42 <VERB>\{                { printf ("{\\char'173}"); }
43 <VERB>\}                { printf ("{\\char'175}"); }
44
45 <NORM>^@\n              { printf( "\\begin{verbatim}\n" ); 
46                           PUSH NORM; BEGIN VERBATIMSIM; }
47 <VERBATIMSIM>^@\n       { printf( "\\end{verbatim}\n" ); POP; }
48
49 <NORM>\\"begin{verbatim}"       { printf( "\\begin{verbatim}" ); 
50                                   PUSH NORM; BEGIN VERBATIM; }
51 <VERBATIM>\\"end{verbatim}"     { printf( "\\end{verbatim}" ); POP; }
52
53 <NORM>^\n{miranda}      { printf ("\\begin{verbatim}\n>" ); 
54                           PUSH NORM; BEGIN MIRANDA; }
55 <MIRANDA>\n{miranda}    { printf( "\n>" ); }
56 <MIRANDA>^\n            { printf ("\\end{verbatim}\n"); POP; }
57 %%
58 int
59 main()
60 {
61     yylex();
62     return(0);
63 }