uhh once again my bodymind refuses to let me actually code, so let me dump some thoughts about the next stage of parser implementation
the fun stuff (limited context sensitivity)
background:
so there's the applicative structure, and then we let a parser be able to fail based on its result
(<*>) :: f (a -> b) -> f a -> f b and compact :: f (Maybe a) -> f a
so if a section of a parser can fail, we have to go through and actually compute whether it will return Just or Nothing
but most parts of a parser won't fail in this way, so we need to be smarter about how we encode it
(I'm in a weird bind where I refuse to let myself do the obvious but very inefficient routes)
we need to pull out the algebra of failure specifically, aside from computing the actual result of the parser
basically this creates segments where we need to apply the applicative computation,
these segments can overlap, in the case of compact (compact x <*> compact y), which can fail if the first or the second fail, or the whole combined parser fails
basically each piece of logic, CST -> Maybe Failure, needs to be tagged by referential identity, to avoid recomputing it a lot due to nondeterminism of the parser,
so the ingredients are:
- each rule gets potentially several deduplicated pieces of logic attached to subfragments, with [start,end] indices
- we need a way to advance it during the matching process; for now it will be an array of CST bits to feed in, but later it will actual be memoized in some way
so I guess this means it needs to be
data Options = Array
{ pName :: nt
, rName :: r
, rule :: Fragment (nt /\ Options) cat
, logicParts :: EqSet
{ start :: Int
, end :: Int
-- RefEq
, logic :: Array (CST nt r o) -> Boolean
}
, advanced :: Array (CST nt r o)
}
and then there's rules for how to advance the state, which I have mostly written out already, and for how to check whether it is failed, and so on
- if any
logicPartfails, thatOptionis filtered out - no options for a rule means that it cannot succeed
- if any
logicPartsucceeds whenlength advanced >= end, it is filtered out oflogicParts(since it will always succeed) - an option with no
logicPartsfor a rule means that it will always succeed- so other options for the same
(rule, advanced)can be dropped
- so other options for the same
