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
96
97
98
99
100
101
102
103
104
//! Parser and syntax tree for the XPath 2.0 subset that the official e-invoicing validation
//! stylesheets use, and for the XSLT pieces built on it: match patterns, sequence types
//! (`as` attributes) and attribute value templates.
//!
//! Only syntax is handled here: function names are resolved to namespaces but not to
//! functions, and nothing is evaluated. The subset is closed: a construct outside it is
//! refused with an [`ErrorKind::Unsupported`] error naming it, never parsed as something
//! else. Supported:
//!
//! - path expressions on the axes `child`, `attribute`, `self`, `parent`, `ancestor`,
//! `ancestor-or-self`, `descendant-or-self` (and `//`), `preceding-sibling`, `preceding`,
//! `following-sibling`; name tests, wildcards and the kind tests `node()`, `text()`,
//! `comment()`, `processing-instruction()`, `element(name?)`, `attribute(name?)`;
//! predicates; filter expressions as steps;
//! - `for`, `some`, `every` (one or more bindings), `if then else`, `to`, `instance of`,
//! `castable as`, general and value comparisons, `or`, `and`, `+ - * div idiv mod`,
//! unary `-`, `|`, sequences, literals (numeric literals keep their kind and text),
//! variable references, `.`, function calls;
//! - patterns of XSLT 2.0 without `id()`/`key()`, plus the XSLT 3.0 forms `root()` and
//! `(A | B)[p]`.
//!
//! Refused: `intersect`, `except`, the `union` keyword, `treat as`, `cast as`, node
//! comparisons, unary `+`, XPath comments, the `descendant`, `following` and `namespace`
//! axes, `document-node()`, `schema-element()`, `schema-attribute()`, typed `element()` and
//! `attribute()` tests, `item()`, `empty-sequence()`, atomic types other than `xs:string`,
//! `xs:anyURI`, `xs:boolean`, `xs:integer`, `xs:decimal` and `xs:date`, and every XPath 3.0
//! addition except the zero-argument `document-uri()`, which is an ordinary function call
//! here.
//!
//! ```
//! use einvoice_xpath::{parse_expr, NamespaceMap, XS_NAMESPACE};
//!
//! let ns = NamespaceMap::new().bind("xs", XS_NAMESPACE);
//! let expr = parse_expr("xs:decimal(Amount) * 2 = 10", &ns)?;
//! assert_eq!(expr.to_string(), "xs:decimal(Amount) * 2 = 10");
//! assert!(parse_expr("a intersect b", &ns).is_err());
//! # Ok::<(), einvoice_xpath::Error>(())
//! ```
pub use ;
pub use ;
pub use ;
use Parser;
/// Parses an XPath expression (XPath 2.0 production \[1\] `XPath ::= Expr`).
///
/// # Errors
///
/// A syntax error, a construct outside the supported subset, or an undeclared prefix.
/// Parses an XSLT match pattern.
///
/// # Errors
///
/// A syntax error, a construct outside the supported subset, or an undeclared prefix.
/// Parses a sequence type, as in an XSLT `as` attribute.
///
/// # Errors
///
/// A syntax error, an unsupported or unknown type, or an undeclared prefix.
/// Parses an attribute value template.
///
/// # Errors
///
/// A misplaced `}`, an empty or unterminated `{...}`, or an error in an expression.