Sublime Forum

Custom syntax : Brace in the same or the next line

#1

Anyone could help me ?

Is there a syntax for supporting these cases (brace in the same or in the next line) ? I tested a lot of them, but to no avail…
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.).
If you are sure that it’s not supported, please tell me.

My latest try:

  CONTEXT_META_country_rank_1a:
    - match: '^\s+(country_rank)\b(\s*=\s*\{)'
      captures:
        1: game.command.txt
      push:
        - meta_content_scope: meta_scope_country_rank
        - include: CONTEXT_META_country_rank_2
  CONTEXT_META_country_rank_1b:
    - match: '^\s+(country_rank)\b(\s*=\s*$)'
      captures:
        1: game.command.txt
    - match: '\{'
      push:
        - meta_content_scope: meta_scope_country_rank
        - include: CONTEXT_META_country_rank_2
  CONTEXT_META_country_rank_2:
    - match: '\}'
      pop: true
    - match: '\b(tier|rank)\b'
      scope: game.parameter.txt
    - match: '\{'
      push: CONTEXT_META_country_rank_2

Syntax is broken when the brace is in the next line.

0 Likes

[Solved] Curly brackets causing unwanted line wrapping in custom syntax?
#2

what’s broken about it apart from the completely non-standard scope names? the following syntax tests all pass:

# SYNTAX TEST "carpenter.sublime-syntax"
 country_rank = {
# ^^^^^^^^^^^ game.command.txt
#                ^ meta_scope_country_rank
    tier = { kingdom }
#   ^^^^ meta_scope_country_rank game.parameter.txt
    rank = 1
#   ^^^^ meta_scope_country_rank game.parameter.txt
}
#^ - meta_scope_country_rank

 country_rank =
# ^^^^^^^^^^^ game.command.txt
{
#^ meta_scope_country_rank
    tier = { kingdom }
#   ^^^^ meta_scope_country_rank game.parameter.txt
    rank = 1
#   ^^^^ meta_scope_country_rank game.parameter.txt
}
#^ - meta_scope_country_rank

(assuming a main context of:

  main:
    - include: CONTEXT_META_country_rank_1a
    - include: CONTEXT_META_country_rank_1b

)

0 Likes

#3

Thank you again for helping me.

I know this example works, but if the file is a bit more complex, it doesn’t work (and I don’t know why).

Example:
try.txt

country = {
    tag = FRA

    country_rank = {
        tier = { kingdom duchy }
        rank = 1
    } 

    effect = {
        prestige = 200
    }
}

country = {
    tag = RUS

    country_rank =
    {
        tier = { kingdom duchy }
        rank = 2
    }

    effect = 
    {
        prestige = 400
    }
}

carpenter.sublime-syntax

%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: carpenter
file_extensions:
  - txt
scope: source.txt

contexts:

  main:
    - include: CONTEXT_META_country_1a
    - include: CONTEXT_META_country_1b


  CONTEXT_META_country_1a:
    - match: '^(country)\b(\s*=\s*\{)'
      captures:
        1: entity.name.tag
      push:
        - meta_content_scope: meta_scope_country
        - include: CONTEXT_META_country_2
  CONTEXT_META_country_1b:
    - match: '^(country)\b(\s*=\s*$)'
      captures:
        1: entity.name.tag
    - match: '\{'
      push:
        - meta_content_scope: meta_scope_country
        - include: CONTEXT_META_country_2
  CONTEXT_META_country_2:
    - match: '\}'
      pop: true
    - match: '\b(tag)\b'
      scope: entity.name.tag
    - include: CONTEXT_META_country_rank_1a
    - include: CONTEXT_META_country_rank_1b
    - include: CONTEXT_META_effect_1a
    - include: CONTEXT_META_effect_1b
    - match: '\{'
      push: CONTEXT_META_country_2

  CONTEXT_META_country_rank_1a:
    - match: '^\s+(country_rank)\b(\s*=\s*\{)'
      captures:
        1: entity.name.tag
      push:
        - meta_content_scope: meta_scope_country_rank
        - include: CONTEXT_META_country_rank_2
  CONTEXT_META_country_rank_1b:
    - match: '^\s+(country_rank)\b(\s*=\s*$)'
      captures:
        1: entity.name.tag
    - match: '\{'
      push:
        - meta_content_scope: meta_scope_country_rank
        - include: CONTEXT_META_country_rank_2
  CONTEXT_META_country_rank_2:
    - match: '\}'
      pop: true
    - match: '\b(tier|rank)\b'
      scope: support.constant
    - match: '\{'
      push: CONTEXT_META_country_rank_2

  CONTEXT_META_effect_1a:
    - match: '^\s+(effect)\b(\s*=\s*\{)'
      captures:
        1: entity.name.tag
      push:
        - meta_content_scope: meta_scope_effect
        - include: CONTEXT_META_effect_2
  CONTEXT_META_effect_1b:
    - match: '^\s+(effect)\b(\s*=\s*$)'
      captures:
        1: entity.name.tag
    - match: '\{'
      push:
        - meta_content_scope: meta_scope_effect
        - include: CONTEXT_META_effect_2
  CONTEXT_META_effect_2:
    - match: '\}'
      pop: true
    - match: '\b(prestige)\b'
      scope: support.constant
#    - include:
    - match: '\{'
      push: CONTEXT_META_effect_2

“prestige” is not highlighted. Why ?

0 Likes

#4
%YAML 1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
name: carpenter
file_extensions:
  - txt
scope: source.txt

contexts:

  main:
    - match: '^(country)\s*=\s*'
      captures:
        1: entity.name.tag
      push: [CONTEXT_META_inside_country, expect_open_brace]
  CONTEXT_META_inside_country:
    - meta_content_scope: meta_scope_country
    - match: '\}'
      pop: true
    - match: '\b(tag)\b'
      scope: entity.name.tag
    - match: '^\s+(country_rank)\s*=\s*'
      captures:
        1: entity.name.tag
      push: [CONTEXT_META_inside_country_rank, expect_open_brace]
    - match: '^\s+(effect)\b\s*=\s*'
      captures:
        1: entity.name.tag
      push: [CONTEXT_META_inside_effect, expect_open_brace]
  CONTEXT_META_inside_country_rank:
    - meta_content_scope: meta_scope_country_rank
    - match: '\}'
      pop: true
    - match: '\b(tier|rank)\b\s*=\s*'
      captures:
        1: support.constant
      push:
        - match: \{
          push:
            - match: \}
              pop: true
        - match: (?=\S)
          pop: true
  CONTEXT_META_inside_effect:
    - meta_content_scope: meta_scope_effect
    - match: '\}'
      pop: true
    - match: '\b(prestige)\b'
      scope: support.constant
  expect_open_brace:
    - match: \{
      pop: true

1 Like