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 12:11:04 CET by Kim Nguyen>
27 %token <string> ATTNAME
28 %token <string> STRING
31 %token <Ast.axis> AXIS
33 %token SLASH SLASHSLASH COLONCOLON STAR PIPE
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),
96 (a,b) :: r -> (a,b,$2) :: (List.map (fun (a,b) -> (a,b,[])) r)
102 AXIS COLONCOLON test { let a, (t,k) = $1, $3 in
104 Attribute when Utils.QNameSet.is_finite t ->
105 [ a, ((Utils.QNameSet.fold
108 (Utils.QName.attribute t) a)
109 t Utils.QNameSet.empty), k) ]
110 | Preceding|Following ->
111 [ (Descendant true, (t,k));
112 if a == Preceding then
113 (PrecedingSibling, (node, NodeKind.Node))
115 (FollowingSibling, (node, NodeKind.Node));
116 (Ancestor true, (node, NodeKind.Node)) ]
120 | test { [ Child, $1 ] }
122 let _ = Format.flush_str_formatter () in
123 let () = Format.fprintf Format.str_formatter "%a" Ast.print_axis $1 in
124 let a = Format.flush_str_formatter () in
125 [Child, (Utils.QNameSet.singleton (Utils.QName.of_string a),NodeKind.Element)]
127 | ATTNAME { [(Attribute,
128 (Utils.QNameSet.singleton (Utils.QName.of_string $1),
129 NodeKind.Attribute))] }
133 NODE { node, NodeKind.Node }
134 | TEXT { text, NodeKind.Text }
135 | STAR { star, NodeKind.Element }
136 | COMMENT { Utils.QNameSet.singleton(Utils.QName.comment),
139 | PI { Utils.QNameSet.singleton(
140 Utils.QName.processing_instruction (
141 Utils.QName.of_string $1)
142 ), NodeKind.ProcessingInstruction
144 | TAG { Utils.QNameSet.singleton(Utils.QName.of_string $1),
150 pred_list_rev { List.rev $1 }
155 | pred_list LB expr RB { $3 :: $1 }
159 INT { Number(`Int($1)) }
160 | FLOAT { Number(`Float($1)) }
161 | STRING { String $1 }
162 | SUB expr %prec uminus { Unop(Neg, $2) }
163 | expr AND expr { Binop($1, And, $3) }
164 | expr OR expr { Binop($1, Or, $3) }
165 | expr ADD expr { Binop($1, Add, $3) }
166 | expr SUB expr { Binop($1, Sub, $3) }
167 | expr STAR expr { Binop($1, Mult, $3) }
168 | expr DIV expr { Binop($1, Div, $3) }
169 | expr MOD expr { Binop($1, Mod, $3) }
170 | expr EQ expr { Binop($1, Eq, $3) }
171 | expr NEQ expr { Binop($1, Neq, $3) }
172 | expr LT expr { Binop($1, Lt, $3) }
173 | expr LTE expr { Binop($1, Lte, $3) }
174 | expr GT expr { Binop($1, Gt, $3) }
175 | expr GTE expr { Binop($1, Gte, $3) }
176 | TAG LP arg_list RP { Fun_call(Utils.QName.of_string $1, $3) }
183 | arg_list1 { List.rev $1 }
188 | arg_list1 COMMA expr { $3 :: $1 }