Sublime Forum

Limit with_prototype recursion in sublime-syntax

#1

I would like a feature to provide a hard limit to the with_prototype recursion. Currently, if you have any sort of recursion in your syntax, you are greeted by this when you save it:

Apparent recursion within a "with_prototype" action: 25000 context sanity limit hit

For background, I’ve been attempting to work on a Razor templating engine syntax for HTML/C#, but I seem to have hit a fundamental problem with how Sublime Text handles syntaxes. In Razor, there are two fundamentals that restrict how I can build the syntax. First, you can inject HTML/Code anywhere you please. Second, there isn’t a limit to how many times you can context switch between HTML/Code.

For example, this is valid:
<p>@if (true) { <p>@if (true) { <p @if (true) { <text>class="disabled"</text> }></p> }</p> }</p>

It would output:
<p><p><p class="disabled"></p></p></p>

Because of this, it is absolutely necessary to use with_prototype to inject the code into both the HTML and the C# syntaxes to activate a context switch, since you can type @ at any point to insert code, which can insert text in the document.

The problem is, of course, recursion. The context that handles code has to allow you to switch to HTML. And then the context that handles HTML has to allow you to switch to code.

From what I can tell, there is no way around this. If I wanted to make this work, I would have to duplicate my code about 20 times or so to give about 20 context switches, and on the last one I wouldn’t inject the context switching code. It would provide a limit to the amount of recursion, but it would be a pain to maintain and would be pretty ugly looking.

If I had the ability to do something like:

push: scope:source.cs
with_prototype:
  - include: html_activation
recursion_limit: 10

It would help a bunch. It would be saying that, yes, I know there is recursion, and I would like to limit it to 10 rounds.

It could be implemented internally by counting down the recursion_limit every time one is reached, and once it hits 0 it would not apply the with_prototype.

Anyway, that is my use case and why I would like to see this feature.

1 Like