Overriding styles set by a lexer

100 views
Skip to first unread message

Teodor Petrov

unread,
May 8, 2017, 12:51:06 PM5/8/17
to scintilla...@googlegroups.com
Hello,

I want to improve the Code::Blocks' disassembly window. This window is
using Scintilla and the Asm Lexer to display the disassembly information
provided by the debugger. There is a mode (called mixed mode) that tells
the debugger that we want to see both the assembly and the original
source code of the program (c/c++ in our case). Unfortunately the source
code is lexed as though it is written in assembly language. This looks
rather bad and confusing.

I want to somehow change the style of the source code. I think the least
confusing for our users is if we treat these lines as comments
(SCE_ASM_COMMENT). The information whether a line is asm or source
code is stored outside of scintilla, in an array.

Is it possible to call a lexer with a custom start:end positions from a
SCN_STYLENEEDED event?

Best regards,
Teodor

Neil Hodgson

unread,
May 8, 2017, 7:24:57 PM5/8/17
to scintilla...@googlegroups.com
Teodor Petrov:

> I want to somehow change the style of the source code. I think the least
> confusing for our users is if we treat these lines as comments
> (SCE_ASM_COMMENT). The information whether a line is asm or source
> code is stored outside of scintilla, in an array.
>
> Is it possible to call a lexer with a custom start:end positions from a
> SCN_STYLENEEDED event?

Lexers may treat the start and end positions as suggestions as they may want to move the start back to the beginning of some feature. You could examine the assembler lexers to see if they do anything like this.

It sounds like this is a read-only view so the C/C++ lines could have a comment indicator character (‘;’ or ‘#’) added. An alternative would be to add an invisible character (like ZWSP) and treat that as a comment in the assembler lexer.

For higher quality styling, the lexing of the C/C++ and assembler could be separated by using 3 documents - one containing the C/C++, another containing the assembler, and another with the combined text. The C/C++ and assembler documents are styled in hidden Scintilla instances (either one for each document or a single instance with documents selected into it for lexing). The combined document has its styles set by merging the styles from the language-specific documents. The merger would have to assign separate style number ranges to the 2 languages.

Neil

Reply all
Reply to author
Forward
0 new messages