Skip to content

Commit

Permalink
Fixes rouge-ruby#1009, fixes rouge-ruby#879 issues w/C and C++ highli…
Browse files Browse the repository at this point in the history
…ghting

1. void foo(); without space before ";" does not highlight correctly.
2. else if() in certain contexts highlights incorrectly.
3. any error in a function definition or declaration has the potential
 to cause incorrect highlighting further down in the file.

Contains minor changes to Objc-C lexer to fix dependencies on the
C lexer that were broken by the C lexer fix.
  • Loading branch information
vidarh committed Jan 18, 2019
1 parent e957c74 commit 79d1efe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 39 deletions.
35 changes: 6 additions & 29 deletions lib/rouge/lexers/c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def self.builtins
rule /\d+[lu]*/i, Num::Integer
rule %r(\*/), Error
rule %r([~!%^&*+=\|?:<>/-]), Operator
rule /[()\[\],.]/, Punctuation
rule /[()\[\],.;]/, Punctuation
rule /\bcase\b/, Keyword, :case
rule /(?:true|false|NULL)\b/, Name::Builtin
rule id do |m|
Expand All @@ -133,47 +133,24 @@ def self.builtins

state :root do
mixin :expr_whitespace

# functions
rule %r(
([\w*\s]+?[\s*]) # return arguments
(#{id}) # function name
(\s*\([^;]*?\)) # signature
(#{ws})({) # open brace
(#{ws}?)({|;) # open brace or semicolon
)mx do |m|
# TODO: do this better.
recurse m[1]
token Name::Function, m[2]
recurse m[3]
recurse m[4]
token Punctuation, m[5]
push :function
end

# function declarations
rule %r(
([\w*\s]+?[\s*]) # return arguments
(#{id}) # function name
(\s*\([^;]*?\)) # signature
(#{ws})(;) # semicolon
)mx do |m|
# TODO: do this better.
recurse m[1]
token Name::Function, m[2]
recurse m[3]
recurse m[4]
token Punctuation, m[5]
push :statement
if m[5] == ?{
push :function
end
end

rule(//) { push :statement }
end

state :statement do
rule /;/, Punctuation, :pop!
mixin :expr_whitespace
rule /\{/, Punctuation, :function
mixin :statements
rule /[{}]/, Punctuation
end

state :function do
Expand Down
13 changes: 3 additions & 10 deletions lib/rouge/lexers/objective_c.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,8 @@ def self.builtins
rule /@\d+l?/, Num::Integer
rule /\bin\b/, Keyword

rule /@(?:interface|implementation)\b/ do
token Keyword
goto :classname
end

rule /@(?:class|protocol)\b/ do
token Keyword
goto :forward_classname
end
rule /@(?:interface|implementation)\b/, Keyword, :classname
rule /@(?:class|protocol)\b/, Keyword, :forward_classname

rule /@([[:alnum:]]+)/ do |m|
if self.class.at_keywords.include? m[1]
Expand Down Expand Up @@ -80,7 +73,7 @@ def self.builtins
rule /\{/, Punctuation, :pop!
rule /;/, Error

mixin :statement
mixin :statements
end

state :message do
Expand Down

0 comments on commit 79d1efe

Please sign in to comment.