Expand description
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,descendant-or-self(and//),preceding-sibling,preceding,following-sibling; name tests, wildcards and the kind testsnode(),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,cast as,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 formsroot()and parenthesized patterns as Saxon-HE 12.10 reads them (seeparse_pattern).
Refused: intersect, except, the union keyword, treat as, node
comparisons, unary +, XPath comments, the following and namespace axes (in
patterns, the axes other than child and attribute), 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.
Refused as well, with an ErrorKind::TooDeep error: an expression or pattern nested
deeper than MAX_DEPTH, which would otherwise need a call stack in proportion to
its depth to be read, compiled and evaluated.
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());Structs§
- Atomic
Type - An atomic type name ([53]
AtomicType), limited to the supported types. - Avt
- An attribute value template: literal text and
{expression}parts. - Axis
Step axis::test[predicate]...- Binding
$variable in sequencein afor,someoreveryexpression.- Error
- A parse error, with its position in the parsed text.
- Namespace
Binding - A namespace binding: a namespace node of an element, or a namespace declaration.
- Namespace
Map - A fixed set of prefix bindings.
- Path
Expr - A path expression: an optional leading
/and the steps between slashes. - Path
Pattern - A path pattern:
step,/step,//step, then steps separated by/or//. - Pattern
- An XSLT match pattern: one or more alternatives separated by
|(XSLT 2.0 section 5.5.2 production [1]Pattern). - Pattern
Step - A pattern step (XSLT 2.0 production [4]
PatternStep). - QName
- A qualified name as written (
prefix:localorlocal) together with the namespace it was resolved to when it was parsed. - Sequence
Type - A sequence type ([50]
SequenceType), as ininstance ofand XSLTasattributes.empty-sequence()anditem()are refused by the parser. - Single
Type - A single type ([49]
SingleType), the target ofcast asandcastable as.
Enums§
- Arithmetic
Op - An arithmetic operator.
- Atomic
Kind - The atomic types accepted in sequence types and
castable as. - AvtPart
- One part of an attribute value template.
- Axis
- The supported axes.
descendant,followingandnamespaceare refused by the parser. - Compare
Kind - Which comparison:
=/eq,!=/ne,</lt,<=/le,>/gt,>=/ge. - Comparison
Op - A comparison operator.
- Error
Kind - What went wrong.
- Expr
- An XPath expression (XPath 2.0 production [2]
Exprand below). - Item
Type - An item type ([52]
ItemType). - Kind
Test - The supported kind tests ([54]
KindTest).document-node(),schema-element(),schema-attribute(),processing-instruction(name)and type names inelement()andattribute()are refused by the parser. - Literal
- A literal ([42]
Literal). Numeric literals keep their kind and their exact lexical form: the value is computed when the expression is compiled. - Name
OrWildcard - The argument of
element(...)orattribute(...). - Name
Test - A name test: a
QNameor a wildcard ([36]NameTest, [37]Wildcard). - Node
Test - A node test ([35]
NodeTest). - Occurrence
- An occurrence indicator ([51]
OccurrenceIndicator), or its absence. - Path
Start - Where a path expression starts.
- Path
Step - A step of a path pattern.
- Pattern
Alternative - One alternative of a pattern.
- Pattern
Anchor - What precedes the first step of a path pattern.
- Pattern
Axis - The axes allowed in a pattern step (XSLT 2.0 production [5]
PatternAxis). - Pattern
Link - The separator between two pattern steps.
- Quantifier
someorevery.- Step
- One step of a path ([27]
StepExpr).
Constants§
- FN_
NAMESPACE - The namespace of the XPath functions (
fn:), the default function namespace. - MAX_
DEPTH - The maximum depth of an expression or pattern: deeper, it is refused with an
ErrorKind::TooDeeperror. - XML_
NAMESPACE - The namespace bound to the
xmlprefix in every XML document. - XS_
NAMESPACE - The XML Schema namespace (
xs:), home of the atomic types.
Traits§
- Namespaces
- The statically known namespaces of an expression: what its prefixes are bound to.
Functions§
- is_
name_ char NameCharof XML 1.0 (fifth edition) production [4a], without:.- is_
name_ start_ char NameStartCharof XML 1.0 (fifth edition) production [4], without:.- is_
ncname - Whether
sis anNCName(a name without a colon). - is_
xml_ whitespace - The whitespace of XML and XPath: space, tab, carriage return and line feed.
- parse_
avt - Parses an attribute value template.
- parse_
expr - Parses an XPath expression (XPath 2.0 production [1]
XPath ::= Expr). - parse_
pattern - Parses an XSLT match pattern.
- parse_
sequence_ type - Parses a sequence type, as in an XSLT
asattribute.
Type Aliases§
- Result
- The result of a parse.