Skip to content

Commit

Permalink
Remove obsolete classes in ast and improve printing in some places.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivorforce committed Apr 28, 2024
1 parent 76f6b72 commit 68cca82
Showing 1 changed file with 6 additions and 44 deletions.
50 changes: 6 additions & 44 deletions src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ pub struct FunctionInterface {
pub return_type: Option<Expression>,
}

#[derive(Eq, PartialEq, Clone)]
pub struct KeyedParameter {
pub key: ParameterKey,
pub internal_name: String,
pub param_type: Expression,
}

#[derive(Eq, PartialEq, Clone)]
pub struct TraitDefinition {
pub name: String,
Expand Down Expand Up @@ -155,12 +148,6 @@ pub struct ArrayArgument {
pub type_declaration: Option<Expression>,
}

#[derive(Copy, Clone, PartialEq, Eq)]
pub enum FunctionCallType {
Call,
Subscript,
}

#[derive(PartialEq, Eq, Clone)]
pub enum StringPart {
Literal(String),
Expand Down Expand Up @@ -202,7 +189,7 @@ impl Display for Array {

impl Display for Block {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
write_separated_display(fmt, "\n\n", self.statements.iter())
write_separated_display(fmt, "\n", self.statements.iter())
}
}

Expand Down Expand Up @@ -231,16 +218,13 @@ impl Display for FunctionInterface {

impl Display for TraitDefinition {
fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
write!(fmt, "trait {} {{", self.name)?;

Ok(())
write!(fmt, "trait {} {{\n{}}}", self.name, self.block)
}
}

impl Display for TraitConformanceDeclaration {
fn fmt(&self, fmt: &mut Formatter<'_>) -> std::fmt::Result {
write!(fmt, "declare {} is {} {{}} :: ", self.declared_for, self.declared)?;
Ok(())
write!(fmt, "declare {} is {} {{}} :: {{\n{}}}", self.declared_for, self.declared, self.block)
}
}

Expand All @@ -264,7 +248,6 @@ impl Display for Statement {
Statement::Return(Some(expression)) => write!(fmt, "return {}", expression),
Statement::Return(None) => write!(fmt, "return"),
Statement::Expression(ref expression) => write!(fmt, "{}", expression),

Statement::FunctionDeclaration(function) => write!(fmt, "{}", function),
Statement::Trait(trait_) => write!(fmt, "{}", trait_),
Statement::Conformance(conformance) => write!(fmt, "{}", conformance),
Expand Down Expand Up @@ -293,15 +276,9 @@ impl Display for Term {
}
write!(fmt, "\"")
},
Term::Struct(struct_) => {
write!(fmt, "{}", struct_)
}
Term::Array(array) => {
write!(fmt, "{}", array)
}
Term::Block(block) => {
write!(fmt, "{{\n{}}}", block)
}
Term::Struct(struct_) => write!(fmt, "{}", struct_),
Term::Array(array) => write!(fmt, "{}", array),
Term::Block(block) => write!(fmt, "{{\n{}}}", block),
Term::Dot => write!(fmt, "."),
Term::IfThenElse(if_then_else) => {
write!(fmt, "if {} :: {}", if_then_else.condition, if_then_else.consequent)?;
Expand Down Expand Up @@ -329,21 +306,6 @@ impl Display for ArrayArgument {
}
}

impl Display for KeyedParameter {
fn fmt(&self, fmt: &mut Formatter) -> Result<(), Error> {
write!(fmt, "{}{} '{}", self.key, self.internal_name, self.param_type)
}
}

impl FunctionCallType {
fn bracket_str(&self) -> &str {
return match *self {
FunctionCallType::Call => "()",
FunctionCallType::Subscript => "[]",
};
}
}

impl Display for StringPart {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down

0 comments on commit 68cca82

Please sign in to comment.