There in a data stream are two packets. Each has the header followed by some binary data with unknown length, until another header is found, or EOF is reached. Here is the data: HDR12HDR345 HDR is the header marker 12 and 345 are the binary data.
And here is my current wrong grammar:
grammar TEST;
parse : STREAM EOF;
STREAM : PACKET*;
PACKET : HEADER DATA;
HEADER : 'HDR';
DATA : .*;
The first header token is recognized, but the data token is too long and it consumes the next header and data.
After three days of looking for the solution I did not found any, which matches both, "binary data" and "unknown length" aspects. But stil I think that this must be some common scenario for parsing. ANTLR is not as easy as it looks like for the first sight :(
Thanks for any help or suggestions.