diff --git a/src/parser/grammar.lalrpop b/src/parser/grammar.lalrpop index 2e48d557be..2f578b7ada 100644 --- a/src/parser/grammar.lalrpop +++ b/src/parser/grammar.lalrpop @@ -518,8 +518,9 @@ StrChunks: RichTerm = { }).collect(); RichTerm::from(build_record([ + (FieldPathElem::Ident("tag".into()), RichTerm::from(Term::Enum("SymbolicString".into()))), (FieldPathElem::Ident("prefix".into()), RichTerm::from(Term::Str(prefix.to_owned()))), - (FieldPathElem::Ident("chunks".into()), RichTerm::from(Term::Array(terms, Default::default()))) + (FieldPathElem::Ident("fragments".into()), RichTerm::from(Term::Array(terms, Default::default()))) ], Default::default())) } else { let mut chunks = chunks; @@ -914,7 +915,7 @@ extern { "\"%" => Token::MultiStr(MultiStringToken::End), "m%\"" => Token::Normal(NormalToken::MultiStringStart()), "symbolic string start" => Token::Normal(NormalToken::SymbolicStringStart( - SymbolicStringStart{prefix: <&'input str>, percent_count: })), + SymbolicStringStart{prefix: <&'input str>, length: })), "Num" => Token::Normal(NormalToken::Num), "Dyn" => Token::Normal(NormalToken::Dyn), diff --git a/src/parser/lexer.rs b/src/parser/lexer.rs index e962a0cf8c..f41dd69f6b 100644 --- a/src/parser/lexer.rs +++ b/src/parser/lexer.rs @@ -42,7 +42,7 @@ fn symbolic_string_prefix_and_length<'input>( .expect("The logos regexp ensures this succeeds"); SymbolicStringStart { prefix, - percent_count: postfix.len(), + length: postfix.len(), } } @@ -342,7 +342,7 @@ pub const KEYWORDS: &[&str] = &[ #[derive(Debug, Clone, PartialEq)] pub struct SymbolicStringStart<'input> { pub prefix: &'input str, - pub percent_count: usize, + pub length: usize, } /// The tokens in string mode. @@ -630,8 +630,7 @@ impl<'input> Iterator for Lexer<'input> { Some(Normal( NormalToken::MultiStringStart(delim_size) | NormalToken::SymbolicStringStart(SymbolicStringStart { - percent_count: delim_size, - .. + length: delim_size, .. }), )) => { // for interpolation & closing delimeters we only care about diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 194b6e52bc..9b3d6e378f 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use super::lexer::{Lexer, MultiStringToken, NormalToken, StringToken, Token}; +use super::lexer::{Lexer, MultiStringToken, NormalToken, StringToken, SymbolicStringStart, Token}; use super::utils::{build_record, FieldPathElem}; use crate::error::ParseError; use crate::identifier::Ident; @@ -41,12 +41,16 @@ fn mk_single_chunk(s: &str) -> RichTerm { fn mk_symbolic_single_chunk(prefix: &str, s: &str) -> RichTerm { build_record( [ + ( + FieldPathElem::Ident("tag".into()), + RichTerm::from(Term::Enum("SymbolicString".into())), + ), ( FieldPathElem::Ident("prefix".into()), RichTerm::from(Term::Str(prefix.to_owned())), ), ( - FieldPathElem::Ident("chunks".into()), + FieldPathElem::Ident("fragments".into()), RichTerm::from(Array( Array::new(Rc::new([Str(String::from(s)).into()])), Default::default(), @@ -388,7 +392,10 @@ fn string_lexing() { "empty symbolic string lexes like multi-line str", r#"foo-s%""%"#, vec![ - Token::Normal(NormalToken::SymbolicStringStart(("foo", 3))), + Token::Normal(NormalToken::SymbolicStringStart(SymbolicStringStart { + prefix: "foo", + length: 3, + })), Token::MultiStr(MultiStringToken::End), ], ), @@ -396,7 +403,10 @@ fn string_lexing() { "symbolic string with interpolation", r#"foo-s%"text %{ 1 } etc."%"#, vec![ - Token::Normal(NormalToken::SymbolicStringStart(("foo", 3))), + Token::Normal(NormalToken::SymbolicStringStart(SymbolicStringStart { + prefix: "foo", + length: 3, + })), Token::MultiStr(MultiStringToken::Literal("text ")), Token::MultiStr(MultiStringToken::Interpolation), Token::Normal(NormalToken::NumLiteral(1.0)), @@ -409,7 +419,10 @@ fn string_lexing() { "empty symbolic string with tag", r#"tf-s%""%"#, vec![ - Token::Normal(NormalToken::SymbolicStringStart(("tf", 3))), + Token::Normal(NormalToken::SymbolicStringStart(SymbolicStringStart { + prefix: "tf", + length: 3, + })), Token::MultiStr(MultiStringToken::End), ], ), diff --git a/tests/integration/pass/symbolic-strings.ncl b/tests/integration/pass/symbolic-strings.ncl index daa520e903..4895789ecc 100644 --- a/tests/integration/pass/symbolic-strings.ncl +++ b/tests/integration/pass/symbolic-strings.ncl @@ -1,5 +1,5 @@ let {check, ..} = import "lib/assert.ncl" in -let sym = fun prefix_ chunks_ => { prefix = prefix_, chunks = chunks_ } in +let sym = fun prefix_ fragments_ => { tag = `SymbolicString, prefix = prefix_, fragments = fragments_ } in [ # Static symbolic string foo-s%"hello, world"% == sym "foo" ["hello, world"] ,