Source file doc_lexer.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# 1 "atd/src/doc_lexer.mll"
 
  open Doc_types

  let close_paragraph a1 a2 a3 =
    let a2 =
      match String.concat "" (List.rev a3) with
          "" -> a2
        | s -> Text s :: a2
    in
    match List.rev a2 with
        [] -> a1
      | l -> Paragraph l :: a1

  let rev_concat rev_fragments =
    List.rev rev_fragments |> String.concat ""

  let count_leading_spaces line =
    let n = ref 0 in
    try
      String.iter (function ' ' -> incr n | _ -> raise Exit) line;
      (* blank line = infinite indentation *)
      max_int
    with Exit -> !n

  (* Remove as many leading spaces as possible while maintaining the relative
     visual positioning of the text *)
  let trim_indentation lines =
    match lines with
    | [] -> []
    | first :: other_lines ->
        let removable_indentation =
          List.fold_left
            (fun mini line ->
               min (count_leading_spaces line) mini)
            (count_leading_spaces first) other_lines
        in
        List.map (fun str ->
          let len = String.length str in
          if removable_indentation <= len then
            String.sub str
              removable_indentation
              (String.length str - removable_indentation)
          else
            (* blank line with no or too few leading spaces *)
            ""
        ) lines

# 50 "atd/src/doc_lexer.ml"
let __ocaml_lex_tables = {
  Lexing.lex_base =
   "\000\000\248\255\249\255\005\000\010\000\012\000\001\000\003\000\
    \004\000\255\255\006\000\008\000\014\000\253\255\001\000\009\000\
    \011\000\020\000\025\000\249\255\011\000\030\000\036\000\012\000\
    \013\000\255\255\254\255\014\000\250\255\050\000\248\255\250\255\
    \015\000\056\000\016\000\002\000\253\255\019\000\020\000\255\255\
    \021\000\254\255\022\000\024\000\249\255";
  Lexing.lex_backtrk =
   "\004\000\255\255\255\255\003\000\004\000\004\000\007\000\007\000\
    \255\255\255\255\000\000\001\000\002\000\255\255\255\255\255\255\
    \255\255\005\000\255\255\255\255\004\000\003\000\002\000\004\000\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \005\000\004\000\003\000\005\000\255\255\005\000\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255";
  Lexing.lex_default =
   "\003\000\000\000\000\000\003\000\255\255\255\255\255\255\255\255\
    \255\255\000\000\255\255\255\255\255\255\000\000\255\255\255\255\
    \255\255\255\255\021\000\000\000\255\255\021\000\255\255\255\255\
    \255\255\000\000\000\000\255\255\000\000\033\000\000\000\000\000\
    \255\255\033\000\255\255\255\255\000\000\255\255\255\255\000\000\
    \255\255\000\000\255\255\255\255\000\000";
  Lexing.lex_trans =
   "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\005\000\004\000\013\000\034\000\005\000\255\255\255\255\
    \000\000\000\000\255\255\004\000\017\000\005\000\004\000\004\000\
    \013\000\005\000\000\000\014\000\000\000\017\000\017\000\000\000\
    \005\000\017\000\022\000\022\000\000\000\255\255\022\000\255\255\
    \255\255\000\000\004\000\255\255\005\000\022\000\022\000\000\000\
    \000\000\022\000\000\000\000\000\017\000\000\000\000\000\000\000\
    \000\000\022\000\000\000\036\000\034\000\000\000\255\255\035\000\
    \000\000\255\255\255\255\000\000\022\000\255\255\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\031\000\000\000\000\000\000\000\000\000\000\000\
    \255\255\000\000\000\000\000\000\007\000\000\000\000\000\009\000\
    \000\000\255\255\000\000\000\000\000\000\000\000\000\000\000\000\
    \025\000\000\000\000\000\000\000\000\000\000\000\000\000\039\000\
    \000\000\000\000\000\000\000\000\000\000\023\000\000\000\000\000\
    \000\000\000\000\255\255\006\000\011\000\001\000\008\000\010\000\
    \255\255\009\000\255\255\012\000\016\000\015\000\012\000\015\000\
    \028\000\024\000\026\000\028\000\043\000\042\000\037\000\015\000\
    \038\000\040\000\041\000\043\000\255\255\044\000\020\000\000\000\
    \000\000\000\000\000\000\255\255\000\000\000\000\000\000\000\000\
    \000\000\027\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\032\000\
    \000\000\000\000\000\000\000\000\000\000\255\255\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \002\000\000\000\000\000\000\000\000\000\255\255\000\000\000\000\
    \000\000\000\000\002\000\000\000\002\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\
    \000\000\019\000\000\000\000\000\000\000\000\000\255\255\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\
    \000\000\000\000\030\000\000\000\000\000\000\000\000\000\000\000\
    \255\255";
  Lexing.lex_check =
   "\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\000\000\000\000\014\000\035\000\000\000\003\000\003\000\
    \255\255\255\255\003\000\004\000\004\000\005\000\005\000\004\000\
    \012\000\005\000\255\255\012\000\255\255\017\000\017\000\255\255\
    \000\000\017\000\018\000\018\000\255\255\003\000\018\000\021\000\
    \021\000\255\255\004\000\021\000\005\000\022\000\022\000\255\255\
    \255\255\022\000\255\255\255\255\017\000\255\255\255\255\255\255\
    \255\255\018\000\255\255\029\000\029\000\255\255\021\000\029\000\
    \255\255\033\000\033\000\255\255\022\000\033\000\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\029\000\255\255\255\255\255\255\255\255\255\255\
    \033\000\255\255\255\255\255\255\000\000\255\255\255\255\007\000\
    \255\255\003\000\255\255\255\255\255\255\255\255\255\255\255\255\
    \023\000\255\255\255\255\255\255\255\255\255\255\255\255\037\000\
    \255\255\255\255\255\255\255\255\255\255\018\000\255\255\255\255\
    \255\255\255\255\021\000\000\000\006\000\000\000\007\000\008\000\
    \003\000\010\000\003\000\011\000\015\000\004\000\016\000\005\000\
    \020\000\023\000\024\000\027\000\032\000\034\000\029\000\017\000\
    \037\000\038\000\040\000\042\000\033\000\043\000\018\000\255\255\
    \255\255\255\255\255\255\021\000\255\255\255\255\255\255\255\255\
    \255\255\022\000\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\029\000\
    \255\255\255\255\255\255\255\255\255\255\033\000\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \000\000\255\255\255\255\255\255\255\255\003\000\255\255\255\255\
    \255\255\255\255\004\000\255\255\005\000\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\017\000\255\255\255\255\255\255\
    \255\255\018\000\255\255\255\255\255\255\255\255\021\000\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\
    \255\255\255\255\029\000\255\255\255\255\255\255\255\255\255\255\
    \033\000";
  Lexing.lex_base_code =
   "";
  Lexing.lex_backtrk_code =
   "";
  Lexing.lex_default_code =
   "";
  Lexing.lex_trans_code =
   "";
  Lexing.lex_check_code =
   "";
  Lexing.lex_code =
   "";
}

