Safe Haskell | None |
---|---|
Language | Haskell2010 |
Language.Haskell.Grammar
Description
This module exports the original Haskell 2010 grammar with no extensions. Apart from use of parser combinators and some minor refactorings, the grammar productions closely correspond to those documented in the Haskell 2010 Language Report.
Synopsis
- type Parser (g :: (Type -> Type) -> Type) s = ParserT ((,) [[Lexeme s]]) g s
- data HaskellGrammar l t (f :: Type -> Type) (p :: Type -> Type) = HaskellGrammar {
- haskellModule :: p (f (Module l l f f))
- moduleLevel :: ModuleLevelGrammar l f p
- declarationLevel :: DeclarationGrammar l f p
- body :: p ([f (Import l l f f)], [f (Declaration l l f f)])
- typeTerm :: p (Type l l f f)
- bType :: p (Type l l f f)
- aType :: p (Type l l f f)
- generalTypeConstructor :: p (Type l l f f)
- rhs :: p (EquationRHS l l f f)
- guards :: p (NonEmpty (f (Statement l l f f)))
- qualifiers :: p (NonEmpty (f (Statement l l f f)))
- guard :: p (Statement l l f f)
- qualifier :: p (Statement l l f f)
- expression :: p (f (Expression l l f f))
- infixExpression :: p (f (Expression l l f f))
- leftInfixExpression :: p (f (Expression l l f f))
- lExpression :: p (f (Expression l l f f))
- dExpression :: p (f (Expression l l f f))
- fExpression :: p (f (Expression l l f f))
- aExpression :: p (f (Expression l l f f))
- bareExpression :: p (Expression l l f f)
- openBlockExpression :: p (Expression l l f f)
- closedBlockExpression :: p (Expression l l f f)
- prefixNegation :: p (Expression l l f f)
- alternatives :: p [f (CaseAlternative l l f f)]
- alternative :: p (CaseAlternative l l f f)
- statements :: p (GuardedExpression l l f f)
- statement :: p (f (Sum (Statement l l) (Expression l l) f f))
- fieldBinding :: p (FieldBinding l l f f)
- pattern :: p (Pattern l l f f)
- lPattern :: p (Pattern l l f f)
- aPattern :: p (Pattern l l f f)
- pPattern :: p (Pattern l l f f)
- fieldPattern :: p (FieldPattern l l f f)
- generalConstructor :: p (Constructor l l f f)
- variable :: p (Name l)
- constructor :: p (Name l)
- variableOperator :: p (Name l)
- constructorOperator :: p (Name l)
- operator :: p (Name l)
- qualifiedVariable :: p (QualifiedName l)
- qualifiedConstructor :: p (QualifiedName l)
- qualifiedVariableOperator :: p (QualifiedName l)
- qualifiedConstructorOperator :: p (QualifiedName l)
- qualifiedOperator :: p (QualifiedName l)
- qualifiedConstructorIdentifier :: p (QualifiedName l)
- qualifiedConstructorSymbol :: p (QualifiedName l)
- qualifiedTypeConstructor :: p (QualifiedName l)
- qualifiedVariableIdentifier :: p (QualifiedName l)
- qualifiedVariableSymbol :: p (QualifiedName l)
- constructorIdentifier :: p (Name l)
- constructorSymbol :: p (Name l)
- typeConstructor :: p (Name l)
- typeVar :: p (Name l)
- variableIdentifier :: p (Name l)
- variableSymbol :: p (Name l)
- literal :: p (Value l l f f)
- literalLexeme :: p (Value l l f f)
- doubleColon :: p ()
- rightDoubleArrow :: p ()
- rightArrow :: p ()
- leftArrow :: p ()
- integer :: p Integer
- integerLexeme :: p Integer
- float :: p Rational
- floatLexeme :: p Rational
- decimal :: p t
- octal :: p t
- hexadecimal :: p t
- exponent :: p t
- charLiteral :: p Char
- charLexeme :: p Char
- escape :: p Char
- stringLiteral :: p Text
- stringLexeme :: p Text
- data ModuleLevelGrammar l (f :: Type -> Type) (p :: Type -> Type) = ModuleLevelGrammar {
- exports :: p [f (Export l l f f)]
- export :: p (Export l l f f)
- importDeclaration :: p (Import l l f f)
- importSpecification :: p (ImportSpecification l l f f)
- importItem :: p (ImportItem l l f f)
- members :: p (Members l)
- cname :: p (Name l)
- data DeclarationGrammar l (f :: NodeWrap) (p :: Type -> Type) = DeclarationGrammar {
- topLevelDeclaration :: p (Declaration l l f f)
- declarations :: p [f (Declaration l l f f)]
- declaration :: p (Declaration l l f f)
- inClassDeclaration :: p (Declaration l l f f)
- inInstanceDeclaration :: p (Declaration l l f f)
- equationDeclaration :: p (Declaration l l f f)
- generalDeclaration :: p (Declaration l l f f)
- whereClauses :: p [f (Declaration l l f f)]
- variables :: p (NonEmpty (Name l))
- fixity :: p (Associativity l)
- declaredConstructors :: p [f (DataConstructor l l f f)]
- declaredConstructor :: p (DataConstructor l l f f)
- infixConstructorArgType :: p (Type l l f f)
- strictType :: p (Type l l f f)
- newConstructor :: p (DataConstructor l l f f)
- fieldDeclaration :: p (FieldDeclaration l l f f)
- optionalContext :: p (Context l l f f)
- optionalTypeSignatureContext :: p (Context l l f f)
- context :: p (Context l l f f)
- constraint :: p (Context l l f f)
- typeApplications :: p (Type l l f f)
- simpleType :: p (TypeLHS l l f f)
- classLHS :: p (TypeLHS l l f f)
- derivingClause :: p [f (DerivingClause l l f f)]
- instanceDesignator :: p (ClassInstanceLHS l l f f)
- instanceTypeDesignator :: p (Type l l f f)
- typeVarApplications :: p (Type l l f f)
- typeVarTuple :: p (NonEmpty (f (Type l l f f)))
- foreignDeclaration :: p (Declaration l l f f)
- callingConvention :: p (CallingConvention l)
- safety :: p (CallSafety l)
- foreignType :: p (Type l l f f)
- foreignReturnType :: p (Type l l f f)
- foreignArgType :: p (Type l l f f)
- functionLHS :: p (EquationLHS l l f f)
- qualifiedTypeClass :: p (QualifiedName l)
- typeClass :: p (Name l)
- grammar :: forall l (g :: (Type -> Type) -> Type) t. (Apply g, Haskell l, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) (CaseAlternative l l), Foldable (Serialization (Down Int) t) (Declaration l l), Foldable (Serialization (Down Int) t) (Expression l l), Foldable (Serialization (Down Int) t) (Import l l), Foldable (Serialization (Down Int) t) (Statement l l)) => GrammarBuilder (HaskellGrammar l t (NodeWrap t)) g (ParserT ((,) [[Lexeme t]])) t
- grammar2010 :: (Haskell l, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) (CaseAlternative l l), Foldable (Serialization (Down Int) t) (Declaration l l), Foldable (Serialization (Down Int) t) (Expression l l), Foldable (Serialization (Down Int) t) (Import l l), Foldable (Serialization (Down Int) t) (Statement l l)) => Grammar (HaskellGrammar l t (NodeWrap t)) (ParserT ((,) [[Lexeme t]])) t
- keyword :: forall (g :: (Type -> Type) -> Type) s. (Apply g, Ord s, Show s, TextualMonoid s) => s -> Parser g s ()
- delimiter :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => t -> Parser g t ()
- terminator :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => t -> Parser g t ()
- moduleLexeme :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t (NonEmpty (Name l))
- moduleId :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t (ModuleName l)
- nameQualifier :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t (Name l -> QualifiedName l)
- nameToken :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t t -> Parser g t (Name l)
- constructorSymbolLexeme :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t t
- variableSymbolLexeme :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t t
- whiteSpace :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t ()
- comment :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t ()
- reservedWords :: (Ord t, TextualMonoid t) => Set t
- isLineChar :: Char -> Bool
- isNameTailChar :: Char -> Bool
- isSymbol :: Char -> Bool
- blockOf :: forall (g :: (Type -> Type) -> Type) t node. (Apply g, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) node) => Parser g t (NodeWrap t (node (NodeWrap t) (NodeWrap t))) -> Parser g t [NodeWrap t (node (NodeWrap t) (NodeWrap t))]
- blockWith :: forall (g :: (Type -> Type) -> Type) t node. (Apply g, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) node) => (Int -> t -> NodeWrap t (node (NodeWrap t) (NodeWrap t)) -> Bool) -> Parser g t () -> Parser g t (NodeWrap t (node (NodeWrap t) (NodeWrap t))) -> Parser g t [NodeWrap t (node (NodeWrap t) (NodeWrap t))]
- blockTerminatorKeyword :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, OutlineMonoid t, Show t) => Parser g t ()
- oneExtendedLine :: (Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) node) => Int -> t -> NodeWrap t (node (NodeWrap t) (NodeWrap t)) -> Bool
- verifyStatements :: forall l (g :: (Type -> Type) -> Type) t. (Haskell l, Apply g, Ord t) => [NodeWrap t (Sum (Statement l l) (Expression l l) (NodeWrap t) (NodeWrap t))] -> Parser g t (GuardedExpression l l (NodeWrap t) (NodeWrap t))
- class TextualMonoid t => OutlineMonoid t where
- currentColumn :: t -> Int
- inputColumn :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, OutlineMonoid t) => Parser g t Int
- type NodeWrap s = Wrapped (Down Int) s
- storeToken :: forall (g :: (Type -> Type) -> Type) t a. (Apply g, Ord t, TextualMonoid t) => Parser g t a -> Parser g t a
- wrap :: forall (g :: (Type -> Type) -> Type) t a. (Apply g, Ord t, TextualMonoid t) => Parser g t a -> Parser g t (NodeWrap t a)
- rewrap :: (NodeWrap t a -> b) -> NodeWrap t a -> NodeWrap t b
- unwrap :: NodeWrap t a -> a
- expressionToStatement :: Haskell l => NodeWrap t (Sum (Statement l l) (Expression l l) (NodeWrap t) (NodeWrap t)) -> NodeWrap t (Statement l l (NodeWrap t) (NodeWrap t))
- startSepEndBy :: Alternative m => m a -> m sep -> m [a]
Documentation
type Parser (g :: (Type -> Type) -> Type) s = ParserT ((,) [[Lexeme s]]) g s Source #
The parser keeps track of the lexemes consumed while parsing the current node.
The Haskell 2010 grammar
data HaskellGrammar l t (f :: Type -> Type) (p :: Type -> Type) Source #
Top level of the grammar, including types and expressions
Constructors
Instances
data ModuleLevelGrammar l (f :: Type -> Type) (p :: Type -> Type) Source #
The grammar productions that are relevant only at the module level
Constructors
ModuleLevelGrammar | |
Fields
|
Instances
data DeclarationGrammar l (f :: NodeWrap) (p :: Type -> Type) Source #
The grammar productions that are only relevant inside declarations
Constructors
Instances
grammar :: forall l (g :: (Type -> Type) -> Type) t. (Apply g, Haskell l, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) (CaseAlternative l l), Foldable (Serialization (Down Int) t) (Declaration l l), Foldable (Serialization (Down Int) t) (Expression l l), Foldable (Serialization (Down Int) t) (Import l l), Foldable (Serialization (Down Int) t) (Statement l l)) => GrammarBuilder (HaskellGrammar l t (NodeWrap t)) g (ParserT ((,) [[Lexeme t]])) t Source #
Extensible grammar builder with all the syntax of Haskell 2010
grammar2010 :: (Haskell l, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) (CaseAlternative l l), Foldable (Serialization (Down Int) t) (Declaration l l), Foldable (Serialization (Down Int) t) (Expression l l), Foldable (Serialization (Down Int) t) (Import l l), Foldable (Serialization (Down Int) t) (Statement l l)) => Grammar (HaskellGrammar l t (NodeWrap t)) (ParserT ((,) [[Lexeme t]])) t Source #
Fixed (and thus non-extensible) grammar of Haskell 2010
Lexical layer
keyword :: forall (g :: (Type -> Type) -> Type) s. (Apply g, Ord s, Show s, TextualMonoid s) => s -> Parser g s () Source #
delimiter :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => t -> Parser g t () Source #
terminator :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => t -> Parser g t () Source #
moduleLexeme :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t (NonEmpty (Name l)) Source #
moduleId :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t (ModuleName l) Source #
nameQualifier :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t (Name l -> QualifiedName l) Source #
nameToken :: forall (g :: (Type -> Type) -> Type) l t. (Apply g, Haskell l, Ord t, Show t, TextualMonoid t) => Parser g t t -> Parser g t (Name l) Source #
constructorSymbolLexeme :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t t Source #
variableSymbolLexeme :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t t Source #
whiteSpace :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t () Source #
comment :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, Show t, TextualMonoid t) => Parser g t () Source #
reservedWords :: (Ord t, TextualMonoid t) => Set t Source #
isLineChar :: Char -> Bool Source #
isNameTailChar :: Char -> Bool Source #
Layout parsing
blockOf :: forall (g :: (Type -> Type) -> Type) t node. (Apply g, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) node) => Parser g t (NodeWrap t (node (NodeWrap t) (NodeWrap t))) -> Parser g t [NodeWrap t (node (NodeWrap t) (NodeWrap t))] Source #
The combinator turns a parser for a single block item (statement or case alternative or declaration or ...) into the parser for an aligned block of the things.
Arguments
:: forall (g :: (Type -> Type) -> Type) t node. (Apply g, Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) node) | |
=> (Int -> t -> NodeWrap t (node (NodeWrap t) (NodeWrap t)) -> Bool) | test if the indent, the line and the node parsed from it are a valid block item, |
-> Parser g t () | parser for a keyword that can't start a valid block item, |
-> Parser g t (NodeWrap t (node (NodeWrap t) (NodeWrap t))) | parser for a single block item |
-> Parser g t [NodeWrap t (node (NodeWrap t) (NodeWrap t))] |
A more general form of blockOf
blockTerminatorKeyword :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, OutlineMonoid t, Show t) => Parser g t () Source #
A default argument to blockWith
oneExtendedLine :: (Ord t, Show t, OutlineMonoid t, Foldable (Serialization (Down Int) t) node) => Int -> t -> NodeWrap t (node (NodeWrap t) (NodeWrap t)) -> Bool Source #
A default argument to blockWith
verifyStatements :: forall l (g :: (Type -> Type) -> Type) t. (Haskell l, Apply g, Ord t) => [NodeWrap t (Sum (Statement l l) (Expression l l) (NodeWrap t) (NodeWrap t))] -> Parser g t (GuardedExpression l l (NodeWrap t) (NodeWrap t)) Source #
Check if the given sequence of statements and expressions ends with an expression, and if they do pack them all
into a single GuardedExpression
.
class TextualMonoid t => OutlineMonoid t where Source #
Class of inputs that keep track of their current position in terms of line and column
Methods
currentColumn :: t -> Int Source #
The column of the current input position, i.e. the count of characters from the position to the preceding line start
Instances
OutlineMonoid (LinePositioned Text) Source # | |
Defined in Language.Haskell.Grammar Methods currentColumn :: LinePositioned Text -> Int Source # | |
OutlineMonoid (Shadowed Text) Source # | |
Defined in Language.Haskell.Grammar |
inputColumn :: forall (g :: (Type -> Type) -> Type) t. (Apply g, Ord t, OutlineMonoid t) => Parser g t Int Source #
Returns the column of the current input position
Node wrapping
type NodeWrap s = Wrapped (Down Int) s Source #
The wrap of every parsed AST node keeps track of the parsed input range and the lexemes consumed from it.
storeToken :: forall (g :: (Type -> Type) -> Type) t a. (Apply g, Ord t, TextualMonoid t) => Parser g t a -> Parser g t a Source #
wrap :: forall (g :: (Type -> Type) -> Type) t a. (Apply g, Ord t, TextualMonoid t) => Parser g t a -> Parser g t (NodeWrap t a) Source #
Apply the argument parser and wrap the resulting node.
rewrap :: (NodeWrap t a -> b) -> NodeWrap t a -> NodeWrap t b Source #
Rewrap the node with an empty wrap.
Utility functions
expressionToStatement :: Haskell l => NodeWrap t (Sum (Statement l l) (Expression l l) (NodeWrap t) (NodeWrap t)) -> NodeWrap t (Statement l l (NodeWrap t) (NodeWrap t)) Source #
Convert a tagged Sum
of either Statement
or Expression
into a Statement
.
startSepEndBy :: Alternative m => m a -> m sep -> m [a] Source #
Parses a sequence of zero or more occurrences of p
, separated and optionally started or ended by one or more of
sep
.
Orphan instances
(Apply g, Ord t, Show t, TextualMonoid t) => LexicalParsing (Parser g t) Source # | |
Methods lexicalWhiteSpace :: Parser g t () # someLexicalSpace :: Parser g t () # lexicalComment :: Parser g t () # lexicalSemicolon :: Parser g t Char # lexicalToken :: Parser g t a -> Parser g t a # identifierToken :: Parser g t (ParserInput (Parser g t)) -> Parser g t (ParserInput (Parser g t)) # isIdentifierStartChar :: Char -> Bool # isIdentifierFollowChar :: Char -> Bool # identifier :: Parser g t (ParserInput (Parser g t)) # keyword :: ParserInput (Parser g t) -> Parser g t () # | |
(Apply g, Ord t, Show t, TextualMonoid t) => TokenParsing (Parser g t) Source # | |