From a4470a2e26fc4cf43e9af80d741c68c58383f3c6 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 26 Apr 2024 00:37:59 +0200 Subject: rebel-parse: ast: store string kind again We need the kind after all, as different string kinds will need different escaping for interpolation. --- crates/rebel-parse/src/ast.rs | 7 ++++++- crates/rebel-parse/src/grammar/recipe.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/rebel-parse/src/ast.rs b/crates/rebel-parse/src/ast.rs index 648a79e..389523e 100644 --- a/crates/rebel-parse/src/ast.rs +++ b/crates/rebel-parse/src/ast.rs @@ -132,12 +132,17 @@ pub struct FuncParam<'a> { pub typ: Expr<'a>, } +pub use token::StringKind; + #[derive(Debug, Clone, PartialEq, Eq)] pub enum Literal<'a> { Unit, Boolean(bool), Integer(u64), - String(Vec>), + String { + pieces: Vec>, + kind: StringKind, + }, Tuple(Vec>), Array(Vec>), Map(Vec>), diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 49b1689..9b79d41 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -97,9 +97,12 @@ peg::parser! { / [Token::Number(content)] { ? ast::Literal::number(content) } - / [Token::String(String { pieces, .. })] { ? - let ast_pieces = pieces.iter().map(|piece| piece.try_into()).collect::>()?; - Ok(ast::Literal::String(ast_pieces)) + / [Token::String(String { pieces, kind })] { ? + let pieces = pieces + .iter() + .map(|piece| piece.try_into()) + .collect::>()?; + Ok(ast::Literal::String{ pieces, kind: *kind }) } / p('(') p(')') { ast::Literal::Unit } / p('(') elements:(expr() ** p(',')) p(',')? p(')') { -- cgit v1.2.3