sixu 0.14.1

Experimental Visual Novel Scripting Language
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
//! CST node definitions

use super::span::SpanInfo;
use crate::format;

/// Trivia:不影响语义的语法元素
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CstTrivia {
    /// 空白(空格、制表符、换行)
    Whitespace { content: String, span: SpanInfo },

    /// 单行注释 // ...
    LineComment {
        content: String, // 不含 //
        span: SpanInfo,
    },

    /// 块注释 /* ... */
    BlockComment {
        content: String, // 不含 /* */
        span: SpanInfo,
    },
}

impl CstTrivia {
    pub fn span(&self) -> &SpanInfo {
        match self {
            Self::Whitespace { span, .. } => span,
            Self::LineComment { span, .. } => span,
            Self::BlockComment { span, .. } => span,
        }
    }

    pub fn content(&self) -> &str {
        match self {
            Self::Whitespace { content, .. } => content,
            Self::LineComment { content, .. } => content,
            Self::BlockComment { content, .. } => content,
        }
    }

    /// 是否包含换行
    pub fn has_newline(&self) -> bool {
        self.content().contains('\n')
    }
}

/// CST 根节点(代表整个文件)
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstRoot {
    /// 文件名
    pub name: String,

    /// 所有节点(包括 trivia)
    pub nodes: Vec<CstNode>,

    /// 全文 span
    pub span: SpanInfo,
}

impl CstRoot {
    /// 转换为 AST Story
    pub fn to_ast(&self) -> crate::error::Result<crate::format::Story> {
        let mut paragraphs = Vec::new();

        for node in &self.nodes {
            if let CstNode::Paragraph(para) = node {
                paragraphs.push(para.to_ast()?);
            }
        }

        Ok(crate::format::Story {
            name: self.name.clone(),
            paragraphs,
        })
    }
}

/// CST 节点(所有可能的语法元素)
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CstNode {
    /// Trivia(空白、注释)
    Trivia(CstTrivia),

    /// 段落定义
    Paragraph(CstParagraph),

    /// 命令
    Command(CstCommand),

    /// 系统调用
    SystemCall(CstSystemCall),

    /// 文本行
    TextLine(CstTextLine),

    /// 代码块
    Block(CstBlock),

    /// 嵌入代码
    EmbeddedCode(CstEmbeddedCode),

    /// 属性(如 #[cond(...)], #[while(...)], #[loop])
    Attribute(CstAttribute),

    /// 错误节点(解析失败但需要保留的部分)
    Error {
        content: String,
        span: SpanInfo,
        message: String,
    },
}

impl CstNode {
    pub fn span(&self) -> SpanInfo {
        match self {
            Self::Trivia(t) => *t.span(),
            Self::Paragraph(p) => p.span,
            Self::Command(c) => c.span,
            Self::SystemCall(s) => s.span,
            Self::TextLine(t) => t.span,
            Self::Block(b) => b.span,
            Self::EmbeddedCode(e) => e.span,
            Self::Attribute(a) => a.span,
            Self::Error { span, .. } => *span,
        }
    }
}

/// 属性节点 #[keyword(condition)]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstAttribute {
    /// 属性关键字(cond, if, while, loop 等)
    pub keyword: String,

    /// 关键字的位置
    pub keyword_span: SpanInfo,

    /// 条件表达式(如果有)
    pub condition: Option<String>,

    /// 条件表达式的位置(如果有)
    pub condition_span: Option<SpanInfo>,

    /// #[ 的位置
    pub open_token: SpanInfo,

    /// ] 的位置
    pub close_token: SpanInfo,

    /// 整个属性的范围
    pub span: SpanInfo,

    /// 前导 trivia
    pub leading_trivia: Vec<CstTrivia>,
}

impl CstAttribute {
    /// 转换为 AST Attribute
    pub fn to_ast(&self) -> format::Attribute {
        format::Attribute {
            keyword: self.keyword.clone(),
            condition: self.condition.clone(),
        }
    }
}

/// 命令语法风格
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CommandSyntax {
    /// 括号风格:@cmd(a=1, b=2)
    Parenthesized {
        /// ( 的位置
        open_paren: SpanInfo,
        /// ) 的位置
        close_paren: SpanInfo,
    },

    /// 空格分隔:@cmd a=1 b=2
    SpaceSeparated,
}

/// 命令节点 @command arg1=val1 arg2
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstCommand {
    /// 语义信息(复用 AST)
    pub command: String,

    /// @ 符号的位置
    pub at_token: SpanInfo,

    /// 命令名的位置
    pub name_span: SpanInfo,

    /// 参数列表
    pub arguments: Vec<CstArgument>,

    /// 命令调用语法风格
    pub syntax: CommandSyntax,

    /// 整个命令的范围
    pub span: SpanInfo,

    /// 前导 trivia(命令前的空白/注释)
    pub leading_trivia: Vec<CstTrivia>,
}

