better-parse icon indicating copy to clipboard operation
better-parse copied to clipboard

How to do recursion?

Open JohnLCaron opened this issue 3 years ago • 0 comments

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<OdlStruct> 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.

JohnLCaron avatar Mar 12 '23 18:03 JohnLCaron