Sublime Forum

Syntax Creation

#1

Hallo,

I’m trying to write my one syntax to highlighting in a personalized way doxygen lines.
I created the file “doxygen_comments.sublime-syntax” and added it to my Packages/User dir.
The file is the following

%YAML 1.2

file_extensions: [c, h]
scope: doxygen.comments.c

contexts:
main:
# Comments begin with a ‘//!’ or ‘///’ and finish at the end of the line.
- match: \b(///||//!)
scope: doxygen.comments.line.c
push:
- meta_scope: doxygen.comments.line.end.c
- match: $\n?
pop: true

I then tried to add

    {
        "scope": "doxygen.comments",
        "foreground": "var(red)"
    }

into my Monokai.sublime-color-scheme but no changes are applied to the code, even changing the match pattern.
I’m surely doing sth wrong but I cannot pinpoint the error.
My sublime build is 3176

thanks

0 Likes

#2

Guess it’s not that easy.

A sublime-syntax file is meant to define the structure of the whole language such as C but not only parts of it. If you assign your syntax definition to C files, you’d need to provide rules for any language element such as keywords, strings, etc.

In order to add support for custom comments, you’d need to extract the C.sublime-syntax from the Packages/C.sublime-syntax via “View Package Resource” command, save it to your User package and modify it in order to add the comments.

But doing so would cause you never to see updates on the original syntax definition anymore.

There is no simple solution to inject pieces of rules into existing syntax definitions.

0 Likes

#3

Ok, thanks for the reply!
I think it is only a short modification so it would be not a big deal to re-add it to the new C.sublime-syntax after every update.

Thanks again!

0 Likes

#4
0 Likes

#5

Just as an obligatory note on this, you can install OverrideAudit to get warnings whenever a file you’re overriding has been altered by it’s author as an extra safety net so that you don’t have to rely on your memory when updates happen.

0 Likes