[project @ 1998-10-07 16:33:23 by simonm]
[ghc-hetmet.git] / glafp-utils / sgmlverb / sgmlverb.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  VERBENV
15 sp                      [ \t]*
16 nl                      {sp}\n{sp}
17 comment                 \%.*$
18 miranda                 ([0-9]+(\-([0-9]+)?)?)?>
19 %{
20 #define PUSH            states[top++] =
21 #define POP             BEGIN states[--top]
22 #define yywrap()        1
23 %}
24 %%
25                         int states[256];
26                         int top;
27                         BEGIN NORM;
28                         top = 0;
29 <NORM>@@                { printf ("@"); }
30 <NORM>@                 { printf ("<tt>"); PUSH NORM;  BEGIN VERB; }
31 <NORM>\\%               { printf ("&percnt;"); }
32 <NORM>{comment}         { }
33 <VERB>@                 { printf ("</tt>");  POP; }
34 <VERB>@@                { printf ("@"); }
35 <VERB>\>                { printf ("&gt;"); }
36 <VERB>\<                { printf ("&lt;"); }
37 <VERB>\#                { printf ("&num;"); }
38 <VERB>\$                { printf ("&dollar;"); }
39 <VERB>\%                { printf ("&percnt;"); }
40 <VERB>\&                { printf ("&amp;"); }
41 <VERB>\~                { printf ("&tilde;"); }
42 <VERB>\^                { printf ("&circ;"); }
43
44 <NORM>\<verb\>           { printf ("<verb>"); PUSH NORM; BEGIN VERBENV; }
45 <NORM>\<code\>           { printf ("<code>"); PUSH NORM; BEGIN VERBENV; }
46 <NORM>\\begin\{code\}    { printf ("<code>"); PUSH NORM; BEGIN VERBENV; }
47 <VERBENV>\<\/verb\>      { printf ("</verb>"); POP; }
48 <VERBENV>\<\/code\>      { printf ("</code>"); POP; }
49 <VERBENV>\<\\end\{code\} { printf ("</code>"); POP; }
50 <VERBENV>\&\&            { printf ("&"); }
51 <VERBENV>\&              { printf ("&ero;"); }
52 <VERBENV>\<\/            { printf ("&etago;"); }
53
54 %%
55 int
56 main()
57 {
58     yylex();
59     return(0);
60 }
61
62 /*
63 <VERB>\_                { printf ("{\\char'137}"); }
64 <VERB>\\                { printf ("{\\char'134}"); }
65 <VERB>\{                { printf ("{\\char'173}"); }
66 <VERB>\}                { printf ("{\\char'175}"); }
67 */