lib/code/parser/string.rb in template-ruby-0.2.4 vs lib/code/parser/string.rb in template-ruby-0.3.0

- old
+ new

@@ -1,15 +1,18 @@ class Code class Parser class String < Parslet::Parser rule(:number) { ::Code::Parser::Number.new } rule(:name) { ::Code::Parser::Name.new.name } + rule(:code) { ::Code::Parser::Code.new } rule(:single_quote) { str("'") } rule(:double_quote) { str('"') } rule(:backslash) { str("\\") } rule(:colon) { str(":") } + rule(:opening_curly_bracket) { str("{") } + rule(:closing_curly_bracket) { str("}") } rule(:zero) { str("0") } rule(:one) { str("1") } rule(:two) { str("2") } rule(:three) { str("3") } @@ -29,10 +32,14 @@ rule(:n) { str("n") | str("N") } rule(:r) { str("r") | str("R") } rule(:t) { str("t") | str("T") } rule(:u) { str("u") | str("U") } + rule(:interpolation) do + opening_curly_bracket >> code >> closing_curly_bracket + end + rule(:base_16_digit) do zero | one | two | three | four | five | six | seven | eight | nine | a | b | c | d | e | f end @@ -40,23 +47,31 @@ (backslash >> u >> base_16_digit.repeat(4, 4)) | (backslash >> (b | f | n | r | t)) | (backslash.ignore >> any) end rule(:single_quoted_character) do - escaped_character | (single_quote.absent? >> any) + escaped_character | (opening_curly_bracket.absent? >> single_quote.absent? >> any) end rule(:double_quoted_character) do - escaped_character | (double_quote.absent? >> any) + escaped_character | (opening_curly_bracket.absent? >> double_quote.absent? >> any) end rule(:single_quoted_string) do - single_quote.ignore >> single_quoted_character.repeat >> + single_quote.ignore >> + ( + interpolation.as(:interpolation) | + single_quoted_character.repeat(1).as(:characters) + ).repeat >> single_quote.ignore end rule(:double_quoted_string) do - double_quote.ignore >> double_quoted_character.repeat >> + double_quote.ignore >> + ( + interpolation.as(:interpolation) | + double_quoted_character.repeat(1).as(:characters) + ).repeat >> double_quote.ignore end rule(:symbol) { colon.ignore >> name }