# How to deactivate/exclude a "repository" under some context in a grammar package

#1

I’m now developing a grammar package for a typesetting language named SATySFi. SATySFi has several states, two of which are program state and inline state, and transition between states is made by a dedicated syntax. For example, an opening brace `{` in a program state starts an inline state and the corresponding `}` resumes a program state.

In my Atom package, I want to highlight keywords like `let` in program state but not in inline state because `let` in inline state is just an English verb. Same can be said for other stuff like integer numerals.

I tried to make a prototype for this context-sensitive feature (see the CSON below). However, this grammar still scopes `let` in inline state as `keyword.other.satysfi`. I understand the reason but this is not what I want. I’m looking for how to deactivate/exclude the program state grammar in inline state part and is it possible?

``````scopeName: "source.satysfi"
name: "SATySFi"
fileTypes: [
"saty"
]
patterns: [
{
include: "#programState"
}
{
include: "#inlineState"
}
]
repository:
programState:
patterns: [
{
begin: "\\{"
beginCaptures:
0:
name: "punctuation.transition.program-to-inline.begin.satysfi"
end: "\\}"
endCaptures:
0:
name: "punctuation.transition.program-to-inline.end.satysfi"
patterns: [
include: "#inlineState"
]
}
{
match: "\\blet\\b"
name: "keyword.other.satysfi"
}
]
inlineState:
patterns: [
# grammar for inline state here.
]
``````

#2

I’ll need to test it, but a combination of injection selectors might work. Will update when I experiment.

Edit: is there a demo we can test with? The grammar seems to be working fine as-is. For example, the text `let { let }` is correctly scoped (the outer one is picked up on, the inner one ignored).

#3

Well, you are right. The reason I get incorrect scope is that I have nested `{}` strcutures in the actual document and the closing `}` was parsed incorrectly. I need to develop the grammar more, but that will solve the problem I had today.

Sorry for taking your time and thanks!

#4

And do nested braces mean something important, or are they just like TeX groups when already in inline mode? I think you just need a rule that looks for the opening brace and finishes at a closing brace, to ensure they stay balanced.