cyrusfirheir / twee3-language-tools

[ VSCode extension ] Syntax highlighting and programmatic language tools for Twee 3, and Twine 2 storyformats.
https://marketplace.visualstudio.com/items?itemName=cyrusfirheir.twee3-language-tools
MIT License
47 stars 16 forks source link

Display error when using else macro before elseif macro #87

Open MinusGix opened 2 years ago

MinusGix commented 2 years ago

IT would be useful to provide an error when putting the else macro before the elseif macro in an if statement.

<<if $thing>>
<<else>> /* Should error */
<<elseif>>
<</if>>

While we could add a complex feature to the children's tags to allow specifying complex patterns, I think this can be resolved in a good enough manner by just adding a field to a children called after which specifies the names of other children that it must appear after.

children: [
    "elseif",
    {
       "name": "else",
       "max": 1,
       "after": ["elseif"]
    }
]

And so if it sees an else before elseif (which isn't too complex of a modification of the existing counting code), then it produces an error.

pramod74 commented 2 years ago

Hi @MinusGix,

I would like to work on this issue. I understand that the validation needs to be updated in sugarcube-2/macros.json. Kindly confirm, and assign me this issue.

MinusGix commented 2 years ago

The issue is about implementing the checks to validate the proposed after field, and so would need more than just modifications to the macros.json file. See: https://github.com/cyrusfirheir/twee3-language-tools/blob/master/src/sugarcube-2/macros.ts#L518 (I'm open to splitting off that bit of code to a separate function to make it cleaner, too). If you still feel up for it, then I can assign this to you.

pramod74 commented 2 years ago

Thanks for the update, @MinusGix. I am sorry but this seems to be beyond my current level of expertise. Apologies.