I don't have any concrete proposal to make, but the general idea is to provide some way for the application to install callbacks that the lexers can access at the point where they classify identifiers as keywords. For example, the IDocument interface could be extended to provide a list of KeywordProvider (or similar) objects to the lexers. Then all of the lexers would have to be modified to take advantage of this feature, but I don't see any way around that.
So the question (mostly for Neil), is there any interest in a feature like this for scintilla?
Jason
> We implemented this by hacking scintilla to style the document with
> a lexer and *also* deliver style notifications as if it were styled by the
> container. So the lexer first styles a range and then the application
> restyles the same range changing the style of identifiers as needed.
Glbthnrrk!
> I don't have any concrete proposal to make, but the general idea is
> to provide some way for the application to install callbacks that the
> lexers can access at the point where they classify identifiers as keywords.
I've been thinking about moving in the opposite direction - making
lexers more isolated for a couple of scenarios. They are performing
lexing in separate threads or in sandboxed processes. Sandboxing is
becoming more common in OS X 10.7 and Windows 8 and would diminish the
potential for security problems with Scintilla lexers by isolating
them into processes with very restricted capabilities. As
cross-process calls are slow, there would be a need to improve the
caching of the state produced by the lexer and folder so that it was
all returned to the application at the completion of each range.
Calling back to the application to determine the keyword status of
each identifier would be expensive in this situation compared to
keyword classifiers that can be implemented inside the sandbox
process.
Neil
Okay, I agree that the lexers calling back into application code isn't ideal for a number of reasons (stability, performance, etc.), but it's the best that I could come up with for this situation. Do you have any suggestion for how we can implement this kind of dynamic keyword classification in a more principled manner?
Thanks,
Jason
> Okay, I agree that the lexers calling back into application code
> isn't ideal for a number of reasons (stability, performance, etc.),
> but it's the best that I could come up with for this situation.
I don't want to close the door completely but there are competing
directions here.
> Do you have any suggestion for how we can implement this kind
> of dynamic keyword classification in a more principled manner?
In many cases, it is possible to dynamically compile word lists
from the database and use the existing functionality. You'll probably
now tell me that this is too slow for your situation.
Neil
namespace foo {
class foo {
foo(int foo);
};
}
In many cases, it is possible to dynamically compile word lists
from the database and use the existing functionality. You'll probably
now tell me that this is too slow for your situation.It's not even that it's too slow, it just doesn't work. Different entity kinds can share the same name. Consider this snippet as styled by understand:namespace foo {
class foo {
foo(int foo);
};
}Each occurrence of foo should have a different style. For this to work the callback would certainly have to provide the document position (or line and column) in addition to the identifier.
It would be better to treat this as an experimental branch.
ILexer::PrivateCall can be used to implement arbitrary application to
lexer communication. Pass your KeywordProvider pointer through
PrivateCall then call it when needed. There will probably be three
code insertions into each object-based lexer for classifying one form
of word: declaration of KeywordProvider; implementation of PrivateCall
to set; and a call inside word classification code. It should not take
all that much work to write the code then create a set of patches that
can be reapplied if the upstream lexers change.
The diversity of keyword handling in current lexers due to the
semantic importance of some keywords and keyword-like things (such as
string type prefixes) may make it impossible to write a completely
automatic patching script.
Publishing your derived lexers would then allow others to experiment.
Neil
Interesting, I never noticed PrivateCall before. I may try this. It would certainly be less horrible than the current hack. My only concern is that it might be even more difficult to maintain going forward. Thanks,
Jason