Skip to content

Commit

Permalink
Improve Literal string regex
Browse files Browse the repository at this point in the history
  • Loading branch information
morenol committed May 30, 2020
1 parent e871df6 commit ebddfe6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum Token<'a> {
IntegerNum(i64),
#[regex("[0-9]+\\.[0-9]+", |lex| lex.slice().parse())]
FloatNum(f64),
#[regex("\"[A-Za-z0-9 ]*\"", |lex| Cow::Borrowed(&lex.slice()[1..lex.slice().len()-1]))]
#[regex(r#""(?:[^"]|\\")*""#, |lex| Cow::Borrowed(&lex.slice()[1..lex.slice().len()-1]))]
String(Cow<'a, str>),

// Operators
Expand Down
1 change: 1 addition & 0 deletions tests/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn basic_math_expression() -> Result<()> {

#[test]
fn basic_string_expression() -> Result<()> {
assert_render_template_eq("{{ \"hello, world!\" }}", "hello, world!")?;
assert_render_template_eq("{{ \"123\" * 3 }}", "123123123")?;
assert_render_template_eq("{{ \"abc\" * 0 }}", "")?;
assert_render_template_eq("{{ \"hello\" + \" \" + \"world\"}}", "hello world")?;
Expand Down

0 comments on commit ebddfe6

Please sign in to comment.