lib/rouge/lexers/make.rb in rouge-3.30.0 vs lib/rouge/lexers/make.rb in rouge-4.0.0

- old
+ new

@@ -18,15 +18,10 @@ notdir or origin patsubst realpath shell sort strip subst suffix value warning wildcard word wordlist words ) end - # TODO: Add support for special keywords - # bsd_special = %w( - # include undef error warning if else elif endif for endfor - # ) - def initialize(opts={}) super @shell = Shell.new(opts) end @@ -39,41 +34,48 @@ rule %r/([-s]?include)((?:[\t ]+[^\t\n #]+)+)/ do groups Keyword, Literal::String::Other end - rule %r/(ifn?def|ifn?eq)([\t ]+)([^#\n]+)/ do + rule %r/((?:ifn?def|ifn?eq|unexport)\b)([\t ]+)([^#\n]+)/ do groups Keyword, Text, Name::Variable end - rule %r/(?:else|endif)[\t ]*(?=[#\n])/, Keyword + rule %r/(?:else|endif|endef|endfor)[\t ]*(?=[#\n])/, Keyword rule %r/(export)([\t ]+)(?=[\w\${}()\t -]+\n)/ do groups Keyword, Text push :export end rule %r/export[\t ]+/, Keyword # assignment - rule %r/([\w${}().-]+)([\t ]*)([!?:+]?=)/m do |m| - token Name::Variable, m[1] - token Text, m[2] - token Operator, m[3] + rule %r/(override\b)*([\t ]*)([\w${}().-]+)([\t ]*)([!?:+]?=)/m do |m| + groups Name::Builtin, Text, Name::Variable, Text, Operator push :shell_line end rule %r/"(\\\\|\\.|[^"\\])*"/, Str::Double rule %r/'(\\\\|\\.|[^'\\])*'/, Str::Single rule %r/([^\n:]+)(:+)([ \t]*)/ do groups Name::Label, Operator, Text push :block_header end + + rule %r/(override\b)*([\t ])*(define)([\t ]+)([^#\n]+)/ do + groups Name::Builtin, Text, Keyword, Text, Name::Variable + end + + rule %r/(\$[({])([\t ]*)(#{Make.functions.join('|')})([\t ]+)/m do + groups Name::Function, Text, Name::Builtin, Text + push :shell_expr + end end state :export do - rule %r/[\w\${}()-]/, Name::Variable + rule %r/[\w[\$]{1,2}{}()-]/, Name::Variable rule %r/\n/, Text, :pop! rule %r/[\t ]+/, Text end state :block_header do @@ -105,25 +107,32 @@ rule(//) { @shell.reset!; pop! } end state :shell do # macro interpolation - rule %r/\$[({][\t ]*\w[\w:=%.]*[\t ]*[)}]/i, Name::Variable + rule %r/[\$]{1,2}[({]/, Punctuation, :macro_expr + # function invocation rule %r/(\$[({])([\t ]*)(#{Make.functions.join('|')})([\t ]+)/m do - groups Name::Function, Text, Name::Builtin, Text + groups Punctuation, Text, Name::Builtin, Text push :shell_expr end rule(/\\./m) { delegate @shell } - stop = /\$\(|\$\{|\(|\)|\}|\\|$/ + stop = /[\$]{1,2}\(|[\$]{1,2}\{|\(|\)|\}|\\|$/ rule(/.+?(?=#{stop})/m) { delegate @shell } rule(stop) { delegate @shell } end + state :macro_expr do + rule %r/[)}]/, Punctuation, :pop! + rule %r/\n/, Text, :pop! + mixin :shell + end + state :shell_expr do rule(/[({]/) { delegate @shell; push } - rule %r/[)}]/, Name::Function, :pop! + rule %r/[)}]/, Punctuation, :pop! mixin :shell end state :shell_line do rule %r/\n/, Text, :pop!