prql_ast/
stmt.rs

1use std::collections::HashMap;
2
3use enum_as_inner::EnumAsInner;
4use semver::VersionReq;
5use serde::{Deserialize, Serialize};
6
7use crate::{expr::Expr, Span};
8
9#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize, Default)]
10pub struct QueryDef {
11    pub version: Option<VersionReq>,
12    #[serde(default)]
13    pub other: HashMap<String, String>,
14}
15
16#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
17pub enum VarDefKind {
18    Let,
19    Into,
20}
21
22// The following code is tested by the tests_misc crate to match stmt.rs in prql_compiler.
23
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25pub struct Stmt {
26    #[serde(flatten)]
27    pub kind: StmtKind,
28    #[serde(skip)]
29    pub span: Option<Span>,
30
31    pub annotations: Vec<Annotation>,
32}
33
34#[derive(Debug, EnumAsInner, PartialEq, Clone, Serialize, Deserialize)]
35pub enum StmtKind {
36    QueryDef(Box<QueryDef>),
37    Main(Box<Expr>),
38    VarDef(VarDef),
39    TypeDef(TypeDef),
40    ModuleDef(ModuleDef),
41}
42
43#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
44pub struct VarDef {
45    pub name: String,
46    pub value: Box<Expr>,
47    pub ty_expr: Option<Box<Expr>>,
48    pub kind: VarDefKind,
49}
50
51#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
52pub struct TypeDef {
53    pub name: String,
54    pub value: Option<Box<Expr>>,
55}
56
57#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
58pub struct ModuleDef {
59    pub name: String,
60    pub stmts: Vec<Stmt>,
61}
62
63#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
64pub struct Annotation {
65    pub expr: Box<Expr>,
66}