-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.mly
53 lines (41 loc) · 947 Bytes
/
parser.mly
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
%{
let string_of_chars chars =
let buf = Buffer.create 1000 in
List.iter (Buffer.add_char buf) chars;
Buffer.contents buf
%}
%token <char> CHAR
%token <string> STRING
%token COMMA CRLF EOF
%start templatetext
%start csvtext
%type <(bool * string) list> templatetext
%type <string list list> csvtext
%type <string list> csvrow
%type <string> csventry
%type <char list> chars
%%
templatetext:
EOF { [] }
| chars templatetext { (true, string_of_chars $1) :: $2 }
| STRING templatetext { (false, $1) :: $2 }
;
csvtext:
EOF { [] }
| csvrow EOF { [$1] }
| csvrow CRLF csvtext { $1 :: $3 }
;
csvrow:
{ [] }
| csventry { [$1] }
| csventry COMMA csvrow { $1 :: $3 }
;
csventry:
chars { string_of_chars $1 }
| STRING { $1 }
;
chars:
{ [] }
| CHAR chars { $1 :: $2 }
;
%%