firedbg_rust_parser/def/
body.rs

1use firedbg_protocol::source::LineColumn;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5pub enum StmtOrExpr {
6    Stmt(Statement),
7    Expr(Expression),
8}
9
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct Statement {
12    pub ty: StatementType,
13    pub loc: LineColumn,
14}
15
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub enum StatementType {
18    Let {
19        binding: Binding,
20        mutable: bool,
21    },
22    LetAssign {
23        binding: Binding,
24        mutable: bool,
25    },
26    Assign {
27        binding: Binding,
28        assign_op: AssignOp,
29    },
30    Constant {
31        binding: Binding,
32    },
33    Static {
34        binding: Binding,
35    },
36    Break {},
37    Continue {},
38    Other(String),
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
42pub enum Binding {
43    Var(String),
44    Field {
45        base: String,
46        inter: Option<String>,
47        member: String,
48    },
49    Other(String),
50}
51
52#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
53pub enum AssignOp {
54    Assign,
55    /// The addition assignment operator `+=`
56    AddAssign,
57    /// The bitwise AND assignment operator `&=`
58    BitAndAssign,
59    /// The bitwise OR assignment operator `|=`
60    BitOrAssign,
61    /// The bitwise XOR assignment operator `^=`
62    BitXorAssign,
63    /// The division assignment operator `/=`
64    DivAssign,
65    /// The multiplication assignment operator `*=`
66    MulAssign,
67    /// The remainder assignment operator `%=`
68    RemAssign,
69    /// The left shift assignment operator `<<=`
70    ShlAssign,
71    /// The right shift assignment operator `>>=`
72    ShrAssign,
73    /// The subtraction assignment operator `-=`
74    SubAssign,
75    Other(String),
76}
77
78#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
79pub struct Expression {
80    pub ty: ExpressionType,
81    pub loc: LineColumn,
82}
83
84#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
85pub enum ExpressionType {
86    Other(String),
87}
88
89impl From<Statement> for StmtOrExpr {
90    fn from(stmt: Statement) -> Self {
91        Self::Stmt(stmt)
92    }
93}
94
95impl From<Expression> for StmtOrExpr {
96    fn from(expr: Expression) -> Self {
97        Self::Expr(expr)
98    }
99}