grammar-combinators 0.2.5 → 0.2.6
raw patch · 3 files changed
+24/−27 lines, 3 files
Files
- Text/GrammarCombinators/Parser/UUParse.hs +21/−26
- changelog +2/−0
- grammar-combinators.cabal +1/−1
Text/GrammarCombinators/Parser/UUParse.hs view
@@ -22,6 +22,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeFamilies #-} -- | UUParse compatibility module. module Text.GrammarCombinators.Parser.UUParse (@@ -40,28 +41,22 @@ import Data.Enumerable (enumerate) -newtype Loc = MkLoc Int deriving Show---- We just count tokens for now (not lines and colums with handling here for newlines etc), --- locations cannot be used atm anyway...-instance IsLocationUpdatedBy Loc t where- advance (MkLoc p) _ = MkLoc $ p + 1--newtype WrapP t v = WP { unWP :: P (Str (ConcreteToken t) [ConcreteToken t] Loc) v }+newtype WrapP t loc ct v = WP { unWP :: P (Str (ConcreteToken t) [ConcreteToken t] loc) v } -instance (Token t) => ProductionRule (WrapP t) where+instance (Token t) => ProductionRule (WrapP t loc ct) where a >>> b = WP $ unWP a <*> unWP b a ||| b = WP $ unWP a <|> unWP b endOfInput = WP $ const () <$> pEnd die = WP empty -instance (Token t) => EpsProductionRule (WrapP t) where+instance (Token t) => EpsProductionRule (WrapP t loc ct) where epsilon v = WP $ pure v -instance (Token t) => LiftableProductionRule (WrapP t) where+instance (Token t) => LiftableProductionRule (WrapP t loc ct) where epsilonL v _ = epsilon v -instance (Token t) => TokenProductionRule (WrapP t) t where+instance (Token t, Show ct, ConcreteToken t ~ ct, IsLocationUpdatedBy loc ct) =>+ TokenProductionRule (WrapP t loc ct) t where token tt = let sat :: ConcreteToken t -> Bool@@ -72,35 +67,35 @@ -- | Parse a given string according to a given regular grammar, starting from a given -- start symbol using the UUParse error-correcting parsing library (always -- produces a result)-parseUUR :: forall phi t r ix.- (Token t) =>+parseUUR :: forall loc phi t r ix.+ (Token t, IsLocationUpdatedBy loc (ConcreteToken t)) => ProcessingRegularGrammar phi t r ->- phi ix -> [ConcreteToken t] -> r ix+ phi ix -> loc -> [ConcreteToken t] -> r ix parseUUR gram idx = parseUURule $ gram idx -- | Parse a given string according to a given grammar, starting from a given -- start symbol using the UUParse error-correcting parsing library (always -- produces a result)-parseUU :: forall phi t r ix.- (Token t) =>+parseUU :: forall loc phi t r ix.+ (Token t, IsLocationUpdatedBy loc (ConcreteToken t)) => ProcessingContextFreeGrammar phi t r ->- phi ix -> [ConcreteToken t] -> r ix+ phi ix -> loc -> [ConcreteToken t] -> r ix parseUU gram = parseUUR (unfoldRecursion gram) -- | Parse a given string according to a given regular production rule using the -- UUParse error-correcting parsing library (always produces a result).-parseUURule :: forall phi t r v.- (Token t) =>- RegularRule phi r t v ->+parseUURule :: forall loc phi t r v.+ (Token t, IsLocationUpdatedBy loc (ConcreteToken t)) =>+ RegularRule phi r t v -> loc -> [ConcreteToken t] -> v-parseUURule rule s = - parse (unWP rule <* pEnd) $ createStr (MkLoc 0) s +parseUURule rule loc s = + parse (unWP rule <* pEnd) $ createStr loc s -- | Parse a given string according to a given extended grammar, starting from a given -- start symbol using the UUParse error-correcting parsing library (always -- produces a result)-parseUUE :: forall phi t r ix.- (Token t) =>+parseUUE :: forall loc phi t r ix.+ (Token t, IsLocationUpdatedBy loc (ConcreteToken t)) => ProcessingExtendedContextFreeGrammar phi t r ->- phi ix -> [ConcreteToken t] -> r ix+ phi ix -> loc -> [ConcreteToken t] -> r ix parseUUE gram = parseUU (unfoldLoops gram)
changelog view
@@ -1,5 +1,7 @@ -*-change-log-*- +0.2.6+ Fix the previous fix with GHC 7. 0.2.5 Fix compatibility with non-backwards compatible UUParse 2.7.1. 0.2.4 Grammar-combinators v0.2.4 is released. Home page back to
grammar-combinators.cabal view
@@ -1,5 +1,5 @@ Name: grammar-combinators-Version: 0.2.5+Version: 0.2.6 Description: The grammar-combinators library is a novel parsing library using an explicit representation of recursion to provide various novel