Issue #878 resolved

Obj-C Preprocessor Directives Flagged "err" with Gobbled Whitespace

Daniel Shannon
created an issue

Hi there, First of all, thank you for your incredible work on Pygments. It's really a thing of beauty. I noticed, however, that valid preprocessor directives are flagged as errors if they're preceded by gobbled whitespace. For example, running the following through the Objective-C lexer:

    #import <Foundation/Foundation.h>
    #import "MyFancyClass.h"

    int main(int argc, char *argv[])
    {

…with the command pygmentize -l objectivec -f html -F gobble:n=4 -o pyggy.html pyggy.txt produces the following HTML:

<div class="highlight"><pre><span class="err">#</span><span class="n">import</span> <span class="o">&lt;</span><span class="n">Foundation</span><span class="o">/</span><span class="n">Foundation</span><span class="p">.</span><span class="n">h</span><span class="o">&gt;</span>
<span class="err">#</span><span class="n">import</span> <span class="s">&quot;MyFancyClass.h&quot;</span>

<span class="kt">int</span> <span class="n">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
</pre></div>

It's all kosher—the spaces are gobbled and the formatting is lovely as expected—except that the preprocessor directive is flagged.

I'm using Python v3.3 and Pygments v1.6dev-20130607, if that helps. Happy to provide any more information if it'd be useful. Thanks for taking a look!

Comments (2)

  1. Georg Brandl repo owner

    This is an unfortunate combination because filters are applied after lexing.

    However, preprocessor directives were never meant to be anchored at the line start, so the fix for that should have fixed your problem here.

  2. Log in to comment