Finish current version of pretty print.
This commit is contained in:
parent
58c66b437e
commit
9805a3aad5
@ -745,26 +745,26 @@ fn build_call_statement(call_statement_pair: Pair<Rule>) -> CallStatement {
|
|||||||
while let Some(inner_pair) = inner.next() {
|
while let Some(inner_pair) = inner.next() {
|
||||||
match inner_pair.as_rule() {
|
match inner_pair.as_rule() {
|
||||||
Rule::ObjectAccess => {
|
Rule::ObjectAccess => {
|
||||||
result = Expression::Suffix(SuffixExpression::ObjectAccess(build_object_access(
|
result = Expression::ObjectAccess(build_object_access(
|
||||||
result, inner_pair,
|
result, inner_pair,
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
Rule::ParenthesesCall => {
|
Rule::ParenthesesCall => {
|
||||||
result = Expression::Suffix(SuffixExpression::Call(build_call_expression(
|
result = Expression::Call(build_call_expression(
|
||||||
result, inner_pair,
|
result, inner_pair,
|
||||||
)));
|
));
|
||||||
}
|
}
|
||||||
Rule::PlusPlus => {
|
Rule::PlusPlus => {
|
||||||
result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression {
|
result = Expression::UnarySuffix(SuffixExpression {
|
||||||
expression: Box::new(result),
|
expression: Box::new(result),
|
||||||
operator: SuffixUnaryOperator::PlusPlus,
|
operator: SuffixUnaryOperator::PlusPlus,
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
Rule::MinusMinus => {
|
Rule::MinusMinus => {
|
||||||
result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression {
|
result = Expression::UnarySuffix(SuffixExpression {
|
||||||
expression: Box::new(result),
|
expression: Box::new(result),
|
||||||
operator: SuffixUnaryOperator::MinusMinus,
|
operator: SuffixUnaryOperator::MinusMinus,
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
@ -971,28 +971,28 @@ fn build_suffix_expression(suffix_pair: Pair<Rule>) -> Expression {
|
|||||||
while let Some(suffix_pair) = inner.next() {
|
while let Some(suffix_pair) = inner.next() {
|
||||||
match suffix_pair.as_rule() {
|
match suffix_pair.as_rule() {
|
||||||
Rule::ObjectAccess => {
|
Rule::ObjectAccess => {
|
||||||
result = Expression::Suffix(SuffixExpression::ObjectAccess(build_object_access(
|
result = Expression::ObjectAccess(build_object_access(
|
||||||
result,
|
result,
|
||||||
suffix_pair,
|
suffix_pair,
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
Rule::ParenthesesCall => {
|
Rule::ParenthesesCall => {
|
||||||
result = Expression::Suffix(SuffixExpression::Call(build_call_expression(
|
result = Expression::Call(build_call_expression(
|
||||||
result,
|
result,
|
||||||
suffix_pair,
|
suffix_pair,
|
||||||
)))
|
))
|
||||||
}
|
}
|
||||||
Rule::PlusPlus => {
|
Rule::PlusPlus => {
|
||||||
result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression {
|
result = Expression::UnarySuffix(SuffixExpression {
|
||||||
expression: Box::new(result),
|
expression: Box::new(result),
|
||||||
operator: SuffixUnaryOperator::PlusPlus,
|
operator: SuffixUnaryOperator::PlusPlus,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
Rule::MinusMinus => {
|
Rule::MinusMinus => {
|
||||||
result = Expression::Suffix(SuffixExpression::Unary(UnarySuffixExpression {
|
result = Expression::UnarySuffix(SuffixExpression {
|
||||||
expression: Box::new(result),
|
expression: Box::new(result),
|
||||||
operator: SuffixUnaryOperator::MinusMinus,
|
operator: SuffixUnaryOperator::MinusMinus,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
|
@ -455,7 +455,9 @@ pub enum Expression {
|
|||||||
Ternary(TernaryExpression),
|
Ternary(TernaryExpression),
|
||||||
Binary(BinaryExpression),
|
Binary(BinaryExpression),
|
||||||
UnaryPrefix(PrefixExpression),
|
UnaryPrefix(PrefixExpression),
|
||||||
Suffix(SuffixExpression),
|
UnarySuffix(SuffixExpression),
|
||||||
|
Call(CallExpression),
|
||||||
|
ObjectAccess(ObjectAccess),
|
||||||
Literal(Literal),
|
Literal(Literal),
|
||||||
FullyQualifiedName(FullyQualifiedName),
|
FullyQualifiedName(FullyQualifiedName),
|
||||||
Closure(Closure),
|
Closure(Closure),
|
||||||
@ -482,10 +484,9 @@ pub struct PrefixExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum SuffixExpression {
|
pub struct SuffixExpression {
|
||||||
Call(CallExpression),
|
expression: Box<Expression>,
|
||||||
ObjectAccess(ObjectAccess),
|
operator: SuffixUnaryOperator,
|
||||||
Unary(UnarySuffixExpression),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -495,12 +496,6 @@ pub struct CallExpression {
|
|||||||
pub arguments: CallArguments,
|
pub arguments: CallArguments,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct UnarySuffixExpression {
|
|
||||||
expression: Box<Expression>,
|
|
||||||
operator: SuffixUnaryOperator,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct TurboFish(pub GenericArguments);
|
pub struct TurboFish(pub GenericArguments);
|
||||||
|
|
||||||
|
@ -6,6 +6,64 @@ pub trait PrettyPrint {
|
|||||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()>;
|
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 {
|
impl PrettyPrint for Identifier {
|
||||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
||||||
writer.writeln_indented(&format!("Identifier({})", self.name))
|
writer.writeln_indented(&format!("Identifier({})", self.name))
|
||||||
@ -231,20 +289,46 @@ impl PrettyPrint for ModuleLevelDeclaration {
|
|||||||
Interface(interface) => interface.pretty_print(writer),
|
Interface(interface) => interface.pretty_print(writer),
|
||||||
Class(class) => class.pretty_print(writer),
|
Class(class) => class.pretty_print(writer),
|
||||||
Function(function) => function.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 {
|
impl PrettyPrint for InterfaceLevelDeclaration {
|
||||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
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 {
|
impl PrettyPrint for ModuleDeclaration {
|
||||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
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();
|
writer.increase_indent();
|
||||||
self.identifier.pretty_print(writer)?;
|
self.identifier.pretty_print(writer)?;
|
||||||
for declaration in &self.declarations {
|
for declaration in &self.declarations {
|
||||||
@ -257,7 +341,10 @@ impl PrettyPrint for ModuleDeclaration {
|
|||||||
|
|
||||||
impl PrettyPrint for InterfaceDeclaration {
|
impl PrettyPrint for InterfaceDeclaration {
|
||||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
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();
|
writer.increase_indent();
|
||||||
self.identifier.pretty_print(writer)?;
|
self.identifier.pretty_print(writer)?;
|
||||||
self.generics.pretty_print(writer)?;
|
self.generics.pretty_print(writer)?;
|
||||||
@ -272,18 +359,525 @@ impl PrettyPrint for InterfaceDeclaration {
|
|||||||
|
|
||||||
impl PrettyPrint for ClassDeclaration {
|
impl PrettyPrint for ClassDeclaration {
|
||||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
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 {
|
impl PrettyPrint for FunctionDefinition {
|
||||||
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
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 {
|
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<()> {
|
fn pretty_print(&self, writer: &mut IndentWriter) -> std::io::Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -841,7 +841,9 @@ impl Unparse for Expression {
|
|||||||
Ternary(ternary) => ternary.unparse(buf),
|
Ternary(ternary) => ternary.unparse(buf),
|
||||||
Binary(binary) => binary.unparse(buf),
|
Binary(binary) => binary.unparse(buf),
|
||||||
UnaryPrefix(prefix) => prefix.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),
|
Literal(literal) => literal.unparse(buf),
|
||||||
FullyQualifiedName(fully_qualified_name) => fully_qualified_name.unparse(buf),
|
FullyQualifiedName(fully_qualified_name) => fully_qualified_name.unparse(buf),
|
||||||
Closure(closure) => closure.unparse(buf),
|
Closure(closure) => closure.unparse(buf),
|
||||||
@ -886,12 +888,9 @@ impl Unparse for PrefixExpression {
|
|||||||
|
|
||||||
impl Unparse for SuffixExpression {
|
impl Unparse for SuffixExpression {
|
||||||
fn unparse(&self, buf: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
fn unparse(&self, buf: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
||||||
use SuffixExpression::*;
|
self.expression.unparse(buf)?;
|
||||||
match self {
|
self.operator.unparse(buf)?;
|
||||||
Call(call) => call.unparse(buf),
|
unparse_ok!()
|
||||||
ObjectAccess(object) => object.unparse(buf),
|
|
||||||
Unary(unary) => unary.unparse(buf),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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 {
|
impl Unparse for TurboFish {
|
||||||
fn unparse(&self, buf: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
fn unparse(&self, buf: &mut dyn std::fmt::Write) -> std::fmt::Result {
|
||||||
write!(buf, "::")?;
|
write!(buf, "::")?;
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
mod ast_dump;
|
|
||||||
mod p3;
|
mod p3;
|
||||||
|
mod unparse;
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::p3::pretty_print_parse;
|
use crate::p3::pretty_print_parse;
|
||||||
use ast_dump::unparse;
|
use crate::unparse::unparse;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
|
Loading…
Reference in New Issue
Block a user