uu-parsinglib 2.7.2.2 → 2.7.3
raw patch · 5 files changed
+26/−14 lines, 5 files
Files
- src/Text/ParserCombinators/UU/BasicInstances.hs +7/−7
- src/Text/ParserCombinators/UU/CHANGELOG.hs +5/−1
- src/Text/ParserCombinators/UU/Core.hs +5/−5
- src/Text/ParserCombinators/UU/Demo/Examples.hs +8/−0
- uu-parsinglib.cabal +1/−1
src/Text/ParserCombinators/UU/BasicInstances.hs view
@@ -143,13 +143,13 @@ pSatisfy p (Insertion msg a cost) = pSymExt splitState (Succ (Zero Infinite)) Nothing where splitState :: forall r. ((a -> (Str a state loc) -> Steps r) -> (Str a state loc) -> Steps r) splitState k (Str tts msgs pos del_ok) - = show_attempt ("Try Predicate: " ++ msg ++ "\n") (+ = show_attempt ("Try Predicate: " ++ msg ++ " at position " ++ show pos ++ "\n") ( let ins exp = (cost, k a (Str tts (msgs ++ [Inserted (show a) pos exp]) pos False)) in if LL.null tts then Fail [msg] [ins] else let t = LL.head tts ts = LL.tail tts- del exp = (5, splitState k (Str ts (msgs ++ [Deleted (show t) pos exp]) (advance pos t) True ))+ del exp = (4, splitState k (Str ts (msgs ++ [Deleted (show t) pos exp]) (advance pos t) True )) in if p t then show_symbol ("Accepting symbol: " ++ show t ++ " at position: " ++ show pos ++"\n") (Step 1 (k t (Str ts msgs (advance pos t) True)))@@ -175,7 +175,7 @@ pSym :: (Eq a,Show a, IsLocationUpdatedBy loc a, LL.ListLike state a) => a -> P (Str a state loc) a pSym t = pSymInsert t (Insertion (show t) t 5) --- | `pMunchL` recognises the longest prefix of the input for which the passed predicate holds. The message parameer is used when tracing has been switched on. +-- | `pMunchL` recognises the longest prefix of the input for which the passed predicate holds. The message parameter is used when tracing has been switched on. pMunchL :: forall loc state a .((Show a, loc `IsLocationUpdatedBy` a, LL.ListLike state a) => (a -> Bool) -> String -> P (Str a state loc) [a]) pMunchL p msg = pSymExt splitState (Zero Infinite) Nothing where splitState :: forall r. (([a] -> (Str a state loc) -> Steps r) -> (Str a state loc) -> Steps r)@@ -193,7 +193,7 @@ pMunch :: forall loc state a .((Show a, loc `IsLocationUpdatedBy` a, LL.ListLike state a) => (a -> Bool) -> P (Str a state loc) [a]) pMunch p = pMunchL p "" --- | `pTokenCost` succeeds iis parameter is a prefix of the input. +-- | `pTokenCost` succeeds if its parameter is a prefix of the input. pTokenCost :: forall loc state a .((Show a, Eq a, loc `IsLocationUpdatedBy` a, LL.ListLike state a) => [a] -> Int -> P (Str a state loc) [a]) pTokenCost as cost = if null as then error "Module: BasicInstances, function: pTokenCost; call with empty token"@@ -227,7 +227,7 @@ {-# INLINE show_tokens #-} show_tokens :: String -> b -> b-show_tokens m v = {- trace m -} v+show_tokens m v = {- trace m -} v {-# INLINE show_munch #-} show_munch :: String -> b -> b@@ -235,7 +235,7 @@ {-# INLINE show_symbol #-} show_symbol :: String -> b -> b-show_symbol m v = {- trace m -} v+show_symbol m v = {- trace m -} v {-# INLINE show_attempt #-}-show_attempt m v = {- trace m -} v+show_attempt m v = {- trace m -} v
src/Text/ParserCombinators/UU/CHANGELOG.hs view
@@ -1,8 +1,12 @@ -- | This module just contains the CHANGELOG --+-- Version 2.7.3+--+-- better behaviour when inserting at end of input+-- -- Version 2.7.2.2 ----- fixed the case where the left hand operand of <<||> strats with a monadic bind+-- fixed the case where the left hand operand of <<||> starts with a monadic bind -- -- Version 2.7.2.1 --
src/Text/ParserCombinators/UU/Core.hs view
@@ -217,14 +217,14 @@ Nothing `alt` q = q p `alt` Nothing = p Just p `alt` Just q = Just (p <|>q)- in mkParser ((if b then flip else id) alt np nq) (pe <|> qe) rl+ in mkParser ((if b then id else flip) alt np nq) (pe <|> qe) rl empty = mkParser empty empty Infinite instance ExtAlternative (P st) where P ap np pl pe <<|> P aq nq ql qe = let (rl, b) = nat_min pl ql 0 bestx :: Steps a -> Steps a -> Steps a- bestx = (if b then flip else id) best+ bestx = (if b then id else flip) best choose:: T st a -> T st a -> T st a choose (T ph pf pr) (T qh qf qr) = T (\ k st -> let left = norm (ph k st)@@ -513,9 +513,9 @@ traverse :: Int -> Steps a -> Int -> Int -> Int traverse 0 _ v c = trace' ("traverse " ++ show' 0 v c ++ " choosing" ++ show v ++ "\n") v-traverse n (Step _ l) v c = trace' ("traverse Step " ++ show' n v c ++ "\n") (traverse (n - 1 ) l (v-n) c)-traverse n (Micro _ l) v c = trace' ("traverse Micro " ++ show' n v c ++ "\n") (traverse n l v c)-traverse n (Apply _ l) v c = {- trace' ("traverse Apply " ++ show n ++ "\n")-} (traverse n l v c)+traverse n (Step _ l) v c = trace' ("traverse Step " ++ show' n v c ++ "\n") (traverse (n - 1 ) l (v - n) c)+traverse n (Micro x l) v c = trace' ("traverse Micro " ++ show' n v c ++ "\n") (traverse n l v c)+traverse n (Apply _ l) v c = trace' ("traverse Apply " ++ show n ++ "\n") (traverse n l v c) traverse n (Fail m m2ls) v c = trace' ("traverse Fail " ++ show m ++ show' n v c ++ "\n") (foldr (\ (w,l) c' -> if v + w < c' then traverse (n - 1 ) l (v+w) c' else c') c (map ($m) m2ls)
src/Text/ParserCombinators/UU/Demo/Examples.hs view
@@ -121,6 +121,14 @@ putStrLn "-- " where show_errors :: (Show a) => [a] -> IO () show_errors = sequence_ . (map (putStrLn . show))+run' p inp = do let r@(a, errors) = parse ( (,) <$> p <*> pEnd) (createStr (LineColPos 0 0 0) inp)+ if null errors then return ()+ else do putStr ("-- Correcting steps: \n")+ show_errors errors + putStrLn ("-- Result: " ++ show a) + putStrLn "-- "+ where show_errors :: (Show a) => [a] -> IO ()+ show_errors = sequence_ . (map (putStrLn . show)) -- | Our first two parsers are simple; one recognises a single 'a' character and the other one a single 'b'. Since we will use them later we -- convert the recognised character into `String` so they can be easily combined.
uu-parsinglib.cabal view
@@ -1,5 +1,5 @@ Name: uu-parsinglib-Version: 2.7.2.2+Version: 2.7.3 Build-Type: Simple License: MIT Copyright: S Doaitse Swierstra