Friday, July 21, 2023

syntax files: how to prevent embedded syntax from leaking out of a region?

I developed a syntax file for Noweb -- if you're unfamiliar, it's a Literate Programming tool. Noweb source is LaTeX source, but with embedded code blocks. The embedded code blocks are delimited, and I define a syntax region that recognizes the delimiters. Inside a code block, I get highlighting that corresponds to the source code language. Outside, I get LaTeX highlighting.

But I have a problem with Perl highlighting that escapes past the end of a Perl code block. That is, source after the end of the code block is getting formatted as Perl, not as LaTeX.

Not all Perl breaks out -- I can't put my finger on it yet, but specific Perl constructs break out. For example, when I delete an elsif() clause, the problem disappears.

I'm closely following the examples in the Vim documentation. I'm already supplying the "keepend" argument to the syntax region, which is supposed to limit the embedded syntax to the region.

My working theory is that where the Perl syntax highlighting rules use "extend", this is letting the Perl syntax leak out of the region. Here's a quote from the stock perl.vim:
    syn region perlBraces start="{" end="}" transparent extend
The "extend" argument could be the reason the Perl syntax leaks out of the region.

Given this background, the question is, in my syntax file how can I reliably ALWAYS limit embedded language highlighting to the region that contains it, without the chance that the embedded language can break out?

Cheers!
Edward

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/9b5325f7-f81a-4f6f-b938-f16ba163821an%40googlegroups.com.

No comments:

Post a Comment