Coder Social home page Coder Social logo

Comments (4)

kyx0r avatar kyx0r commented on July 22, 2024

Hi,

The syntax highlighting pattern for standard Python strings fails with embedded escaped quotes.

Yeah, that's probably because nobody ever bothered to make them better :D
For instance c quotes pattern is exceptionally robust. I rarely deal with python in my work
so it had less of my attention.

P. S. I am trying to understand how the highlight structure's end and blkend work. Please give me some hints.

I am in the processes of making changes with some ideas gained over the year, so readme is a bit out of date. It will be updated once I feel like I've exhausted my ideas.

The way end works, its a 16 byte array of chars, each char can take 3 states: -1, 0, 1. It determines where the result of a pattern match continues. 16 corresponds to 16 groups that could be defined, more than enough.

0 means nothing special happens (default) advance sp by the length of the matched group.
-1 means the pattern group that matched will be highlighted but treated like it didn't match. thus the string pointer is set to sp+1. Notice the +1 is necessary otherwise we would be stuck in an infinite loop matching the same pattern over and over. So its not exactly no match operation, more like a way to let other patterns passthrough.
1 same concept as -1 except we advance by the starting location of the group match. i.e if match was (5,10) add sp+5

blkend tells which group is going to terminate the multiline block. if its negative the same group that started the block terminates the block. There are a few gochas, for example when screen is positioned going up instead of down, it is always assumed that group 1 will do the termination in that case.

Hope this helps, I know its arcane, but the purpose is to have a minimal and lean implementation.

from nextvi.

 avatar commented on July 22, 2024

from nextvi.

kyx0r avatar kyx0r commented on July 22, 2024

I have attached the old Python program which I have been using for testing;

Use null pointer, I don't think github reply attachments work (or you forgot to attach it).
https://0x0.st/

I added extra strings near the top. The highlighting is quite good, but the result is sometimes bizarre: on line 591, the fd.write call uses a triple-quoted string; the string ends on line 616, but the highlighting continues until line 626. The highlighting changes as I move around in the file. Is that expected?

Moving up screen up won't do it right if the pattern is not fully enclosed (screen wise)

Btw, my multiline pattern now looks like this:
{"py", "((?:[!\"\"\"]*\"{3}\n$)|(?:\"{3}[!\"\"\"]*)|\"{3})", {6}, {0}, -1},

Did you happen to test it? I think its better because it handles this:

fsjfjsdj """ jdfsjfj

"""

jdfsjfj will be highlighted.

I use 6 for color, a special string a separate color I guess ha ha.

-Kyryl

from nextvi.

 avatar commented on July 22, 2024

from nextvi.

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.