Skip to main content

Crate einvoice_xpath

Crate einvoice_xpath 

Source
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-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());

Structs§

AtomicType
An atomic type name ([53] AtomicType), limited to the supported types.
Avt
An attribute value template: literal text and {expression} parts.
AxisStep
axis::test[predicate]...
Binding
$variable in sequence in a for, some or every expression.
Error
A parse error, with its position in the parsed text.
NamespaceMap
A fixed set of prefix bindings.
PathExpr
A path expression: an optional leading / and the steps between slashes.
PathPattern
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).
PatternStep
A pattern step (XSLT 2.0 production [4] PatternStep).
QName
A qualified name as written (prefix:local or local) together with the namespace it was resolved to when it was parsed.
SequenceType
A sequence type ([50] SequenceType), as in instance of and XSLT as attributes. empty-sequence() and item() are refused by the parser.
SingleType
A single type ([49] SingleType), the target of castable as.

Enums§

ArithmeticOp
An arithmetic operator.
AtomicKind
The atomic types accepted in sequence types and castable as.
AvtPart
One part of an attribute value template.
Axis
The supported axes. descendant, following and namespace are refused by the parser.
CompareKind
Which comparison: =/eq, !=/ne, </lt, <=/le, >/gt, >=/ge.
ComparisonOp
A comparison operator.
ErrorKind
What went wrong.
Expr
An XPath expression (XPath 2.0 production [2] Expr and below).
ItemType
An item type ([52] ItemType).
KindTest
The supported kind tests ([54] KindTest). document-node(), schema-element(), schema-attribute(), processing-instruction(name) and type names in element() and attribute() 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.
NameOrWildcard
The argument of element(...) or attribute(...).
NameTest
A name test: a QName or a wildcard ([36] NameTest, [37] Wildcard).
NodeTest
A node test ([35] NodeTest).
Occurrence
An occurrence indicator ([51] OccurrenceIndicator), or its absence.
PathStart
Where a path expression starts.
PatternAlternative
One alternative of a pattern.
PatternAnchor
What precedes the first step of a path pattern.
PatternAxis
The axes allowed in a pattern step (XSLT 2.0 production [5] PatternAxis).
PatternLink
The separator between two pattern steps.
Quantifier
some or every.
Step
One step of a path ([27] StepExpr).

Constants§

FN_NAMESPACE
The namespace of the XPath functions (fn:), the default function namespace.
XML_NAMESPACE
The namespace bound to the xml prefix 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
NameChar of XML 1.0 (fifth edition) production [4a], without :.
is_name_start_char
NameStartChar of XML 1.0 (fifth edition) production [4], without :.
is_ncname
Whether s is an NCName (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 as attribute.

Type Aliases§

Result
The result of a parse.