From 5f67aa72d52962e07d8e90fe79a448d22d2747bd Mon Sep 17 00:00:00 2001 From: John Doty Date: Wed, 7 Feb 2024 06:11:25 -0800 Subject: [PATCH] [fine] Remember to use this function --- fine/src/compiler.rs | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/fine/src/compiler.rs b/fine/src/compiler.rs index d0375b02..a98f411e 100644 --- a/fine/src/compiler.rs +++ b/fine/src/compiler.rs @@ -3,7 +3,7 @@ use std::rc::Rc; use crate::{ parser::{Child, SyntaxTree, Tree, TreeKind, TreeRef}, - semantics::{Declaration, Environment, Location, Semantics, Type}, + semantics::{string_constant_to_string, Declaration, Environment, Location, Semantics, Type}, tokens::TokenKind, }; @@ -330,24 +330,7 @@ fn compile_literal(c: &mut Compiler, t: TreeRef, tr: &Tree) -> CR { Instruction::PushFalse }), Type::String => { - let mut result = String::new(); - let mut input = tok.as_str().chars(); - while let Some(ch) = input.next() { - if ch == '\\' { - if let Some(ch) = input.next() { - match ch { - 'n' => result.push('\n'), - 'r' => result.push('\r'), - 't' => result.push('\t'), - _ => result.push(ch), - } - } else { - result.push(ch) - } - } else { - result.push(ch) - } - } + let result = string_constant_to_string(tok.as_str()); let index = c.add_string(result); c.push(Instruction::PushString(index)) }