Hi guys and gals,
I need help solving this problem so I hope you can help :)
I would like to have grammar that would have it's structure strictly defined, but part of the structure should not be parsed by my grammar but put into some sort of a buffer (string) for later use.
My grammar looks like this:
grammar RSL;
rsl: sectionStructs? sectionProgram;
sectionProgram: 'section' 'program' '{' '}';
sectionStructs: 'section' 'structs' '{' structDef+ '}';
sectionName: ID;
structDef: 'struct' ID '{' varDef+ '}' ';';
varDef: ID ID ';';
ID: [a-zA-Z_][a-zA-Z_\-0-9]*;
WS : [ \t\r\n\u000C]+ -> skip
;
COMMENT
: '/*' .*? '*/' -> skip
;
LINE_COMMENT
: '//' ~[\r\n]* -> skip
;
And my wish is to have this sort of parsing going on:
section structs {
struct TestStruct {
int var1;
float var2;
...
};
struct Struct2 {
int var1;
...
};
}
section program {
// Do not parse anything that would be in this section
// just store it in a buffer for later use.
}
So all contents of section program should be stored in a string for a later use and no grammar rules should apply to program.
What is the best way of approaching this problem?
Thanks!