How to do recursion?
Opened this issue · 0 comments
JohnLCaron commented
Im failing to do recursion:
val group : Parser<OdlStruct> by (groupStart and zeroOrMore(group) and groupEnd).map { // line 58
(name1 : String, nested : List<OdlStruct>, name2 : String ) ->
val result = OdlStruct(name1)
result.nested.addAll(nested)
result
}
on input like:
GROUP=SwathStructure
GROUP=SWATH_1
GROUP=Dimension
END_GROUP=Dimension
...
END_GROUP=SWATH_1
END_GROUP=SwathStructure
I get error:
Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method com.github.h0tk3y.betterParse.grammar.Grammar.getValue, parameter <this>
at com.github.h0tk3y.betterParse.grammar.Grammar.getValue(Grammar.kt)
at com.sunya.netchdf.parser.OdlParser.getGroup(OdlParser.kt:58)
at com.sunya.netchdf.parser.OdlParser.<clinit>(OdlParser.kt:58)
presumably from "zeroOrMore(group)"
I guess I need a to instantiate a new Parser instead of trying to reference the group(?), but im stymied how to do that.
Maybe something simple Im missing?
Thanks for your help and the cool library.