Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Objective-C vs Mathematica lexer disambiguation #2103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/rouge/guessers/disambiguation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ def match?(filename)
disambiguate '*.m' do
next ObjectiveC if matches?(/@(end|implementation|protocol|property)\b/)
next ObjectiveC if contains?('@"')

next Mathematica if contains?('(*')
# Opening brace at end of line
next ObjectiveC if matches?(/\s*{\s*$/)
EthanArbuckle marked this conversation as resolved.
Show resolved Hide resolved

# Objective-C may use dereferenced pointers in statements: `if (*foo == 0)`.
# This is similar to Mathmatica's comment syntax: `(* comment *)`.
# Disambiguate by checking for any amount of whitespace (or no whitespace) followed by (*
next Mathematica if matches?(/^\s*\(\*/)
next Mathematica if contains?(':=')

next Mason if matches?(/<%(def|method|text|doc|args|flags|attr|init|once|shared|perl|cleanup|filter)([^>]*)(>)/)
Expand Down
1 change: 1 addition & 0 deletions spec/lexers/objective_c_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
it 'guesses by source' do
assert_guess :filename => 'foo.h', :source => '@"foo"'
assert_guess :filename => 'foo.h', :source => '@implementation Foo'
assert_guess :filename => 'foo.m', :source => 'if (*bar == 0) {'
end
end
end