vendredi 3 février 2017

Perl6: Convert Match object to JSON-serializable hash

I am currently gettin' my hands dirty on some Perl6. Specifically I am trying to write a Fortran parser based on grammars (the Fortran::Grammar module)

For testing purposes, I would like to have the possiblity to convert a Match object into a JSON-serializable Hash.

Googling / official Perl6 documentation didn't help. My apologies if I overlooked something.

My attempts so far:

  • I know that one can convert a Match $m to a Hash via $m.hash. But this keeps nested Match objects.
  • Since this just has to be solvable via recursion, I tried but gave up in favor of asking first for the existance of a simpler/existing solution here
  • Dealing with Match objects' contents is obviously best accomplished via make/made. I would love to have a super simple Actions object to hand to .parse with a default method for all matches that basically just does a make $/.hash or something the like. I just have no idea on how to specify a default method.

Aucun commentaire:

Enregistrer un commentaire