I’m trying to create a custom AsciiDoc syntax for ST3 and am facing problems handling nested blocks with variable-lenght balanced delimiters:
[TIP]
===============
A TIP admonition block.
[NOTE]
=======
A NOTE admonition block nested inside the TIP block.
=======
===============
Since syntax RegExs only work on single lines, and because syntax don’t offer variables to store a macthed string, I can’t find a way to establish when a newly encountered block delimiter is marking the end of the current block or the beginning of a new nested block.
The only apparent way to achieve this would be to first trying to capture a delimiter with the same-lenght of the opening one (in which case the context can be popped); failing that, any match of four or more = chars would be the start of a new block.
I couldn’t find any syntax that uses balanced delimiters this way (the ST AsciiDoc syntaxes are mostly broken, and the markdown syntax doesn’t support nesting balanced block), so I wasn’t able to find inspiration in others’ syntaxes — but maybe it’s just because I don’t know where to look for, i.e. me not knowing which languages/syntaxes support a similar feature.
Nested blocks of this type are quite common in AsciiDoc, and being able to handle them correctly is important — e.g. section headings inside these blocks are not accounted for the document structure, nor in the TOC, so mismatching a nested block opening delimiter for the closing delimiter of the main block can have undesired consequences not only on the document’s syntax coloring but also (and most of all) on plugins designed to handle the document structure.
Can anyone help me on this?
- Is there a package which supports this type of syntax construct, which I could study?
- Is it indeed possible to achieve this in ST3 syntaxes?
I was hoping that maybe the Oniguruma engine exposes some advanced RegEx patterns to allow attaching functions to a capturing group, or store it on some interal variable or stack — whatever hack might help referencing the previous match of the opening delimiter.
It would be great if ST3 syntaxes natively supported some kind of temporary storage variables associated with each context, allowing to reference them from withing the RegEx patterns.