PrismJS / prism

Lightweight, robust, elegant syntax highlighting.
https://prismjs.com
MIT License
12.3k stars 1.3k forks source link

Prism C++ incorrectly colors overloaded operator< and operator> in sequence #3686

Open AlexLearnCpp opened 1 year ago

AlexLearnCpp commented 1 year ago

Repro steps:

bool operator< (const Foo& f1, const Foo& f2)
{
    return f1.foo < f2.foo;
}

bool operator> (const Foo& f1, const Foo& f2)
{
    return f1.foo > f2.foo;
}

Note that foo < f2.foo from the top function and the > in operator> in the bottom function are the wrong color.

AlexLearnCpp commented 1 year ago

Issue still outstanding

LeaVerou commented 12 months ago

Hi there, this is what I see:

image

I see the issue with foo < f2.foo, but operator> in the second function seems fine?

AlexLearnCpp commented 11 months ago

Agreed. It appears this has been partially fixed since it was originally filed. Thanks for reviewing.

ferdnyc commented 3 months ago

@AlexLearnCpp

It appears this has been partially fixed since it was originally filed.

Actually, I don't think it has. If anything, it's even more broken, despite the results appearing better.

If you turn on "Show tokens", you can see that the only reason the body of operator> highlights "correctly" is that Prism is matching the > in operator> with the < from the previous function, instead of recognizing it as a new function declaration!

image

(It's that three-level nested boxiness around everything from the foo in f1.foo to the end of operator> that's the troubling part.)

LeaVerou commented 3 months ago

It's neither fixed nor more broken folks — Prism was feature frozen before this bug was filed so we could work on v2 and the maintainer who was leading that effort got swamped with other things. My plan is currently to take over work on v2 this fall.