1 {
2 open Lexing;;
3
4 let need_space =
5 ref false;;
6
7 let addspace () =
8 if !need_space then begin print_char ' '; need_space := false end;;
9 }
10
11 rule main = parse
12 "\\begin{syntax}" {
13 print_string "\\begin{rawhtml}\n<PRE>\n";
14 need_space := false;
15 syntax lexbuf;
16 print_string "</PRE>\n\\end{rawhtml}\n";
17 main lexbuf }
18 | "\\@" {
19 print_string "@";
20 main lexbuf }
21 | "@" {
22 print_string "%\n\\begin{rawhtml}";
23 need_space := false;
24 syntax lexbuf;
25 print_string "\\end{rawhtml}%\n";
26 main lexbuf }
27 | _ {
28 print_char (lexeme_char lexbuf 0); main lexbuf }
29 | eof {
30 () }
31
32 and syntax = parse
33 "\\end{syntax}" { () }
34 | "@" { () }
35 | '\'' {
36 addspace();
37 print_string "<font color=\"blue\"><code>";
38 inquote lexbuf;
39 print_string "</code></font>";
40 need_space := true;
41 syntax lexbuf }
42 | '\"' {
43 addspace();
44 print_string "<font color=\"blue\"><code>";
45 indoublequote lexbuf;
46 print_string "</code></font>";
47 need_space := true;
48 syntax lexbuf }
49 | ['a'-'z'] ['a'-'z' '0'-'9' '-'] * {
50 addspace();
51 print_string "<i>";
52 print_string (lexeme lexbuf);
53 print_string "</i>";
54 need_space := true;
55 syntax lexbuf }
56 | '\\' ['a'-'z''A'-'Z'] + {
57 begin match lexeme lexbuf with
58 "\\ldots" -> print_string "..."; need_space := false
59 | s -> Printf.eprintf "Warning: %s ignored.\n" s
60 end;
61 syntax lexbuf }
62 | '_' _ {
63 print_string "<SUB>";
64 print_char(lexeme_char lexbuf 1);
65 print_string "</SUB>";
66 syntax lexbuf }
67 | '^' _ {
68 print_string "<SUP>";
69 print_char(lexeme_char lexbuf 1);
70 print_string "</SUP>";
71 syntax lexbuf }
72 | ":" {
73 print_string ":\n ";
74 need_space := false;
75 syntax lexbuf }
76 | "|" {
77 print_string "\n | ";
78 need_space := false;
79 syntax lexbuf }
80 | ";" {
81 print_string "\n\n";
82 need_space := false;
83 syntax lexbuf }
84 | [ '{' '[' '('] {
85 addspace(); print_string (lexeme lexbuf); syntax lexbuf }
86 | [ '}' ']' ')'] {
87 print_string (lexeme lexbuf); syntax lexbuf }
88 | "{{" {
89 addspace(); print_string "{"; syntax lexbuf }
90 | "}}" {
91 print_string "}+"; syntax lexbuf }
92 | "||" {
93 print_string " | "; need_space := false; syntax lexbuf }
94 | [ ' ' '\n' '\t' '~'] {
95 syntax lexbuf }
96 | [ ',' ] {
97 print_char(lexeme_char lexbuf 0); syntax lexbuf }
98 | _ {
99 Printf.eprintf "Warning: %s ignored at char %d.\n"
100 (lexeme lexbuf) (lexeme_start lexbuf);
101 syntax lexbuf }
102
103 and inquote = parse
104 '\'' { () }
105 | '&' { print_string "&amp;"; inquote lexbuf }
106 | '<' { print_string "&lt;"; inquote lexbuf }
107 | '>' { print_string "&gt;"; inquote lexbuf }
108 | _ { print_char (lexeme_char lexbuf 0); inquote lexbuf }
109
110 and indoublequote = parse
111 '"' { () }
112 | '&' { print_string "&amp;"; indoublequote lexbuf }
113 | '<' { print_string "&lt;"; indoublequote lexbuf }
114 | '>' { print_string "&gt;"; indoublequote lexbuf }
115 | _ { print_char (lexeme_char lexbuf 0); indoublequote lexbuf }
116
117
118