Pull requests

#141 Merged
Deleted repository
default (cbaef3a78a4a)
birkenfeld/pygments-main pygments-main

Improve and unify C family language lexers

  1. Alastair Houghton

This change removes a lot of repetitious code from compiled.py, fixes the problem of inconsistent highlighting between C, C++ and Objective-C lexers on the same (C compatible) piece of code, and allows the straightforward implementation of Objective-C++ support, which is included.

It also fixes the long-standing problem of Objective-C not being recognised in .h files, which are now autodetected as Objective-C on the basis of some of the ObjC keywords.

  • Learn about pull requests

Comments (4)

  1. Tim Hatch

    I don't have an objection to the inherit functionality, I think that's great and we've needed it for some time. I'd like to wait for Georg's sign-off on it however.

    You may need to look at analyse_text more closely -- for some uses, it's called even for files that don't match .h, and 0.5 is probably too high. Also I think the comment for the two analyse_text was copy-pasted.

    Overall +1 from me (with minor changes).

  2. Alastair Houghton author

    I've made the adjustments you suggested and updated the pull request. As far as analyse_text() goes, I’m not quite sure what the problem is that you’re referring to, but I changed the value returned by the C/C++ lexers to 0.1 (it just has to be higher than the value returned when the Objective-C analyse_text() method fails to find any Objective-C specific constructs). I also adjusted the priority values, since priority is treated similarly to the return value of analyse_text() in lexers/__init__.py.

    Worth mentioning too that I set the priority values so that .h and .hh will always pick C/C++ rather than the Objective-C variants if there is no code to analyse. That's deliberate — if it defaulted to Objective-C/C++, while it would always highlight correctly with those lexers (since they are a strict superset of C/C++), it might confuse software that was trying to use Pygments to detect file types but that didn't support Objective-C/C++.