Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabling CoffeeScript lexer in SciTE?

I noticed there is a LexCoffeeScript.cxx file in the SciTE source code; however, SciTE does not seem to have a CoffeeScript menu option in its Languages menu.

Adding the option manually doesn't help -- there still isn't any syntax coloring.

Is there any way to enable the built-in lexer (instead of resorting to an external one)?

like image 466
user541686 Avatar asked Jan 10 '12 16:01

user541686


2 Answers

Apparently, the CoffeeScript lexer is compiled in Scintilla but not used by SciTE. I mean that there is no coffeescript.properties file or any other file that would refer to the lexer. You cat try to create your own and set the lexer for file extension you use to coffeescript:

# Define SciTE settings for Coffeescript files.
file.patterns.coffeescript=*.coffee
filter.coffeescript=Coffeescript (coffee)|$(file.patterns.coffeescript)|
lexer.$(file.patterns.coffeescript)=coffeescript
...

Then you would define keywords, coloring styles and other stuff supported by the lexer - check out its sources. You can get inspiration in cpp.properties, e.g. (The lexer for C/C++ and similar languages is called cpp.) Here are supported lexical states:

val SCE_COFFEESCRIPT_DEFAULT=0
val SCE_COFFEESCRIPT_COMMENT=1
val SCE_COFFEESCRIPT_COMMENTLINE=2
val SCE_COFFEESCRIPT_COMMENTDOC=3
val SCE_COFFEESCRIPT_NUMBER=4
val SCE_COFFEESCRIPT_WORD=5
val SCE_COFFEESCRIPT_STRING=6
val SCE_COFFEESCRIPT_CHARACTER=7
val SCE_COFFEESCRIPT_UUID=8
val SCE_COFFEESCRIPT_PREPROCESSOR=9
val SCE_COFFEESCRIPT_OPERATOR=10
val SCE_COFFEESCRIPT_IDENTIFIER=11
val SCE_COFFEESCRIPT_STRINGEOL=12
val SCE_COFFEESCRIPT_VERBATIM=13
val SCE_COFFEESCRIPT_REGEX=14
val SCE_COFFEESCRIPT_COMMENTLINEDOC=15
val SCE_COFFEESCRIPT_WORD2=16
val SCE_COFFEESCRIPT_COMMENTDOCKEYWORD=17
val SCE_COFFEESCRIPT_COMMENTDOCKEYWORDERROR=18
val SCE_COFFEESCRIPT_GLOBALCLASS=19
val SCE_COFFEESCRIPT_STRINGRAW=20
val SCE_COFFEESCRIPT_TRIPLEVERBATIM=21
val SCE_COFFEESCRIPT_HASHQUOTEDSTRING=22
val SCE_COFFEESCRIPT_COMMENTBLOCK=22
val SCE_COFFEESCRIPT_VERBOSE_REGEX=23
val SCE_COFFEESCRIPT_VERBOSE_REGEX_COMMENT=24

All .properties files are loaded automatically by the line import * from SciTEGlobal.properties. You can also add Coffeescript|coffee||\ to menu.language to get a new menu item in Languages and/or *.coffee to source.files to see the extnsion in the File Open dialog.

It is strange that the author did not provide the .properties file with the lexer. It can be that the JavaScript lexer can be used instead. You could ask about it in the SciTE mailing list.

--- Ferda

like image 93
Ferdinand Prantl Avatar answered Sep 23 '22 14:09

Ferdinand Prantl


Ferda's answer is right on.

Here is a sample coffeescript.properties file to get started and save you some time...

# Define SciTE settings for Coffeescript files.
file.patterns.coffeescript=*.coffee
filter.coffeescript=Coffeescript (coffee)|$(file.patterns.coffeescript)|
lexer.$(file.patterns.coffeescript)=coffeescript

keywordclass.coffeescript=abstract boolean break byte case catch char class \
const continue debugger default delete do double else enum export extends \
final finally float for function goto if implements import in instanceof \
int interface long native new package private protected public \
return short static super switch synchronized this throw throws \
transient try typeof var void volatile while with
keywords.$(file.patterns.coffeescript)=$(keywordclass.coffeescript)

keywordclass2.coffeescript=$
keywords2.$(file.patterns.coffeescript)=$(keywordclass2.coffeescript)

# White space 
style.coffeescript.0=fore:#808080
# Comment: ### ###
style.coffeescript.1=$(colour.code.comment.box),$(font.code.comment.box)
# Line Comment: #
style.coffeescript.2=$(colour.code.comment.line),$(font.code.comment.line)
# Doc comment: block comments beginning with /** or /*!
style.coffeescript.3=$(colour.code.comment.doc),$(font.code.comment.doc)
# Number
style.coffeescript.4=$(colour.number)
# Keyword
style.coffeescript.5=$(colour.keyword),bold
# Double quoted string
style.coffeescript.6=$(colour.string)
# Single quoted string
style.coffeescript.7=$(colour.char)
# UUIDs (only in IDL)
style.coffeescript.8=fore:#804080
# Preprocessor
style.coffeescript.9=$(colour.preproc)
# Operators
style.coffeescript.10=fore:#FF6600,bold
# Identifiers
style.coffeescript.11=fore:#FF1493
# End of line where string is not closed
style.coffeescript.12=fore:#000000,$(font.monospace),back:#E0C0E0,eolfilled
# Verbatim strings 
style.coffeescript.13=fore:#007F00,$(font.monospace),back:#E0FFE0,eolfilled
# Regular expressions for JavaScript
style.coffeescript.14=fore:#3F7F3F,$(font.monospace),back:#E0F0FF,eolfilled
# Doc Comment Line: line comments beginning with /// or //!.
style.coffeescript.15=$(colour.code.comment.doc),$(font.code.comment.doc)
# Keywords2
style.coffeescript.16=fore:#B00040
# Comment keyword
style.coffeescript.17=fore:#3060A0,$(font.code.comment.doc)
# Comment keyword error
style.coffeescript.18=fore:#804020,$(font.code.comment.doc)
# Raw strings 
style.coffeescript.20=$(colour.string),back:#FFF3FF,eolfilled
# Triple-quoted strings
style.coffeescript.21=$(font.monospace),fore:#007F00,back:#E0FFE0,eolfilled
# Hash-quoted strings for Pike
style.coffeescript.22=$(font.monospace),fore:#007F00,back:#E7FFD7,eolfilled
# Verbose Regex
style.coffeescript.23=fore:#659900
# Verbose Regex Comment
style.coffeescript.24=$(colour.code.comment.doc)
like image 41
ruffbytes Avatar answered Sep 19 '22 14:09

ruffbytes