Sublime Forum

Beginner syntax highlighting question (symbols, extending)

#1

Wonder if anyone could answer a few questions? Looking to create a syntax highlighter for CSS that is more permissive of an extended (Sass-like) syntax. The file format of the files will remain as .css but it will allow for nesting, variables and the like.

A typical code rule might look like this:

.hd-Nav_Wrapper { display: flex; padding-top: $size-half; min-height: 150vh; transition: transform .5s cubic-bezier(0.68, -0.55, 0.265, 1.55); z-index: 10; &[aria-expanded="true"] { transform: translate3d(-30%, 0, 0); } @media (min-width: $XM) { flex-direction: row; flex: 1 0 100%; padding: 0 $size-half; } }

Obviously the default Sublime CSS parser chokes on this syntax and fails to generate symbols (for ‘find in project’).

Q. Can a sublime-syntax plugin also set new symbol definitions? So that once a user selected the new language Sublime would be able to index symbols within the files (despite the files still having a *.css extension)?

0 Likes

#2

A .sublime-syntax can only tag the codes with scopes.
To detect the symbols, you have to create .tmPreferences files that say which scopes correspond to symbol declaration.

Have a look at https://github.com/gwenzek/scalaSublimeSyntax.
My .sublime-syntax is used by Sublime to tag the code, while the scala-symbol-class.tmPreferences tells that the scope “meta.class.identifier” is a symbol declaration.

0 Likes

#3

Thanks gwensek, I’ll take a look at that. Appreciate it!

0 Likes

#4

Here some links to the TextMate Manual. Syntax Highlighting in ST works with this rules.
http://manual.macromates.com/en/language_grammars.html
http://manual.macromates.com/en/scope_selectors
http://manual.macromates.com/en/regular_expressions#syntax_oniguruma

0 Likes

#5

[quote=“BugFix”]Here some links to the TextMate Manual. Syntax Highlighting in ST works with this rules.
http://manual.macromates.com/en/language_grammars.html[/quote]

Since build 3084 Sublime has a new format for syntax file which is more powerful.
https://www.sublimetext.com/docs/3/syntax.html

If you intend to create a new plugin I’d recommend to use it.

0 Likes

#6

docs.sublimetext.info/en/latest/ … mbols.html

0 Likes

#7

Thanks for the additional info. I’ll definitely have a go with the new format. :smile:

0 Likes