I have a tricky question (at least in my perspective), regarding Scalas parser combinators and recursive parsing. I currently building a small parser which should be able to parse PL/1 structures like this:
dcl 1 data,
3 subData,
5 tmp char(15),
5 tmp1 char(15),
3 subData2,
5 tmp2 char(10),
5 tmp3 char(5);
In this scenario I want to build a AST as follows:
Record(data) -> (Record(subData),Record(subData2))
Record(subData) -> (Char(tmp),Char(tmp1))
Record(subData2) -> (Char(tmp2),Char(tmp3))
Meaning that the parent element should be connected to its children. In my world this should result in a recursive parser in some way, however my problem is how to control when to stop going down in sublevels. For instance when parsing the the "3 subdata" record structure, it should stop when hitting a level number which is not lower in itself, in this case the line "3 subData2,".
Can someone help with this issue, or point me in a good direction. My current solution is to solved this problem after I have parsed an unconnected structure.
Thanks in advance.
Regards Stefan