/
parser_path.trx
95 lines (77 loc) · 3.37 KB
/
parser_path.trx
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
(*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(* shorcuts to other files *)
;slash_nosp <- Opa_lexer.slash_nosp
;deco_ml_identifier_nosp <- Opa_parser.deco_ml_identifier_nosp
;ml_identifier_nosp <- Opa_lexer.ml_identifier_nosp
;ml_identifier <- Opa_lexer.ml_identifier
;underscore_nosp <- Opa_lexer.underscore_nosp
;lbracket <- Opa_lexer.lbracket
;lbracket_nosp <- Opa_lexer.lbracket_nosp
;rbracket <- Opa_lexer.rbracket
;rbracket_nosp <- Opa_lexer.rbracket_nosp
;lbrace <- Opa_lexer.lbrace
;lbrace_nosp <- Opa_lexer.lbrace_nosp
;rbrace <- Opa_lexer.rbrace
;rbrace_nosp <- Opa_lexer.rbrace_nosp
;spacing <- Opa_lexer.spacing
;semic <- Opa_lexer.semic
(* path definition, ie for [db pathdef : typ] or [db pathdef = expr] *)
;pathdef_nosp <-slash_nosp ml_identifier_nosp:i
(slash_nosp ml_identifier_nosp:i {{QmlAst.Db.Decl_fld i}}
/ "[]" {{ QmlAst.Db.Decl_set [] }}
/ "[_]" {{ QmlAst.Db.Decl_set [] }})*:l
{{ (QmlAst.Db.Decl_fld i)::l }}
;/** todo: extend to multiple index **/
setindex_def <- lbrace (=list1(ml_identifier,semic)):i rbrace
{{ QmlAst.Db.Decl_set [List.sort String.compare i] }}
;pathdef_type_nosp <- slash_nosp ml_identifier_nosp:i
(slash_nosp ml_identifier_nosp:i {{QmlAst.Db.Decl_fld i}}
/ lbracket setindex_def:i rbracket {{i}})*:l
{{ (QmlAst.Db.Decl_fld i)::l }}
;/** database path definition without type **/
pathdef <- spacing pathdef_nosp:v {{ v }}
;/** database path definition with type **/
pathdef_type <- spacing pathdef_type_nosp:v {{ v }}
(* path for reading *)
;/** database query **/
query <- querytype:qt path:p {{ p, qt }}
(* path for writing (no leading !,@ etc.) *)
; /** database write path **/
path_write <- slash_nosp path:p {{ p }}
;querytype <- [?] slash_nosp {{ QmlAst.Db.Option }}
/ [!] slash_nosp {{ QmlAst.Db.Valpath }}
/ [@] slash_nosp {{ QmlAst.Db.Ref }}
/ slash_nosp {{ QmlAst.Db.Default }}
;path = Opa_parser.careful_deco just_path
;just_path <- deco_ml_identifier_nosp:i path_elem*:l {{ let (s,label) = i in ((FldKey s),label) :: l }}
;path_elem = Opa_parser.careful_deco just_path_elem
;just_path_elem <- slash_nosp ml_identifier_nosp:i {{ FldKey i }}
/ lbracket_nosp Opa_parser.expr:e rbracket {{ ExprKey e }}
/ lbracket_nosp spacing [?] rbracket {{ NewKey }}
(**
{7 Separated lists}
*)
(** list where a the separator must occur *)
let list2 element separator = element:e (separator element:e {{e}})+:l
{{ e :: l }}
(**Non-empty lists*)
let list1 element separator = element:e (separator element {{__2}})*:l
{{ e :: l }};
(**Possibly empty lists*)
let list0 element separator = (=list1(element,separator))?:o
{{ match o with
| None -> []
| Some l -> l
}}