[antlr-interest] How I do... ? with lexer only rules.
Felix A.A.
felixaa at ono.com
Sat Jul 28 13:39:11 PDT 2012
Hello!
I'm trying to implement a simple parsing over custom .c files with added
syntax.
Ex: test.c
.
// I don't need this in output
int func1(int a, int b);
//I need this.
@parseme int func2(int a, int b);
//and this .
@parseme
void func3()
{
Int a;
//put here where ever
.
{
//inside block
}
return;
}
.
I want to use a fuzzy parsing approach on the lexer phase then, on the
parser rules, rewrite token with TokenRewriteStream and templates.
Well it's a lexer piece .
lexer grammar Lexi;
options {filter = true;}
// Pick everything between @parseme and ';' or '{ }'
METHOD
: HEADER .* (';' | BODY )
;
fragment
HEADER
: '@' ('parseme' | 'PARSEME') ;
fragment
BODY: '{' .* '}' ;
.
.
The problem is simple for a expert look:
1- Lexer stop parse when found ';' before to reach the last '}' on "
@parseme void func3() .. "
2- Lexer stop parse when found inside block right curly.
3- And surely more cases don't tested yet.
The problem is really obvious. Is the solution too?? I hope soo !! J
Thanks to all and good work!! with ANTLR.
More information about the antlr-interest
mailing list