tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

SugarCube parse errors in HTML comments have bad effect #43

Closed boyland closed 4 years ago

boyland commented 4 years ago

I was trying to determine why an <<if>> macro was failing and was commenting out parts in the middle and it still failed. It turns out that a <</link>> was missing one of its closing greater-than signs and so it snarfed up the <<else>> token.

:: Start
<<set $step to 10>>
<<include "Step 06">>
<<include "Step 07">>

:: Step 06
<<if $step gte 6>>Before6
<<if $step is 6>>Then<!-- <<link "AddHi">>
<</link>--><<else>>Else<</if>> After6<</if>>

:: Step 07
<<if $step gte 7>>Before7
<<if $step is 7>>Then<!-- <<link "AddHi">>
<</link>>--><<else>>Else<</if>> After7<</if>>

The output is:

Before6
After6
Before7
Else After7

I think this is a parsing bug and a parsing mis-feature:

tmedwards commented 4 years ago

The v2 "parser" is an anachronism that's being replaced for v3. There are no plans to perform major surgery on any of it, so don't get your hopes up.

Parsing misfeature: It would be nice if <</link><<else>> would generate an error rather than silently be treated as a legal synonym for <</link>>.

That I should be able to swing.

boyland commented 4 years ago

I don't have any opinions on v2 versus v3. Is v3 intended to be a newly architectured parser for the same (or slightly updated) language specification? In that case, it's unlikely to have the same bugs (good). I appreciate that it might be able to generate errors for "obviously" broken tags. I'm trying to do the same in my Eclipse plugin for SugarCube.

tmedwards commented 4 years ago

Is v3 intended to be a newly architectured parser for the same (or slightly updated) language specification? In that case, it's unlikely to have the same bugs (good).

The current plan for SugarCube v3 is to switch to a separate lexer and parser design, rather than the combined parser design that v2 currently uses.

Uzume commented 3 years ago

For reference, the relevant parsing issue for SugarCube v3 is: tmedwards/sugarcube-3#4