Indentation rules for custom VS Code syntax

Viewed 201

I'm trying to create an indentation rule for this custom syntax. It's very similar to a JavaScript switch statement, but I can't for the life of me work out how to correctly unindent the next line upon pressing return.

Here is what it should look like:

CHOICE {
    "Hello!":
        name "Hi there."
    "Um.. hello?":
        name "Er.. hi?"
}

My language-configuration.json file has this rule so far:

...
"indentationRules": {
    "increaseIndentPattern": "\":",
    // TODO: "decreaseIndentPattern": ""
}

So it correctly matches the ending double quote and colon of the previous line and indents the next line, however I can't work out how to unindent the next line upon pressing return. This is what it does at the moment:

CHOICE {
    "Hello!":
        name "Hi there."
        "Um.. hello?":
            name "Er.. hi?"
}

The closest I can think of doing is using decreaseIndentPattern to detect when a double quote is opened, however, this also affects previous lines so that doesn't really work.

My other idea was this: \"\n\s*\" which would check the previous line ends in a double quote (not a colon) and that the current line starts with a quote, and therefore unindent the current line, but this didn't work.

I saw these options too, but wasn't sure if I could apply them or not: bracketIndentNextLinePattern, disableIndentNextLinePattern.

Also, my starting rule was initially this: \".*\"\: however it causing the line after a line NOT ending in a double quote to indent for some reason?

After several hours of trying to fix this I've reached the end of my tether, so hopefully someone can point me in the right direction. Thank you.

0 Answers
Related