~tedks/+junk/spacer

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
%{
  open Ast
  let parse_error s = print_endline s
%}
%token <string> STRING

%type <string list> file
%token SEP EOF 
%token <string> LINE

%type <Ast.cardstr> line
%token <string> CLOZE
%token <string> DEFIN
%token <string> LIST

%type <Ast.card> defin
%token DEFSPLIT


%type <Ast.card> list
%type <(int * string) list> entries
%token <string> LISTSTR
%token BEGINLIST
%token <int> ENTRYSTART

%start file line defin list
%% 
file:
| EOF { [] }
| LINE EOF { [] }			/* discard the last string */
| LINE SEP file { $1 :: $3 }

line:
| CLOZE { Clozestr($1) }
| DEFIN { Definstr($1) }
| LIST { Liststr($1) }

defin:
| STRING DEFSPLIT STRING { Defin($1, $3) }

list:
| LISTSTR BEGINLIST entries { List($1, $3) }

entries:
| EOF { [] }
| ENTRYSTART LISTSTR entries { ($1, $2) :: $3 }