Skip to content

Commit

Permalink
Refactored trait methods AST representation to be included in trait AST
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacShelton committed Dec 15, 2024
1 parent 63747d1 commit 581f371
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/ast/traits.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
use super::Privacy;
use super::{Parameters, Privacy, Type};
use crate::source_files::Source;

#[derive(Clone, Debug)]
pub struct Trait {
pub name: String,
pub source: Source,
pub privacy: Privacy,
pub methods: Vec<TraitMethod>,
}

#[derive(Clone, Debug)]
pub struct TraitMethod {
pub name: String,
pub parameters: Parameters,
pub return_type: Type,
pub source: Source,
}
11 changes: 2 additions & 9 deletions src/parser/parse_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ use super::{
Parser,
};
use crate::{
ast::{Parameters, Privacy, Trait, Type},
ast::{Parameters, Privacy, Trait, TraitMethod},
inflow::Inflow,
source_files::Source,
token::{Token, TokenKind},
};

pub struct TraitMethod {
pub name: String,
pub parameters: Parameters,
pub return_type: Type,
pub source: Source,
}

impl<'a, I: Inflow<Token>> Parser<'a, I> {
pub fn parse_trait(&mut self, annotations: Vec<Annotation>) -> Result<Trait, ParseError> {
let source = self.source_here();
Expand Down Expand Up @@ -51,6 +43,7 @@ impl<'a, I: Inflow<Token>> Parser<'a, I> {
name,
source,
privacy,
methods,
})
}

Expand Down

0 comments on commit 581f371

Please sign in to comment.