-
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.
- Loading branch information
Showing
4 changed files
with
101 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use super::parser::*; | ||
|
||
#[derive(Debug)] | ||
pub struct Interpreter; | ||
|
||
impl Interpreter { | ||
pub fn new() -> Self { | ||
Interpreter | ||
} | ||
|
||
pub async fn interpret(&self, nodes: Vec<ASTNode>) -> Vec<String> { | ||
let mut results = Vec::new(); | ||
|
||
for node in nodes { | ||
match node { | ||
ASTNode::ProviderBlock { name, properties } => { | ||
results.push(self.interpret_provider_block(name, properties).await); | ||
} | ||
ASTNode::ResourceBlock { | ||
name, | ||
resource_type, | ||
properties, | ||
} => { | ||
results.push( | ||
self.interpret_resource_block(name, resource_type, properties) | ||
.await, | ||
); | ||
} | ||
} | ||
} | ||
results | ||
} | ||
|
||
pub async fn interpret_provider_block( | ||
&self, | ||
name: String, | ||
properties: Vec<(String, ASTValue)>, | ||
) -> String { | ||
let mut result = format!("Provider: {}", name); | ||
|
||
for (key, value) in properties { | ||
match value { | ||
ASTValue::StringLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), | ||
ASTValue::NumberLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), | ||
} | ||
} | ||
result | ||
} | ||
|
||
pub async fn interpret_resource_block( | ||
&self, | ||
name: String, | ||
resource_type: String, | ||
properties: Vec<(String, ASTValue)>, | ||
) -> String { | ||
let mut result = format!("Resource: {} {}", resource_type, name); | ||
|
||
for (key, value) in properties { | ||
match value { | ||
ASTValue::StringLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), | ||
ASTValue::NumberLiteral(val) => result.push_str(&format!("\n {}: {}", key, val)), | ||
} | ||
} | ||
result | ||
} | ||
} |
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,2 +1,4 @@ | ||
pub mod interpreter; | ||
pub mod lexer; | ||
pub mod parser; | ||
pub mod lexer; | ||
pub mod prelude; |
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 @@ | ||
pub use crate::iaas::{interpreter::*, lexer::*, parser::*}; |
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