2 (***********************************************************************)
6 (* Kim Nguyen, LRI UMR8623 *)
7 (* Université Paris-Sud & CNRS *)
9 (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
10 (* Recherche Scientifique. All rights reserved. This file is *)
11 (* distributed under the terms of the GNU Lesser General Public *)
12 (* License, with the special exception on linking described in file *)
15 (***********************************************************************)
18 Time-stamp: <Last modified on 2013-03-13 14:21:53 CET by Kim Nguyen>
27 %token <string> ATTNAME
28 %token <string> STRING
31 %token <Ast.axis> AXIS
33 %token SLASH SLASHSLASH COLONCOLON STAR PIPE DOT DOTDOT
34 %token EQ NEQ LT GT LTE GTE OR AND ADD SUB DIV MOD
35 %token NODE TEXT COMMENT
48 %type <Ast.path> xpath_query
57 path_rev { List.rev $1 }
61 simple_path { [ $1 ] }
62 | path_rev PIPE simple_path { $3 :: $1 }
67 absolute_path { Absolute (List.rev $1) }
68 | relative_path { Relative (List.rev $1) }
72 SLASH relative_path { $2 }
73 | SLASHSLASH relative_path { $2 @
75 (node, NodeKind.Node),
80 step is always a small list, of size 1-3 so @ is
85 | relative_path SLASH step { $3 @ $1 }
86 | relative_path SLASHSLASH step { $3 @
88 (node, NodeKind.Node),
94 DOT { [ (Self, (node, NodeKind.Node), []) ] }
95 | DOTDOT { [ (Parent, (node, NodeKind.Node), []) ] }
96 | axis_test pred_list {
98 (a,b) :: r -> (a,b,$2) :: (List.map (fun (a,b) -> (a,b,[])) r)
104 AXIS COLONCOLON test { let a, (t,k) = $1, $3 in
106 Attribute when Utils.QNameSet.is_finite t ->
107 [ a, ((Utils.QNameSet.fold
110 (Utils.QName.attribute t) a)
111 t Utils.QNameSet.empty), k) ]
112 | Preceding|Following ->
113 [ (Descendant true, (t,k));
114 if a == Preceding then
115 (PrecedingSibling, (node, NodeKind.Node))
117 (FollowingSibling, (node, NodeKind.Node));
118 (Ancestor true, (node, NodeKind.Node)) ]
122 | test { [ Child, $1 ] }
124 let _ = Format.flush_str_formatter () in
125 let () = Format.fprintf Format.str_formatter "%a" Ast.print_axis $1 in
126 let a = Format.flush_str_formatter () in
127 [Child, (Utils.QNameSet.singleton (Utils.QName.of_string a),NodeKind.Element)]
129 | ATTNAME { [(Attribute,
130 (Utils.QNameSet.singleton (Utils.QName.of_string $1),
131 NodeKind.Attribute))] }
135 NODE { node, NodeKind.Node }
136 | TEXT { text, NodeKind.Text }
137 | STAR { star, NodeKind.Element }
138 | COMMENT { Utils.QNameSet.singleton(Utils.QName.comment),
141 | PI { (if $1 = "" then star
142 else Utils.QNameSet.singleton(
143 Utils.QName.processing_instruction (
144 Utils.QName.of_string $1)
145 )), NodeKind.ProcessingInstruction
147 | TAG { Utils.QNameSet.singleton(Utils.QName.of_string $1),
153 pred_list_rev { List.rev $1 }
158 | pred_list LB expr RB { $3 :: $1 }
162 INT { Number(`Int($1)) }
163 | FLOAT { Number(`Float($1)) }
164 | STRING { String $1 }
165 | SUB expr %prec uminus { Unop(Neg, $2) }
166 | expr AND expr { Binop($1, And, $3) }
167 | expr OR expr { Binop($1, Or, $3) }
168 | expr ADD expr { Binop($1, Add, $3) }
169 | expr SUB expr { Binop($1, Sub, $3) }
170 | expr STAR expr { Binop($1, Mult, $3) }
171 | expr DIV expr { Binop($1, Div, $3) }
172 | expr MOD expr { Binop($1, Mod, $3) }
173 | expr EQ expr { Binop($1, Eq, $3) }
174 | expr NEQ expr { Binop($1, Neq, $3) }
175 | expr LT expr { Binop($1, Lt, $3) }
176 | expr LTE expr { Binop($1, Lte, $3) }
177 | expr GT expr { Binop($1, Gt, $3) }
178 | expr GTE expr { Binop($1, Gte, $3) }
179 | TAG LP arg_list RP { Fun_call(Utils.QName.of_string $1, $3) }
186 | arg_list1 { List.rev $1 }
191 | arg_list1 COMMA expr { $3 :: $1 }