Sublime Forum

Syntax Definition for Hjson

#1

I’m trying to create a syntax definition for Hjson (details at http://hjson.org).

Sample:

{
  # commas and most quotes are optional:
  foo: 555
  bar: "text"
  database:
  {
    port: 555
    server: localhost
  }
}

It’s a superset of JSON (for config files), so I started with a copy of the JSON syntax.

One problem I ran into is that I can’t get Sublime to handle the case that commas are optional when there is a line feed. I looked at JSON’s

        - match: ":"
          scope: punctuation.separator.dictionary.key-value.json
          push:
            - meta_scope: meta.structure.dictionary.value.json
            - match: '(,)|(?=\})'
              captures:
                1: punctuation.separator.dictionary.pair.json
              pop: true
            - include: value
            - match: '[^\s,]'
              scope: invalid.illegal.expected-dictionary-separator.json

and tried to modify the match: '(,)|(?=\})' to something like match: '(,)|\n|(?=\})'. But that won’t work for the case in the database sample above since the objects opening { is on the next line.

My current non working version is here: http://github.com/laktak/sublime-hjson/blob/sl3/Hjson.sublime-syntax. Any tips are welcome!

1 Like

#2

you could change the - match: ":" to - match: ":\s*\n?" or something, to pick up the optional line feed there, if that will help?

0 Likes

#3

Thanks, that’s a cool idea! Works better than anything else I’ve tried.

0 Likes