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 separated_nonempty_list(PIPE, simple_path) { $1 }
57 absolute_path { Absolute (List.rev $1) }
58 | relative_path { Relative (List.rev $1) }
62 SLASH relative_path { $2 }
63 | SLASHSLASH relative_path { $2 @
65 (node, NodeKind.Node),
70 step is always a small list, of size 1-3 so @ is
76 | relative_path SLASH step { $3 @ $1 }
77 | relative_path SLASHSLASH step { $3 @
79 (node, NodeKind.Node),
85 DOT { [ (Self, (node, NodeKind.Node), []) ] }
86 | DOTDOT { [ (Parent, (node, NodeKind.Node), []) ] }
87 | axis_test pred_list {
89 (a,b) :: r -> (a,b,$2) :: (List.map (fun (a,b) -> (a,b,[])) r)
95 AXIS COLONCOLON test { let a, (t,k) = $1, $3 in
97 Attribute when QNameSet.is_finite t ->
101 (QName.attribute t) a)
102 t QNameSet.empty), k) ]
103 | Preceding|Following ->
104 [ (Descendant true, (t,k));
105 if a == Preceding then
106 (PrecedingSibling, (node, NodeKind.Node))
108 (FollowingSibling, (node, NodeKind.Node));
109 (Ancestor true, (node, NodeKind.Node)) ]
113 | test { [ Child, $1 ] }
115 let _ = Format.flush_str_formatter () in
116 let () = Format.fprintf Format.str_formatter "%a" Ast.print_axis $1 in
117 let a = Format.flush_str_formatter () in
118 [Child, (QNameSet.singleton (QName.of_string a),NodeKind.Element)]
120 | ATTNAME { [(Attribute,
121 (QNameSet.singleton (QName.of_string $1),
122 NodeKind.Attribute))] }
126 NODE { node, NodeKind.Node }
127 | TEXT { text, NodeKind.Text }
128 | STAR { node, NodeKind.Element }
129 | COMMENT { QNameSet.singleton(QName.comment),
132 | PI { (if $1 = "" then star
133 else QNameSet.singleton(
134 QName.processing_instruction (
136 )), NodeKind.ProcessingInstruction
138 | TAG { QNameSet.singleton(QName.of_string $1),
144 pred_list_rev { List.rev $1 }
149 | pred_list LB expr RB { $3 :: $1 }
153 INT { Number(`Int($1)) }
154 | FLOAT { Number(`Float($1)) }
155 | STRING { String $1 }
156 | SUB expr %prec uminus { Unop(Neg, $2) }
157 | e1 = expr; op = binop; e2 = expr { Binop(e1, op, e2) }
158 | TAG LP arg_list RP { Fun_call(QName.of_string $1, $3) }
180 | arg_list1 { List.rev $1 }
185 | arg_list1 COMMA expr { $3 :: $1 }