impl CstCommand {
    /// 转换为 AST CommandLine
    pub fn to_ast(&self) -> format::CommandLine {
        format::CommandLine {
            command: self.command.clone(),
            arguments: self.arguments.iter().map(|a| a.to_ast()).collect(),
        }
    }
}

/// 系统调用节点 #goto paragraph="main"
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstSystemCall {
    /// 系统调用名
    pub command: String,

    /// # 符号的位置
    pub hash_token: SpanInfo,

    /// 命令名的位置
    pub name_span: SpanInfo,

    /// 参数列表
    pub arguments: Vec<CstArgument>,

    /// 调用语法风格
    pub syntax: CommandSyntax,

    /// 整个调用的范围
    pub span: SpanInfo,

    /// 前导 trivia
    pub leading_trivia: Vec<CstTrivia>,
}

impl CstSystemCall {
    /// 转换为 AST SystemCallLine
    pub fn to_ast(&self) -> format::SystemCallLine {
        format::SystemCallLine {
            command: self.command.clone(),
            arguments: self.arguments.iter().map(|a| a.to_ast()).collect(),
        }
    }
}

/// 参数节点 name=value 或 flag
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstArgument {
    /// 参数名
    pub name: String,

    /// 参数名的位置
    pub name_span: SpanInfo,

    /// = 的位置(如果有)
    pub equals_token: Option<SpanInfo>,

    /// 参数值(None 表示布尔标志)
    pub value: Option<CstValue>,

    /// 整个参数的范围
    pub span: SpanInfo,

    /// 前导 trivia(参数前的空白/注释)
    pub leading_trivia: Vec<CstTrivia>,

    /// 尾随 trivia(参数后的逗号、空白等)
    pub trailing_trivia: Vec<CstTrivia>,
}

impl CstArgument {
    /// 转换为 AST Argument
    pub fn to_ast(&self) -> format::Argument {
        format::Argument {
            name: self.name.clone(),
            value: self
                .value
                .as_ref()
                .map(|v| v.to_ast())
                .unwrap_or(format::RValue::Literal(format::Literal::Boolean(true))),
        }
    }
}

/// 引号类型
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum QuoteStyle {
    Double,   // "
    Single,   // '
    Backtick, // `
}

/// 值的种类
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CstValueKind {
    /// 字符串 "..." 或 '...'
    String {
        /// 引号类型
        quote: QuoteStyle,
    },

    /// 模板字符串 `...`
    TemplateString,

    /// 整数
    Integer,

    /// 浮点数
    Float,

    /// 布尔值
    Boolean,

    /// 变量引用 foo.bar.baz
    Variable,

    /// 数组 [...]
    Array,
}

/// 值节点(字符串、数字、变量等)
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstValue {
    /// 值的种类
    pub kind: CstValueKind,

    /// 原始文本(含引号、前缀等)
    pub raw: String,

    /// 解析后的值(用于生成 AST)
    pub parsed: format::RValue,

    /// 值的位置
    pub span: SpanInfo,
}

impl CstValue {
    /// 转换为 AST RValue
    pub fn to_ast(&self) -> format::RValue {
        self.parsed.clone()
    }
}

// ===== Phase 2-4 的节点(暂时使用占位定义) =====

/// 段落节点 ::paragraph_name(param1, param2="default") { ... }
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstParagraph {
    /// 段落名
    pub name: String,

    /// :: 符号的位置
    pub colon_token: SpanInfo,

    /// 段落名的位置
    pub name_span: SpanInfo,

    /// 参数列表(可选)
    pub parameters: Vec<CstParameter>,

    /// ( 的位置(如果有参数)
    pub open_paren: Option<SpanInfo>,

    /// ) 的位置(如果有参数)
    pub close_paren: Option<SpanInfo>,

    /// 段落体
    pub block: CstBlock,

    /// 整个段落的范围
    pub span: SpanInfo,

    /// 前导 trivia
    pub leading_trivia: Vec<CstTrivia>,
}

impl CstParagraph {
    pub fn to_ast(&self) -> crate::error::Result<format::Paragraph> {
        Ok(format::Paragraph {
            name: self.name.clone(),
            parameters: self.parameters.iter().map(|p| p.to_ast()).collect(),
            block: self.block.to_ast()?,
        })
    }
}

/// 段落参数 param1, param2="default"
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstParameter {
    /// 参数名
    pub name: String,

    /// 参数名的位置
    pub name_span: SpanInfo,

    /// = 的位置(如果有默认值)
    pub equals_token: Option<SpanInfo>,

    /// 默认值(可选)
    pub default_value: Option<CstValue>,

    /// 整个参数的范围
    pub span: SpanInfo,

    /// 前导 trivia
    pub leading_trivia: Vec<CstTrivia>,

    /// 尾随 trivia(逗号、空白等)
    pub trailing_trivia: Vec<CstTrivia>,
}

