mod expr;
mod pat;
mod stmt;
mod structure_eq;
pub use expr::*;
pub use pat::*;
pub use stmt::*;
pub use structure_eq::StructureEq;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Span {
pub start_line: u32,
pub start_col: u32,
pub end_line: u32,
pub end_col: u32,
}
impl Span {
pub fn from_ts(start: tree_sitter::Point, end: tree_sitter::Point) -> Self {
Self {
start_line: start.row as u32 + 1,
start_col: start.column as u32,
end_line: end.row as u32 + 1,
end_col: end.column as u32,
}
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Program {
pub body: Vec<Stmt>,
}
impl Program {
pub fn new(body: Vec<Stmt>) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Param {
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub type_annotation: Option<String>,
}
impl Param {
pub fn new(name: impl Into<String>) -> Self {
Self {
name: name.into(),
type_annotation: None,
}
}
pub fn typed(name: impl Into<String>, annotation: impl Into<String>) -> Self {
Self {
name: name.into(),
type_annotation: Some(annotation.into()),
}
}
}
impl From<&str> for Param {
fn from(s: &str) -> Self {
Param::new(s)
}
}
impl From<String> for Param {
fn from(s: String) -> Self {
Param::new(s)
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Function {
pub name: String,
pub params: Vec<Param>,
#[serde(skip_serializing_if = "Option::is_none")]
pub return_type: Option<String>,
pub body: Vec<Stmt>,
}
impl Function {
pub fn new(name: impl Into<String>, params: Vec<Param>, body: Vec<Stmt>) -> Self {
Self {
name: name.into(),
params,
return_type: None,
body,
}
}
pub fn anonymous(params: Vec<Param>, body: Vec<Stmt>) -> Self {
Self::new("", params, body)
}
}