1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #696 resolved

Objective-C file incorrectly identified as Matlab file

Louis Feng
created an issue

There's a bug posted for bitbucket that depends on Pygments: https://bitbucket.org/site/master/issue/1532/code-highlighting-for-objective-c-m-files#comment-630115

If you look at the actual code for ObjectiveCLexer https://bitbucket.org/birkenfeld/pygments-main/src/28711fa3f32f/pygments/lexers/compiled.py

{{{

!python

def analyse_text(text): if '@"' in text: # strings return True if re.match(r'[[a-zA-Z0-9.]:', text): # message return True return False }}} It's simply inadequate to analyse Objective-C files correctly. If anything it should try to detect keywords like Osman Ungur, Interface, and Implementation. Another issue is in the MatlabLexer, where by default analyse_text returns 0.1 https://bitbucket.org/birkenfeld/pygments-main/src/28711fa3f32f/pygments/lexers/math.py

{{{

!python

def analyse_text(text): if re.match('^\s*%', text, re.M): # comment return 0.9 elif re.match('^!\w+', text, re.M): # system cmd return 0.9 return 0.1 }}} So when these two competes, MablabLexer simply wins by default.

Comments (2)

  1. Louis Feng reporter

    See attached example objective-c code and the results from Pygments 1.4 output.

    > python hightlight_code.py 
    <pygments.lexers.PerlLexer>
    <pygments.lexers.MatlabLexer>
    <pygments.lexers.ObjectiveCLexer>
    objc 0.0
    matlab 0.1
    
  2. Log in to comment