use alloc::boxed::Box;
use alloc::string::String;
use alloc::vec::Vec;
use crate::lexer::Span;
use super::{Constraint, FieldNode};
#[derive(Clone, Debug)]
pub enum ValueOrExpr {
Value(JsonValue),
Expr {
span: Span,
raw: String,
expr: Expr,
},
}
#[derive(Clone, Debug)]
pub enum JsonValue {
Null(Span),
Bool(Span, bool),
Number(Span, String),
Str(Span, String),
Array(Span, Vec<JsonValue>),
Object(Span, Vec<ObjectEntry>),
}
#[derive(Clone, Debug)]
pub struct ObjectEntry {
pub key_span: Span,
pub key: String,
pub value: JsonValue,
}
impl JsonValue {
pub const fn span(&self) -> &Span {
match *self {
Self::Null(ref s)
| Self::Bool(ref s, _)
| Self::Number(ref s, _)
| Self::Str(ref s, _)
| Self::Array(ref s, _)
| Self::Object(ref s, _) => s,
}
}
}
#[derive(Clone, Debug)]
pub enum Expr {
Literal { span: Span, value: ExprLiteral },
Ident { span: Span, name: String },
Call {
span: Span,
func: Box<Expr>,
args: Vec<Expr>,
},
Dot {
span: Span,
object: Box<Expr>,
field_span: Span,
field: String,
},
Index {
span: Span,
object: Box<Expr>,
index: Box<Expr>,
},
}
impl Expr {
pub const fn span(&self) -> &Span {
match *self {
Self::Literal { ref span, .. }
| Self::Ident { ref span, .. }
| Self::Call { ref span, .. }
| Self::Dot { ref span, .. }
| Self::Index { ref span, .. } => span,
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum ExprLiteral {
Number(String),
String(String),
Bool(bool),
}
#[derive(Clone, Debug)]
pub enum CountNode {
Field {
span: Span,
field: FieldNode,
where_: Option<Box<Constraint>>,
},
Value {
span: Span,
value: ValueOrExpr,
name: Option<NameNode>,
where_: Option<Box<Constraint>>,
},
}
#[derive(Clone, Debug)]
pub struct NameNode {
pub span: Span,
pub name: String,
}