-
I have a mode that should start with @{ and end with a matching }, and can contain abitrarily nested brackets (and any other characters). My tokens are as below. What is the best way to define the pattern for exit Gate token ? Or should I instead use a function that counts open/close brackets as shown in Custom Token Patterns ? const EnterGate = createToken({
name: "EnterGate",
pattern: /@{/
push_mode: "gate"
});
const ExitGate = createToken({
name: "ExitGate",
pattern: /}/
pop_mode: true
});
const Gate = createToken({
name: "Gate",
pattern: /.*/
}); |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@dhowe You can push another mode to the mode stack (even the same mode) and keep the |
Beta Was this translation helpful? Give feedback.
-
Thanks. This approach works in terms of tokens but I'm not sure how to get the full content of the mode (including all the brackets) into a rule. Would be ideal if I could match ONE rule with everything between the Here are a few examples (which would occur in the middle of a string of other tokens): @{ a: { $exists: true }}
@{ a: "ab" }
@{ a: "繁體" }
@{ a: 3, $or: [ { b: { $lt: 30 } }, { c: /^p*/ } ] } |
Beta Was this translation helpful? Give feedback.
@dhowe You can push another mode to the mode stack (even the same mode) and keep the
pop_mode: true
for}
. That way, you will only leave the mode when encountering a corresponding}
for the first@{
that entered the mode.