[auto
ekmett@gmail.com**20090504034315
Ignore-this: a4a7ee8e916df4f22145a724a7d2804a
] {
hunk ./doc/html/parsimony/Text-Parsimony-Char.html 24
+>Source code
| | | | | | | | | | | | | | | | | | | | | | | | | Source code | | | | | | | | | Source code | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Source code | | | | | | | | | | | | | Source code | | | | | Source codefmapParser :: (a -> b) -> Parser m t a -> Parser m t b | pureParser :: a -> Parser m t a |
appParser :: Parser m t (a -> b) -> Parser m t a -> Parser m t b |
fmapParser :: Mode m => (a -> b) -> Parser m t a -> Parser m t b |
|
pureParser :: Mode m => a -> Parser m t a |
|
appParser :: Mode m => Parser m t (a -> b) -> Parser m t a -> Parser m t b |
|
| | | This parser is capable of parsing a token stream and obtaining an answer
+ |
| | This parser may only be used to recognize a token stream as belonging to a context-free language
+ |
| | Parser invariants provided by smart constructors:
+ - a Name never contains a Name directly
+ 2 Labels never contain Labels directly
+ 3 an Alt never contains an Alt directly
+ 4 a Greedy never contains a Greedy directly
+ 5 a Skip never contains a Skip transitively
+
Unenforceable invariants required for the parallel parser:
+ - The parse tree is finite
+
|
| | A parser mode defines what optimizations are possible, and how much information must be retained
+ |
| | | | fmapParser :: (a -> b) -> Parser m t a -> Parser m t b |
|
pureParser :: a -> Parser m t a |
|
| fmapParser :: Mode m => (a -> b) -> Parser m t a -> Parser m t b | |
| Generate a parser that recognizes a single token using a predicate
+ | | | | | | | | | | | | |
treat a non-recognizing parser as a recognizing one to reduce redundant rules
+ | | | | |
Annotate a parser with what it should say was expected if the first character in it is unconsumed
+ | | |
Multiple parsers returning multiple answers
+ | | |
Prefers the result from the left when present. Only accepts parses from the right hand parser
+ when the left hand parser fails.
+ | | |
Multiple parsers returning the results from the left-most parser that matches anything
+ | | |
parser that accepts the empty string used by Recognizing parsers where necessary
+ | Source code | | | | | | | | | Source code | | | | | | | | | Source codeappParser | Text.Parsimony.Prim, Text.Parsimony |
fmapParser | Text.Parsimony.Prim, Text.Parsimony |
pureParser | Text.Parsimony.Prim, Text.Parsimony |
Name _ n -> eval n
- Labels ls l -> Parsec.labels (eval l) ls
+ Name n _ -> eval n
+ Labels l ls -> Parsec.labels (eval l) ls
hunk ./doc/html/parsimony/src/Text-Parsimony-Parsec.html 41
-eval_ :: Parsec.Stream s m Char => Parser Recognizing Char e -> Parsec.ParsecT s u m ()
+eval_ :: (Mode mode, Parsec.Stream s m Char) => Parser mode Char e -> Parsec.ParsecT s u m ()
hunk ./doc/html/parsimony/src/Text-Parsimony-Parsec.html 43
- App f x -> eval_ f *> eval_ x
+ App f x -> eval_ f >> eval_ x
hunk ./doc/html/parsimony/src/Text-Parsimony-Parsec.html 48
- Name _ n -> eval_ n
- Labels ls l -> Parsec.labels (eval_ l) ls
- Skip s -> eval_ s
+ Name p _ -> eval_ p
+ Labels p ls -> Parsec.labels (eval_ p) ls
+ Skip p -> eval_ p
hunk ./doc/html/parsimony/src/Text-Parsimony-Prim.html 29
- , fmapParser, pureParser, appParser, satisfy, skip
- , (<<$), (*>>), (<<*)
- , name
- , labels
- , (<?>)
- , choice
- , (<<|>)
- , greedyChoice
- ) where
-
-import Control.Applicative
-import Control.Arrow (Arrow, arr)
-import Control.Category
-import Prelude hiding ((.),id)
-import Text.Parsimony.Util
-import Unsafe.Coerce (unsafeCoerce)
-import Data.Traversable
-#ifdef X_OverloadedStrings
-import Data.String
-#endif
-
-
-data Parsing
-data Recognizing
-
-
+
+ , satisfy, skip
+ , (<<$), (*>>), (<<*)
+ , named
+ , recognizing
+ , labels
+ , (<?>)
+ , choice
+ , (<<|>)
+ , greedyChoice
+ , epsilon
+ ) where
+
+import Control.Applicative
+import Control.Arrow (Arrow, arr)
+import Control.Category
+import Prelude hiding ((.),id)
+import Text.Parsimony.Util
+import Unsafe.Coerce (unsafeCoerce)
+import Data.Traversable
+#ifdef X_OverloadedStrings
+import Data.String
+#endif
+
+
+data Parsing
hunk ./doc/html/parsimony/src/Text-Parsimony-Prim.html 56
-
-
-
-
-
-
-
-
-
-
-
-data Parser m t a where
- App :: Parser m t (a -> b) -> Parser m t a -> Parser m t b
- Pure :: Pure m a -> Parser m t a
- Alt :: [Parser m t a] -> Parser m t a
- Greedy :: [Parser m t a] -> Parser m t a
- Satisfy :: Fun m t a -> (t -> Bool) -> Parser m t a
- Skip :: Parser Recognizing t a -> Parser m t ()
- Name :: String -> Parser m t a -> Parser m t a
- Labels :: [String] -> Parser m t a -> Parser m t a
-
-class (Arrow (Fun m), Applicative (Pure m)) => Mode m where
- type Pure m :: * -> *
- type Fun m :: * -> * -> *
+
+data Recognizing
+
+
+
+
+
+
+
+
+
+
+
+
+
+data Parser m t a where
+ App :: Parser m t (a -> b) -> Parser m t a -> Parser m t b
+ Pure :: Pure m a -> Parser m t a
+ Alt :: [Parser m t a] -> Parser m t a
+ Greedy :: [Parser m t a] -> Parser m t a
+ Satisfy :: Fun m t a -> (t -> Bool) -> Parser m t a
+ Skip :: Parser Recognizing t a -> Parser m t ()
+ Name :: Parser m t a -> String -> Parser m t a
+ Labels :: Parser m t a -> [String] -> Parser m t a
hunk ./doc/html/parsimony/src/Text-Parsimony-Prim.html 81
- fmapParser :: (a -> b) -> Parser m t a -> Parser m t b
- pureParser :: a -> Parser m t a
- appParser :: Parser m t (a -> b) -> Parser m t a -> Parser m t b
- skip :: Parser Recognizing t a -> Parser m t ()
+
+class (Arrow (Fun m), Applicative (Pure m)) => Mode m where
+ type Pure m :: * -> *
+ type Fun m :: * -> * -> *
hunk ./doc/html/parsimony/src/Text-Parsimony-Prim.html 86
- fmapParser g (App f x) = App (fmap g <$> f) x
- fmapParser g (Pure a) = Pure (g <$> a)
- fmapParser g (Alt as) = Alt (fmap g <$> as)
- fmapParser g (Greedy as) = Greedy (fmap g <$> as)
- fmapParser g (Satisfy s p) = Satisfy (arr g . s) p
- fmapParser _ s@(Skip _) = unsafeCoerce s
- fmapParser g (Name s p) = Name s (g <$> p)
- fmapParser g (Labels s p) = Labels s (g <$> p)
-
- pureParser = Pure . pure
-
- skip = Skip
-
-satisfy :: Mode m => (t -> Bool) -> Parser m t t
-satisfy = Satisfy id
+ fmapParser :: (a -> b) -> Parser m t a -> Parser m t b
+ pureParser :: a -> Parser m t a
+ appParser :: Parser m t (a -> b) -> Parser m t a -> Parser m t b
+ skip :: Parser Recognizing t a -> Parser m t ()
+
+ fmapParser g (App f x) = App (fmap g <$> f) x
+ fmapParser g (Pure a) = Pure (g <$> a)
+ fmapParser g (Alt as) = Alt (fmap g <$> as)
+ fmapParser g (Greedy as) = Greedy (fmap g <$> as)
+ fmapParser g (Satisfy s p) = Satisfy (arr g . s) p
+ fmapParser _ s@(Skip _) = unsafeCoerce s
+ fmapParser g (Name p s) = Name (g <$> p) s
+ fmapParser g (Labels p ss) = Labels (g <$> p) ss
+
+ pureParser = Pure . pure
hunk ./doc/html/parsimony/src/Text-Parsimony-Prim.html 102
-
-instance Mode Parsing where
- type Pure Parsing = Id
- type Fun Parsing = (->)
-
- appParser (Pure f) (Pure x) = Pure (f <*> x)
- appParser (Pure f) (Satisfy s p) = Satisfy (runId f <$> s) p
- appParser f x = App f x
-
-
-instance Mode Recognizing where
- type Pure Recognizing = TrivialApplicative
- type Fun Recognizing = TrivialArrow
-
- skip = unsafeCoerce
- fmapParser _ = unsafeCoerce
-
- appParser Pure{} x = unsafeCoerce x
- appParser f Pure{} = unsafeCoerce f
- appParser f x = App f x
-
- pureParser _ = unsafeCoerce epsilon where
-
- epsilon :: Parser Recognizing Magic ()
- epsilon = Pure undefined
-
-instance Mode m => Functor (Parser m t) where
- fmap = fmapParser
-
-instance Mode m => Applicative (Parser m t) where
- pure = pureParser
- (<*>) = appParser
+ skip = Skip
+
+
+satisfy :: Mode m => (t -> Bool) -> Parser m t t
+satisfy = Satisfy id
+
+
+recognizing :: Mode m => Parser m t a -> Parser Recognizing t a
+recognizing = unsafeCoerce
+
+
+instance Mode Parsing where
+ type Pure Parsing = Id
+ type Fun Parsing = (->)
+
+ appParser (Pure f) (Pure x) = Pure (f <*> x)
+ appParser (Pure f) (Satisfy s p) = Satisfy (runId f <$> s) p
+ appParser f x = App f x
+
+
+instance Mode Recognizing where
+ type Pure Recognizing = TrivialApplicative
+ type Fun Recognizing = TrivialArrow
+
+ skip = unsafeCoerce
+ fmapParser _ = unsafeCoerce
+
+ appParser Pure{} x = unsafeCoerce x
+ appParser f Pure{} = unsafeCoerce f
+ appParser f x = App f x
+
+ pureParser _ = unsafeCoerce epsilon
hunk ./doc/html/parsimony/src/Text-Parsimony-Prim.html 135
-instance Mode m => Alternative (Parser m t) where
- empty = Alt []
- Alt as <|> Alt bs = Alt (as ++ bs)
- Alt as <|> b = Alt (as ++ [b])
- a <|> Alt bs = Alt (a : bs)
- a <|> b = Alt [a,b]
+
+epsilon :: Parser Recognizing Magic ()
+epsilon = Pure undefined `named` "epsilon"
+
+instance Mode m => Functor (Parser m t) where
+ fmap = fmapParser
hunk ./doc/html/parsimony/src/Text-Parsimony-Prim.html 142
-
-
-(<<$) :: Mode m => a -> Parser Recognizing t b -> Parser m t a
-a <<$ p = const a <$> skip p
-
-
-(*>>) :: Mode m => Parser Recognizing t a -> Parser m t b -> Parser m t b
-a *>> b = const id <$> skip a <*> b
-
-
-(<<*) :: Mode m => Parser m t a -> Parser Recognizing t b -> Parser m t a
-a <<* b = const <$> a <*> skip b
-
-
-name :: String -> Parser m t a -> Parser m t a
-name s (Name _ p) = Name s p
-name s p = Name s p
-
-labels :: [String] -> Parser m t a -> Parser m t a
-labels s (Labels _ p) = Labels s p
-labels s p = Labels s p
-
-(<?>) :: Parser m t a -> String -> Parser m t a
-p <?> s = labels [s] p
-
-choice :: [Parser m t a] -> Parser m t a
-choice = Alt . foldr flatten [] where
- flatten (Alt bs) as = bs ++ as
- flatten a as = a : as
-
-(<<|>) :: Parser m t a -> Parser m t a -> Parser m t a
-Greedy as <<|> Greedy bs = Greedy (as ++ bs)
-Greedy as <<|> a = Greedy (as ++ [a])
-a <<|> Greedy as = Greedy (a : as)
-a <<|> b = Greedy [a,b]
-
-greedyChoice :: [Parser m t a] -> Parser m t a
-greedyChoice = Greedy . foldr flatten [] where
- flatten (Greedy bs) as = bs ++ as
- flatten a as = a : as
-
-#ifdef X_OverloadedStrings
-instance Mode m => IsString (Parser m Char String) where
- fromString = traverse (\x -> satisfy (==x) <?> show [x])
-#endif
-
+instance Mode m => Applicative (Parser m t) where
+ pure = pureParser
+ (<*>) = appParser
+
+instance Mode m => Alternative (Parser m t) where
+ empty = Alt []
+ Alt as <|> Alt bs = Alt (as ++ bs)
+ Alt as <|> b = Alt (as ++ [b])
+ a <|> Alt bs = Alt (a:bs)
+ a <|> b = Alt [a,b]
+
+
+(<<$) :: Mode m => a -> Parser Recognizing t b -> Parser m t a
+a <<$ p = const a <$> skip p
+
+
+(*>>) :: Mode m => Parser Recognizing t a -> Parser m t b -> Parser m t b
+a *>> b = const id <$> skip a <*> b
+
+
+(<<*) :: Mode m => Parser m t a -> Parser Recognizing t b -> Parser m t a
+a <<* b = const <$> a <*> skip b
+
+
+named :: Parser m t a -> String -> Parser m t a
+named (Name p _) = Name p
+named p = Name p
+
+
+labels :: Parser m t a -> [String] -> Parser m t a
+labels (Labels p _) = Labels p
+labels p = Labels p
+
+
+(<?>) :: Parser m t a -> String -> Parser m t a
+p <?> s = labels p [s]
+
+
+choice :: [Parser m t a] -> Parser m t a
+choice = Alt . foldr flatten [] where
+ flatten (Alt bs) as = bs ++ as
+ flatten a as = a : as
+
+
+
+(<<|>) :: Parser m t a -> Parser m t a -> Parser m t a
+Greedy as <<|> Greedy bs = Greedy (as ++ bs)
+Greedy as <<|> a = Greedy (as ++ [a])
+a <<|> Greedy as = Greedy (a : as)
+a <<|> b = Greedy [a,b]
+
+
+greedyChoice :: [Parser m t a] -> Parser m t a
+greedyChoice = Greedy . foldr flatten [] where
+ flatten (Greedy bs) as = bs ++ as
+ flatten a as = a : as
+
+
+#ifdef X_OverloadedStrings
+instance Mode m => IsString (Parser m Char String) where
+ fromString = traverse (\x -> satisfy (==x) <?> show [x])
+#endif
}
|