aboutsummaryrefslogtreecommitdiff
path: root/src/eval.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/eval.rs')
-rw-r--r--src/eval.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/eval.rs b/src/eval.rs
index e13cec3..029cffe 100644
--- a/src/eval.rs
+++ b/src/eval.rs
@@ -1,4 +1,4 @@
1//! tree walking interpreter for trawk 1//! tree walking interpreter for tbsp
2 2
3use crate::ast; 3use crate::ast;
4use std::{collections::HashMap, fmt}; 4use std::{collections::HashMap, fmt};
@@ -112,6 +112,8 @@ impl Value {
112 fn mul(&self, other: &Self) -> Result { 112 fn mul(&self, other: &Self) -> Result {
113 match (self, other) { 113 match (self, other) {
114 (Self::Integer(s), Self::Integer(o)) => Ok(Self::Integer(*s * *o)), 114 (Self::Integer(s), Self::Integer(o)) => Ok(Self::Integer(*s * *o)),
115 (Self::Integer(s), Self::String(o)) => Ok(Self::String(o.repeat(*s as usize))),
116 (Self::String(_), Self::Integer(_)) => other.mul(self),
115 _ => Err(Error::UndefinedBinOp( 117 _ => Err(Error::UndefinedBinOp(
116 ast::BinOp::Arith(ast::ArithOp::Mul), 118 ast::BinOp::Arith(ast::ArithOp::Mul),
117 self.ty(), 119 self.ty(),
@@ -656,13 +658,13 @@ impl<'a> Context<'a> {
656 658
657pub fn evaluate(file: &str, program: &str, language: tree_sitter::Language) -> Result { 659pub fn evaluate(file: &str, program: &str, language: tree_sitter::Language) -> Result {
658 let mut parser = tree_sitter::Parser::new(); 660 let mut parser = tree_sitter::Parser::new();
659 let _ = parser.set_language(language); 661 let _ = parser.set_language(&language);
660 662
661 let tree = parser.parse(file, None).unwrap(); 663 let tree = parser.parse(file, None).unwrap();
662 let cursor = tree.walk(); 664 let cursor = tree.walk();
663 665
664 let program = ast::Program::new().from_str(program).unwrap(); 666 let program = ast::Program::new().from_str(program).unwrap();
665 let mut ctx = Context::new(tree_sitter_md::language()) 667 let mut ctx = Context::new(language)
666 .with_input(file.to_owned()) 668 .with_input(file.to_owned())
667 .with_cursor(cursor) 669 .with_cursor(cursor)
668 .with_program(program)?; 670 .with_program(program)?;