0
votes

I'm parsing a stream with record fragments that are always sequential, but not always consecutive, e.g., in the example below line 1 and 3 are part of the same record and while line 1 will always come before line 3 it is possible to get an entirely unrelated line between them, in this case line 2, which parenthetically needs to be matched up with line 4.

1: [[aaaa
2: [[bbbb
3: aaaa]]
4: bbbb]]

If there is deterministic way to match the record fragments, could ANTLR handle this kind of fragmentation? If so, what would the grammar look like?

1
If there is a deterministic lexical procedure to reshuffle the input, then you could use it to build a front-end filter which feeds the corrected input into your parser. If you are thinking of building a grammar which accepts intermingled input, then the answer is probably "no", but it would be useful to see a more precise problem statement.rici
Thanks @rici, What do you mean by lexical procedure?rbinnun

1 Answers

1
votes

No, this is not possible (and I wonder if that is even desirable, given that you cannot match start and stop parts of intermingled input in an arbitrarily deep source nesting). Input is always processed as it comes from the input stream. You could of course fake the input by feeding in different parts of the source on certain conditions. But that would require to preprocess the input to a level that is almost the same as the following parsing stage.