[antlr-interest] Building syntax highlighters with ANTLR

Gerald Rosenberg gerald at certiv.net
Wed Apr 15 22:23:45 PDT 2009


Looked like you were trying to discern the true extent of a comment, 
which is just a delimited block.  That is what a pair matcher 
does.  My specific application is different, but the technique is the same.

At 10:06 PM 4/15/2009, Sam Harwell wrote:
>It looks like we are working towards two very different goals. I'm 
>not trying to do any parsing, block structure analysis, pair 
>matching, etc. I'm just trying to color comments, identifiers, 
>keywords, etc with individual colors.
>
>Sam
>
>From: antlr-interest-bounces at antlr.org 
>[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Gerald Rosenberg
>Sent: Wednesday, April 15, 2009 11:29 PM
>To: antlr-interest at antlr.org
>Subject: Re: [antlr-interest] Building syntax highlighters with ANTLR
>
>A better approach is to use a predicate.  That way you don't have to 
>intercept every lexer token and makes it considerably easier to 
>handle multiple pair sets.
>
>@lexer ::members {
>   public boolean pairMatch(int limit) {
>     return PairMatcherHelper.pairMatch(input, limit);
>   }
>   public boolean pairMatch(int limit, char beg, char end) {
>     return PairMatcherHelper.pairMatch(input, limit, beg, end);
>   }
>}
>
>BRACE_BLOCK :'{' { pairMatch(200) }? ;
>BRACKET_BLOCK :'[' { pairMatch(50, '[', ']') }? ;
>
>PairMatcherHelper#pairMatch then does full nested pair matching, 
>subject to certain limitations.  Does respect Antlr's backtracking semantics.
>
>Note, the attached version is set up for just for single char delimiters.
>
>
>
>
>At 10:56 AM 4/15/2009, Sam Harwell wrote:
>
>
>The new method uses a very different override of NextToken(). The 
>outer loop is largely a duplication of the functionality of 
>Lexer.NextToken(). I've highlighted the key section that reliably 
>manages the lexer state information (yay HTML email).
>
>public override IToken NextToken()
>{
>     for ( ; ; )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090415/164bda6b/attachment.html 


More information about the antlr-interest mailing list