blob: 5149917806b51647d4462b231b996193452491fd (
plain)
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
|
{
open Js_of_ocaml
exception SyntaxError of string * Lexing.lexbuf
exception Eof
type arrow =
| Forward
| Backward
| Both
| None
type jstring = Js.js_string Js.t
type res =
| NewLine
| Root of jstring
| Entry of jstring * (jstring * jstring * arrow) option
| Redirection of jstring * jstring * arrow
| Separator
let get_arrow = begin function
| "<-" -> Backward
| "<->" -> Both
| "--" -> None
| _ -> Forward
end
}
let space = ['\000' '\t' '\x0C' ' ']
let spaces = space*
let newline = spaces ("\r\n" | '\n' | '\r')+
(* Any character except the delimiters and spaces *)
let regular = [^ '\n' '\x0C' '\r' ]
let target_id = ['A'-'Z' 'a'-'z' '0'-'9']+ (':' ['0'-'9']+)?
let arrow = "->" | "--" | "<-" | "<->"
rule parse_line = shortest
| eof { raise Eof }
| newline {NewLine}
| space+ '-'+ newline {Separator}
| (target_id as _1) newline { Root (Js.string _1) }
| (spaces as _1)
(arrow as _arrow) space+
(target_id as _target) spaces
(regular* as comment) newline
{ Redirection ( Js.string _target, Js.string comment, (get_arrow _arrow))}
| spaces
(regular+ as _2) space+
(arrow as _arrow) space+
(target_id as _target) spaces
(regular* as comment) newline
{ Entry (Js.string _2, Some (Js.string _target, Js.string comment, (get_arrow _arrow)))}
| (spaces as _1)
(regular+ as _2) newline
{ Entry (Js.string _2, None) }
|