lib/rouge/lexers/shell.rb in rouge-0.0.13 vs lib/rouge/lexers/shell.rb in rouge-0.0.14

- old
+ new

@@ -40,30 +40,44 @@ rule /[\[\]{}()=]/, 'Operator' rule /&&|\|\|/, 'Operator' # rule /\|\|/, 'Operator' rule /<<</, 'Operator' # here-string - rule /<<-?\s*(\'?)\\?(\w+)[\w\W]+?\2/, 'Literal.String' + rule /<<-?\s*(\'?)\\?(\w+)\1/ do |m| + lsh = 'Literal.String.Heredoc' + token lsh + heredocstr = Regexp.escape(m[2]) + + push do + rule /\s*#{heredocstr}\s*\n/, lsh, :pop! + rule /.*?\n/, lsh + end + end end state :double_quotes do # NB: "abc$" is literally the string abc$. # Here we prevent :interp from interpreting $" as a variable. rule /(?:\$#?)?"/, 'Literal.String.Double', :pop! mixin :interp rule /[^"`\\$]+/, 'Literal.String.Double' end + state :single_quotes do + rule /'/, 'Literal.String.Single', :pop! + rule /[^']+/, 'Literal.String.Single' + end + state :data do rule /\\./, 'Literal.String.Escape' rule /\$?"/, 'Literal.String.Double', :double_quotes # single quotes are much easier than double quotes - we can # literally just scan until the next single quote. # POSIX: Enclosing characters in single-quotes ( '' ) # shall preserve the literal value of each character within the # single-quotes. A single-quote cannot occur within single-quotes. - rule /$?'[^']*'/, 'Literal.String.Single' + rule /$?'/, 'Literal.String.Single', :single_quotes rule /\*/, 'Keyword' rule /;/, 'Text' rule /\s+/, 'Text'