-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from Ph0enixKM/A9
A9 Feature: Add Block
- Loading branch information
Showing
4 changed files
with
56 additions
and
2 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use heraclitus_compiler::prelude::*; | ||
use super::statement::Statement; | ||
|
||
#[derive(Debug)] | ||
pub struct Block { | ||
statements: Vec<Statement> | ||
} | ||
|
||
impl Block { | ||
fn error(&mut self, meta: &mut DefaultMetadata, mut details: ErrorDetails) { | ||
if let Some(path) = meta.path.clone() { | ||
if let Ok(location) = details.get_pos_by_file(&path) { | ||
Logger::new_err(path, location) | ||
.attach_message("Undefined syntax") | ||
.show() | ||
.exit(); | ||
} else { | ||
println!("Couldn't load file '{}'", path); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl SyntaxModule<DefaultMetadata> for Block { | ||
fn new() -> Self { | ||
Block { | ||
statements: vec![] | ||
} | ||
} | ||
|
||
fn parse(&mut self, meta: &mut DefaultMetadata) -> SyntaxResult { | ||
loop { | ||
if let None = meta.get_token_at(meta.get_index()) { | ||
break; | ||
} | ||
let mut statemant = Statement::new(); | ||
if let Err(details) = statemant.parse(meta) { | ||
self.error(meta, details); | ||
} | ||
self.statements.push(statemant); | ||
} | ||
Ok(()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
mod statement; | ||
pub mod statement; | ||
pub mod block; |
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