parsing - Monadic parse with uu-parsinglib -
i'm trying create monadic parser using uu_parsinglib. thought had covered, i'm getting unexpected results in testing
a cut down example of parser is:
ptype :: parser asttype ptype = addlength 0 $ (amb n_list) <- pname let r_list = filter attributefilter n_list case r_list of (astname_idname : [] ) -> return (asttype a) (astname_typename : [] ) -> return (asttype a) _ -> pfail namefilter :: astname' -> bool namefilter = case of (astname_idname _) -> true (astname_typename _) -> true _ -> false data asttype = asttype astname data astname = amb [astname'] data astname' = astname_idname astname astname_typename astname astname_othername astname astname_simple string pname ambiguous parser. want type parser apply post filter, , return alternatives satisfy namefilter, wrapped asttype.
if there none, should fail.
(i realise example i've given fail if there more 1 valid match in list, example serves purpose)
now, works far can see. problem lies when use in more complicated grammars, odd matches seem occur. suspect problem addlength 0 part
what separate out monadic , applicative parts. create monadic parser filtering component, , apply pname using <**> operator.
alternatively
i'd settle explanation of addlength doing.
i've put fudge/workaround use monadic parsing uu-parsinglib. way ever use monadic parsers analysis overly generous initial parser, , selectively fail results.
bind' :: parser -> (a -> parser b) -> parser b bind' a@(p _ _ _ l') b = let (p t nep e _) = (a >>= b) in p t nep e l' the important thing remember when using parser
a -> m b must consume no input. must either return transformed version of a, or fail.
warning
testing on minimal currently, , behaviour not enforced type. fudge.
Comments
Post a Comment