1 {
2 open Lexing;;
3 open Printf;;
4
5 let print_char_repr c =
6 match c with
7 | '\'' -> printf "{\\textquotesingle}"
8 | '`' -> printf "{\\textasciigrave}"
9 | _ -> printf "\\char%d" (int_of_char c);
10 ;;
11 }
12
13 rule main = parse
14 "\\begin{syntax}" {
15 print_string "\\begin{syntax}";
16 syntax lexbuf }
17 | "\\begin{verbatim}" | "\\begin{camlexample}" as s {
18 print_string s;
19 verbatim lexbuf }
20 | "\\@" {
21 print_string "@";
22 main lexbuf }
23 | "@" {
24 print_string "\\synt{";
25 syntax lexbuf }
26 | _ {
27 print_char (lexeme_char lexbuf 0); main lexbuf }
28 | eof {
29 () }
30
31 and syntax = parse
32 "\\end{syntax}" {
33 print_string "\\end{syntax}";
34 main lexbuf }
35 | "@" {
36 print_string "}";
37 main lexbuf }
38 | '\'' {
39 print_string "\\token{";
40 inquote lexbuf }
41 | '\"' {
42 print_string "\\token{";
43 indoublequote lexbuf }
44 | "epsilon" { print_string "\\emptystring"; syntax lexbuf }
45 | ['a'-'z' 'A'-'Z'] ['a'-'z' 'A'-'Z' '0'-'9' '-'] * as lxm {
46 print_string "\\nonterm{";
47 print_string lxm ;
48 print_string"}";
49 syntax lexbuf }
50 | '@' (['a'-'z' 'A'-'Z'] ['a'-'z' 'A'-'Z' '0'-'9' '-'] * as lxm) '@' {
51 print_string "\\nt{";
52 print_string lxm ;
53 print_string"}";
54 syntax lexbuf }
55
56 | '\\' ['a'-'z''A'-'Z'] + {
57 print_string (lexeme lexbuf);
58 syntax lexbuf }
59 | ['_' '^'] _ {
60 print_string (lexeme lexbuf);
61 syntax lexbuf }
62 | "{" { print_string "\\brepet{}"; syntax lexbuf }
63 | "}" { print_string "\\erepet{}"; syntax lexbuf }
64 | "{{" { print_string "\\brepets{}"; syntax lexbuf }
65 | "}}" { print_string "\\erepets{}"; syntax lexbuf }
66 | "[" { print_string "\\boption{}"; syntax lexbuf }
67 | "]" { print_string "\\eoption{}"; syntax lexbuf }
68 | "(" { print_string "\\bparen{}"; syntax lexbuf }
69 | ")" { print_string "\\eparen{}"; syntax lexbuf }
70 | "||" { print_string "\\orelse{}"; syntax lexbuf }
71 | ":" { print_string "\\is{}"; syntax lexbuf }
72 | "|" { print_string "\\alt{}"; syntax lexbuf }
73 | ";" { print_string "\\sep{}"; syntax lexbuf }
74 | "\\\\" { print_string "\\cutline{}"; syntax lexbuf }
75 | _ {
76 print_char (lexeme_char lexbuf 0);
77 syntax lexbuf }
78
79 and inquote = parse
80 ['A'-'Z' 'a'-'z' '0'-'9'] {
81 print_char (lexeme_char lexbuf 0);
82 inquote lexbuf }
83 | '\'' {
84 print_string "}";
85 syntax lexbuf }
86 | _ {
87 print_char_repr (lexeme_char lexbuf 0);
88 inquote lexbuf }
89
90 and indoublequote = parse
91 ['A'-'Z' 'a'-'z' '0'-'9'] {
92 print_char (lexeme_char lexbuf 0);
93 indoublequote lexbuf }
94 | '"' {
95 print_string "}";
96 syntax lexbuf }
97 | _ {
98 print_char_repr (lexeme_char lexbuf 0);
99 indoublequote lexbuf }
100
101 and verbatim = parse
102 "\n\\end{verbatim}"|"\\end{camlexample}" as s {
103 print_string s;
104 main lexbuf }
105 | _ {
106 print_char (lexeme_char lexbuf 0);
107 verbatim lexbuf }
108