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 (***********************************************************************)
23 %token <string> ATTNAME
24 %token <string> STRING
27 %token <Ast.axis> AXIS
29 %token SLASH SLASHSLASH COLONCOLON STAR PIPE DOT DOTDOT
30 %token EQ NEQ LT GT LTE GTE OR AND ADD SUB DIV MOD
31 %token NODE TEXT COMMENT
44 %type <Ast.path> xpath_query
53 path_rev { List.rev $1 }
57 simple_path { [ $1 ] }
58 | path_rev PIPE simple_path { $3 :: $1 }
63 absolute_path { Absolute (List.rev $1) }
64 | relative_path { Relative (List.rev $1) }
68 SLASH relative_path { $2 }
69 | SLASHSLASH relative_path { $2 @
71 (node, NodeKind.Node),
76 step is always a small list, of size 1-3 so @ is
81 | relative_path SLASH step { $3 @ $1 }
82 | relative_path SLASHSLASH step { $3 @
84 (node, NodeKind.Node),
90 DOT { [ (Self, (node, NodeKind.Node), []) ] }
91 | DOTDOT { [ (Parent, (node, NodeKind.Node), []) ] }
92 | axis_test pred_list {
94 (a,b) :: r -> (a,b,$2) :: (List.map (fun (a,b) -> (a,b,[])) r)
100 AXIS COLONCOLON test { let a, (t,k) = $1, $3 in
102 Attribute when QNameSet.is_finite t ->
106 (QName.attribute t) a)
107 t QNameSet.empty), k) ]
108 | Preceding|Following ->
109 [ (Descendant true, (t,k));
110 if a == Preceding then
111 (PrecedingSibling, (node, NodeKind.Node))
113 (FollowingSibling, (node, NodeKind.Node));
114 (Ancestor true, (node, NodeKind.Node)) ]
118 | test { [ Child, $1 ] }
120 let _ = Format.flush_str_formatter () in
121 let () = Format.fprintf Format.str_formatter "%a" Ast.print_axis $1 in
122 let a = Format.flush_str_formatter () in
123 [Child, (QNameSet.singleton (QName.of_string a),NodeKind.Element)]
125 | ATTNAME { [(Attribute,
126 (QNameSet.singleton (QName.of_string $1),
127 NodeKind.Attribute))] }
131 NODE { node, NodeKind.Node }
132 | TEXT { text, NodeKind.Text }
133 | STAR { node, NodeKind.Element }
134 | COMMENT { QNameSet.singleton(QName.comment),
137 | PI { (if $1 = "" then star
138 else QNameSet.singleton(
139 QName.processing_instruction (
141 )), NodeKind.ProcessingInstruction
143 | TAG { QNameSet.singleton(QName.of_string $1),
149 pred_list_rev { List.rev $1 }
154 | pred_list LB expr RB { $3 :: $1 }
158 INT { Number(`Int($1)) }
159 | FLOAT { Number(`Float($1)) }
160 | STRING { String $1 }
161 | SUB expr %prec uminus { Unop(Neg, $2) }
162 | expr AND expr { Binop($1, And, $3) }
163 | expr OR expr { Binop($1, Or, $3) }
164 | expr ADD expr { Binop($1, Add, $3) }
165 | expr SUB expr { Binop($1, Sub, $3) }
166 | expr STAR expr { Binop($1, Mult, $3) }
167 | expr DIV expr { Binop($1, Div, $3) }
168 | expr MOD expr { Binop($1, Mod, $3) }
169 | expr EQ expr { Binop($1, Eq, $3) }
170 | expr NEQ expr { Binop($1, Neq, $3) }
171 | expr LT expr { Binop($1, Lt, $3) }
172 | expr LTE expr { Binop($1, Lte, $3) }
173 | expr GT expr { Binop($1, Gt, $3) }
174 | expr GTE expr { Binop($1, Gte, $3) }
175 | TAG LP arg_list RP { Fun_call(QName.of_string $1, $3) }
182 | arg_list1 { List.rev $1 }
187 | arg_list1 COMMA expr { $3 :: $1 }