-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started working on adding traits to use with generics
- Loading branch information
1 parent
e104876
commit 1e8a2e9
Showing
8 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use super::Privacy; | ||
use crate::source_files::Source; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Trait { | ||
pub name: String, | ||
pub source: Source, | ||
pub privacy: Privacy, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use super::{ | ||
annotation::{Annotation, AnnotationKind}, | ||
error::ParseError, | ||
Parser, | ||
}; | ||
use crate::{ | ||
ast::{Privacy, Trait}, | ||
inflow::Inflow, | ||
token::{Token, TokenKind}, | ||
}; | ||
|
||
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(); | ||
self.input.advance(); | ||
|
||
let name = self.parse_identifier(Some("for trait name after 'trait' keyword"))?; | ||
self.ignore_newlines(); | ||
|
||
let mut privacy = Privacy::Private; | ||
|
||
for annotation in annotations { | ||
match annotation.kind { | ||
AnnotationKind::Public => privacy = Privacy::Public, | ||
_ => return Err(self.unexpected_annotation(&annotation, Some("for trait"))), | ||
} | ||
} | ||
|
||
self.ignore_newlines(); | ||
self.parse_token(TokenKind::OpenCurly, Some("to begin trait body"))?; | ||
|
||
while !self.input.peek_is_or_eof(TokenKind::CloseCurly) { | ||
todo!("parse trait body"); | ||
} | ||
|
||
self.parse_token(TokenKind::CloseCurly, Some("to end trait body"))?; | ||
|
||
Ok(Trait { | ||
name, | ||
source, | ||
privacy, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters