Sublime Forum

Adding a custom syntax via .xml file

#1

I’m a fire alarm programmer working primarily on Edwards systems. I was told Edwards’ EST panels use a modified version of C++ for syntax in writing the program rules for their systems. Normally, Edwards suggests using Jens File Editor (which is quite old) in order to write the programming rules for their systems. I’m looking for a way to add syntax highlighting for EST panels into Sublime.

I found this old forum post with a custom Notepad++ syntax in it that I’m hoping I can use to transfer to Sublime. It seems the poster has setup a user defined language as an .xml file that you select from within Notepad++. http://www.thealarmtech.com/forum/viewtopic.php?t=107

Is there any way I could convert that .xml file to a .tmLanguage or sublime-syntax file and use it in Sublime? Or, is anyone familiar with EST’s programming language and how I could achieve the same syntax highlighting within Sublime?

Sorry if this post is somewhat vague. I am fairly new to the programming world and Edwards isn’t exactly looking to support this. I could certainly just use Jens File Editor, I just prefer not to.

0 Likes

#2

You don’t have to. ST supports .tmLanguage.

0 Likes

#3

You could create a EST3.sublime-syntax in your user folder with following content as a starting point, which implements the same behavior as the Notepad++ custom user language.

%YAML 1.2
---
# See http://www.sublimetext.com/docs/syntax.html
scope: source.est3

file_extensions:
  - est3
  - sdu

contexts:
  main:
    - include: comments
    - include: commands
    - include: parameters
    - include: punctuations
    - include: sections
    - include: strings

  comments:
    - match: \{
      scope: punctuation.definition.comment.begin.est3
      push: comment-body

  comment-body:
    - meta_scope: comment.block.est3
    - match: \}
      scope: punctuation.definition.comment.end.est3
      pop: 1

  sections:
    - match: \[
      scope: punctuation.definition.section.begin.est3
      push: section-body

  section-body:
    - meta_scope: meta.section.est3
    - meta_content_scope: entity.name.section.est3
    - match: \]
      scope: punctuation.definition.section.end.est3
      pop: 1

  commands:
    - match: |-
        (?xi:
          [-+]?ON | [-+]?OFF | ACTIVATE | \+?AMPON | -AMP | DELAYACTIVATE | DLY | MON
        | -?MSGOFF | \+?MSGON | DELAY | STEADY | DISABLE | FAST | TROUBLE | RLYCFG | TO
        )\b
      scope: keyword.control.est3
    - match: (?i:ALARM|Activation|SW)\b
      scope: keyword.control.est3

  parameters:
    - match: (?i:-HIGH|-low|nso|sup|visible|SMOKE|-SET|AUDIBLE|WATERFLOW|CMDLIST|HEAT)\b
      scope: variable.parameter.st3
    - match: \d+\b
      scope: constant.numeric.est3

  punctuations:
    - match: '[:;]'
      scope: punctuation.terminator.statement.est3
    - match: ','
      scope: punctuation.separator.comma.est3

  strings:
    - match: \'
      scope: punctuation.definition.string.begin.est3
      push: single-quoted-strings

  single-quoted-strings:
    - meta_scope: meta.string.est3 string.quoted.single.est3
    - match: \'
      scope: punctuation.definition.string.end.est3
      pop: 1
0 Likes

#4

That worked great! I’ll just look into adjusting my colors and I’m all set. Thanks a lot.

0 Likes