[antlr-interest] Visual Studio syntax highlighting for an
Antlrgrammar
Micheal J
open.zone at virgin.net
Mon Dec 5 09:58:26 PST 2005
> One disadvantage of Babel is that it's old-skool C++.
> However, Visual
> Studio 2005 expands this API with managed wrappers enabling an entire
> language service to be implemented in C#. (The C# classes
> lack flex/bison
> integration however.)
There are C# ports of CUP and JFlex. And there is also the similar CSTools
suite and Mono's Jay/C#+flex port too. All will allow flex/bison-like
grammars to be used with a few changes with C#.
I've just added a "%antlr" mode to C# Flex in fact to make csflex->ANTLR
integration easier. Needs testing. Sowhatdoyousay?... ;-)
> The required
> C# interface looks like this:
>
> void IScanner.SetSource(string source, int offset);
> bool IScanner.ScanTokenAndProvideInfoAboutIt(TokenInfo tokenInfo,
> ref int state);
>
> The idea is that the editor passes a single line of text to
> SetSource(),
> and then calls ScanTokenAndProvideInfoAboutIt() repeatedly to
> obtain the
> colored tokens for that line. In this situation, the only context
> available to the lexer is a single "state" integer (which for
> Babel stores
> flex's "yy_start" global variable). Unfortunately, since Antlr is a
> recursive descent design, there isn't an obvious way to
> restart the lexer
> e.g. in the middle of a multiline comment. Has anyone else
> dealt with this
> problem before?
I think Bodgan Mitu did. And the ANTLRStudio guy too I would guess (if he
indeed uses ANTLR for his lexing/parsing).
> More generally, has anyone implemented a Visual Studio
> language service
> using an Antlr grammar? Or, is it difficult to port an Antlr
> grammar to
> flex/bison? :-)
I'm no flex/bison expert but, I shouldn't think so as long as you aren't
using too much of the cool technology in ANTLR (e.g. sempreds).
Micheal
More information about the antlr-interest
mailing list