[project @ 1997-12-15 11:14:46 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 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 ("<tt>"); PUSH NORM;  BEGIN VERB; }
30 <VERB>@                 { printf ("</tt>");  POP; }
31 <VERB>@@                { printf ("@"); }
32 <VERB>\>                { printf ("&gt;"); }
33 <VERB>\<                { printf ("&lt;"); }
34 <VERB>\#                { printf ("&num;"); }
35 <VERB>\$                { printf ("&dollar;"); }
36 <VERB>\%                { printf ("&percnt;"); }
37 <VERB>\&                { printf ("&amp;"); }
38 <VERB>\~                { printf ("&tilde;"); }
39 <VERB>\^                { printf ("&circ;"); }
40
41 <NORM>\<verb\>          { printf ("<verb>"); PUSH NORM; BEGIN VERBENV; }
42 <VERBENV>\<\/verb\>     { printf ("</verb>"); POP; }
43 <VERBENV>\&\&           { printf ("&"); }
44 <VERBENV>\&             { printf ("&ero;"); }
45 <VERBENV>\<\/           { printf ("&etago;"); }
46
47 %%
48 int
49 main()
50 {
51     yylex();
52     return(0);
53 }
54
55 /*
56 <VERB>\_                { printf ("{\\char'137}"); }
57 <VERB>\\                { printf ("{\\char'134}"); }
58 <VERB>\{                { printf ("{\\char'173}"); }
59 <VERB>\}                { printf ("{\\char'175}"); }
60 */