Sublime Forum

Help With Custom Sublime-Syntax File

#1

I’m writing a custom sublime syntax file, and I’m trying to get python style function highlighting (function name one color, parentheses normal-color) that looks like this, but I can’t get the parentheses to be normal-colored. This is the closest I could get.

Anybody think they could help?

Code:

%YAML 1.2
---
name: TAS
file_extensions: [tas]
scope: source.tas

contexts:
  main:
    - match: \b(test)\b
      scope: keyword.control.tas
    - match: '"'
      push: double-quote
    - match: "'"
      push: single-quote
    - match: ':'
      push: comment
    - match: .*[(]
      push: function

  double-quote:
    - meta_scope: string.quoted.double.tas
    - match: \\.
      scope: constant.character.escape.tas
    - match: '"'
      scope: punctuation.definition.string.end
      pop: true

  single-quote:
    - meta_scope: string.quoted.single.tas
    - match : \\.
      scope: constant.character.escape.tas
    - match: "'"
      scope: punctuation.definition.string.end
      pop: true

  comment:
    - meta_scope: comment.tas
    - match: '\n'
      pop: true

  function:
    - meta_scope: support.function.builtin.tas
    - match: \(
      scope: punctuation.section.arguments.begin.tas
    - match: \)
      pop: true

  arguments:
    - meta_scope: punctuation.section.arguments.begin.tas
    - match: .*[)]
      pop: true0
0 Likes

#2

First of all, I would recommend to create a section for each element you want to support and include this in the main section. This makes it easy to reuse single rules in several contexts.

Function highlighting should be done as shown in function-call section as it includes the standardized meta.scopes, too.

%YAML 1.2
---
name: TAS
file_extensions: [tas]
scope: source.tas

contexts:
  main:
    - include: comment
    - include: double-quote
    - include: single-quote
    - include: function-call
    - include: variables

  comment:
    - match: ':'
      scope: punctuation.definition.comment.tas
      push:
        - meta_scope: comment.line.tas
        - match: $
          pop: true

  double-quote:
    - match: '"'
      scope: punctuation.definition.string.begin.tas
      push:
        - meta_scope: string.quoted.double.tas
        - match: \\.
          scope: constant.character.escape.tas
        - match: '"'
          scope: punctuation.definition.string.end.tas
          pop: true

  single-quote:
    - match: "'"
      scope: punctuation.definition.string.begin.tas
      push:
        - meta_scope: string.quoted.single.tas
        - match : \\.
          scope: constant.character.escape.tas
        - match: "'"
          scope: punctuation.definition.string.end.tas
          pop: true

  variables:
    - match: \b(test)\b
      scope: keyword.control.tas

  function-call:
    - match: (\w+)\s*(?=\()
      captures:
        0: meta.function-call.tas
        1: variable.function.builtin.tas
      push: function-call-arguments

  function-call-arguments:
    - match: \(
      scope: punctuation.section.parameters.begin.tas
      set:
        - meta_scope: meta.function-call.parameters.tas
        - match: \)
          scope: punctuation.section.parameters.end.tas
          pop: true
        - match: ','
          scope: punctuation.separator.parameters.tas
        - include: main
4 Likes

#3

Fantastic! Thank you so much!

0 Likes

#4

Also compare:

0 Likes