Skip to main content

sevenmark_parser/ast/
expression.rs

1use serde::Serialize;
2
3use super::{Element, Span};
4
5/// 논리 연산자 종류
6#[derive(Debug, Clone, Serialize, PartialEq)]
7pub enum LogicalOperatorKind {
8    Or,  // ||
9    And, // &&
10    Not, // !
11}
12
13/// 논리 연산자 (위치 정보 포함)
14#[derive(Debug, Clone, Serialize)]
15pub struct LogicalOperator {
16    #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
17    pub span: Span,
18    pub kind: LogicalOperatorKind,
19}
20
21/// 비교 연산자 종류
22#[derive(Debug, Clone, Serialize, PartialEq)]
23pub enum ComparisonOperatorKind {
24    Equal,        // ==
25    NotEqual,     // !=
26    GreaterThan,  // >
27    LessThan,     // <
28    GreaterEqual, // >=
29    LessEqual,    // <=
30}
31
32/// 비교 연산자 (위치 정보 포함)
33#[derive(Debug, Clone, Serialize)]
34pub struct ComparisonOperator {
35    #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
36    pub span: Span,
37    pub kind: ComparisonOperatorKind,
38}
39
40/// 조건식 Expression AST
41#[derive(Debug, Clone, Serialize)]
42pub enum Expression {
43    /// 논리 OR 연산 (||)
44    Or {
45        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
46        span: Span,
47        operator: LogicalOperator,
48        left: Box<Expression>,
49        right: Box<Expression>,
50    },
51    /// 논리 AND 연산 (&&)
52    And {
53        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
54        span: Span,
55        operator: LogicalOperator,
56        left: Box<Expression>,
57        right: Box<Expression>,
58    },
59    /// 논리 NOT 연산 (!)
60    Not {
61        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
62        span: Span,
63        operator: LogicalOperator,
64        inner: Box<Expression>,
65    },
66    /// 비교 연산 (==, !=, >, <, >=, <=)
67    Comparison {
68        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
69        span: Span,
70        left: Box<Expression>,
71        operator: ComparisonOperator,
72        right: Box<Expression>,
73    },
74    /// 함수 호출 (int, len, str)
75    FunctionCall {
76        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
77        span: Span,
78        name: String,
79        arguments: Vec<Expression>,
80    },
81    /// 문자열 리터럴
82    StringLiteral {
83        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
84        span: Span,
85        value: Vec<Element>,
86    },
87    /// 숫자 리터럴
88    NumberLiteral {
89        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
90        span: Span,
91        value: i64,
92    },
93    /// 불리언 리터럴
94    BoolLiteral {
95        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
96        span: Span,
97        value: bool,
98    },
99    /// Null 리터럴
100    Null {
101        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
102        span: Span,
103    },
104    /// 괄호 그룹
105    Group {
106        #[cfg_attr(not(feature = "include_locations"), serde(skip_serializing))]
107        span: Span,
108        inner: Box<Expression>,
109    },
110    /// 기존 Element를 expression 안에 포함 (Variable, Null 매크로 등)
111    Element(Box<Element>),
112}