let rec paragraph a1 a2 a3 lexbuf =
   __ocaml_lex_paragraph_rec a1 a2 a3 lexbuf 0
and __ocaml_lex_paragraph_rec a1 a2 a3 lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
let
# 62 "atd/src/doc_lexer.mll"
                                 s
# 177 "atd/src/doc_lexer.ml"
= Lexing.sub_lexeme lexbuf (lexbuf.Lexing.lex_start_pos + 1) lexbuf.Lexing.lex_curr_pos in
# 63 "atd/src/doc_lexer.mll"
                        ( paragraph a1 a2 (s :: a3) lexbuf )
# 181 "atd/src/doc_lexer.ml"

  | 1 ->
# 65 "atd/src/doc_lexer.mll"
                        ( let code = inline_verbatim [] lexbuf in
                          let a2 =
                            match String.concat "" (List.rev a3) with
                                "" -> a2
                              | s -> Text s :: a2
                          in
                          let a2 = Code code :: a2 in
                          paragraph a1 a2 [] lexbuf
                        )
# 194 "atd/src/doc_lexer.ml"

  | 2 ->
# 75 "atd/src/doc_lexer.mll"
                        ( let pre = verbatim [] [] lexbuf in
                          let a1 = close_paragraph a1 a2 a3 in
                          let a1 = Pre pre :: a1 in
                          paragraph a1 [] [] lexbuf
                        )
# 203 "atd/src/doc_lexer.ml"

  | 3 ->
let
# 80 "atd/src/doc_lexer.mll"
                        s
# 209 "atd/src/doc_lexer.ml"
= Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in
# 81 "atd/src/doc_lexer.mll"
                        ( paragraph a1 a2 (s :: a3) lexbuf )
# 213 "atd/src/doc_lexer.ml"

  | 4 ->
# 83 "atd/src/doc_lexer.mll"
                        ( paragraph a1 a2 (" " :: a3) lexbuf )
# 218 "atd/src/doc_lexer.ml"

  | 5 ->
# 85 "atd/src/doc_lexer.mll"
                        ( let a1 = close_paragraph a1 a2 a3 in
                          paragraph a1 [] [] lexbuf
                        )
# 225 "atd/src/doc_lexer.ml"

  | 6 ->
# 88 "atd/src/doc_lexer.mll"
                        ( let a1 = close_paragraph a1 a2 a3 in
                          List.rev a1 )
# 231 "atd/src/doc_lexer.ml"

  | 7 ->
let
# 91 "atd/src/doc_lexer.mll"
         c
