C/C++ conditional statement

Issue #1478 new
Artem Shinkarov
created an issue

In the following C/C++ program:

int main() {
    return x?y:z;

y is still incorrectly identified as label. I have:

<span class="n">x</span><span class="o">?</span><span class="nl">y</span><span class="p">:</span><span class="n">z</span>

I am using Pygments version 2.2.0, (c) 2006-2017 by Georg Brandl..

The issue 436 is marked as resolved, but if I look at the code, I cannot wrap my head around why this should be the case.
The existing rule for Label is this:

(r'([a-zA-Z_]\w*)(\s*)(:)(?!:)', bygroups(Name.Label, Text, Punctuation))

So all it says is that ID :<whatever> is good, but ID :: is not. However, this doesn't solve the original problem --- in x?y:z y is still parsed as label. I guess the right solution would be to enter a different state after we have seen ? and within that state ignore the label rule. As in C/C++ the e1 ? e2 : e3 is an expression, therefore it cannot contain labels.

Comments (0)

  1. Log in to comment