Coder Social home page Coder Social logo

highlight Python docstrings about nextvi HOT 8 CLOSED

 avatar commented on August 25, 2024
highlight Python docstrings

from nextvi.

Comments (8)

kyx0r avatar kyx0r commented on August 25, 2024

At the moment this is not possible due to pattern invariance, i.e. the start and end pattern consist of the same string pattern which is ambiguous. And what's possible won't be that great, for example:

{"py", "(\"\"\"[!\"\"\"]*)|(^[ \t]*\"\"\".*$)", {4 | SYN_IT}, {0}, 2},

In this case it will only work if starting string does not contain [ \t] and the ending pattern has it. Otherwise the priority is always given to the ending pattern due to shortest match first regex rule which won't trigger a start of a multiline block.

No matter how you look at it the patterns are the same (or could be the same theoretically).

One solution is to provide a way for user to specify the starting pattern such that the start and end are the same match group, and since they will be the same the 2nd match will terminate the blockhl.
This will be enough to terminate the block, but im not sure if highlighting """.* and .*""" will work. That's the case where everything before the first """ and after the last """ must not match .

I have to revisit this in the future.

from nextvi.

 avatar commented on August 25, 2024

from nextvi.

kyx0r avatar kyx0r commented on August 25, 2024

Hi Claude,

I've made a promising change. Pull the last commit and try this pattern out:

{"/", "\"{3}.*\"{3}", {5 | SYN_IT}, {0}},
{"/", "((?:[!\"\"\"]*\"{3}\n$)|(?:^\"{3}.*)|\"{3})", {4 | SYN_IT}, {0}, -1},

It comes pretty close to what you want, here are the test cases:

   ashds """ sdhash
123
asdas
asd
hasdhas """ sdhadh

Not quite, hasdhas and sdhash are not highlighted

""" sdhash
123
asdas
asd
hasdhas """

All good.

""" sdhash
123
asdas
asd
hasdhas """df

Not quite, hasdhas not highlighted but the block is terminated.

""" sdhash
123
asdas
asd
"""

All good.

"""
123
asdas
asd
"""

All good.

absbdabs """ 123 asdas asd """ sdf s

All good.

""" 123 asdas asd """

All good.

hh """ 123 asdas asd """

All good.

""" 123 asdas asd """ hsdfhshd

All good.

from nextvi.

 avatar commented on August 25, 2024

from nextvi.

kyx0r avatar kyx0r commented on August 25, 2024

Are these two patterns working together? It looks like the first one will detect a single line docstring, but not trigger on a multi-line docstring. I am assuming the .* will not include newlines.

Yes, multiline patterns are those that contain non zero value for blkend struct member.

In more general contexts, some have suggested this pattern. Note the use of the non-greedy ? which nextvi supports. """[\s\S]?""" I think nextvi's regex does not support meta characters, right? If so, is there an equivalent to the [\s\S] ?

Right, [\s\S] is not supported because it can be achieved by just hard entering the character values into [],
I don't remember exactly but for example \s would be equalent to something like [ \t-\r]

There remains the difficulty of the identical docstring start and end markers. The second pattern has three options: a line ending with """, a line beginning with """, and just """. Is the order of these three options significant?

The order is significant, what comes first gets tested first.

This covers all the common uses of a docstring (in my limited experience). I could run into imaginative uses of docstrings. :-) Excellent! Thanks. P. S. I added the following to the Python section of conf. I like to highlight docstrings as comments.

Aye, I think I will add this to the base version as it demonstates single multiline pattern group. Its only valid if blkend is negative.

-Kyryl

from nextvi.

 avatar commented on August 25, 2024

from nextvi.

kyx0r avatar kyx0r commented on August 25, 2024

Ah, I see if docstring must be preceded by ): maybe a different approach could be used.

from nextvi.

 avatar commented on August 25, 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.