License | BSD-3-Clause |
---|---|
Maintainer | Jamie Willis |
Stability | unstable |
Safe Haskell | None |
Language | Haskell2010 |
This module exposes all of the required functionality found in the internals of the library out to the user API.
Since: 0.1.0.0
Synopsis
- module Parsley.Internal.Core
- data Reg (r :: Type) a
- conditional :: ParserOps rep => [(rep (a -> Bool), Parser b)] -> Parser a -> Parser b -> Parser b
- pure :: ParserOps rep => rep a -> Parser a
- satisfy :: ParserOps rep => rep (Char -> Bool) -> Parser Char
- (<*>) :: Parser (a -> b) -> Parser a -> Parser b
- (<*) :: Parser a -> Parser b -> Parser a
- (*>) :: Parser a -> Parser b -> Parser b
- empty :: Parser a
- (<|>) :: Parser a -> Parser a -> Parser a
- lookAhead :: Parser a -> Parser a
- notFollowedBy :: Parser a -> Parser ()
- try :: Parser a -> Parser a
- branch :: Parser (Either a b) -> Parser (a -> c) -> Parser (b -> c) -> Parser c
- chainPre :: Parser (a -> a) -> Parser a -> Parser a
- chainPost :: Parser a -> Parser (a -> a) -> Parser a
- newRegister :: Parser a -> (forall r. Reg r a -> Parser b) -> Parser b
- get :: Reg r a -> Parser a
- put :: Reg r a -> Parser a -> Parser ()
- debug :: String -> Parser a -> Parser a
- class Quapplicative q where
- data WQ a
- type Code a = Q (TExp a)
- class Trace where
- compile :: forall compiled a. Trace => Parser a -> (forall x. Maybe (MVar x) -> Fix Combinator x -> Set IΣVar -> IMVar -> IΣVar -> compiled x) -> (compiled a, DMap MVar compiled)
- class (InputPrep input, Ops input) => Input input
- eval :: forall input a. (Input input, Trace) => Code input -> (LetBinding input a a, DMap MVar (LetBinding input a)) -> Code (Maybe a)
- codeGen :: (Trace, PositionOps o) => Maybe (MVar x) -> Fix Combinator x -> Set IΣVar -> IMVar -> IΣVar -> LetBinding o a x
Documentation
module Parsley.Internal.Core
data Reg (r :: Type) a Source #
This is an opaque representation of a parsing register. It cannot be manipulated as a user, and the
type parameter r
is used to ensure that it cannot leak out of the scope it has been created in.
It is the abstracted representation of a runtime storage location.
Since: 0.1.0.0
:: ParserOps rep | |
=> [(rep (a -> Bool), Parser b)] | A list of predicates and their outcomes |
-> Parser a | A parser whose result is used to choose an outcome |
-> Parser b | A parser who will be executed if no predicates succeed |
-> Parser b |
conditional fqs p def
first parses p
, then it will try each of the predicates in fqs
in turn
until one of them returns True
. The corresponding parser for the first predicate that succeeded
is then executes, or if none of the predicates succeeded then the def
parser is executed.
Since: 0.1.0.0
pure :: ParserOps rep => rep a -> Parser a Source #
Lift a value into the parser world without consuming input or having any other effect.
Since: 0.1.0.0
:: ParserOps rep | |
=> rep (Char -> Bool) | The predicate that a character must satisfy to be parsed |
-> Parser Char | A parser that matches a single character matching the predicate |
Attempts to read a single character matching the provided predicate. If it succeeds, the character will be returned and consumed, otherwise the parser will fail having consumed no input.
Since: 0.1.0.0
(<*>) :: Parser (a -> b) -> Parser a -> Parser b infixl 4 Source #
Sequential application of one parser's result to another's. The parsers must both succeed, one after the other to combine their results. If either parser fails then the combinator will fail.
Since: 0.1.0.0
(<*) :: Parser a -> Parser b -> Parser a infixl 4 Source #
Sequence two parsers, keeping the result of the second and discarding the result of the first.
Since: 0.1.0.0
(*>) :: Parser a -> Parser b -> Parser b infixl 4 Source #
Sequence two parsers, keeping the result of the first and discarding the result of the second.
Since: 0.1.0.0
(<|>) :: Parser a -> Parser a -> Parser a infixr 3 Source #
This combinator implements branching within a parser. It is left-biased, so that if the first branch
succeeds, the second will not be attempted. In accordance with parsec
semantics, if the first
branch failed having consumed input the second branch cannot be taken. (see try
)
Since: 0.1.0.0
lookAhead :: Parser a -> Parser a Source #
This combinator will attempt to parse a given parser. If it succeeds, the result is returned without having consumed any input. If it fails, however, any consumed input remains consumed.
Since: 0.1.0.0
notFollowedBy :: Parser a -> Parser () Source #
This combinator will ensure that a given parser fails. If the parser does fail, a ()
is returned
and no input is consumed. If the parser succeeded, then this combinator will fail, however it will
not consume any input.
Since: 0.1.0.0
try :: Parser a -> Parser a Source #
This combinator allows a parser to backtrack on failure, which is to say that it will
not have consumed any input if it were to fail. This is important since parsec
semantics demand
that the second branch of (
can only be taken if the first did not consume input on failure.<|>
)
Excessive use of try
will reduce the efficiency of the parser and effect the generated error
messages. It should only be used in one of two circumstances:
- When two branches of a parser share a common leading prefix (in which case, it is often better to try and factor this out).
- When a parser needs to be executed atomically (for example, tokens).
Since: 0.1.0.0
:: Parser (Either a b) | The first parser to execute |
-> Parser (a -> c) | The parser to execute if the first returned a |
-> Parser (b -> c) | The parser to execute if the first returned a |
-> Parser c |
One of the core Selective
operations. The behaviour of branch p l r
is to first to parse
p
, if it fails then the combinator fails. If p
succeeded then if its result is a Left
, then
the parser l
is executed and applied to the result of p
, otherwise r
is executed and applied
to the right from a Right
.
Crucially, only one of l
or r
will be executed on p
's success.
Since: 0.1.0.0
chainPre :: Parser (a -> a) -> Parser a -> Parser a Source #
This combinator parses repeated applications of an operator to a single final operand. This is primarily used to parse prefix operators in expressions.
Since: 0.1.0.0
chainPost :: Parser a -> Parser (a -> a) -> Parser a Source #
This combinator parses repeated applications of an operator to a single initial operand. This is primarily used to parse postfix operators in expressions.
Since: 0.1.0.0
:: Parser a | Parser with which to initialise the register |
-> (forall r. Reg r a -> Parser b) | Used to generate the second parser to execute |
-> Parser b |
Creates a new register initialised with the value obtained from parsing the first argument. This register is provided to the second argument, a function that generates a parser depending on operations derived from the register. This parser is then performed.
Note: The rank-2 type here serves a similar purpose to that in the ST
monad. It prevents the
register from leaking outside of the scope of the function, safely encapsulating the stateful
effect of the register.
Since: 0.1.0.0
get :: Reg r a -> Parser a Source #
Fetches a value from a register and returns it as its result.
Since: 0.1.0.0
put :: Reg r a -> Parser a -> Parser () Source #
Puts the result of the given parser into the given register. The old value in the register will be lost.
Since: 0.1.0.0
:: String | The name that identifies the wrapped parser in the debug trace |
-> Parser a | The parser to track during execution |
-> Parser a |
This combinator can be used to debug parsers that have gone wrong. Simply
wrap a parser with debug name
and when that parser is executed it will
print a debug trace on entry and exit along with the current context of the
input.
Since: 0.1.0.0
class Quapplicative q where Source #
This class is used to manipulate the representations of both user-land values and defunctionalised representations. It can be used to construct these values as well as extract their underlying value and code representation on demand.
It is named after the Applicative
class, with the Q
standing for "code". The (
operator
is analogous to >*<
)(<*>)
and makeQ
analogous to pure
.
Since: 0.1.0.0
makeQ :: a -> Code a -> q a Source #
Combines a value with its representation to build one of the representation types.
Since: 0.1.0.0
Extracts the regular value out of the representation.
Since: 0.1.0.0
_code :: q a -> Code a Source #
Extracts the representation of the value as code.
Since: 0.1.0.0
(>*<) :: q (a -> b) -> q a -> q b infixl 9 Source #
Pronounced "quapp", this can be used to combine the code of a function with the code of a value.
const5 = makeQ const [||const||] >*< makeQ 5 [||5||]
is the same as saying
const5 = makeQ (const 5) [||const 5||]
It is more idiomatically found as the output to the IdiomsPlugin
.
Since: 0.1.0.0
Instances
Quapplicative WQ Source # | This instance is used to manipulate values of Since: 0.1.0.0 |
Quapplicative Defunc Source # | This instance is used to manipulate values of Since: 0.1.0.0 |
Pronounced "with code", this datatype is the representation for user-land values. It pairs
a value up with its representation as Haskell Code
. It should be manipulated using
Quapplicative
.
Since: 0.1.0.0
type Code a = Q (TExp a) Source #
A type alias for typed template haskell code, which represents the Haskell AST for a given value.
Since: 0.1.0.0
Instances
Trace Source # | This instance, when in scope, will enable additional debug output from the Parsley compilation process. It will always superscede the default instance defined in Parsley. Since: 0.1.0.0 |
Defined in Parsley.Internal.Verbose | |
Trace Source # | The default instance for Since: 0.1.0.0 |
compile :: forall compiled a. Trace => Parser a -> (forall x. Maybe (MVar x) -> Fix Combinator x -> Set IΣVar -> IMVar -> IΣVar -> compiled x) -> (compiled a, DMap MVar compiled) Source #
class (InputPrep input, Ops input) => Input input Source #
Instances
Input ByteString Source # | |
Defined in Parsley.Internal.Backend.Machine | |
Input ByteString Source # | |
Defined in Parsley.Internal.Backend.Machine | |
Input Text Source # | |
Defined in Parsley.Internal.Backend.Machine | |
Input Stream Source # | |
Defined in Parsley.Internal.Backend.Machine | |
Input CharList Source # | |
Defined in Parsley.Internal.Backend.Machine | |
Input Text16 Source # | |
Defined in Parsley.Internal.Backend.Machine | |
Input [Char] Source # | |
Defined in Parsley.Internal.Backend.Machine | |
Input (UArray Int Char) Source # | |
Defined in Parsley.Internal.Backend.Machine |
eval :: forall input a. (Input input, Trace) => Code input -> (LetBinding input a a, DMap MVar (LetBinding input a)) -> Code (Maybe a) Source #
codeGen :: (Trace, PositionOps o) => Maybe (MVar x) -> Fix Combinator x -> Set IΣVar -> IMVar -> IΣVar -> LetBinding o a x Source #