aboutsummaryrefslogtreecommitdiff
path: root/lib/parser.mly
blob: f14550e0e8ed236c013129a2962ab9cd76463ed0 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
%{
  open Ast_types
%}
%token COMMA
%token INCREMENT
%token <string> IDENTIFIER
%token UUIDV4
%token NEWLINE
%token SEMICOLON
%token NAME
%token COLON
%token DOT
%token EOF
%token PAST
%token FUTURE
%token NOW
%token INTSYMBOL 
%token <int> INT
%token LBRACE
%token RBRACE
%token EMAIL
%token <string> STRING
%token USERNAME
%start <ast_table option > prog 
%% 

prog: 
  | e = expr; EOF { Some e }
  ;

id_or_other:
  | IDENTIFIER { $1 }
  | NAME { "name" }
  | UUIDV4 { "uuidv4" }
  | INCREMENT { "increment" }
  | EMAIL { "email" }
  | USERNAME { "username" }


expr:
  | tbl = id_or_other; LBRACE; amount = INT; RBRACE; COLON; r = row; NEWLINE; e = expr { Table (tbl, amount, r, e) }
  | tbl = id_or_other; LBRACE; amount = INT; RBRACE; COLON; r = row; SEMICOLON; e = expr { Table (tbl,amount, r, e) }
  | tbl = id_or_other; LBRACE; amount = INT; RBRACE; COLON; r = row { Table (tbl,amount, r, End) }
  ;

row: 
  | row_title = id_or_other; parent = id_or_other; DOT; parent_id = id_or_other; COMMA; r = row { Foreign (parent,parent_id,row_title, r) }
  | row_title = id_or_other; parent = id_or_other; DOT; parent_id = id_or_other; { Foreign (parent,parent_id,row_title, End) }

  | row_title = id_or_other; UUIDV4; COMMA; r = row { Uuidv4 (row_title, r) }
  | row_title = id_or_other; UUIDV4 { Uuidv4 (row_title, End) }

  | row_title = id_or_other; LBRACE; union = union_fields; RBRACE; COMMA; r = row { List (row_title, union, r) }
  | row_title = id_or_other; LBRACE; union = union_fields; RBRACE { List (row_title, union, End) }

  | row_title = id_or_other; NAME; COMMA; r = row { Name (row_title, r) }
  | row_title = id_or_other; NAME { Name (row_title, End) }

  | row_title = id_or_other; EMAIL; COMMA; r = row { Email (row_title, r) }
  | row_title = id_or_other; EMAIL { Email (row_title, End) }

  | row_title = id_or_other; PAST; COMMA; r = row { Past (row_title, r) }
  | row_title = id_or_other; PAST { Past (row_title, End) }

  | row_title = id_or_other; FUTURE; COMMA; r = row { Future (row_title, r) }
  | row_title = id_or_other; FUTURE { Future (row_title, End) }

  | row_title = id_or_other; NOW; COMMA; r = row { Now (row_title, r) }
  | row_title = id_or_other; NOW { Now (row_title, End) }

  | row_title = id_or_other; USERNAME; COMMA; r = row { Username (row_title, r) }
  | row_title = id_or_other; USERNAME { Username (row_title, End) }

  | row_title = id_or_other; INCREMENT; COMMA; r = row { Increment (row_title, r) }
  | row_title = id_or_other; INCREMENT { Increment (row_title, End) }

  | row_title = id_or_other; const = STRING; COMMA; r = row { Const (row_title, const, r) }
  | row_title = id_or_other; const = STRING { Const (row_title, const, End) }

  | row_title = id_or_other; INTSYMBOL;LBRACE;min = INT;COMMA;max = INT;RBRACE;COMMA; r = row { Int (row_title,min,max,r) }
  | row_title = id_or_other; INTSYMBOL;LBRACE;min = INT;COMMA;max = INT;RBRACE; { Int (row_title,min,max,End) }
  ;

union_fields: 
  vl = separated_list(COMMA, STRING) { vl }
  ;