# Sublime syntax pop multiple levels

**URL:** <https://forum.sublimetext.com/t/sublime-syntax-pop-multiple-levels/15608>\
**Category:** General Discussion\
**Created:** [September 3, 2015, 2:17pm UTC](https://forum.sublimetext.com/t/sublime-syntax-pop-multiple-levels/15608 "2015-09-03T14:17:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ismell](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/ismell/32/45650_2.png) [@ismell](https://forum.sublimetext.com/u/ismell)\
**Post date:** [September 3, 2015, 2:17pm UTC](https://forum.sublimetext.com/t/sublime-syntax-pop-multiple-levels/15608/1 "2015-09-03T14:17:48Z")

</div>

I was looking for some sublime-syntax help. I have the following code:

```auto
field:
  - match: "[a-zA-Z_]+\\d_]*\\s*:"
    push:
      - meta_scope: meta.message.field
      - include: string
      - include: constant
constant:
  - match: \b(?:true|false|null)\b
    scope: constant.language
    pop: true # Pops meta.message.field
string:
  - match: '"'
    captures:
      0: punctuation.definition.string.begin
    push:
      - meta_scope: string.quoted.double
      - match: '"'
        captures:
          0: punctuation.definition.string.end
        pop: true # I want to pop string.quoted.double and meta.message.field
  - match: '[a-zA-Z_]\w*'
    scope: string.unquoted
    pop: true # Pops meta.message.field
```

It matches

```auto
foo: bar
foo: true
foo: "bar"
```

The problem is that the double quote leaves the _meta.message.field_ scope on the stack. Is there a way to have the closing double quote pop twice so _meta.message.field_ gets popped off the stack as well?

---

<div class="post-metadata">

**Author:** ![gwenzek](https://forum.sublimetext.com/letter_avatar_proxy/v4/letter/g/7c8e57/32.png) [@gwenzek](https://forum.sublimetext.com/u/gwenzek)\
**Post date:** [September 7, 2015, 7:24am UTC](https://forum.sublimetext.com/t/sublime-syntax-pop-multiple-levels/15608/2 "2015-09-07T07:24:35Z")

</div>

I don’t think there is a way to pop several context at once.

In your case you can come around by replacing the

```auto
- match: '"'
    captures:
      0: punctuation.definition.string.begin
    push: ...
```

By:

```auto
- match: '"'
    captures:
      0: punctuation.definition.string.begin
    set: ...
```

Indeed once you know your field is a string, the end of the string will be the end of the field.  
You may need to add a meta.message.field inside the string, I’m not sure.

---

<div class="post-metadata">

**Author:** ![FichteFoll](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/fichtefoll/32/43583_2.png) [@FichteFoll](https://forum.sublimetext.com/u/FichteFoll)\
**Post date:** [September 7, 2015, 10:30am UTC](https://forum.sublimetext.com/t/sublime-syntax-pop-multiple-levels/15608/3 "2015-09-07T10:30:17Z")

</div>

There’s two ways to pop multiple contexts. The first is, as gwenzek mentioned, to just use “set” instead of “push”, but it only works if you indeed want this behavior.  
The other option is a lookahead/behind pattern in a few pop patterns that either do or do not consume actually characters. You can see an example of this in the default HTML.sublime-syntax where it includes PHP, irrc.

---

<div class="post-metadata">

**Author:** ![ismell](https://forum.sublimetext.com/user_avatar/forum.sublimetext.com/ismell/32/45650_2.png) [@ismell](https://forum.sublimetext.com/u/ismell)\
**Post date:** [September 22, 2016, 2:46pm UTC](https://forum.sublimetext.com/t/sublime-syntax-pop-multiple-levels/15608/4 "2016-09-22T14:46:03Z")

</div>

So clear\_scopes: was added in 3116

> [@Dev Build 3116](https://forum.sublimetext.com/t/dev-build-3116/21148):
>
> Dev Build 3116 is out now at [https://www.sublimetext.com/3dev](https://www.sublimetext.com/3dev) Settings now open in a new window, with the default and user settings side-by-side. Likewise for key bindings. Another highlight is the on\_hover API, which is used by the new show\_definition functionality. The basics of on\_hover are: class Example(sublime\_plugin.EventListener): def on\_hover(self, view, point, hover\_zone): pass hover\_zone will be one of sublime.HOVER\_TEXT, sublime.HOVER\_GUTTER or sublime.HOVER\_MARGIN. Along with o…
