xsd_schema/xpath/ast/expressions.rs
1// ============================================================================
2// Expression Nodes
3// ============================================================================
4
5use super::{AstNodeId, SourceSpan};
6
7/// Comma-separated sequence of expressions.
8///
9/// In XPath, `(a, b, c)` creates a sequence containing results of a, b, and c.
10#[derive(Debug, Clone)]
11pub struct ExprNode {
12 /// List of expression IDs in the sequence.
13 pub items: Vec<AstNodeId>,
14 /// Source location.
15 pub span: SourceSpan,
16}
17
18impl ExprNode {
19 /// Create a sequence with a single expression.
20 pub fn single(id: AstNodeId, span: SourceSpan) -> Self {
21 Self {
22 items: vec![id],
23 span,
24 }
25 }
26
27 /// Create a sequence with multiple expressions.
28 pub fn sequence(items: Vec<AstNodeId>, span: SourceSpan) -> Self {
29 Self { items, span }
30 }
31
32 /// Append an expression to the sequence.
33 pub fn append(&mut self, id: AstNodeId, end: usize) {
34 self.items.push(id);
35 self.span.end = end;
36 }
37}
38
39/// Literal value node.
40#[derive(Debug, Clone)]
41pub enum ValueNode {
42 /// Empty sequence `()`.
43 Empty,
44 /// String literal.
45 String(String),
46 /// Boolean literal (used internally, not in XPath syntax).
47 Boolean(bool),
48 /// Integer literal (stored as string for arbitrary precision).
49 Integer(String),
50 /// Decimal literal (stored as string for arbitrary precision).
51 Decimal(String),
52 /// Double literal (stored as string to preserve exact representation).
53 Double(String),
54 /// Typed value (for runtime computed values).
55 Typed(crate::types::value::XmlValue),
56}
57
58/// Context item reference (`.`).
59#[derive(Debug, Clone)]
60pub struct ContextItemNode {
61 /// Source location.
62 pub span: SourceSpan,
63}
64
65impl ContextItemNode {
66 pub fn new(span: SourceSpan) -> Self {
67 Self { span }
68 }
69}
70
71/// Variable reference (`$prefix:localname` or `$localname`).
72#[derive(Debug, Clone)]
73pub struct VarRefNode {
74 /// Namespace prefix (empty string if none).
75 pub prefix: String,
76 /// Local name.
77 pub local_name: String,
78 /// Resolved variable slot (set during binding phase).
79 pub slot: Option<u32>,
80 /// Source location.
81 pub span: SourceSpan,
82}
83
84impl VarRefNode {
85 pub fn new(prefix: String, local_name: String, span: SourceSpan) -> Self {
86 Self {
87 prefix,
88 local_name,
89 slot: None,
90 span,
91 }
92 }
93}