Giter Site home page Giter Site logo

Comments (6)

isagalaev avatar isagalaev commented on May 19, 2024

I think I fixed it. Can you check your code with the latest master revision?

from highlight.js.

KamilaBorowska avatar KamilaBorowska commented on May 19, 2024

Confirmed. Broken. This change any broken non-obvious regexpes, like following:

split //, 'abc';

It was working previously. I'm aware that Perl is extremally context-sensitive language, but now it's second extreme. I don't think that parsing this without extreme ammount of work is possible, but what about checking spaces around / character (usually you would put space before regexp, but not inside it :P).

from highlight.js.

isagalaev avatar isagalaev commented on May 19, 2024

It's not that extremely complex, it's a matter of carefully defining after which lexems a regexp is allowed. Right now I put only a pretty general set of symbols but as your example showed we need to add some keywords too, as javascript does. For Perl, I presume, those will be at least split and return. Can you tell after which other keywords one may expect a regexp?

from highlight.js.

KamilaBorowska avatar KamilaBorowska commented on May 19, 2024

Anything with non-empty prototype, except that in this case it would be considered as boolean value of match at $_ (for example, print /abc/ is actually print($_ =~ /abc/).

But more seriously, I would also add grep to this list, as grepping by regexp sort of makes sense... But if you would want completeness, things like my @matches = reverse /\w+/g also make sense in Perl (list of all words in $_ in reverse order)... yeah... I'm aware it can be annoying... Perl is very ambiguous... and if you will include subroutine prototypes...

It's nearly impossible to highlight Perl correctly. The syntax highlighter used by Github (Pygments) is pretty nice, but totally fails at $a / $b / $c (but it fails at lot more, like s < > { } (but it's not code you should write), oh wait... your tool also fails at it... but I think it's topic for separate issue, in fact, I've checked code like this in your highlighter just to find this issue).

Also, I have noticed that this change also broken regexes after statement modifiers (all statement modifiers should be allowed) and other literal keywords like or. This also should be fixed.

Also: Just a small note, I think you forgot typeof in that list in JavaScript.

from highlight.js.

isagalaev avatar isagalaev commented on May 19, 2024

Since highlighter is not a full-blown translator, it allows more freedom in handling syntax. The point to which it really makes sense to try is, basically, highlighting that doesn't break in a spectacular way. For example, if you mistake division for a regexp you have the whole rest of the line highlighted wrong, and it's ugly. But failing to highlight the regexp in some rare case is OK. So I'd be happy with just putting all those keywords you mentioned in a regexp context starter. Or you have better ideas (I saw you forked the repository)?

totally fails at $a / $b / $c (but it fails at lot more, like s < > { } (but it's not code you should write), oh wait... your tool also fails at it...

Can you be more specific? It's better to file a new issue on that.

BTW we have a discussion group, there are more people than here :-).

from highlight.js.

isagalaev avatar isagalaev commented on May 19, 2024

Added the keywords you mentioned. I'm going to close the issue for now, we can fix any remaining cases as they appear in the wild. Thanks!

from highlight.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.