lib/rouge/lexers/shell.rb in rouge-2.0.7 vs lib/rouge/lexers/shell.rb in rouge-2.1.0

- old
+ new

@@ -27,42 +27,61 @@ complete declare dirs disown echo enable eval exec exit export false fc fg getopts hash help history jobs kill let local logout popd printf pushd pwd read readonly set shift shopt source suspend test time times trap true type typeset ulimit umask unalias unset wait + + ls tar cat grep sudo ).join('|') state :basic do rule /#.*$/, Comment rule /\b(#{KEYWORDS})\s*\b/, Keyword rule /\bcase\b/, Keyword, :case - rule /\b(#{BUILTINS})\s*\b(?!\.)/, Name::Builtin + rule /\b(#{BUILTINS})\s*\b(?!(\.|-))/, Name::Builtin + rule /[.](?=\s)/, Name::Builtin - rule /^\S*[\$%>#] +/, Generic::Prompt - rule /(\b\w+)(=)/ do |m| groups Name::Variable, Operator end - rule /[\[\]{}()=]/, Operator + rule /[\[\]{}()!=>]/, Operator rule /&&|\|\|/, Operator - rule /<<</, Operator # here-string - rule /<<-?\s*(\'?)\\?(\w+)\1/ do |m| - lsh = Str::Heredoc - token lsh - heredocstr = Regexp.escape(m[2]) + # here-string + rule /<<</, Operator - push do - rule /\s*#{heredocstr}\s*\n/, lsh, :pop! - rule /.*?\n/, lsh + rule /(<<-?)(\s*)(\'?)(\\?)(\w+)(\3)/ do |m| + groups Operator, Text, Str::Heredoc, Str::Heredoc, Name::Constant, Str::Heredoc + @heredocstr = Regexp.escape(m[5]) + push :heredoc + end + end + + state :heredoc do + rule /\n/, Str::Heredoc, :heredoc_nl + rule /[^$\n]+/, Str::Heredoc + mixin :interp + rule /[$]/, Str::Heredoc + end + + state :heredoc_nl do + rule /\s*(\w+)\s*\n/ do |m| + if m[1] == @heredocstr + token Name::Constant + pop! 2 + else + token Str::Heredoc end end + + rule(//) { pop! } end + state :double_quotes do # NB: "abc$" is literally the string abc$. # Here we prevent :interp from interpreting $" as a variable. rule /(?:\$#?)?"/, Str::Double, :pop! mixin :interp @@ -93,12 +112,14 @@ # single-quotes. A single-quote cannot occur within single-quotes. rule /'/, Str::Single, :single_quotes rule /\*/, Keyword - rule /;/, Text - rule /[^=\*\s{}()$"'`\\<]+/, Text + rule /;/, Punctuation + + rule /--?[\w-]+/, Name::Tag + rule /[^=\*\s{}()$"'`;\\<]+/, Text rule /\d+(?= |\Z)/, Num rule /</, Text mixin :interp end @@ -115,12 +136,12 @@ mixin :root end state :math do rule /\)\)/, Keyword, :pop! - rule %r([-+*/%^|&]|\*\*|\|\|), Operator - rule /\d+/, Num + rule %r([-+*/%^|&!]|\*\*|\|\|), Operator + rule /\d+(#\w+)?/, Num mixin :root end state :case do rule /\besac\b/, Keyword, :pop! @@ -145,9 +166,10 @@ rule /\$\(\(/, Keyword, :math rule /\$\(/, Keyword, :paren rule /\${#?/, Keyword, :curly rule /`/, Str::Backtick, :backticks rule /\$#?(\w+|.)/, Name::Variable + rule /\$[*@]/, Name::Variable end state :root do mixin :basic mixin :data