66 lines
1.2 KiB
Rust
66 lines
1.2 KiB
Rust
use crate::FileId;
|
|
|
|
#[derive(Debug)]
|
|
pub struct ParsedFile {
|
|
pub file_id: FileId,
|
|
pub nodes: Vec<Node>,
|
|
pub errors: Vec<ParseError>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct Node {
|
|
pub range: SourceRange,
|
|
pub data: NodeData,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub struct SourceRange {
|
|
pub start: usize,
|
|
pub end: usize,
|
|
}
|
|
|
|
impl std::fmt::Display for SourceRange {
|
|
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(formatter, "{}..{}", self.start, self.end)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum NodeData {
|
|
Apply(Apply),
|
|
Inherit(Inherit),
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct Apply {
|
|
pub function: Expr,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub enum Expr {
|
|
Ident(Ident),
|
|
Select(Box<Select>),
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct Ident {
|
|
pub name: String,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct Select {
|
|
pub receiver: Expr,
|
|
pub attrs: Vec<Ident>,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct Inherit {
|
|
pub attr_count: usize,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct ParseError {
|
|
pub range: SourceRange,
|
|
pub message: String,
|
|
}
|