oak_actionscript/formatter/
mod.rs1#![doc = include_str!("readme.md")]
2
3use crate::ast::{ActionScriptItem, ActionScriptRoot};
4
5pub struct ActionScriptFormatter {
7 _indent_level: usize,
9 _indent_str: String,
11}
12
13impl ActionScriptFormatter {
14 pub fn new() -> Self {
16 Self { _indent_level: 0, _indent_str: " ".to_string() }
17 }
18
19 pub fn format(&self, source: &str) -> String {
21 source.to_string()
23 }
24
25 pub fn format_ast(&self, root: &ActionScriptRoot) -> String {
27 let mut result = String::new();
28
29 for (i, item) in root.items.iter().enumerate() {
30 if i > 0 {
31 result.push_str("\n\n");
32 }
33 result.push_str(&self.format_item(item));
34 }
35
36 result
37 }
38
39 fn format_item(&self, item: &ActionScriptItem) -> String {
41 match item {
42 ActionScriptItem::Class => "class {} // TODO".to_string(),
43 ActionScriptItem::Interface => "interface {} // TODO".to_string(),
44 ActionScriptItem::Function => "function() {} // TODO".to_string(),
45 ActionScriptItem::Variable => "var x; // TODO".to_string(),
46 ActionScriptItem::Package => "package {} // TODO".to_string(),
47 ActionScriptItem::Import => "import {} // TODO".to_string(),
48 }
49 }
50
51 fn _get_indent(&self) -> String {
52 self._indent_str.repeat(self._indent_level)
53 }
54}
55
56impl Default for ActionScriptFormatter {
57 fn default() -> Self {
58 Self::new()
59 }
60}