diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-26 00:37:59 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-04-26 00:39:28 +0200 |
commit | a4470a2e26fc4cf43e9af80d741c68c58383f3c6 (patch) | |
tree | 0f130dd5e1e70e98693c1890b89b075e17c30625 /crates/rebel-parse | |
parent | 175c790cc730c01283c1aa0cf65cfce8c7152d4b (diff) | |
download | rebel-a4470a2e26fc4cf43e9af80d741c68c58383f3c6.tar rebel-a4470a2e26fc4cf43e9af80d741c68c58383f3c6.zip |
rebel-parse: ast: store string kind again
We need the kind after all, as different string kinds will need
different escaping for interpolation.
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r-- | crates/rebel-parse/src/ast.rs | 7 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 9 |
2 files changed, 12 insertions, 4 deletions
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<StringPiece<'a>>), + String { + pieces: Vec<StringPiece<'a>>, + kind: StringKind, + }, Tuple(Vec<Expr<'a>>), Array(Vec<Expr<'a>>), Map(Vec<MapEntry<'a>>), 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::<Result<_, _>>()?; - Ok(ast::Literal::String(ast_pieces)) + / [Token::String(String { pieces, kind })] { ? + let pieces = pieces + .iter() + .map(|piece| piece.try_into()) + .collect::<Result<_, _>>()?; + Ok(ast::Literal::String{ pieces, kind: *kind }) } / p('(') p(')') { ast::Literal::Unit } / p('(') elements:(expr() ** p(',')) p(',')? p(')') { |