impl CstParameter {
    pub fn to_ast(&self) -> format::Parameter {
        format::Parameter {
            name: self.name.clone(),
            default_value: self.default_value.as_ref().and_then(|v| match &v.parsed {
                format::RValue::Literal(lit) => Some(lit.clone()),
                _ => None,
            }),
        }
    }
}

/// 代码块(Phase 2)
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstBlock {
    pub open_brace: SpanInfo,
    pub children: Vec<CstNode>,
    pub close_brace: SpanInfo,
    pub span: SpanInfo,
}

impl CstBlock {
    pub fn to_ast(&self) -> crate::error::Result<format::Block> {
        let mut children = Vec::new();
        let mut pending_attributes: Vec<format::Attribute> = Vec::new();
        let mut pending_marker: Option<format::LineMarker> = None;

        for node in &self.children {
            match node {
                CstNode::Attribute(attr) => {
                    pending_attributes.push(attr.to_ast());
                }
                CstNode::Trivia(CstTrivia::LineComment { content, .. }) => {
                    if let Some(marker) = parse_marker_directive_content(content)? {
                        if pending_marker.is_some() {
                            return Err(anyhow::anyhow!("duplicate marker directive before child").into());
                        }
                        pending_marker = Some(marker);
                    } else {
                        children.push(ast_comment_child(format::CommentKind::Line, content));
                    }
                }
                CstNode::Trivia(CstTrivia::BlockComment { content, .. }) => {
                    children.push(ast_comment_child(format::CommentKind::Block, content));
                }
                CstNode::Command(cmd) => {
                    children.push(format::Child {
                        marker: pending_marker.take(),
                        attributes: std::mem::take(&mut pending_attributes),
                        content: format::ChildContent::CommandLine(cmd.to_ast()),
                    });
                }
                CstNode::SystemCall(sc) => {
                    children.push(format::Child {
                        marker: pending_marker.take(),
                        attributes: std::mem::take(&mut pending_attributes),
                        content: format::ChildContent::SystemCallLine(sc.to_ast()),
                    });
                }
                CstNode::TextLine(tl) => {
                    let mut child = tl.to_ast()?;
                    child.marker = pending_marker.take();
                    child.attributes = std::mem::take(&mut pending_attributes);
                    children.push(child);
                }
                CstNode::Block(b) => {
                    children.push(format::Child {
                        marker: pending_marker.take(),
                        attributes: std::mem::take(&mut pending_attributes),
                        content: format::ChildContent::Block(b.to_ast()?),
                    });
                }
                CstNode::EmbeddedCode(ec) => {
                    children.push(format::Child {
                        marker: pending_marker.take(),
                        attributes: std::mem::take(&mut pending_attributes),
                        content: format::ChildContent::EmbeddedCode(ec.code.clone()),
                    });
                }
                CstNode::Trivia(CstTrivia::Whitespace { .. }) => {
                    // Trivia 不转换到 AST
                }
                CstNode::Paragraph(_) => {
                    // Paragraph 不应该在 block 内
                }
                CstNode::Error { .. } => {
                    // 错误节点跳过
                }
            }
        }

        if pending_marker.is_some() {
            return Err(anyhow::anyhow!("dangling marker directive at end of block").into());
        }

        Ok(format::Block::new(children))
    }
}

fn ast_comment_child(kind: format::CommentKind, content: &str) -> format::Child {
    format::Child {
        marker: None,
        attributes: vec![],
        content: format::ChildContent::Comment(format::Comment {
            kind,
            content: content.to_string(),
        }),
    }
}

fn parse_marker_directive_content(
    content: &str,
) -> crate::error::Result<Option<format::LineMarker>> {
    let Some(id) = content.strip_prefix("#marker id=") else {
        return Ok(None);
    };

    let marker = format::LineMarker::parse_id(id)
        .ok_or_else(|| anyhow::anyhow!("marker directive requires a strict alphanumeric id"))?;

    Ok(Some(marker))
}

/// 文本行 [leading] text #tailing
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstTextLine {
    /// 前导文本(如 [角色名])
    pub leading: Option<CstLeadingText>,

    /// 主文本内容
    pub text: Option<CstText>,

    /// 后缀标记(如 #wait)
    pub tailing: Option<CstTailingText>,

    /// 整行的范围
    pub span: SpanInfo,

    /// 前导 trivia
    pub leading_trivia: Vec<CstTrivia>,
}

