xpath/context.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use crate::Dom;
6
7/// The context during evaluation of an XPath expression.
8#[derive(Debug)]
9pub(crate) struct EvaluationCtx<D: Dom> {
10 /// The "current" node in the evaluation.
11 pub(crate) context_node: D::Node,
12 /// Details needed for evaluating a predicate list.
13 pub(crate) predicate_ctx: Option<PredicateCtx>,
14}
15
16#[derive(Clone, Copy, Debug)]
17pub(crate) struct PredicateCtx {
18 pub(crate) index: usize,
19 pub(crate) size: usize,
20}
21
22impl<D: Dom> EvaluationCtx<D> {
23 /// Prepares the context used while evaluating the XPath expression.
24 pub(crate) fn new(context_node: D::Node) -> Self {
25 EvaluationCtx {
26 context_node,
27 predicate_ctx: None,
28 }
29 }
30
31 /// Creates a new context using the provided node as the context node.
32 pub(crate) fn subcontext_for_node(&self, node: D::Node) -> Self {
33 EvaluationCtx {
34 context_node: node,
35 predicate_ctx: self.predicate_ctx,
36 }
37 }
38}