diff --git a/src/ast/build.rs b/src/ast/build.rs index d17331b..d5874b8 100644 --- a/src/ast/build.rs +++ b/src/ast/build.rs @@ -745,26 +745,26 @@ fn build_call_statement(call_statement_pair: Pair) -> CallStatement { while let Some(inner_pair) = inner.next() { match inner_pair.as_rule() { Rule::ObjectAccess => { - result = Expression::Suffix(SuffixExpression::ObjectAccess(build_object_access( + result = Expression::ObjectAccess(build_object_access( result, inner_pair, - ))); + )); } Rule::ParenthesesCall => { - result = Expression::Suffix(SuffixExpression::Call(build_call_expression( + result = Expression::Call(build_call_expression( result, inner_pair, - ))); + )); } Rule::PlusPlus => { - result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression { + result = Expression::UnarySuffix(SuffixExpression { expression: Box::new(result), operator: SuffixUnaryOperator::PlusPlus, - })); + }); } Rule::MinusMinus => { - result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression { + result = Expression::UnarySuffix(SuffixExpression { expression: Box::new(result), operator: SuffixUnaryOperator::MinusMinus, - })); + }); } _ => unreachable!(), } @@ -971,28 +971,28 @@ fn build_suffix_expression(suffix_pair: Pair) -> Expression { while let Some(suffix_pair) = inner.next() { match suffix_pair.as_rule() { Rule::ObjectAccess => { - result = Expression::Suffix(SuffixExpression::ObjectAccess(build_object_access( + result = Expression::ObjectAccess(build_object_access( result, suffix_pair, - ))) + )) } Rule::ParenthesesCall => { - result = Expression::Suffix(SuffixExpression::Call(build_call_expression( + result = Expression::Call(build_call_expression( result, suffix_pair, - ))) + )) } Rule::PlusPlus => { - result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression { + result = Expression::UnarySuffix(SuffixExpression { expression: Box::new(result), operator: SuffixUnaryOperator::PlusPlus, - })) + }) } Rule::MinusMinus => { - result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression { + result = Expression::UnarySuffix(SuffixExpression { expression: Box::new(result), operator: SuffixUnaryOperator::MinusMinus, - })) + }) } _ => unreachable!(), } diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 2759c77..87df058 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -455,7 +455,9 @@ pub enum Expression { Ternary(TernaryExpression), Binary(BinaryExpression), UnaryPrefix(PrefixExpression), - Suffix(SuffixExpression), + UnarySuffix(SuffixExpression), + Call(CallExpression), + ObjectAccess(ObjectAccess), Literal(Literal), FullyQualifiedName(FullyQualifiedName), Closure(Closure), @@ -482,10 +484,9 @@ pub struct PrefixExpression { } #[derive(Debug)] -pub enum SuffixExpression { - Call(CallExpression), - ObjectAccess(ObjectAccess), - Unary(UnarySuffixExpression), +pub struct SuffixExpression { + expression: Box, + operator: SuffixUnaryOperator, } #[derive(Debug)] @@ -495,12 +496,6 @@ pub struct CallExpression { pub arguments: CallArguments, } -#[derive(Debug)] -pub struct UnarySuffixExpression { - expression: Box, - operator: SuffixUnaryOperator, -} - #[derive(Debug)] pub struct TurboFish(pub GenericArguments); diff --git a/src/ast/pretty_print.rs b/src/ast/pretty_print.rs index e2381d2..fe63219 100644 --- a/src/ast/pretty_print.rs +++ b/src/ast/pretty_print.rs @@ -6,6 +6,64 @@ pub trait PrettyPrint { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()>; } +impl PrettyPrint for Operator { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use Operator::*; + match self { + Binary(o) => o.pretty_print(writer), + PrefixUnary(o) => o.pretty_print(writer), + SuffixUnary(o) => o.pretty_print(writer), + } + } +} + +impl PrettyPrint for BinaryOperator { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use BinaryOperator::*; + match self { + Or => writer.write("||"), + And => writer.write("&&"), + EqualTo => writer.write("=="), + NotEqualTo => writer.write("!="), + Greater => writer.write(">"), + Less => writer.write("<"), + GreaterEqual => writer.write(">="), + LessEqual => writer.write("<="), + Add => writer.write("+"), + Subtract => writer.write("-"), + Multiply => writer.write("*"), + Divide => writer.write("/"), + Modulo => writer.write("%"), + LeftShift => writer.write("<<"), + RightShift => writer.write(">>"), + } + } +} + +impl PrettyPrint for PrefixUnaryOperator { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use PrefixUnaryOperator::*; + match self { + Spread => writer.write("..."), + BorrowMut => writer.write("&mut"), + Borrow => writer.write("&"), + Mut => writer.write("mut"), + Not => writer.write("!"), + Negative => writer.write("-"), + } + } +} + +impl PrettyPrint for SuffixUnaryOperator { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use SuffixUnaryOperator::*; + match self { + PlusPlus => writer.write("++"), + MinusMinus => writer.write("--"), + } + } +} + impl PrettyPrint for Identifier { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { writer.writeln_indented(&format!("Identifier({})", self.name)) @@ -231,20 +289,46 @@ impl PrettyPrint for ModuleLevelDeclaration { Interface(interface) => interface.pretty_print(writer), Class(class) => class.pretty_print(writer), Function(function) => function.pretty_print(writer), - PlatformFunction(platform_function) => platform_function.pretty_print(writer) + PlatformFunction(platform_function) => platform_function.pretty_print(writer), } } } impl PrettyPrint for InterfaceLevelDeclaration { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { - todo!() + use InterfaceLevelDeclaration::*; + match self { + Module(module) => module.pretty_print(writer), + Interface(interface) => interface.pretty_print(writer), + Class(class) => class.pretty_print(writer), + Function(function) => function.pretty_print(writer), + OperatorFunction(operator_function) => operator_function.pretty_print(writer), + } + } +} + +impl PrettyPrint for ClassLevelDeclaration { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use ClassLevelDeclaration::*; + match self { + Module(module) => module.pretty_print(writer), + Interface(interface) => interface.pretty_print(writer), + Class(class) => class.pretty_print(writer), + Function(function) => function.pretty_print(writer), + OperatorFunction(operator_function) => operator_function.pretty_print(writer), + PlatformFunction(platform_function) => platform_function.pretty_print(writer), + Property(property) => property.pretty_print(writer), + Field(field) => field.pretty_print(writer), + } } } impl PrettyPrint for ModuleDeclaration { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { - writer.writeln_indented(&format!("ModuleDeclaration(is_public = {})", self.is_public))?; + writer.writeln_indented(&format!( + "ModuleDeclaration(is_public = {})", + self.is_public + ))?; writer.increase_indent(); self.identifier.pretty_print(writer)?; for declaration in &self.declarations { @@ -257,7 +341,10 @@ impl PrettyPrint for ModuleDeclaration { impl PrettyPrint for InterfaceDeclaration { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { - writer.writeln_indented(&format!("InterfaceDeclaration(is_public = {})", self.is_public))?; + writer.writeln_indented(&format!( + "InterfaceDeclaration(is_public = {})", + self.is_public + ))?; writer.increase_indent(); self.identifier.pretty_print(writer)?; self.generics.pretty_print(writer)?; @@ -272,18 +359,525 @@ impl PrettyPrint for InterfaceDeclaration { impl PrettyPrint for ClassDeclaration { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { - todo!() + writer.writeln_indented(&format!("ClassDeclaration(is_public = {})", self.is_public))?; + writer.increase_indent(); + self.identifier.pretty_print(writer)?; + self.generics.pretty_print(writer)?; + if let Some(class_constructor) = &self.class_constructor { + class_constructor.pretty_print(writer)?; + } + self.implements.pretty_print(writer)?; + for declaration in &self.declarations { + declaration.pretty_print(writer)?; + } + writer.decrease_indent(); + Ok(()) } } impl PrettyPrint for FunctionDefinition { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { - todo!() + writer.writeln_indented(&format!( + "FunctionDefinition(is_public = {})", + self.is_public + ))?; + writer.increase_indent(); + if let Some(modifier) = &self.modifier { + modifier.pretty_print(writer)?; + } + self.generics.pretty_print(writer)?; + self.identifier.pretty_print(writer)?; + self.parameters.pretty_print(writer)?; + self.return_type.pretty_print(writer)?; + self.body.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for OperatorFunctionDefinition { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented(&format!( + "OperatorFunctionDefinition(is_public = {})", + self.is_public + ))?; + writer.increase_indent(); + if let Some(modifier) = &self.modifier { + modifier.pretty_print(writer)?; + } + self.generics.pretty_print(writer)?; + self.operator.pretty_print(writer)?; + self.parameters.pretty_print(writer)?; + self.return_type.pretty_print(writer)?; + self.body.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) } } impl PrettyPrint for PlatformFunctionDeclaration { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented(&format!( + "PlatformFunctionDeclaration(is_public = {})", + self.is_public + ))?; + writer.increase_indent(); + if let Some(modifier) = &self.modifier { + modifier.pretty_print(writer)?; + } + self.generics.pretty_print(writer)?; + self.identifier.pretty_print(writer)?; + self.parameters.pretty_print(writer)?; + self.return_type.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for InterfaceFunctionDeclaration { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("InterfaceFunctionDeclaration")?; + writer.increase_indent(); + if let Some(modifier) = &self.modifier { + modifier.pretty_print(writer)?; + } + self.generics.pretty_print(writer)?; + self.identifier.pretty_print(writer)?; + self.parameters.pretty_print(writer)?; + self.return_type.pretty_print(writer)?; + if let Some(body) = &self.body { + body.pretty_print(writer)?; + } + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for InterfaceOperatorFunctionDeclaration { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("InterfaceOperatorFunctionDeclaration")?; + writer.increase_indent(); + if let Some(modifier) = &self.modifier { + modifier.pretty_print(writer)?; + } + self.generics.pretty_print(writer)?; + self.operator.pretty_print(writer)?; + self.parameters.pretty_print(writer)?; + self.return_type.pretty_print(writer)?; + if let Some(body) = &self.body { + body.pretty_print(writer)?; + } + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for FunctionModifier { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use FunctionModifier::*; + writer.writeln_indented(&format!( + "FunctionModifier({})", + match self { + Static => "static", + Cons => "cons", + Mut => "mut", + Ref => "ref", + MutRef => "mut ref", + } + )) + } +} + +impl PrettyPrint for FunctionBody { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use FunctionBody::*; + match self { + Equals(expression) => { + writer.writeln_indented("EqualsFunctionBody")?; + writer.increase_indent(); + expression.pretty_print(writer)?; + writer.decrease_indent(); + } + Block(block_statement) => { + writer.writeln_indented("BlockFunctionBody")?; + writer.increase_indent(); + block_statement.pretty_print(writer)?; + writer.decrease_indent(); + } + Alias(identifier) => { + writer.writeln_indented("AliasFunctionBody")?; + writer.increase_indent(); + identifier.pretty_print(writer)?; + writer.decrease_indent(); + } + } + Ok(()) + } +} + +impl PrettyPrint for ClassConstructor { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("ClassConstructor")?; + writer.increase_indent(); + for constructor_parameter in &self.0 { + constructor_parameter.pretty_print(writer)?; + } + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for ClassConstructorParameter { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use ClassConstructorParameter::*; + match self { + Property(property) => { + writer.writeln_indented("PropertyConstructorParameter")?; + writer.increase_indent(); + property.pretty_print(writer)?; + writer.decrease_indent(); + } + Field(field) => { + writer.writeln_indented("FieldConstructorParameter")?; + writer.increase_indent(); + field.pretty_print(writer)?; + writer.decrease_indent(); + } + } + Ok(()) + } +} + +impl PrettyPrint for PropertyDeclaration { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented(&format!( + "PropertyDeclaration(is_mutable = {})", + self.is_mutable + ))?; + writer.increase_indent(); + self.identifier.pretty_print(writer)?; + self.declared_type.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for FieldDeclaration { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented(&format!( + "FieldDeclaration(is_mutable = {})", + self.is_mutable + ))?; + writer.increase_indent(); + self.identifier.pretty_print(writer)?; + self.declared_type.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for BlockStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("BlockStatement")?; + writer.increase_indent(); + for statement in &self.statements { + statement.pretty_print(writer)?; + } + if let Some(expression) = &self.expression { + expression.pretty_print(writer)?; + } + Ok(()) + } +} + +impl PrettyPrint for Statement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use Statement::*; + match self { + BlockStatement(block_statement) => block_statement.pretty_print(writer), + VariableDeclarationStatement(s) => s.pretty_print(writer), + AssignStatement(s) => s.pretty_print(writer), + CallStatement(s) => s.pretty_print(writer), + ReturnStatement(s) => s.pretty_print(writer), + IfStatement(s) => s.pretty_print(writer), + IfElseStatement(s) => s.pretty_print(writer), + WhileStatement(s) => s.pretty_print(writer), + ForStatement(s) => s.pretty_print(writer), + } + } +} + +impl PrettyPrint for VariableDeclarationStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented(&format!( + "VariableDeclarationStatement(is_mutable = {})", + self.is_mutable + ))?; + writer.increase_indent(); + self.identifier.pretty_print(writer)?; + if let Some(declared_type) = &self.declared_type { + declared_type.pretty_print(writer)?; + } + if let Some(initializer) = &self.initializer { + initializer.pretty_print(writer)?; + } + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for AssignStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("AssignStatement")?; + writer.increase_indent(); + self.lhs.pretty_print(writer)?; + self.rhs.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for CallStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("CallStatement")?; + writer.increase_indent(); + self.0.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for ReturnStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("ReturnStatement")?; + if let Some(expression) = &self.0 { + writer.increase_indent(); + expression.pretty_print(writer)?; + writer.decrease_indent(); + } + Ok(()) + } +} + +impl PrettyPrint for IfStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("IfStatement")?; + writer.increase_indent(); + self.condition.pretty_print(writer)?; + self.then_block.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for IfElseStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("IfElseStatement")?; + writer.increase_indent(); + self.condition.pretty_print(writer)?; + self.then_block.pretty_print(writer)?; + for else_if in &self.else_ifs.0 { + else_if.condition.pretty_print(writer)?; + else_if.then_block.pretty_print(writer)?; + } + self.else_block.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for WhileStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("WhileStatement")?; + writer.increase_indent(); + self.condition.pretty_print(writer)?; + self.body.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for ForStatement { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("ForStatement")?; + writer.increase_indent(); + self.variable.pretty_print(writer)?; + self.iterator.pretty_print(writer)?; + self.body.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for Expression { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use Expression::*; + match self { + Ternary(e) => e.pretty_print(writer), + Binary(e) => e.pretty_print(writer), + UnaryPrefix(e) => e.pretty_print(writer), + UnarySuffix(e) => e.pretty_print(writer), + Call(e) => e.pretty_print(writer), + ObjectAccess(o) => o.pretty_print(writer), + Literal(literial) => literial.pretty_print(writer), + FullyQualifiedName(fqn) => fqn.pretty_print(writer), + Closure(closure) => closure.pretty_print(writer), + } + } +} + +impl PrettyPrint for TernaryExpression { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("TernaryExpression")?; + writer.increase_indent(); + self.condition.pretty_print(writer)?; + self.true_expression.pretty_print(writer)?; + self.false_expression.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for BinaryExpression { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("BinaryExpression")?; + writer.increase_indent(); + self.left.pretty_print(writer)?; + self.operator.pretty_print(writer)?; + self.right.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for PrefixExpression { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("PrefixExpression")?; + writer.increase_indent(); + self.operator.pretty_print(writer)?; + self.expression.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for SuffixExpression { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("SuffixExpression")?; + writer.increase_indent(); + self.expression.pretty_print(writer)?; + self.operator.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for CallExpression { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("CallExpression")?; + writer.increase_indent(); + self.callee.pretty_print(writer)?; + if let Some(turbo_fish) = &self.turbo_fish { + turbo_fish.pretty_print(writer)?; + } + self.arguments.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for TurboFish { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("TurboFish")?; + writer.increase_indent(); + self.0.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for CallArguments { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("CallArguments")?; + writer.increase_indent(); + for call_argument in &self.0 { + call_argument.pretty_print(writer)?; + } + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for CallArgument { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("CallArgument")?; + writer.increase_indent(); + self.0.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for Closure { fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { todo!() } -} \ No newline at end of file +} + +impl PrettyPrint for ObjectAccess { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("ObjectAccess")?; + writer.increase_indent(); + self.receiver.pretty_print(writer)?; + self.navigations.pretty_print(writer)?; + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for ObjectNavigations { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + writer.writeln_indented("ObjectNavigations")?; + writer.increase_indent(); + for object_navigation in &self.0 { + object_navigation.pretty_print(writer)?; + } + writer.decrease_indent(); + Ok(()) + } +} + +impl PrettyPrint for ObjectNavigation { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use ObjectNavigation::*; + match self { + Index(e) => { + writer.writeln_indented("Index")?; + writer.increase_indent(); + e.pretty_print(writer)?; + writer.decrease_indent(); + } + Identifier(identifier) => { + writer.writeln_indented("Property")?; + writer.increase_indent(); + identifier.pretty_print(writer)?; + writer.decrease_indent(); + } + } + Ok(()) + } +} + +impl PrettyPrint for Literal { + fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> { + use Literal::*; + match self { + Integer(i) => writer.writeln_indented(&format!("Integer({})", i)), + Long(l) => writer.writeln_indented(&format!("Long({})", l)), + Double(d) => writer.writeln_indented(&format!("Double({})", d)), + USize(u) => writer.writeln_indented(&format!("USize({})", u)), + String(s) => writer.writeln_indented(&format!("String({})", s)), + Boolean(b) => writer.writeln_indented(&format!("Boolean({})", b)), + } + } +} diff --git a/src/ast/unparse.rs b/src/ast/unparse.rs index c45b7b1..5802f8b 100644 --- a/src/ast/unparse.rs +++ b/src/ast/unparse.rs @@ -841,7 +841,9 @@ impl Unparse for Expression { Ternary(ternary) => ternary.unparse(buf), Binary(binary) => binary.unparse(buf), UnaryPrefix(prefix) => prefix.unparse(buf), - Suffix(suffix) => suffix.unparse(buf), + UnarySuffix(suffix) => suffix.unparse(buf), + Call(call) => call.unparse(buf), + ObjectAccess(object_access) => object_access.unparse(buf), Literal(literal) => literal.unparse(buf), FullyQualifiedName(fully_qualified_name) => fully_qualified_name.unparse(buf), Closure(closure) => closure.unparse(buf), @@ -886,12 +888,9 @@ impl Unparse for PrefixExpression { impl Unparse for SuffixExpression { fn unparse(&self, buf: &mut dyn std::fmt::Write) -> std::fmt::Result { - use SuffixExpression::*; - match self { - Call(call) => call.unparse(buf), - ObjectAccess(object) => object.unparse(buf), - Unary(unary) => unary.unparse(buf), - } + self.expression.unparse(buf)?; + self.operator.unparse(buf)?; + unparse_ok!() } } @@ -906,14 +905,6 @@ impl Unparse for CallExpression { } } -impl Unparse for UnarySuffixExpression { - fn unparse(&self, buf: &mut dyn std::fmt::Write) -> std::fmt::Result { - self.expression.unparse(buf)?; - self.operator.unparse(buf)?; - unparse_ok!() - } -} - impl Unparse for TurboFish { fn unparse(&self, buf: &mut dyn std::fmt::Write) -> std::fmt::Result { write!(buf, "::")?; diff --git a/src/bin/dmc/main.rs b/src/bin/dmc/main.rs index 4b34a31..c221d18 100644 --- a/src/bin/dmc/main.rs +++ b/src/bin/dmc/main.rs @@ -1,10 +1,10 @@ -mod ast_dump; mod p3; +mod unparse; use std::path::PathBuf; use crate::p3::pretty_print_parse; -use ast_dump::unparse; +use crate::unparse::unparse; use clap::{Parser, Subcommand}; #[derive(Debug, Parser)] diff --git a/src/bin/dmc/ast_dump.rs b/src/bin/dmc/unparse.rs similarity index 100% rename from src/bin/dmc/ast_dump.rs rename to src/bin/dmc/unparse.rs