Check out this toy syntax:
%YAML 1.2
---
scope: source.toy
contexts:
  main:
    - match: -{3}
      scope: keyword.control.frontmatter.toy
      set: [main-after-frontmatter, frontmatter]
    - include: main-after-frontmatter
  frontmatter:
    - match: -{3}
      pop: true
      scope: keyword.control.frontmatter.toy
  main-after-frontmatter:
    - match: -{3,}
      scope: support.function.toy
Example:

Hope this helps!
EDIT: Think of there being an imaginary context stack. You push and pop contexts with this imaginary context stack with push, pop and set, where set just means “first pop then push”. We start out in the main context. We then match three dashes, so we “set”, that is, “pop and then push”, two new contexts on the stack, namely main-after-frontmatter and frontmatter. Imagine then that frontmatter is at the top of the stack. This means the match rules from the frontmatter context will take place for the characters ahead. When it encounters three dashes it’ll pop the frontmatter context off the context stack, and we are left with only one context, namely main-after-frontmatter.