impl CstTextLine {
    pub fn to_ast(&self) -> crate::error::Result<format::Child> {
        let leading_ast = match &self.leading {
            Some(l) => l.to_ast(),
            None => format::LeadingText::None,
        };

        let text_ast = match &self.text {
            Some(t) => t.to_ast()?,
            None => format::Text::None,
        };

        let tailing_ast = match &self.tailing {
            Some(t) => t.to_ast(),
            None => format::TailingText::None,
        };

        Ok(format::Child {
            marker: None,
            attributes: vec![],
            content: format::ChildContent::TextLine(leading_ast, text_ast, tailing_ast),
        })
    }
}

/// 前导文本 [...]
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstLeadingText {
    /// [ 的位置
    pub open_bracket: SpanInfo,

    /// 前导文本内容(可以是字符串或模板)
    pub content: CstLeadingTextContent,

    /// ] 的位置
    pub close_bracket: SpanInfo,

    /// 整个前导文本的范围
    pub span: SpanInfo,
}

impl CstLeadingText {
    pub fn to_ast(&self) -> format::LeadingText {
        match &self.content {
            CstLeadingTextContent::Text(text) => format::LeadingText::Text(text.clone()),
            CstLeadingTextContent::Template(tpl) => {
                // 将 CST template 转为 AST template
                format::LeadingText::TemplateLiteral(tpl.to_ast())
            }
        }
    }
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CstLeadingTextContent {
    /// 普通文本或带引号的文本
    Text(String),
    /// 模板字符串
    Template(CstTemplateLiteral),
}

/// 主文本内容
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstText {
    /// 文本种类
    pub kind: CstTextKind,

    /// 原始文本(含引号等)
    pub raw: String,

    /// 解析后的文本(用于生成 AST)
    pub parsed: String,

    /// 文本位置
    pub span: SpanInfo,
}

impl CstText {
    pub fn to_ast(&self) -> crate::error::Result<format::Text> {
        Ok(match &self.kind {
            CstTextKind::Bare => format::Text::Text(self.parsed.clone()),
            CstTextKind::Quoted(_) => format::Text::Text(self.parsed.clone()),
            CstTextKind::Template(tpl) => format::Text::TemplateLiteral(tpl.to_ast()),
        })
    }
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CstTextKind {
    /// 裸文本(不转义)
    Bare,
    /// 带引号的文本(支持转义)
    Quoted(QuoteStyle),
    /// 模板字符串
    Template(CstTemplateLiteral),
}

/// 后缀标记 #wait
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstTailingText {
    /// # 的位置
    pub hash_token: SpanInfo,

    /// 标记名
    pub marker: String,

    /// 标记名的位置
    pub marker_span: SpanInfo,

    /// 整个标记的范围
    pub span: SpanInfo,
}

impl CstTailingText {
    pub fn to_ast(&self) -> format::TailingText {
        format::TailingText::Text(self.marker.clone())
    }
}

/// 模板字符串 `text ${var}`
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstTemplateLiteral {
    /// 模板的各个部分
    pub parts: Vec<CstTemplatePart>,

    /// 整个模板的范围
    pub span: SpanInfo,
}

impl CstTemplateLiteral {
    pub fn to_ast(&self) -> format::TemplateLiteral {
        let parts = self.parts.iter().map(|p| p.to_ast()).collect();
        format::TemplateLiteral { parts }
    }
}

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum CstTemplatePart {
    /// 文本部分
    Text { content: String, span: SpanInfo },
    /// 变量插值 ${...}
    Value {
        /// ${ 的位置
        open_token: SpanInfo,
        /// 变量
        variable: format::Variable,
        /// 变量的位置
        variable_span: SpanInfo,
        /// } 的位置
        close_token: SpanInfo,
        /// 整个插值的范围
        span: SpanInfo,
    },
}

impl CstTemplatePart {
    pub fn to_ast(&self) -> format::TemplateLiteralPart {
        match self {
            CstTemplatePart::Text { content, .. } => {
                format::TemplateLiteralPart::Text(content.clone())
            }
            CstTemplatePart::Value { variable, .. } => {
                format::TemplateLiteralPart::Value(format::RValue::Variable(variable.clone()))
            }
        }
    }
}

/// 嵌入代码语法风格
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum EmbeddedCodeSyntax {
    Brace, // @{ ... }
    Hash,  // ## ... ##
}

/// 嵌入代码节点
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CstEmbeddedCode {
    pub syntax: EmbeddedCodeSyntax,
    pub code: String,
    pub span: SpanInfo,
}

impl CstEmbeddedCode {
    pub fn to_ast(&self) -> crate::error::Result<format::Child> {
        Ok(format::Child {
            marker: None,
            attributes: vec![],
            content: format::ChildContent::EmbeddedCode(self.code.clone()),
        })
    }
}