Safe Haskell | None |
---|---|
Language | Haskell2010 |
Semantic of the grammar combinators used to express parsers, in the convenient tagless-final encoding.
Synopsis
- type TermGrammar = Term ValueCode
- class Applicable repr where
- (<$>) :: TermGrammar (a -> b) -> repr a -> repr b
- (<&>) :: repr a -> TermGrammar (a -> b) -> repr b
- (<$) :: TermGrammar a -> repr b -> repr a
- ($>) :: repr a -> TermGrammar b -> repr b
- pure :: TermGrammar a -> repr a
- (<*>) :: repr (a -> b) -> repr a -> repr b
- liftA2 :: TermGrammar (a -> b -> c) -> repr a -> repr b -> repr c
- (<*) :: repr a -> repr b -> repr a
- (*>) :: repr a -> repr b -> repr b
- (<**>) :: repr a -> repr (a -> b) -> repr b
- class Alternable repr where
- (<|>) :: repr a -> repr a -> repr a
- empty :: repr a
- try :: repr a -> repr a
- (<+>) :: Applicable repr => Alternable repr => repr a -> repr b -> repr (Either a b)
- optionally :: Applicable repr => Alternable repr => repr a -> TermGrammar b -> repr b
- optional :: Applicable repr => Alternable repr => repr a -> repr ()
- option :: Applicable repr => Alternable repr => TermGrammar a -> repr a -> repr a
- choice :: Alternable repr => [repr a] -> repr a
- maybeP :: Applicable repr => Alternable repr => repr a -> repr (Maybe a)
- manyTill :: Applicable repr => Alternable repr => repr a -> repr b -> repr [a]
- class Selectable repr where
- class Matchable repr where
- conditional :: Eq a => repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b
- match :: Eq a => repr a -> [TermGrammar a] -> (TermGrammar a -> repr b) -> repr b -> repr b
- class Foldable repr where
- class Satisfiable tok repr where
- satisfy :: [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok
- item :: repr tok
- data ErrorItem tok
- class Lookable repr where
- (<:>) :: Applicable repr => repr a -> repr [a] -> repr [a]
- sequence :: Applicable repr => [repr a] -> repr [a]
- traverse :: Applicable repr => (a -> repr b) -> [a] -> repr [b]
- repeat :: Applicable repr => Int -> repr a -> repr [a]
- between :: Applicable repr => repr o -> repr c -> repr a -> repr a
- string :: Applicable repr => Alternable repr => Satisfiable Char repr => [Char] -> repr [Char]
- oneOf :: Lift tok => Eq tok => Satisfiable tok repr => [tok] -> repr tok
- noneOf :: Lift tok => Eq tok => Satisfiable tok repr => [tok] -> repr tok
- ofChars :: Lift tok => Eq tok => [tok] -> CodeQ tok -> CodeQ Bool
- more :: Applicable repr => Satisfiable Char repr => Lookable repr => repr ()
- char :: Applicable repr => Satisfiable Char repr => Char -> repr Char
- anyChar :: Satisfiable Char repr => repr Char
- token :: Lift tok => Show tok => Eq tok => Applicable repr => Satisfiable tok repr => tok -> repr tok
- tokens :: Lift tok => Eq tok => Show tok => Applicable repr => Alternable repr => Satisfiable tok repr => [tok] -> repr [tok]
- void :: Applicable repr => repr a -> repr ()
- unit :: Applicable repr => repr ()
- pfoldr :: Applicable repr => Foldable repr => TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
- pfoldr1 :: Applicable repr => Foldable repr => TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b
- pfoldl :: Applicable repr => Foldable repr => TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b
- pfoldl1 :: Applicable repr => Foldable repr => TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b
- chainl1' :: Applicable repr => Foldable repr => TermGrammar (a -> b) -> repr a -> repr (b -> a -> b) -> repr b
- chainl1 :: Applicable repr => Foldable repr => repr a -> repr (a -> a -> a) -> repr a
- chainl :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr (a -> a -> a) -> TermGrammar a -> repr a
- many :: Applicable repr => Foldable repr => repr a -> repr [a]
- manyN :: Applicable repr => Foldable repr => Int -> repr a -> repr [a]
- some :: Applicable repr => Foldable repr => repr a -> repr [a]
- skipMany :: Applicable repr => Foldable repr => repr a -> repr ()
- skipManyN :: Applicable repr => Foldable repr => Int -> repr a -> repr ()
- skipSome :: Applicable repr => Foldable repr => repr a -> repr ()
- sepBy :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a]
- sepBy1 :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a]
- endBy :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a]
- endBy1 :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a]
- sepEndBy :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a]
- sepEndBy1 :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a]
Type TermGrammar
type TermGrammar = Term ValueCode Source #
Class Applicable
class Applicable repr where Source #
This is like the usual Functor
and Applicative
type classes
from the base
package, but using (
instead of just TermGrammar
a)(a)
to be able to use and pattern match on some usual terms of type (a)
(like id
)
and thus apply some optimizations.
(repr)
, for "representation", is the usual tagless-final abstraction
over the many semantics that this syntax (formed by the methods
of type class like this one) will be interpreted.
Nothing
(<$>) :: TermGrammar (a -> b) -> repr a -> repr b infixl 4 Source #
(a2b
parses like <$>
ra)(ra)
but maps its returned value with (a2b)
.
(<&>) :: repr a -> TermGrammar (a -> b) -> repr b infixl 4 Source #
(<$) :: TermGrammar a -> repr b -> repr a infixl 4 Source #
(a
parses like <$
rb)(rb)
but discards its returned value by replacing it with (a)
.
($>) :: repr a -> TermGrammar b -> repr b infixl 4 Source #
(ra
parses like $>
b)(ra)
but discards its returned value by replacing it with (b)
.
pure :: TermGrammar a -> repr a Source #
(
parses the empty string, always succeeding in returning pure
a)(a)
.
pure :: Liftable repr => Applicable (Output repr) => TermGrammar a -> repr a Source #
(
parses the empty string, always succeeding in returning pure
a)(a)
.
(<*>) :: repr (a -> b) -> repr a -> repr b infixl 4 Source #
(ra2b
parses sequentially <*>
ra)(ra2b)
and then (ra)
,
and returns the application of the function returned by (ra2b)
to the value returned by (ra)
.
(<*>) :: Liftable2 repr => Applicable (Output repr) => repr (a -> b) -> repr a -> repr b infixl 4 Source #
(ra2b
parses sequentially <*>
ra)(ra2b)
and then (ra)
,
and returns the application of the function returned by (ra2b)
to the value returned by (ra)
.
liftA2 :: TermGrammar (a -> b -> c) -> repr a -> repr b -> repr c Source #
(
parses sequentially liftA2
a2b2c ra rb)(ra)
and then (rb)
,
and returns the application of (a2b2c)
to the values returned by those parsers.
(<*) :: repr a -> repr b -> repr a infixl 4 Source #
(ra
parses sequentially <*
rb)(ra)
and then (rb)
,
and returns like (ra)
, discarding the return value of (rb)
.
(*>) :: repr a -> repr b -> repr b infixl 4 Source #
(ra
parses sequentially *>
rb)(ra)
and then (rb)
,
and returns like (rb)
, discarding the return value of (ra)
.
(<**>) :: repr a -> repr (a -> b) -> repr b infixl 4 Source #
Instances
Class Alternable
class Alternable repr where Source #
Nothing
(<|>) :: repr a -> repr a -> repr a infixl 3 Source #
(rl
parses <|>
rr)(rl)
and return its return value or,
if it fails, parses (rr)
from where (rl)
has left the input stream,
and returns its return value.
(empty)
parses nothing, always failing to return a value.
try :: repr a -> repr a Source #
(
records the input stream position,
then parses like try
ra)(ra)
and either returns its value it it succeeds or fails
if it fails but with a reset of the input stream to the recorded position.
Generally used on the first alternative: (
.try
rl <|>
rr)
(<|>) :: Liftable2 repr => Alternable (Output repr) => repr a -> repr a -> repr a infixl 3 Source #
(rl
parses <|>
rr)(rl)
and return its return value or,
if it fails, parses (rr)
from where (rl)
has left the input stream,
and returns its return value.
empty :: Liftable repr => Alternable (Output repr) => repr a Source #
(empty)
parses nothing, always failing to return a value.
try :: Liftable1 repr => Alternable (Output repr) => repr a -> repr a Source #
(
records the input stream position,
then parses like try
ra)(ra)
and either returns its value it it succeeds or fails
if it fails but with a reset of the input stream to the recorded position.
Generally used on the first alternative: (
.try
rl <|>
rr)
(<+>) :: Applicable repr => Alternable repr => repr a -> repr b -> repr (Either a b) infixl 3 Source #
Instances
optionally :: Applicable repr => Alternable repr => repr a -> TermGrammar b -> repr b Source #
optional :: Applicable repr => Alternable repr => repr a -> repr () Source #
option :: Applicable repr => Alternable repr => TermGrammar a -> repr a -> repr a Source #
choice :: Alternable repr => [repr a] -> repr a Source #
maybeP :: Applicable repr => Alternable repr => repr a -> repr (Maybe a) Source #
manyTill :: Applicable repr => Alternable repr => repr a -> repr b -> repr [a] Source #
Class Selectable
class Selectable repr where Source #
Nothing
branch :: repr (Either a b) -> repr (a -> c) -> repr (b -> c) -> repr c Source #
branch :: Liftable3 repr => Selectable (Output repr) => repr (Either a b) -> repr (a -> c) -> repr (b -> c) -> repr c Source #
Instances
Class Matchable
class Matchable repr where Source #
Nothing
conditional :: Eq a => repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b Source #
conditional :: Unliftable repr => Liftable1 repr => Matchable (Output repr) => Eq a => repr a -> [TermGrammar (a -> Bool)] -> [repr b] -> repr b -> repr b Source #
match :: Eq a => repr a -> [TermGrammar a] -> (TermGrammar a -> repr b) -> repr b -> repr b Source #
Instances
Class Foldable
class Foldable repr where Source #
Nothing
chainPre :: repr (a -> a) -> repr a -> repr a Source #
chainPost :: repr a -> repr (a -> a) -> repr a Source #
chainPre :: Applicable repr => Alternable repr => repr (a -> a) -> repr a -> repr a Source #
chainPost :: Applicable repr => Alternable repr => repr a -> repr (a -> a) -> repr a Source #
Instances
Class Satisfiable
class Satisfiable tok repr where Source #
Nothing
satisfy :: [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok Source #
satisfy :: Liftable repr => Satisfiable tok (Output repr) => [ErrorItem tok] -> TermGrammar (tok -> Bool) -> repr tok Source #
Instances
Type ErrorItem
Instances
Lift tok => Lift (ErrorItem tok :: Type) Source # | |
Eq tok => Eq (ErrorItem tok) Source # | |
Ord tok => Ord (ErrorItem tok) Source # | |
Defined in Symantic.Parser.Grammar.Combinators compare :: ErrorItem tok -> ErrorItem tok -> Ordering # (<) :: ErrorItem tok -> ErrorItem tok -> Bool # (<=) :: ErrorItem tok -> ErrorItem tok -> Bool # (>) :: ErrorItem tok -> ErrorItem tok -> Bool # (>=) :: ErrorItem tok -> ErrorItem tok -> Bool # | |
Show tok => Show (ErrorItem tok) Source # | |
Class Lookable
class Lookable repr where Source #
Nothing
look :: repr a -> repr a Source #
negLook :: repr a -> repr () Source #
look :: Liftable1 repr => Lookable (Output repr) => repr a -> repr a Source #
negLook :: Liftable1 repr => Lookable (Output repr) => repr a -> repr () Source #
eof :: Liftable repr => Lookable (Output repr) => repr () Source #
Instances
(<:>) :: Applicable repr => repr a -> repr [a] -> repr [a] infixl 4 Source #
sequence :: Applicable repr => [repr a] -> repr [a] Source #
traverse :: Applicable repr => (a -> repr b) -> [a] -> repr [b] Source #
repeat :: Applicable repr => Int -> repr a -> repr [a] Source #
between :: Applicable repr => repr o -> repr c -> repr a -> repr a Source #
string :: Applicable repr => Alternable repr => Satisfiable Char repr => [Char] -> repr [Char] Source #
more :: Applicable repr => Satisfiable Char repr => Lookable repr => repr () Source #
char :: Applicable repr => Satisfiable Char repr => Char -> repr Char Source #
token :: Lift tok => Show tok => Eq tok => Applicable repr => Satisfiable tok repr => tok -> repr tok Source #
tokens :: Lift tok => Eq tok => Show tok => Applicable repr => Alternable repr => Satisfiable tok repr => [tok] -> repr [tok] Source #
void :: Applicable repr => repr a -> repr () Source #
unit :: Applicable repr => repr () Source #
pfoldr :: Applicable repr => Foldable repr => TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b Source #
pfoldr1 :: Applicable repr => Foldable repr => TermGrammar (a -> b -> b) -> TermGrammar b -> repr a -> repr b Source #
pfoldl :: Applicable repr => Foldable repr => TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b Source #
pfoldl1 :: Applicable repr => Foldable repr => TermGrammar (b -> a -> b) -> TermGrammar b -> repr a -> repr b Source #
chainl1' :: Applicable repr => Foldable repr => TermGrammar (a -> b) -> repr a -> repr (b -> a -> b) -> repr b Source #
chainl1 :: Applicable repr => Foldable repr => repr a -> repr (a -> a -> a) -> repr a Source #
chainl :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr (a -> a -> a) -> TermGrammar a -> repr a Source #
many :: Applicable repr => Foldable repr => repr a -> repr [a] Source #
some :: Applicable repr => Foldable repr => repr a -> repr [a] Source #
skipMany :: Applicable repr => Foldable repr => repr a -> repr () Source #
skipSome :: Applicable repr => Foldable repr => repr a -> repr () Source #
sepBy :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a] Source #
sepBy1 :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a] Source #
endBy :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a] Source #
endBy1 :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a] Source #
sepEndBy :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a] Source #
sepEndBy1 :: Applicable repr => Alternable repr => Foldable repr => repr a -> repr b -> repr [a] Source #