On 03/06/2020 13:02, Michel Sauvard wrote:
> Hello
> For different lexers, have you seen my answer?
> Best regards
>
[snip]
>>
>
Hi Michel!
Actually I only skimmed on it, since I was still gathering information
on how to write a Lexer and some of the things you said still didn't
make any sense for me, since I hadn't studied the topic deeply.
I was waiting for Neil to answer my doubts before getting a prototype
working and answering your post.
Moreover I've quite a tight schedule at work - nothing Lua or SciTE
related - so this is something I'm researching on my free time.
From what I understand, given what Neil has just told me in his post,
changing OnStyle once your Lua engine is loaded is a recipe for
disasters, since OnStyle is called so frequently and unpredictably.
That was one of the reasons why I asked Neil about it.
Moreover I think SciTE is a multithreaded application (at least I
observed sometimes it spawns threads on Windows). So there might be
concurrency issues by changing a callback like OnStyle while the script
is running (but I'm just guessing).
I think the best strategy would be to have a piece of code at the
beginning of OnStyle that selects different "lexing engines" according
to props['Language'].
It could be a simple if-elseif chain if you must discriminate among only
a few lexers. Perhaps a more general approach would be something like
(completely untested):
local lexer_engines = {}
lexer_engine.script_zog = function(styler) ... end
lexer_engine.script_asm = function(styler) ... end
lexer_engine.script_c = function(styler) ... end
function OnStyle( styler )
local lang = props['Language']
-- Dispatch to the right implementation
local engine = lexer_engines[ lang ]
if engine then
engine( styler )
else
-- ignore unsupported language or raise error
end
end
This, at least, will be my first approach when I get some time to
actually work on this.
Cheers!
-- Lorenzo