From: Lucas D. <ld...@in...> - 2009-10-02 18:11:39
|
Shlomy Reinstein wrote: > Thanks for the input. Note that my usage of parser generators is for a > completely different purpose. > As you know, syntax highlighting and indentation in jedit are > specified using special-syntax "mode files", and are handled in a very > complex way inside the core. Replacing these with a generated parser > requires changing about half of jEdit... I was more thinking of ways to compile more general grammars into the internal machinery of jEdit (which I know very little about). The current mode-language is not expressive enough to describe the syntax of languages I work with (Standard ML mostly). I'm not sure if this is a limit of the internal machinery of jEdit, or if it is just a limit of the mode language. This is something I've been meaning to figure out for a while, but not quite got round to. > A long time ago I used to think that all editors that offer syntax > highlighting use some grammar files for specifying the grammar of each > mode. I was very surprised (a long time ago) to find that this is not > the case, and in fact each editor has its own custom way of specifying > how to syntax highlight the text and how to auto-indent. > > It took me a while to realize that using a generated parser is not > good enough due to the limitations of such grammars. You cannot parse > a small part of the code (e.g. a single modified line) and update the > data structures accordingly, which is what an editor does on each > change of the text. jEdit maintains the token & parse information of > each line in some cache, and its sophisticated rule handling only > needs to do little work each time (most of the time). Parsing the > entire text of the buffer on each change is not acceptable > (performance wise), though maybe some time in the future it will be > acceptable... > > I am not very familiar with the syntax coloring and indentation in > jEdit, but I'll be glad to share what I do know. Thanks, even that high level view is useful to me. :) I also was naively thinking that general purpose grammars should work out - perhaps interestingly, I've done a little work on composable grammars - this machinery was intended to work with a general grammar's parse tree, so that is can be updated from text anywhere in the string, rather than just at the start - also aiming for text which be edited anywhere and for the parse tree to be updated in a minimal fashion. I should write that up... and maybe also read more about other approaches - any suggested reading? In the meantime, is there is a way to write a mode purely in java, without going through the compilation machinery of a mode file, so that I might have a look at writing my own special syntax highlighter and indentation? I guess I'm wondering what events the syntax highlighter has to respond to, and similarly for indentation, and what functions I might be able to re-use to simply tell jedit what colour to use for what chunks of text... as I write this, I'm starting to think this might be a lot of work... any suggestions and comments would be very welcome, best, lucas -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336. |