[antlr-interest] Beginner problem

José María García Rodríguez darthia at gmail.com
Mon Sep 5 03:21:01 PDT 2005


It seems that you are using a lexer to parse your code blocks. I think
the way to do what you want is to use a lexer that recognise your
tokens (i.e. "<%", "%>" and any other string) and then a parser where
you put the rules to separate the code blocks from text ones.

Please read the docs carefully, and feel free to ask if you have more
questions :)

Regards

-- 
José María García Rodríguez 


2005/9/5, Ayende Rahien <Ayende at ayende.com>:
>  
>  
> 
> First, I'm a complete beginner in both antlr and parsing. 
> 
> Second, I want to build a pre processor that would recognize the following: 
> 
>   
> 
> Code block: anything inside a <% %> 
> 
> Text block: anything else. 
> 
>   
> 
> The idea is to transform the input to so the <% %> would be gone and the
> text would be properly set in: 
> 
> output "text" 
> 
>   
> 
> My (naïve) start is: 
> 
>   
> 
> CODE_BLOCK 
> 
>             :           CODE_START TEXT_BLOCK CODE_END 
> 
>             ; 
> 
>             
> 
> CODE_START 
> 
>             :           "<%" 
> 
>             ; 
> 
>   
> 
> CODE_END 
> 
>             :           "%>" 
> 
>             ; 
> 
>   
> 
> TEXT_BLOCK 
> 
>             :           ~("<%") 
> 
>             ; 
> 
>   
> 
> This fails, but I'm not sure how I can fix this. I read some of the
> documentation on the site, and I'm afraid I can't see a solution. 
> 
> (I know that it's very easy to do this with custom code, but the idea is
> that the moment I've code block and text blocks, I can start transforming
> them by more complex rules.)


More information about the antlr-interest mailing list