Sublime Forum

Help with custom syntax (exclude scopes)

#1

Hello

My custom syntax:

contexts:
  main:
    - match: ^
      push:
        - meta_content_scope: meta.block.depth0.txt
        - match: \}
          pop: true
        - match: \{
          push:
            - meta_content_scope: meta.block.depth1.txt
            - match: \}
              pop: true
            - match: \{
              push:
                - meta_content_scope: meta.block.depth2.txt
                - match: \}
                  pop: true
                - match: \{
                  push:
                    - meta_content_scope: meta.block.depth3.txt
                    - match: \}
                      pop: true

My txt file:

event = {
    only_playable = yes
    min_age = 16

    trigger = {
        culture_is = viking
        NOT = { year = 1010 }
    }
}

How can I exclude meta_content_scope from each other ? For example, only_playable = yes has 2 scopes: meta.block.depth0.txt and meta.block.depth1.txt. It should be meta.block.depth1.txt only.

What i would like:

Thanks for any help

0 Likes

#2

use clear_scopes:

contexts:
  main:
    - match: ^
      push:
        - meta_content_scope: meta.block.depth0.txt
        - match: \}
          pop: true
        - match: \{
          push:
            - clear_scopes: true
            - meta_content_scope: meta.block.depth1.txt
            - match: \}
              pop: true
            - match: \{
              push:
                - clear_scopes: true
                - meta_content_scope: meta.block.depth2.txt
                - match: \}
                  pop: true
                - match: \{
                  push:
                    - clear_scopes: true
                    - meta_content_scope: meta.block.depth3.txt
                    - match: \}
                      pop: true
1 Like

#3

Works perfectly. Thank you.

0 Likes

#4

@kingkeith

I spent several hours on it again and I need to ask help because i’m not making anymore progress. It is too hard for me to correctly understand how working nested scopes. Any help is welcomed.

I have 4 kinds of terms: commands, triggers, operators and event parameters. In this example:

  • commands: event_type1, money, culture (only in effect section), event_type2
  • triggers: culture (only in trigger section), year, old_culture
  • operators: NOT
  • event parameters (appears only in event section): only_playable, min_age, id (x2), trigger, effect

I would like :

  • a meta scope matching event parameters (before the equal signs and inside event_type1 and event_type2) and keeping event_type1 as command (currently my syntax disabling the color of event_type1…)
  • to color triggers only if they are in trigger section
  • to correctly color “culture”. As trigger in trigger section and as command in effect section

My syntax:

contexts:
  prototype:
    - include: context_operators

  main:
    - include: context_meta_triggers
    - include: context_meta_events

  context_event_parameters:  
    - match: '\b(only_playable|min_age|id|trigger|effect)\b'
      scope: game.event_parameters.txt  

  context_triggers:
    - match: '\b(culture|old_culture|year)\b'
      scope: game.conditions.txt

  context_commands:
    - match: '\b(event_type1|event_type2|culture|money)\b'
      scope: game.commands.txt

  context_operators:
    - match: '\b(NOT)\b'
      scope: game.operators.txt

  context_meta_events:
    - match: '\b(event_type1)\b\s*=\s*\{'
      push:
        - meta_scope: context_meta_events1
        - include: context_meta_events2

  context_meta_events2:
    - match: \}
      pop: true
    - include: context_event_parameters
    - match: \{
      push: context_meta_events2

  context_meta_triggers:
    - match: '\b(trigger)\b\s*=\s*\{'
      push:
        - meta_scope: context_meta_triggers1
        - include: context_meta_triggers2

  context_meta_triggers2:
    - match: \}
      pop: true
    - include: context_triggers
    - match: \{
      push: context_meta_triggers2
0 Likes

#5

maybe something like

%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
scope: source.example-carpenter
contexts:
  prototype:
    - include: context_operators

  main:
    - include: context_meta_triggers
    - include: context_meta_events

  context_event_parameters:  
    - match: '\b(only_playable|min_age|id)\b'
      scope: game.event_parameters.txt  

  context_triggers:
    - match: '\b(culture|old_culture|year)\b'
      scope: game.conditions.txt

  context_commands:
    - match: '\b(culture|money)\b'
      scope: game.commands.txt

  context_operators:
    - match: '\b(NOT)\b'
      scope: game.operators.txt

  context_meta_events:
    - match: '\b(event_type\d+)\b(\s*=\s*\{)'
      captures:
        1: game.commands.txt
        2: context_meta_events1
      push:
        - meta_content_scope: context_meta_events1
        - include: context_meta_events2

  context_meta_events2:
    - match: \}
      pop: true
    - include: context_event_parameters
    - include: context_meta_triggers
    - include: context_meta_events
    - include: context_commands
    - match: \{
      push: context_meta_events2

  context_meta_triggers:
    - match: '\b(trigger)\b\s*=\s*\{'
      captures:
        1: game.event_parameters.txt
      push:
        - meta_scope: context_meta_triggers1
        - include: context_meta_triggers2

  context_meta_triggers2:
    - match: \}
      pop: true
    - include: context_triggers
    - match: \{
      push: context_meta_triggers2

0 Likes

#6

Works great. I can make progress again thanks to you :slightly_smiling:

0 Likes

#8

Anyone could help me ? :blush:

Context doesn’t help for differentiating them and the clause function might contain none or more brace pairs. I would like to color its parameters (tier, rank, etc.). I added another possible case with brace in the next line and not just next to the equal sign.

Is there a syntax for supporting all these cases (clause\integer and brace in the same\next line) ? I tested a lot of them, but to no avail…

The integer function is supported:

    - match: '\b(country_rank)\s*=\s*[0-9]'
      captures:
        1: game.commands.txt

The clause function is supported, only if the open brace is in the same line than equal sign:

  CONTEXT_country_rank:
    - match: '\b(society_rank)\b(\s*=\s*\{)'
      captures:
        1: game.commands.txt
        2: meta_scope_country_rank
      push:
        - meta_content_scope: meta_scope_country_rank
        - include: CONTEXT_country_rank_2
  CONTEXT_country_rank_2:
    - match: \}
      pop: true
    - match: '\b(tier|rank)\b'
      scope: game.commands_parameters.txt
    - match: \{
      push: CONTEXT_country_rank_2

Any suggestions for optimizing my syntax are welcomed.

0 Likes