Menu

#122 delimiter stack

Unknown
open
nobody
None
Mercurial
5
2019-09-01
2019-09-01
No

Hi! I was trying to update the syntax highlighting for Python to properly highlight f-strings, and it got... complicated. At least, it got complicated when I tried to handle nested f-strings. One problem is that you can have four types of strings, all nested, some of which use double quotes as their delimiter and some single quotes. You could keep track of all of this using call parameters, but like I said, it was getting complicated.

I realized that it would be very handy to have a stack of delimiter match buffers similar to the stack of subroutines. So I decided to add that feature. Here it is.

Here's an example syntax file that uses the feature:

=Idle
=Bad

:idle Idle
* idle
"([{<" idle push_c
")]
}>" bad noeat
& idle pop_c

:bad Bad
* idle

If you use it (and a patched JOE) to highlight the following:

<<{[(())]}>)

then the last ")" will be highlighted as Bad. (It can only highlight closing brackets that are unmatched since the state machine doesn't work backwards.)

1 Attachments

Related

Patches: #123

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.