(.module: [library [lux #* [abstract [monad (#+ do)]] [control ["." try (#+ Try)] ["." exception (#+ exception:)]] [data [collection [tree (#+ Tree) ["." zipper (#+ Zipper)]]]]]] ["." //]) (type: #export (Parser t a) (//.Parser (Zipper t) a)) (def: #export (run' parser zipper) (All [t a] (-> (Parser t a) (Zipper t) (Try a))) (do try.monad [[zipper output] (//.run parser zipper)] (wrap output))) (def: #export (run parser tree) (All [t a] (-> (Parser t a) (Tree t) (Try a))) (run' parser (zipper.zip tree))) (def: #export value (All [t] (Parser t t)) (function (_ zipper) (#try.Success [zipper (zipper.value zipper)]))) (exception: #export cannot_move_further) (template [ ] [(def: #export (All [t] (Parser t [])) (function (_ zipper) (case ( zipper) #.None (exception.throw ..cannot_move_further []) (#.Some next) (#try.Success [next []]))))] [down zipper.down] [up zipper.up] [right zipper.right] [rightmost zipper.rightmost] [left zipper.left] [leftmost zipper.leftmost] [next zipper.next] [end zipper.end] [previous zipper.previous] [start zipper.start] )