luserdroog
2021-11-14 04:54:08 UTC
Is there a systematic way to discard the extra noise that can occur
when using parser combinators? For example, the `many` combinator
which matches zero or more instances of its argument parser.
In the case of zero matches, it still needs to return a value.
In my situation, I'm simulating everything in PostScript because it's
my favorite language. I'm simulating Lisp cons cells as 2-element
arrays. So for this JSON string,
( [ 3, [ 4, [ 5 ] ] ] ) JSON-parse report
if I make no special effort, I get a resulting value that looks like this:
OK
[[3 [[4 [[5 [[] []]] []]] []]] []]
remainder:[]
All those little empty arrays need to just go away, but not any of the
important array structure. `many` and `maybe` seem to be the chief
culprits, but then their results are propagated back by `alt`s and
`then`s all the way back to the top.
Do I need to make some kind of out-of-band signal for these "zeros"
that I can filter out later? The obvious problem here is that the array
type is being used for too many things. But there's a paucity of
types in PostScript, sigh. For the JSON application, I have nametype
objects available that don't have a JSON corollary.
Do I need to rewrite all the combinators to filter out noise values at
every turn?.
when using parser combinators? For example, the `many` combinator
which matches zero or more instances of its argument parser.
In the case of zero matches, it still needs to return a value.
In my situation, I'm simulating everything in PostScript because it's
my favorite language. I'm simulating Lisp cons cells as 2-element
arrays. So for this JSON string,
( [ 3, [ 4, [ 5 ] ] ] ) JSON-parse report
if I make no special effort, I get a resulting value that looks like this:
OK
[[3 [[4 [[5 [[] []]] []]] []]] []]
remainder:[]
All those little empty arrays need to just go away, but not any of the
important array structure. `many` and `maybe` seem to be the chief
culprits, but then their results are propagated back by `alt`s and
`then`s all the way back to the top.
Do I need to make some kind of out-of-band signal for these "zeros"
that I can filter out later? The obvious problem here is that the array
type is being used for too many things. But there's a paucity of
types in PostScript, sigh. For the JSON application, I have nametype
objects available that don't have a JSON corollary.
Do I need to rewrite all the combinators to filter out noise values at
every turn?.