I found it a bit daunting when i started with my lexer but everything boils down to a few important ideas:
- Put lexer in lexer folder
- Tell scintilla about the lexer you added
- Add your constants to scintilla.iface
- Tell scintilla about your own Constants (if you use any)
- Code/Compile + Repeat until satisfied
An actual example is:
After you create your Lexer Template you name it LexNEW.cxx
- Put LexNew.cxx in
/lexers
folder
- Enter in
/src
and run LexGen.py
, this tells scintilla that there is a new lexer by adding it to Scintilla.h
Now you add your constants to the .iface file. The most important ones are: val SCLEX_NEW=108
where 108
is an unused id number and lex new=SCLEX_NEW SCE_NEW_
where new
is a valid unique short identifier for your lexer.
Put them in the same sections as the others (to avoid confusion later on) and if in doubt use one of the other definitions as a template!
Now below your lex new=
line you can define your own constant values like:
val SCE_NEW_DEFAULT=0
val SCE_NEW_COMMENTLINE=1
val SCE_NEW_COMMENTBLOCK=2
val SCE_NEW_ERROR=31
After this step you are almost ready.
- Enter in
/include
and run Hface.py
which tells scintilla about your new constants.
If your lex code is valid then you are ready to compile.
Remember to repeat that last step every time you create a new constant. The HFace.py
script adds those values to SciLexer.h which you can do manually if you prefer not to do two steps every time.
And thats it my friend after compiled make sure your program sets your lexer with something like: sci.SetLexer(108)
and put some colors to each state like sci.StyleSetFore(01, 0x008800) // SCE_NEW_COMMENTLINE
and so on.
One last thing you will want to use SciLexer.dll
which is the one that contains all lexers not scintilla.dll
Good luck!