Sublime Forum

Need help for New Syntax Definition

#1

Hi,

I tried hard but couldn’t do it as I am not from IT background. Here I need little help please…

Can you please make sample syntax code having two type of scopes:

    • Highlight specific characters
    • Highlight the whole string between two characters.

I’ll just paste it and add the characters as I need.

And how to format these scopes.

Regards,
AA

0 Likes

#2

You’ll have to be a bit more descriptive that this. What exactly are you trying to do. Can you give examples?

0 Likes

#3

Thanks for replying.

I write code in a language that is not well known and no code editor has built-in syntax for that. It’s called Calculation Scripts for Hyperion Planning. So, I want to create my own Syntax Highlighting using Sublime. I just need two kinds of highlighting parameters i.e Operators and Delimiters.

Operator is hardcoding a word in syntax so that where ever that word appears in code, it is highlighted in its respective format. For example, CurryrM2 CurryrM1 Curryr &Budyr &BudyrP1 BudyrP2 BudyrP3 are hardcoded to be highlighted if appear anywhere in code.

Delimiters are like pair of two characters and everything inside them. For example, I define a pair of delimiters as “{” and “}” anything that comes between these middle brackets will be highlighted in its respective format i.e {variable}. If delimiters are “set” and “;” then the highlighting text could be anything between these two delimiters i.e set createnonmissingblk on;

I can highlight my coding language just based on above two parameters. If you could help me to write a basic syntax definition with just one operator and one pair of delimiters then I will add all my needed operators and delimiters myself later on.

Before I was using Windows and I could do this very easily using Notepad++. I wanted to share the screenshot of Notepad++ showing I use Operators and Delimiters there to make syntax highlighting but I don’t see attachment option here in forum. Notepad++ is not available in Macbook so I’m looking for alternative code editors where this basic syntax highlighting feature is available. you can also see the screenshot of Notepad++ at below link:

Thanks again.

0 Likes

#4
%YAML 1.2
---
name: My Language
scope: source.my_language
variables:
  identifier_start: "[[:alpha:]_]"
  identifier: "\b{{identifier_start}}[[:alnum:]_]*\b"

contexts:
  # "prototype" is a special context
  # it will be tested first on the top of EVERY other context
  prototype:
    - include: comment
    - match: "CurryrM2 CurryrM1 Curryr &Budyr &BudyrP1 BudyrP2 BudyrP3"
      scope: string

  comment:
    - match: "/\*"
      scope: punctuation
      push:
        - meta_scope: comment
        - match: "\*/"
          scope: punctuation
          pop: true

  # "main" is the entry point
  main:
    - match: \{
      scope: punctuation
      push:
        - match: \}
          scope: punctuation
          pop: true
        - match: "{{identifier}}"
          scope: variable

    - match: \[\[
      scope: punctuation
      push:
        - match: \]\]
          scope: punctuation
          pop: true

    - match: \bset\b
      scope: keyword
      push:
        - match: "{{identifier}}"
          scope: variable
          set:
            - match: ;
              scope: punctuation
              pop: true
            - match: "[^;]+"
              scope: string

may give you some inspiration.

0 Likes

#5

Great, I’ll try it out. I’m out of words to say you thanks for this.

This is exactly sort of something i needed.

0 Likes