about summary refs log tree commit diff
path: root/src/parse/ast
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse/ast')
-rw-r--r--src/parse/ast/expression.rs17
-rw-r--r--src/parse/ast/nodes.rs22
2 files changed, 31 insertions, 8 deletions
diff --git a/src/parse/ast/expression.rs b/src/parse/ast/expression.rs
index b2b9678..d119a71 100644
--- a/src/parse/ast/expression.rs
+++ b/src/parse/ast/expression.rs
@@ -1,8 +1,10 @@
 use std::fmt::{self, Display, Formatter};
 
+use crate::parse::ast::nodes::StrPart;
+
 use super::nodes::{
     ArrayAccessNode, ArrayNode, BinaryOperator, BlockNode, CallNode, FnNode, Identifier, IfNode,
-    LoopNode, MemberAccessNode, SimpleLiteral, UnaryOperator,
+    LoopNode, MemberAccessNode, SimpleLiteral, StrNode, UnaryOperator,
 };
 
 #[derive(Debug, Clone)]
@@ -23,6 +25,7 @@ pub enum Expression {
     Block(Box<BlockNode>),
     If(Box<IfNode>),
     Loop(Box<LoopNode>),
+    StrLiteral(Box<StrNode>),
     FnLiteral(Box<FnNode>),
     ArrayLiteral(ArrayNode),
     SimpleLiteral(SimpleLiteral),
@@ -82,6 +85,18 @@ impl Expression {
             Expression::Block(block) => {
                 Self::block_fmt(f, block, depth + 1)?;
             }
+            Expression::StrLiteral(node) => {
+                writeln!(f, "{}Str:", pad)?;
+                for (i, statement) in node.parts.iter().enumerate() {
+                    writeln!(f, "{}- {}:", pad, i)?;
+                    match statement {
+                        StrPart::Literal(literal) => {
+                            writeln!(f, "{}{}", "  ".repeat(depth + 1), literal.clone())
+                        }
+                        StrPart::Embed(block) => block.nested_fmt(f, depth + 1),
+                    }?;
+                }
+            }
             Expression::FnLiteral(node) => {
                 write!(f, "{}Fn (", pad)?;
 
diff --git a/src/parse/ast/nodes.rs b/src/parse/ast/nodes.rs
index 2bf3f17..c4bb1e8 100644
--- a/src/parse/ast/nodes.rs
+++ b/src/parse/ast/nodes.rs
@@ -64,7 +64,6 @@ impl UnaryOperator {
 pub enum SimpleLiteral {
     Int(u32),
     Float(f32),
-    Str(String),
     Bool(bool),
 }
 
@@ -73,7 +72,6 @@ impl SimpleLiteral {
         match token.variant {
             Int(int) => Self::Int(int),
             Float(float) => Self::Float(float),
-            Str(string) => Self::Str(string),
             KeywordTrue => Self::Bool(true),
             KeywordFalse => Self::Bool(false),
             _ => panic!("Can't create literal from '{:?}'.", token.variant),
@@ -110,14 +108,20 @@ pub struct MemberAccessNode {
 }
 
 #[derive(Debug, Clone)]
-pub struct FnNode {
-    pub header: FnHeader,
-    pub body: BlockNode,
+pub struct StrNode {
+    pub parts: Vec<StrPart>,
 }
 
 #[derive(Debug, Clone)]
-pub struct ArrayNode {
-    pub elements: Vec<Expression>,
+pub enum StrPart {
+    Literal(String),
+    Embed(Expression)
+}
+
+#[derive(Debug, Clone)]
+pub struct FnNode {
+    pub header: FnHeader,
+    pub body: BlockNode,
 }
 
 #[derive(Debug, Clone)]
@@ -128,6 +132,10 @@ pub struct FnHeader {
 }
 
 #[derive(Debug, Clone)]
+pub struct ArrayNode {
+    pub elements: Vec<Expression>,
+}
+#[derive(Debug, Clone)]
 pub struct IfNode {
     pub conditionals: Vec<ConditionalBlock>,
     pub else_block: Option<BlockNode>,