Say I have the following syntax definition. I want to make it so the {
is tagged with invalid.illegal
so it’s obvious that the closing )
is missing. I also want to make it so the block context matches and continues to work like normal.
main:
- include: parens
- include: block
block:
- match: \{
scope: punctuation.section.block.begin
push:
- match: \}
scope: punctuation.section.block.end
pop: true
parens:
- match: \(
scope: punctuation.section.parens.begin
push:
- match: \)
scope: punctuation.section.parens.end
pop: true
- match: \{
scope: invalid.illegal.stray-terminator-end
pop: true
consume: false # <-- New keyword that will allow applying a scope but not consume it
Example:
if (true {
// ^ invalid.illegal punctuation.section.block.begin.java
}
Though thinking about it more I guess I can work around it by reworking the scopes:
main:
- include: parens
- include: block
block-body:
- match: \}
scope: punctuation.section.block.end
pop: true
block:
- match: \{
scope: punctuation.section.block.begin
push: block-body
parens:
- match: \(
scope: punctuation.section.parens.begin
push:
- match: \)
scope: punctuation.section.parens.end
pop: true
- match: \{
scope: invalid.illegal.stray-terminator-end punctuation.section.block.begin
set: block-body