812cb8416c1fb32622824c7d40d2774de79061bb
[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 #define YY_SKIP_YYWRAP
24 %}
25 %%
26                         int states[256];
27                         int top;
28                         BEGIN NORM;
29                         top = 0;
30 <NORM>@@                { printf ("@"); }
31 <NORM>@                 { printf ("<tt>"); PUSH NORM;  BEGIN VERB; }
32 <NORM>\\%               { printf ("&percnt;"); }
33 <NORM>{comment}         { }
34 <VERB>@                 { printf ("</tt>");  POP; }
35 <VERB>@@                { printf ("@"); }
36 <VERB>\>                { printf ("&gt;"); }
37 <VERB>\<                { printf ("&lt;"); }
38 <VERB>\#                { printf ("&num;"); }
39 <VERB>\$                { printf ("&dollar;"); }
40 <VERB>\%                { printf ("&percnt;"); }
41 <VERB>\&                { printf ("&amp;"); }
42 <VERB>\~                { printf ("&tilde;"); }
43 <VERB>\^                { printf ("&circ;"); }
44
45 <NORM>\<verb\>           { printf ("<verb>"); PUSH NORM; BEGIN VERBENV; }
46 <NORM>\<code\>           { printf ("<code>"); PUSH NORM; BEGIN VERBENV; }
47 <NORM>\\begin\{code\}    { printf ("<code>"); PUSH NORM; BEGIN VERBENV; }
48 <VERBENV>\<\/verb\>      { printf ("</verb>"); POP; }
49 <VERBENV>\<\/code\>      { printf ("</code>"); POP; }
50 <VERBENV>\<\\end\{code\} { printf ("</code>"); POP; }
51 <VERBENV>\&\&            { printf ("&"); }
52 <VERBENV>\&              { printf ("&ero;"); }
53 <VERBENV>\<\/            { printf ("&etago;"); }
54
55 %%
56 int
57 main()
58 {
59     yylex();
60     return(0);
61 }
62
63 /*
64 <VERB>\_                { printf ("{\\char'137}"); }
65 <VERB>\\                { printf ("{\\char'134}"); }
66 <VERB>\{                { printf ("{\\char'173}"); }
67 <VERB>\}                { printf ("{\\char'175}"); }
68 */