# 237 "atd/src/doc_lexer.ml"
= Lexing.sub_lexeme_char lexbuf lexbuf.Lexing.lex_start_pos in
# 91 "atd/src/doc_lexer.mll"
                        ( paragraph a1 a2 (String.make 1 c :: a3) lexbuf )
# 241 "atd/src/doc_lexer.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_paragraph_rec a1 a2 a3 lexbuf __ocaml_lex_state

and inline_verbatim accu lexbuf =
   __ocaml_lex_inline_verbatim_rec accu lexbuf 18
and __ocaml_lex_inline_verbatim_rec accu lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 101 "atd/src/doc_lexer.mll"
                        ( inline_verbatim ("\\" :: accu) lexbuf )
# 253 "atd/src/doc_lexer.ml"

  | 1 ->
# 102 "atd/src/doc_lexer.mll"
                        ( inline_verbatim ("}}" :: accu) lexbuf )
# 258 "atd/src/doc_lexer.ml"

  | 2 ->
# 103 "atd/src/doc_lexer.mll"
                        ( inline_verbatim (" " :: accu) lexbuf )
# 263 "atd/src/doc_lexer.ml"

  | 3 ->
let
# 104 "atd/src/doc_lexer.mll"
                         s
# 269 "atd/src/doc_lexer.ml"
= Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in
# 105 "atd/src/doc_lexer.mll"
                        ( inline_verbatim (s :: accu) lexbuf )
# 273 "atd/src/doc_lexer.ml"

  | 4 ->
let
# 106 "atd/src/doc_lexer.mll"
         c
# 279 "atd/src/doc_lexer.ml"
= Lexing.sub_lexeme_char lexbuf lexbuf.Lexing.lex_start_pos in
# 106 "atd/src/doc_lexer.mll"
                        ( inline_verbatim (String.make 1 c :: accu) lexbuf )
# 283 "atd/src/doc_lexer.ml"

  | 5 ->
# 108 "atd/src/doc_lexer.mll"
                        ( String.concat "" (List.rev accu) )
# 288 "atd/src/doc_lexer.ml"

  | 6 ->
# 110 "atd/src/doc_lexer.mll"
                        ( failwith "Missing `}}'" )
# 293 "atd/src/doc_lexer.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_inline_verbatim_rec accu lexbuf __ocaml_lex_state

and verbatim lines line lexbuf =
   __ocaml_lex_verbatim_rec lines line lexbuf 29
and __ocaml_lex_verbatim_rec lines line lexbuf __ocaml_lex_state =
  match Lexing.engine __ocaml_lex_tables __ocaml_lex_state lexbuf with
      | 0 ->
# 119 "atd/src/doc_lexer.mll"
                        ( verbatim lines ("\\" :: line) lexbuf )
# 305 "atd/src/doc_lexer.ml"

  | 1 ->
# 120 "atd/src/doc_lexer.mll"
                        ( verbatim lines ("}}}" :: line) lexbuf )
# 310 "atd/src/doc_lexer.ml"

  | 2 ->
# 121 "atd/src/doc_lexer.mll"
                        ( verbatim lines ("        " :: line) lexbuf )
# 315 "atd/src/doc_lexer.ml"

  | 3 ->
# 122 "atd/src/doc_lexer.mll"
                        ( verbatim (rev_concat line :: lines) [] lexbuf )
# 320 "atd/src/doc_lexer.ml"

  | 4 ->
let
# 123 "atd/src/doc_lexer.mll"
                         s
# 326 "atd/src/doc_lexer.ml"
= Lexing.sub_lexeme lexbuf lexbuf.Lexing.lex_start_pos lexbuf.Lexing.lex_curr_pos in
# 124 "atd/src/doc_lexer.mll"
                        ( verbatim lines (s :: line) lexbuf )
# 330 "atd/src/doc_lexer.ml"

  | 5 ->
let
# 125 "atd/src/doc_lexer.mll"
         c
# 336 "atd/src/doc_lexer.ml"
= Lexing.sub_lexeme_char lexbuf lexbuf.Lexing.lex_start_pos in
# 125 "atd/src/doc_lexer.mll"
                        ( verbatim lines (String.make 1 c :: line) lexbuf )
# 340 "atd/src/doc_lexer.ml"

  | 6 ->
# 127 "atd/src/doc_lexer.mll"
                        ( List.rev (rev_concat line :: lines)
                          |> trim_indentation )
# 346 "atd/src/doc_lexer.ml"

  | 7 ->
# 130 "atd/src/doc_lexer.mll"
                        ( failwith "Missing `}}}'" )
# 351 "atd/src/doc_lexer.ml"

  | __ocaml_lex_state -> lexbuf.Lexing.refill_buff lexbuf;
      __ocaml_lex_verbatim_rec lines line lexbuf __ocaml_lex_state

;;

# 132 "atd/src/doc_lexer.mll"
 
  let parse_string s =
    let lexbuf = Lexing.from_string s in
    paragraph [] [] [] lexbuf

# 364 "atd/src/doc_lexer.ml"