Sublime Forum

Syntax scope up to corresponding closing brace (multilines)

#1

Hello

Can I easily define a scope from a brace up to corresponding closing brace ?

For example, how highlight all trigger content with a good syntax here ?

    trigger = {
        intrigue = 10
        NOT = {
            flag = rumour_spreader
        }
        courtier = {
            is_female = no
            age = 16
            NOT = {
                flag = impotent
            }
            NOT = {
                children = 1
            }
            NOT = {
                trait = envy
            }
        }
    }

I think my syntax file is unnecessarily complex (I would like one scope and exclude “trigger”).

    - match: \btrigger\b
      push:
        - meta_scope: meta.block.trigger00.txt
        - match: \}
          pop: true
        - include: comments
        - match: \{
          push:
            - meta_scope: meta.block.trigger01.txt
            - match: \}
              pop: true
            - include: comments
            - match: \{
              push:
                - meta_scope: meta.block.trigger02.txt
                - match: \}
                  pop: true
                - include: comments
                - match: \{
                  push:
                    - meta_scope: meta.block.trigger03.txt
                    - match: \}
                      pop: true
                    - include: comments
                    - match: \{
                      push:
                        - meta_scope: meta.block.trigger04.txt
                        - match: \}
                          pop: true
                        - include: comments

Thanks for any help :slightly_smiling:

0 Likes

#2

I’m not entirely sure if I understand you right, but you could try this:

- match: '\btrigger\b\s*=\s*\{'
  push:
    - meta_scope: meta.block.trigger00.txt
    - match: \}
      pop: true
    - include: comments
    - match: \{
      push:
        - include: comments
        - match: \}
          pop: true
0 Likes

#3

Thank you @kingkeith

  • Only one scope now :slightly_smiling: I don’t know how many braces this section might contain though. In my example, only 2. Sometimes, it could be 6 levels. Can I shorten this syntax or I need to write 6 levels ?

  • Or, maybe there is now a solution for regular expression matching multilines ? All of this seems to be a workaround for this “issue”.

0 Likes

#4

you can support infinite nesting like this:

main:
  - match: '\btrigger\b\s*=\s*\{'
    push:
      - meta_scope: meta.block.trigger00.txt
      - include: inside_brace

inside_brace:
  - match: \}
    pop: true
  - include: comments
  - match: \{
    push: inside_brace

1 Like

#5

It works fine. Thank you so much. You resolve my issues in a few minutes. I spent several hours on it…

0 Likes