{-# Language FlexibleContexts, FlexibleInstances, OverloadedStrings, Rank2Types, RecordWildCards, ScopedTypeVariables,
             TypeFamilies, TypeSynonymInstances, TemplateHaskell #-}

-- | Modula-2 grammar adapted from ''Report on the Programming Language Modula-2''

module Language.Modula2.Grammar (module Language.Modula2.Grammar, Lexeme(..), ParsedLexemes(..)) where

import Control.Applicative
import Control.Arrow (first)
import Control.Monad (guard, void)
import Data.Char (isAlphaNum, isDigit, isHexDigit, isLetter, isOctDigit, isSpace)
import Data.List.NonEmpty (NonEmpty, toList)
import Data.Ord (Down)
import Data.Maybe (catMaybes)
import Data.Monoid ((<>))
import Data.Text (Text, unpack)
import Numeric (readOct, readDec, readHex, readFloat)
import Text.Grampa
import Text.Grampa.ContextFree.SortedMemoizing.Transformer.LeftRecursive (ParserT, autochain, lift, tmap)
import Text.Parser.Combinators (sepBy, sepBy1, sepByNonEmpty, try)
import Text.Parser.Token (braces, brackets, parens)

import qualified Rank2
import qualified Rank2.TH
import Language.Oberon.Grammar (Lexeme(..), TokenType(..), ParsedLexemes(Trailing))

import qualified Language.Modula2.Abstract as Abstract
import qualified Language.Modula2.AST as AST

type Parser = ParserT ((,) [[Lexeme]])

-- | The names and types of all the Modula-2 grammar productions
data Modula2Grammar l f p = Modula2Grammar {
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
ident :: p Abstract.Ident,
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Value l l f f)
number :: p (Abstract.Value l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Value l l f f)
integer :: p (Abstract.Value l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Value l l f f)
real :: p (Abstract.Value l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
scaleFactor :: p Text,
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
hexDigit :: p Text,
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
digit :: p Text,
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
octalDigit :: p Text,
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
string_prod :: p Text,
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (QualIdent l)
qualident :: p (Abstract.QualIdent l),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
constantDeclaration :: p (Abstract.Declaration l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Definition l l f f)
constantDefinition :: p (Abstract.Definition l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
constExpression :: p (NodeWrap (Abstract.ConstExpression l l f f)),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p RelOp
relation :: p Abstract.RelOp,
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p
-> p (f (ConstExpression l l f f)
      -> f (ConstExpression l l f f) -> ConstExpression l l f f)
addOperator :: p (f (Abstract.Expression l l f f) -> f (Abstract.Expression l l f f) -> Abstract.Expression l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p
-> p (f (ConstExpression l l f f)
      -> f (ConstExpression l l f f) -> ConstExpression l l f f)
mulOperator :: p (f (Abstract.Expression l l f f) -> f (Abstract.Expression l l f f) -> Abstract.Expression l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (ConstExpression l l f f)
set :: p (Abstract.Expression l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Element l l f f)
element :: p (Abstract.Element l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
typeDeclaration :: p (Abstract.Declaration l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Definition l l f f)
typeDefinition :: p (Abstract.Definition l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
type_prod :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
simpleType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
enumeration :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (IdentList l)
identList :: p (Abstract.IdentList l),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
subrangeType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
arrayType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
recordType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (FieldList l l f f)]
fieldListSequence :: p [f (Abstract.FieldList l l f f)],
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FieldList l l f f)
fieldList :: p (Abstract.FieldList l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Variant l l f f)
variant :: p (Abstract.Variant l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NonEmpty (f (CaseLabels l l f f)))
caseLabelList :: p (NonEmpty (f (Abstract.CaseLabels l l f f))),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (CaseLabels l l f f)
caseLabels :: p (Abstract.CaseLabels l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
setType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
pointerType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
procedureType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FormalParameters l l f f)
formalTypeList :: p (Abstract.FormalParameters l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
variableDeclaration :: p (Abstract.Declaration l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Definition l l f f)
variableDefinition :: p (Abstract.Definition l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Designator l l f f)
designator :: p (Abstract.Designator l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NonEmpty (f (ConstExpression l l f f)))
expList :: p (NonEmpty (f (Abstract.Expression l l f f))),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
expression :: p (NodeWrap (Abstract.Expression l l f f)),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
simpleExpression :: p (NodeWrap (Abstract.Expression l l f f)),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
term :: p (NodeWrap (Abstract.Expression l l f f)),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
factor :: p (NodeWrap (Abstract.Expression l l f f)),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (ConstExpression l l f f)]
actualParameters :: p [f (Abstract.Expression l l f f)],
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
statement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
assignment :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
procedureCall :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (StatementSequence l l f f))
statementSequence :: p (NodeWrap (Abstract.StatementSequence l l f f)),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
ifStatement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
caseStatement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Case l l f f)
case_prod :: p (Abstract.Case l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
whileStatement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
repeatStatement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
forStatement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
loopStatement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
withStatement :: p (Abstract.Statement l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
procedureDeclaration :: p (Abstract.Declaration l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Text, ProcedureHeading l l f f)
procedureHeading :: p (Abstract.Ident, Abstract.ProcedureHeading l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Block l l f f)
block :: p (Abstract.Block l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (Declaration l l f f)]
declarationSequence :: p [f (Abstract.Declaration l l f f)],
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FormalParameters l l f f)
formalParameters :: p (Abstract.FormalParameters l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FPSection l l f f)
fPSection :: p (Abstract.FPSection l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
formalType :: p (Abstract.Type l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
moduleDeclaration :: p (Abstract.Declaration l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
priority :: p (NodeWrap (Abstract.Priority l l f f)),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Export l)
export :: p (Abstract.Export l),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Import l)
import_prod :: p (Abstract.Import l),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Module l l f f)
definitionModule :: p (Abstract.Module l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (Definition l l f f)]
definitionSequence :: p [f (Abstract.Definition l l f f)],
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Module l l f f)
programModule :: p (Abstract.Module l l f f),
   forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (Module l l f f))
compilationUnit :: p (NodeWrap (Abstract.Module l l f f))
   }

type NodeWrap = (,) (Down Int, ParsedLexemes, Down Int)

$(Rank2.TH.deriveAll ''Modula2Grammar)

modula2grammar :: Grammar (Modula2Grammar AST.Language NodeWrap) Parser Text
modula2grammar :: Grammar (Modula2Grammar Language NodeWrap) Parser Text
modula2grammar = Grammar (Modula2Grammar Language NodeWrap) Parser Text
-> Grammar (Modula2Grammar Language NodeWrap) Parser Text
forall (p :: ((* -> *) -> *) -> * -> * -> *) (g :: (* -> *) -> *) s
       (f :: * -> *) (rl :: * -> * -> *) (cb :: * -> *).
(cb ~ Const (g (Const Bool)), f ~ GrammarFunctor (p g s), f ~ rl s,
 LeftRecParsing p g s rl, DeterministicParsing (p g s), Apply g,
 Traversable g, Distributive g, Logistic g) =>
g (Fixed p g s) -> g (Fixed p g s)
autochain (Grammar (Modula2Grammar Language NodeWrap) Parser Text
 -> Grammar (Modula2Grammar Language NodeWrap) Parser Text)
-> Grammar (Modula2Grammar Language NodeWrap) Parser Text
-> Grammar (Modula2Grammar Language NodeWrap) Parser Text
forall a b. (a -> b) -> a -> b
$ (Grammar (Modula2Grammar Language NodeWrap) Parser Text
 -> Grammar (Modula2Grammar Language NodeWrap) Parser Text)
-> Grammar (Modula2Grammar Language NodeWrap) Parser Text
forall (m :: * -> *) (g :: (* -> *) -> *).
(GrammarParsing m, g ~ ParserGrammar m, GrammarConstraint m g,
 Distributive g) =>
(g m -> g m) -> g m
forall (g :: (* -> *) -> *).
(g
 ~ ParserGrammar
     (Fixed
        (ParserT ((,) [[Lexeme]]))
        (Modula2Grammar Language NodeWrap)
        Text),
 GrammarConstraint
   (Fixed
      (ParserT ((,) [[Lexeme]])) (Modula2Grammar Language NodeWrap) Text)
   g,
 Distributive g) =>
(g (Fixed
      (ParserT ((,) [[Lexeme]])) (Modula2Grammar Language NodeWrap) Text)
 -> g (Fixed
         (ParserT ((,) [[Lexeme]]))
         (Modula2Grammar Language NodeWrap)
         Text))
-> g (Fixed
        (ParserT ((,) [[Lexeme]])) (Modula2Grammar Language NodeWrap) Text)
fixGrammar Grammar (Modula2Grammar Language NodeWrap) Parser Text
-> Grammar (Modula2Grammar Language NodeWrap) Parser Text
forall l (g :: (* -> *) -> *).
(Modula2 l, Apply g, LexicalParsing (Parser g Text)) =>
GrammarBuilder (Modula2Grammar l NodeWrap) g Parser Text
grammar

-- | All the productions of Modula-2 grammar
grammar :: forall l g. (Abstract.Modula2 l, Rank2.Apply g, LexicalParsing (Parser g Text))
        => GrammarBuilder (Modula2Grammar l NodeWrap) g Parser Text
grammar :: forall l (g :: (* -> *) -> *).
(Modula2 l, Apply g, LexicalParsing (Parser g Text)) =>
GrammarBuilder (Modula2Grammar l NodeWrap) g Parser Text
grammar g :: Modula2Grammar l NodeWrap (Parser g Text)
g@Modula2Grammar{Parser g Text [NodeWrap (Declaration l l NodeWrap NodeWrap)]
Parser g Text [NodeWrap (Expression l l NodeWrap NodeWrap)]
Fixed
  (ParserT ((,) [[Lexeme]]))
  g
  Text
  [((Down Int, ParsedLexemes, Down Int),
    FieldList l l NodeWrap NodeWrap)]
Parser g Text [NodeWrap (Definition l l NodeWrap NodeWrap)]
Parser
  g Text (NonEmpty (NodeWrap (Expression l l NodeWrap NodeWrap)))
Parser
  g Text (NonEmpty (NodeWrap (CaseLabels l l NodeWrap NodeWrap)))
Parser g Text (IdentList l)
Parser g Text (NodeWrap (Module l l NodeWrap NodeWrap))
Parser g Text (NodeWrap (Expression l l NodeWrap NodeWrap))
Parser g Text (NodeWrap (StatementSequence l l NodeWrap NodeWrap))
Parser g Text (Text, ProcedureHeading l l NodeWrap NodeWrap)
Fixed (ParserT ((,) [[Lexeme]])) g Text Text
Parser g Text (Module l l NodeWrap NodeWrap)
Parser g Text (Declaration l l NodeWrap NodeWrap)
Parser g Text (Type l l NodeWrap NodeWrap)
Parser g Text (Statement l l NodeWrap NodeWrap)
Parser g Text (Expression l l NodeWrap NodeWrap)
Parser g Text (Designator l l NodeWrap NodeWrap)
Parser g Text (Value l l NodeWrap NodeWrap)
Parser g Text (FieldList l l NodeWrap NodeWrap)
Parser g Text (FormalParameters l l NodeWrap NodeWrap)
Parser g Text (FPSection l l NodeWrap NodeWrap)
Parser g Text (Block l l NodeWrap NodeWrap)
Parser g Text (Case l l NodeWrap NodeWrap)
Parser g Text (CaseLabels l l NodeWrap NodeWrap)
Parser g Text (Element l l NodeWrap NodeWrap)
Parser g Text (Import l)
Parser g Text (QualIdent l)
Parser g Text RelOp
Parser g Text (Export l)
Parser g Text (Definition l l NodeWrap NodeWrap)
Parser g Text (Variant l l NodeWrap NodeWrap)
Parser
  g
  Text
  (NodeWrap (Expression l l NodeWrap NodeWrap)
   -> NodeWrap (Expression l l NodeWrap NodeWrap)
   -> Expression l l NodeWrap NodeWrap)
ident :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
number :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Value l l f f)
integer :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Value l l f f)
real :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Value l l f f)
scaleFactor :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
hexDigit :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
digit :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
octalDigit :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
string_prod :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p Text
qualident :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (QualIdent l)
constantDeclaration :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
constantDefinition :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Definition l l f f)
constExpression :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
relation :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p RelOp
addOperator :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p
-> p (f (ConstExpression l l f f)
      -> f (ConstExpression l l f f) -> ConstExpression l l f f)
mulOperator :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p
-> p (f (ConstExpression l l f f)
      -> f (ConstExpression l l f f) -> ConstExpression l l f f)
set :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (ConstExpression l l f f)
element :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Element l l f f)
typeDeclaration :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
typeDefinition :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Definition l l f f)
type_prod :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
simpleType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
enumeration :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
identList :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (IdentList l)
subrangeType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
arrayType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
recordType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
fieldListSequence :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (FieldList l l f f)]
fieldList :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FieldList l l f f)
variant :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Variant l l f f)
caseLabelList :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NonEmpty (f (CaseLabels l l f f)))
caseLabels :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (CaseLabels l l f f)
setType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
pointerType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
procedureType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
formalTypeList :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FormalParameters l l f f)
variableDeclaration :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
variableDefinition :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Definition l l f f)
designator :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Designator l l f f)
expList :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NonEmpty (f (ConstExpression l l f f)))
expression :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
simpleExpression :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
term :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
factor :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
actualParameters :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (ConstExpression l l f f)]
statement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
assignment :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
procedureCall :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
statementSequence :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (StatementSequence l l f f))
ifStatement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
caseStatement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
case_prod :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Case l l f f)
whileStatement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
repeatStatement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
forStatement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
loopStatement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
withStatement :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Statement l l f f)
procedureDeclaration :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
procedureHeading :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Text, ProcedureHeading l l f f)
block :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Block l l f f)
declarationSequence :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (Declaration l l f f)]
formalParameters :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FormalParameters l l f f)
fPSection :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (FPSection l l f f)
formalType :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Type l l f f)
moduleDeclaration :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Declaration l l f f)
priority :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (ConstExpression l l f f))
export :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Export l)
import_prod :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Import l)
definitionModule :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Module l l f f)
definitionSequence :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p [f (Definition l l f f)]
programModule :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (Module l l f f)
compilationUnit :: forall l (f :: * -> *) (p :: * -> *).
Modula2Grammar l f p -> p (NodeWrap (Module l l f f))
ident :: Fixed (ParserT ((,) [[Lexeme]])) g Text Text
number :: Parser g Text (Value l l NodeWrap NodeWrap)
integer :: Parser g Text (Value l l NodeWrap NodeWrap)
real :: Parser g Text (Value l l NodeWrap NodeWrap)
scaleFactor :: Fixed (ParserT ((,) [[Lexeme]])) g Text Text
hexDigit :: Fixed (ParserT ((,) [[Lexeme]])) g Text Text
digit :: Fixed (ParserT ((,) [[Lexeme]])) g Text Text
octalDigit :: Fixed (ParserT ((,) [[Lexeme]])) g Text Text
string_prod :: Fixed (ParserT ((,) [[Lexeme]])) g Text Text
qualident :: Parser g Text (QualIdent l)
constantDeclaration :: Parser g Text (Declaration l l NodeWrap NodeWrap)
constantDefinition :: Parser g Text (Definition l l NodeWrap NodeWrap)
constExpression :: Parser g Text (NodeWrap (Expression l l NodeWrap NodeWrap))
relation :: Parser g Text RelOp
addOperator :: Parser
  g
  Text
  (NodeWrap (Expression l l NodeWrap NodeWrap)
   -> NodeWrap (Expression l l NodeWrap NodeWrap)
   -> Expression l l NodeWrap NodeWrap)
mulOperator :: Parser
  g
  Text
  (NodeWrap (Expression l l NodeWrap NodeWrap)
   -> NodeWrap (Expression l l NodeWrap NodeWrap)
   -> Expression l l NodeWrap NodeWrap)
set :: Parser g Text (Expression l l NodeWrap NodeWrap)
element :: Parser g Text (Element l l NodeWrap NodeWrap)
typeDeclaration :: Parser g Text (Declaration l l NodeWrap NodeWrap)
typeDefinition :: Parser g Text (Definition l l NodeWrap NodeWrap)
type_prod :: Parser g Text (Type l l NodeWrap NodeWrap)
simpleType :: Parser g Text (Type l l NodeWrap NodeWrap)
enumeration :: Parser g Text (Type l l NodeWrap NodeWrap)
identList :: Parser g Text (IdentList l)
subrangeType :: Parser g Text (Type l l NodeWrap NodeWrap)
arrayType :: Parser g Text (Type l l NodeWrap NodeWrap)
recordType :: Parser g Text (Type l l NodeWrap NodeWrap)
fieldListSequence :: Fixed
  (ParserT ((,) [[Lexeme]]))
  g
  Text
  [((Down Int, ParsedLexemes, Down Int),
    FieldList l l NodeWrap NodeWrap)]
fieldList :: Parser g Text (FieldList l l NodeWrap NodeWrap)
variant :: Parser g Text (Variant l l NodeWrap NodeWrap)
caseLabelList :: Parser
  g Text (NonEmpty (NodeWrap (CaseLabels l l NodeWrap NodeWrap)))
caseLabels :: Parser g Text (CaseLabels l l NodeWrap NodeWrap)
setType :: Parser g Text (Type l l NodeWrap NodeWrap)
pointerType :: Parser g Text (Type l l NodeWrap NodeWrap)
procedureType :: Parser g Text (Type l l NodeWrap NodeWrap)
formalTypeList :: Parser g Text (FormalParameters l l NodeWrap NodeWrap)
variableDeclaration :: Parser g Text (Declaration l l NodeWrap NodeWrap)
variableDefinition :: Parser g Text (Definition l l NodeWrap NodeWrap)
designator :: Parser g Text (Designator l l NodeWrap NodeWrap)
expList :: Parser
  g Text (NonEmpty (NodeWrap (Expression l l NodeWrap NodeWrap)))
expression :: Parser g Text (NodeWrap (Expression l l NodeWrap NodeWrap))
simpleExpression :: Parser g Text (NodeWrap (Expression l l NodeWrap NodeWrap))
term :: Parser g Text (NodeWrap (Expression l l NodeWrap NodeWrap))
factor :: Parser g Text (NodeWrap (Expression l l NodeWrap NodeWrap))
actualParameters :: Parser g Text [NodeWrap (Expression l l NodeWrap NodeWrap)]
statement :: Parser g Text (Statement l l NodeWrap NodeWrap)
assignment :: Parser g Text (Statement l l NodeWrap NodeWrap)
procedureCall :: Parser g Text (Statement l l NodeWrap NodeWrap)
statementSequence :: Parser g Text (NodeWrap (StatementSequence l l NodeWrap NodeWrap))
ifStatement :: Parser g Text (Statement l l NodeWrap NodeWrap)
caseStatement :: Parser g Text (Statement l l NodeWrap NodeWrap)
case_prod :: Parser g Text (Case l l NodeWrap NodeWrap)
whileStatement :: Parser g Text (Statement l l NodeWrap NodeWrap)
repeatStatement :: Parser g Text (Statement l l NodeWrap NodeWrap)
forStatement :: Parser g Text (Statement l l NodeWrap NodeWrap)
loopStatement :: Parser g Text (Statement l l NodeWrap NodeWrap)
withStatement :: Parser g Text (Statement l l NodeWrap NodeWrap)
procedureDeclaration :: Parser g Text (Declaration l l NodeWrap NodeWrap)
procedureHeading :: Parser g Text (Text, ProcedureHeading l l NodeWrap NodeWrap)
block :: Parser g Text (Block l l NodeWrap NodeWrap)
declarationSequence :: Parser g Text [NodeWrap (Declaration l l NodeWrap NodeWrap)]
formalParameters :: Parser g Text (FormalParameters l l NodeWrap NodeWrap)
fPSection :: Parser g Text (FPSection l l NodeWrap NodeWrap)
formalType :: Parser g Text (Type l l NodeWrap NodeWrap)
moduleDeclaration :: Parser g Text (Declaration l l NodeWrap NodeWrap)
priority :: Parser g Text (NodeWrap (Expression l l NodeWrap NodeWrap))
export :: Parser g Text (Export l)
import_prod :: Parser g Text (Import l)
definitionModule :: Parser g Text (Module l l NodeWrap NodeWrap)
definitionSequence :: Parser g Text [NodeWrap (Definition l l NodeWrap NodeWrap)]
programModule :: Parser g Text (Module l l NodeWrap NodeWrap)
compilationUnit :: Parser g Text (NodeWrap (Module l l NodeWrap NodeWrap))
..} = Modula2Grammar l NodeWrap (Parser g Text)
g{
   ident = identifier,
   number = integer <|> real <?> "a number",
   integer = lexicalToken (Abstract.integer . fst . head
                           <$> (readDec . unpack <$> takeCharsWhile1 isDigit
                                <|> readOct . unpack <$> takeCharsWhile1 isOctDigit <* string "B"
                                <|> readHex . unpack <$> (digit <> takeCharsWhile isHexDigit) <* string "H")
                           <|> Abstract.charCode . fst . head . readOct . unpack
                               <$> (octalDigit <> takeCharsWhile isOctDigit <* string "C")),
   real = Abstract.real . fst . head . readFloat . unpack
          <$> lexicalToken (takeCharsWhile1 isDigit <> string "." <> takeCharsWhile isDigit <> moptional scaleFactor),
   scaleFactor = string "E" <> moptional (string "+" <|> string "-") <> takeCharsWhile1 isDigit,
   hexDigit = satisfyCharInput isHexDigit,
   digit = satisfyCharInput isDigit,
   octalDigit = satisfyCharInput isOctDigit,
   string_prod = lexicalToken (char '\'' *> takeCharsWhile (\Char
c-> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\'' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n') <* char '\''
                               <|> char '"' *> takeCharsWhile (\Char
c-> Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'"' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n') <* char '"'),
   qualident = Abstract.qualIdent <$> many (ident <* delimiter ".") <*> ident,
   constantDeclaration = Abstract.constantDeclaration <$> (Abstract.identDef <$> ident)
                         <* delimiter "=" <*> constExpression,
   constantDefinition = Abstract.constantDefinition <$> (Abstract.identDef <$> ident)
                        <* delimiter "=" <*> constExpression,
   constExpression = expression,
   relation = Abstract.Equal <$ operator "=" <|> Abstract.Unequal <$ (operator "#" <|> operator "<>")
              <|> Abstract.Less <$ operator "<" <|> Abstract.LessOrEqual <$ operator "<=" 
              <|> Abstract.Greater <$ operator ">" <|> Abstract.GreaterOrEqual <$ operator ">=" 
              <|> Abstract.In <$ keyword "IN",
   addOperator = Abstract.add <$ operator "+" <|> Abstract.subtract <$ operator "-" <|> Abstract.or <$ keyword "OR",
   mulOperator = Abstract.multiply <$ operator "*" <|> Abstract.divide <$ operator "/"
                 <|> Abstract.integerDivide <$ keyword "DIV" <|> Abstract.modulo <$ keyword "MOD"
                 <|> Abstract.and <$ (operator "&" <|> keyword "AND"),
   set = Abstract.set <$> optional qualident <*> braces (sepBy (wrap element) (delimiter ",")),
   element = Abstract.element <$> expression
             <|> Abstract.range <$> expression <* delimiter ".." <*> expression,
   typeDeclaration = Abstract.typeDeclaration <$> (Abstract.identDef <$> ident) <* delimiter "=" <*> wrap type_prod,
   typeDefinition = Abstract.typeDefinition <$> (Abstract.identDef <$> ident) <*> optional (delimiter "=" *> wrap type_prod),
   type_prod = simpleType <|> arrayType <|> recordType <|> setType <|> pointerType <|> procedureType,
   simpleType = Abstract.typeReference <$> qualident
                <|> enumeration
                <|> subrangeType,
   enumeration = Abstract.enumeration <$> parens identList,
   identList = sepByNonEmpty (Abstract.identDef <$> ident) (delimiter ","),
   subrangeType = brackets (Abstract.subRange (Nothing :: Maybe (Abstract.QualIdent l)) <$> constExpression
                            <* delimiter ".." <*> constExpression),
   arrayType =
      Abstract.arrayType <$ keyword "ARRAY" <*> sepBy1 (wrap simpleType) (delimiter ",") <* keyword "OF" <*> wrap type_prod,
   recordType = Abstract.recordType <$ keyword "RECORD" <*> fieldListSequence <* keyword "END",
   fieldListSequence = catMaybes <$> sepBy1 (optional $ wrap fieldList) (delimiter ";"),
   fieldList = (Abstract.fieldList <$> identList <* delimiter ":" <*> wrap type_prod
                :: Parser g Text (Abstract.FieldList l l NodeWrap NodeWrap))
               <|> Abstract.caseFieldList <$ keyword "CASE" <*> optional (ident <* delimiter ":") <*> qualident
                                          <* keyword "OF" <*> sepByNonEmpty (wrap variant) (delimiter "|")
                                          <*> moptional (keyword "ELSE" *> fieldListSequence) <* keyword "END",
   variant = Abstract.variant <$> caseLabelList <* delimiter ":" <*> fieldListSequence,
   caseLabelList = sepByNonEmpty (wrap caseLabels) (delimiter ","),
   caseLabels = Abstract.singleLabel <$> constExpression
                <|> Abstract.labelRange <$> constExpression <* delimiter ".." <*> constExpression,
   setType = Abstract.setType <$ keyword "SET" <* keyword "OF" <*> wrap simpleType,
   pointerType = Abstract.pointerType <$ keyword "POINTER" <* keyword "TO" <*> wrap type_prod,
   procedureType = Abstract.procedureType <$ keyword "PROCEDURE" <*> optional (wrap formalTypeList),
   formalTypeList = Abstract.formalParameters
                    <$> parens (sepBy (wrap $
                                       Abstract.fpSection <$> (True <$ keyword "VAR" <|> pure False) <*> pure [] <*> wrap formalType)
                                      (delimiter ","))
                    <*> optional (delimiter ":" *> qualident),
   variableDeclaration = Abstract.variableDeclaration <$> identList <* delimiter ":" <*> wrap type_prod,
   variableDefinition = Abstract.variableDefinition <$> identList <* delimiter ":" <*> wrap type_prod,
   designator = Abstract.variable . Abstract.nonQualIdent <$> ident -- qualident
                <|> Abstract.field <$> wrap designator <* delimiter "." <*> ident
                <|> Abstract.index <$> wrap designator <*> brackets expList
                <|> Abstract.dereference <$> wrap designator <* operator "^",
   expList = sepByNonEmpty expression (delimiter ","),
   expression = simpleExpression
                <|> wrap (flip Abstract.relation <$> simpleExpression <*> relation <*> simpleExpression)
                <?> "expression",
   simpleExpression =
      wrap (Abstract.positive <$ operator "+" <*> term
            <|> Abstract.negative <$ operator "-" <*> term)
      <|> term
      <|> wrap (simpleExpression <**> addOperator <*> term),
   term = factor <|> wrap (term <**> mulOperator <*> factor),
   factor = wrap (Abstract.literal <$> wrap (number
                                             <|> Abstract.string <$> string_prod)
                  <|> set
                  <|> Abstract.read <$> wrap designator
                  <|> Abstract.functionCall <$> wrap designator <*> actualParameters
                  <|> (Abstract.not <$ (operator "~" <|> keyword "NOT") <*> factor
                       :: Parser g Text (Abstract.Expression l l NodeWrap NodeWrap)))
            <|> parens expression,
   actualParameters = parens (sepBy expression (delimiter ",")),
   statement = assignment <|> procedureCall <|> ifStatement <|> caseStatement 
               <|> whileStatement <|> repeatStatement <|> loopStatement <|> forStatement <|> withStatement 
               <|> Abstract.exitStatement <$ keyword "EXIT" 
               <|> Abstract.returnStatement <$ keyword "RETURN" <*> optional expression
               <|> pure Abstract.emptyStatement
               <?> "statement",
   assignment  =  Abstract.assignment <$> wrap designator <* delimiter ":=" <*> expression,
   procedureCall = Abstract.procedureCall <$> wrap designator <*> optional actualParameters,
   statementSequence = wrap (Abstract.statementSequence <$> sepBy1 (wrap statement) (delimiter ";")),
   ifStatement = Abstract.ifStatement <$ keyword "IF"
       <*> sepByNonEmpty (wrap $ Abstract.conditionalBranch <$> expression <* keyword "THEN" <*> statementSequence)
                         (keyword "ELSIF")
       <*> optional (keyword "ELSE" *> statementSequence) <* keyword "END",
   caseStatement = Abstract.caseStatement <$ keyword "CASE" <*> expression
       <*  keyword "OF" <*> sepBy1 (wrap case_prod) (delimiter "|")
       <*> optional (keyword "ELSE" *> statementSequence) <* keyword "END",
   case_prod = Abstract.caseAlternative <$> caseLabelList <* delimiter ":" <*> statementSequence,
   whileStatement = Abstract.whileStatement <$ keyword "WHILE" <*> expression <* keyword "DO"
                    <*> statementSequence <* keyword "END",
   repeatStatement = Abstract.repeatStatement <$ keyword "REPEAT"
                     <*> statementSequence <* keyword "UNTIL" <*> expression,
   forStatement = 
      Abstract.forStatement <$ keyword "FOR" <*> ident <* delimiter ":=" <*> expression
      <* keyword "TO" <*> expression <*> optional (keyword "BY" *> constExpression)
      <* keyword "DO" <*> statementSequence <* keyword "END",
   loopStatement = Abstract.loopStatement <$ keyword "LOOP" <*> statementSequence <* keyword "END",
   withStatement = Abstract.withStatement <$ keyword "WITH" <*> wrap designator <* keyword "DO"
                   <*> statementSequence <* keyword "END",
   procedureDeclaration = do (procedureName, heading) <- sequenceA <$> wrap procedureHeading
                             delimiter ";"
                             body <- wrap block
                             lexicalToken (string procedureName)
                             return (Abstract.procedureDeclaration heading body),
   procedureHeading = Abstract.procedureHeading <$ keyword "PROCEDURE"
                      <**> do name <- ident
                              params <- optional (wrap formalParameters)
                              return (\Text
-> Maybe
     ((Down Int, ParsedLexemes, Down Int),
      FormalParameters l l NodeWrap NodeWrap)
-> ProcedureHeading l l NodeWrap NodeWrap
proc-> (Text
name, Text
-> Maybe
     ((Down Int, ParsedLexemes, Down Int),
      FormalParameters l l NodeWrap NodeWrap)
-> ProcedureHeading l l NodeWrap NodeWrap
proc Text
name Maybe
  ((Down Int, ParsedLexemes, Down Int),
   FormalParameters l l NodeWrap NodeWrap)
params)),
   block = Abstract.block <$> declarationSequence <*> optional (keyword "BEGIN" *> statementSequence)
           <* keyword "END",
   declarationSequence = concatMany (keyword "CONST" *> many (wrap constantDeclaration <* delimiter ";")
                                     <|> keyword "TYPE" *> many (wrap typeDeclaration <* delimiter ";")
                                     <|> keyword "VAR" *> many (wrap variableDeclaration <* delimiter ";")
                                     <|> (:[]) <$> (wrap procedureDeclaration <* delimiter ";"
                                                    <|> wrap moduleDeclaration <* delimiter ";"))
                         <?> "declarations",
   formalParameters = Abstract.formalParameters <$> parens (sepBy (wrap fPSection) (delimiter ";"))
                      <*> optional (delimiter ":" *> qualident),
   fPSection = Abstract.fpSection <$> (True <$ keyword "VAR" <|> pure False) 
               <*> sepBy1 ident (delimiter ",") <* delimiter ":" <*> wrap formalType,
   formalType = Abstract.arrayType [] <$ keyword "ARRAY" <* keyword "OF" <*> wrap formalType 
                <|> Abstract.typeReference <$> qualident,
   moduleDeclaration = do keyword "MODULE"
                          name <- ident
                          Abstract.moduleDeclaration name <$> optional priority <* delimiter ";"
                             <*> many import_prod <*> optional export <*> wrap block <* lexicalToken (string name),
   priority = brackets constExpression,
   export = Abstract.moduleExport <$ keyword "EXPORT" <*> (True <$ keyword "QUALIFIED" <|> pure False)
            <*> sepByNonEmpty ident (delimiter ",") <* delimiter ";",
   import_prod = Abstract.moduleImport <$> optional (keyword "FROM" *> ident)
                 <* keyword "IMPORT" <*> sepByNonEmpty ident (delimiter ",") <* delimiter ";",
   definitionModule = keyword "DEFINITION" *> keyword "MODULE" *>
                      do name <- ident
                         delimiter ";"
                         Abstract.definitionModule name <$> many import_prod <*> optional export <*> definitionSequence
                                                   <* keyword "END" <* lexicalToken (string name) <* delimiter ".",
   definitionSequence =  concatMany (keyword "CONST" *> many (wrap constantDefinition <* delimiter ";")
                                     <|> keyword "TYPE" *> many (wrap typeDefinition <* delimiter ";")
                                     <|> keyword "VAR" *> many (wrap variableDefinition <* delimiter ";")
                                     <|> (:[]) <$> (wrap (Abstract.procedureDefinition <$> wrap (snd <$> procedureHeading))
                                                    <* delimiter ";"))
                         <?> "definitions",
   programModule = do con <- (Abstract.implementationModule <$ keyword "IMPLEMENTATION"
                              <|> pure Abstract.programModule) <* keyword "MODULE"
                      name <- ident
                      con name <$> optional priority <* delimiter ";" <*> many import_prod
                               <*> wrap block <* lexicalToken (string name) <* delimiter ".",
   compilationUnit = wrap (lexicalWhiteSpace *> (definitionModule <|> programModule)) <* skipMany (char '\x1a' *> lexicalWhiteSpace)
   }

instance TokenParsing (Parser (Modula2Grammar l f) Text) where
   someSpace :: Parser (Modula2Grammar l f) Text ()
someSpace = Parser (Modula2Grammar l f) Text ()
forall (m :: * -> *). LexicalParsing m => m ()
someLexicalSpace
   token :: forall a.
Parser (Modula2Grammar l f) Text a
-> Parser (Modula2Grammar l f) Text a
token = Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
forall a.
Parser (Modula2Grammar l f) Text a
-> Parser (Modula2Grammar l f) Text a
forall (m :: * -> *) a. LexicalParsing m => m a -> m a
lexicalToken

instance LexicalParsing (Parser (Modula2Grammar l f) Text) where
   lexicalComment :: Parser (Modula2Grammar l f) Text ()
lexicalComment = do Text
c <- Parser (Modula2Grammar l f) Text Text
forall (g :: (* -> *) -> *). Apply g => Parser g Text Text
comment
                       ([[Lexeme]], ()) -> Parser (Modula2Grammar l f) Text ()
forall (m :: * -> *) s a (g :: (* -> *) -> *).
(Applicative m, Ord s) =>
m a -> ParserT m g s a
lift ([[Text -> Lexeme
Comment Text
c]], ())
   lexicalWhiteSpace :: Parser (Modula2Grammar l f) Text ()
lexicalWhiteSpace = Parser (Modula2Grammar l f) Text ()
forall (g :: (* -> *) -> *).
(Apply g, LexicalParsing (Parser g Text)) =>
Parser g Text ()
whiteSpace
   isIdentifierStartChar :: Char -> Bool
isIdentifierStartChar = Char -> Bool
isLetter
   isIdentifierFollowChar :: Char -> Bool
isIdentifierFollowChar = Char -> Bool
isAlphaNum
   identifierToken :: Parser
  (Modula2Grammar l f)
  Text
  (ParserInput (Parser (Modula2Grammar l f) Text))
-> Parser
     (Modula2Grammar l f)
     Text
     (ParserInput (Parser (Modula2Grammar l f) Text))
identifierToken Parser
  (Modula2Grammar l f)
  Text
  (ParserInput (Parser (Modula2Grammar l f) Text))
word = Parser (Modula2Grammar l f) Text Text
-> Parser (Modula2Grammar l f) Text Text
forall a.
Parser (Modula2Grammar l f) Text a
-> Parser (Modula2Grammar l f) Text a
forall (m :: * -> *) a. LexicalParsing m => m a -> m a
lexicalToken (do Text
w <- Parser (Modula2Grammar l f) Text Text
Parser
  (Modula2Grammar l f)
  Text
  (ParserInput (Parser (Modula2Grammar l f) Text))
word
                                           Bool -> Parser (Modula2Grammar l f) Text ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Text
w Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Text]
reservedWords)
                                           Text -> Parser (Modula2Grammar l f) Text Text
forall a.
a -> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
forall (m :: * -> *) a. Monad m => a -> m a
return Text
w)
   lexicalToken :: forall a.
Parser (Modula2Grammar l f) Text a
-> Parser (Modula2Grammar l f) Text a
lexicalToken Parser (Modula2Grammar l f) Text a
p = (Text, a) -> a
forall a b. (a, b) -> b
snd ((Text, a) -> a)
-> Fixed
     (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text (Text, a)
-> Parser (Modula2Grammar l f) Text a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (([[Lexeme]], (Text, a)) -> ([[Lexeme]], (Text, a)))
-> Fixed
     (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text (Text, a)
-> Fixed
     (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text (Text, a)
forall b (m :: * -> *) a (g :: (* -> *) -> *) s.
AmbiguityDecidable b =>
(m a -> m b) -> ParserT m g s a -> ParserT m g s b
tmap ([[Lexeme]], (Text, a)) -> ([[Lexeme]], (Text, a))
forall {b}. ([[Lexeme]], (Text, b)) -> ([[Lexeme]], (Text, b))
addOtherToken (Parser (Modula2Grammar l f) Text a
-> Fixed
     (ParserT ((,) [[Lexeme]]))
     (Modula2Grammar l f)
     Text
     (ParserInput (Parser (Modula2Grammar l f) Text), a)
forall a.
Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
-> Fixed
     (ParserT ((,) [[Lexeme]]))
     (Modula2Grammar l f)
     Text
     (ParserInput (Parser (Modula2Grammar l f) Text), a)
forall (m :: * -> *) a.
ConsumedInputParsing m =>
m a -> m (ParserInput m, a)
match Parser (Modula2Grammar l f) Text a
p) Parser (Modula2Grammar l f) Text a
-> Parser (Modula2Grammar l f) Text ()
-> Parser (Modula2Grammar l f) Text a
forall a b.
Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text b
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser (Modula2Grammar l f) Text ()
forall (m :: * -> *). LexicalParsing m => m ()
lexicalWhiteSpace
      where addOtherToken :: ([[Lexeme]], (Text, b)) -> ([[Lexeme]], (Text, b))
addOtherToken ([], (Text
i, b
x)) = ([[TokenType -> Text -> Lexeme
Token TokenType
Other Text
i]], (Text
i, b
x))
            addOtherToken ([[Lexeme]]
t, (Text
i, b
x)) = ([[Lexeme]]
t, (Text
i, b
x))
   keyword :: ParserInput (Parser (Modula2Grammar l f) Text)
-> Parser (Modula2Grammar l f) Text ()
keyword ParserInput (Parser (Modula2Grammar l f) Text)
s = Parser (Modula2Grammar l f) Text ()
-> Parser (Modula2Grammar l f) Text ()
forall a.
Parser (Modula2Grammar l f) Text a
-> Parser (Modula2Grammar l f) Text a
forall (m :: * -> *) a. LexicalParsing m => m a -> m a
lexicalToken (ParserInput (Parser (Modula2Grammar l f) Text)
-> Parser
     (Modula2Grammar l f)
     Text
     (ParserInput (Parser (Modula2Grammar l f) Text))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string ParserInput (Parser (Modula2Grammar l f) Text)
s
                             Parser (Modula2Grammar l f) Text Text
-> Parser (Modula2Grammar l f) Text ()
-> Parser (Modula2Grammar l f) Text ()
forall a b.
Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text b
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Char -> Bool) -> Parser (Modula2Grammar l f) Text ()
forall (m :: * -> *). InputCharParsing m => (Char -> Bool) -> m ()
notSatisfyChar Char -> Bool
isAlphaNum
                             Parser (Modula2Grammar l f) Text ()
-> Parser (Modula2Grammar l f) Text ()
-> Parser (Modula2Grammar l f) Text ()
forall a b.
Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text b
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ([[Lexeme]], ()) -> Parser (Modula2Grammar l f) Text ()
forall (m :: * -> *) s a (g :: (* -> *) -> *).
(Applicative m, Ord s) =>
m a -> ParserT m g s a
lift ([[TokenType -> Text -> Lexeme
Token TokenType
Keyword Text
ParserInput (Parser (Modula2Grammar l f) Text)
s]], ()))
               Parser (Modula2Grammar l f) Text ()
-> String -> Parser (Modula2Grammar l f) Text ()
forall a.
Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
-> String
-> Fixed (ParserT ((,) [[Lexeme]])) (Modula2Grammar l f) Text a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> (String
"keyword " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
ParserInput (Parser (Modula2Grammar l f) Text)
s)

comment :: Rank2.Apply g => Parser g Text Text
comment :: forall (g :: (* -> *) -> *). Apply g => Parser g Text Text
comment = Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. Parsing m => m a -> m a
try (ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text)
-> Fixed
     (ParserT ((,) [[Lexeme]]))
     g
     Text
     (ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string Text
ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text)
"(*"
               Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a. Semigroup a => a -> a -> a
<> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall (p :: * -> *) a. (Alternative p, Monoid a) => p a -> p a
concatMany (Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall (g :: (* -> *) -> *). Apply g => Parser g Text Text
comment Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a.
Show a =>
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall (m :: * -> *) a. (Parsing m, Show a) => m a -> m ()
notFollowedBy (ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text)
-> Fixed
     (ParserT ((,) [[Lexeme]]))
     g
     Text
     (ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string Text
ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text)
"*)") Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a b.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text b
-> Fixed (ParserT ((,) [[Lexeme]])) g Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
Fixed
  (ParserT ((,) [[Lexeme]]))
  g
  Text
  (ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text))
forall (m :: * -> *). InputParsing m => m (ParserInput m)
anyToken Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a. Semigroup a => a -> a -> a
<> (Char -> Bool)
-> Fixed
     (ParserT ((,) [[Lexeme]]))
     g
     Text
     (ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text))
forall (m :: * -> *).
InputCharParsing m =>
(Char -> Bool) -> m (ParserInput m)
takeCharsWhile Char -> Bool
isCommentChar)
               Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a. Semigroup a => a -> a -> a
<> ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text)
-> Fixed
     (ParserT ((,) [[Lexeme]]))
     g
     Text
     (ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string Text
ParserInput (Fixed (ParserT ((,) [[Lexeme]])) g Text)
"*)")
   where isCommentChar :: Char -> Bool
isCommentChar Char
c = Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'*' Bool -> Bool -> Bool
&& Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'('

whiteSpace :: Rank2.Apply g => LexicalParsing (Parser g Text) => Parser g Text ()
whiteSpace :: forall (g :: (* -> *) -> *).
(Apply g, LexicalParsing (Parser g Text)) =>
Parser g Text ()
whiteSpace = Fixed (ParserT ((,) [[Lexeme]])) g Text ()
spaceChars Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a b.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text b
-> Fixed (ParserT ((,) [[Lexeme]])) g Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall (m :: * -> *) a. Parsing m => m a -> m ()
skipMany (Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall (m :: * -> *). LexicalParsing m => m ()
lexicalComment Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a b.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text b
-> Fixed (ParserT ((,) [[Lexeme]])) g Text b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
spaceChars) Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> String -> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> String -> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> String
"whitespace"
   where spaceChars :: Fixed (ParserT ((,) [[Lexeme]])) g Text ()
spaceChars = ((Char -> Bool)
-> Fixed
     (ParserT ((,) [[Lexeme]])) g Text (ParserInput (Parser g Text))
forall (m :: * -> *).
InputCharParsing m =>
(Char -> Bool) -> m (ParserInput m)
takeCharsWhile1 Char -> Bool
isSpace Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> (Text -> Fixed (ParserT ((,) [[Lexeme]])) g Text ())
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a b.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> (a -> Fixed (ParserT ((,) [[Lexeme]])) g Text b)
-> Fixed (ParserT ((,) [[Lexeme]])) g Text b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Text
ws-> ([[Lexeme]], ()) -> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall (m :: * -> *) s a (g :: (* -> *) -> *).
(Applicative m, Ord s) =>
m a -> ParserT m g s a
lift ([[Text -> Lexeme
WhiteSpace Text
ws]], ())) Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. DeterministicParsing m => m a -> m a -> m a
<<|> () -> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a. a -> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()

wrap :: Rank2.Apply g => Parser g Text a -> Parser g Text (NodeWrap a)
wrap :: forall (g :: (* -> *) -> *) a.
Apply g =>
Parser g Text a -> Parser g Text (NodeWrap a)
wrap = (\Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
p-> (Down Int -> (ParsedLexemes, a) -> Down Int -> NodeWrap a)
-> Fixed (ParserT ((,) [[Lexeme]])) g Text (Down Int)
-> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
-> Fixed (ParserT ((,) [[Lexeme]])) g Text (Down Int)
-> Parser g Text (NodeWrap a)
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 Down Int -> (ParsedLexemes, a) -> Down Int -> NodeWrap a
forall {a} {b} {b} {c}. a -> (b, b) -> c -> ((a, b, c), b)
surround Fixed (ParserT ((,) [[Lexeme]])) g Text (Down Int)
Fixed
  (ParserT ((,) [[Lexeme]]))
  g
  Text
  (ParserPosition (Fixed (ParserT ((,) [[Lexeme]])) g Text))
forall (m :: * -> *). InputParsing m => m (ParserPosition m)
getSourcePos Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
p Fixed (ParserT ((,) [[Lexeme]])) g Text (Down Int)
Fixed
  (ParserT ((,) [[Lexeme]]))
  g
  Text
  (ParserPosition (Fixed (ParserT ((,) [[Lexeme]])) g Text))
forall (m :: * -> *). InputParsing m => m (ParserPosition m)
getSourcePos) (Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
 -> Parser g Text (NodeWrap a))
-> (Parser g Text a
    -> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a))
-> Parser g Text a
-> Parser g Text (NodeWrap a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (([[Lexeme]], (ParsedLexemes, a))
 -> ([[Lexeme]], (ParsedLexemes, a)))
-> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
-> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
forall b (m :: * -> *) a (g :: (* -> *) -> *) s.
AmbiguityDecidable b =>
(m a -> m b) -> ParserT m g s a -> ParserT m g s b
tmap ([[Lexeme]], (ParsedLexemes, a))
-> ([[Lexeme]], (ParsedLexemes, a))
forall {a} {t :: * -> *} {b}.
(Monoid a, Foldable t) =>
(t [Lexeme], (ParsedLexemes, b)) -> (a, (ParsedLexemes, b))
store (Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
 -> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a))
-> (Parser g Text a
    -> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a))
-> Parser g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((,) ([Lexeme] -> ParsedLexemes
Trailing []) (a -> (ParsedLexemes, a))
-> Parser g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text (ParsedLexemes, a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>)
   where surround :: a -> (b, b) -> c -> ((a, b, c), b)
surround a
start (b
lexemes, b
p) c
end = ((a
start, b
lexemes, c
end), b
p)
         store :: (t [Lexeme], (ParsedLexemes, b)) -> (a, (ParsedLexemes, b))
store (t [Lexeme]
wss, (Trailing [Lexeme]
ws', b
a)) = (a
forall a. Monoid a => a
mempty, ([Lexeme] -> ParsedLexemes
Trailing ([Lexeme] -> ParsedLexemes) -> [Lexeme] -> ParsedLexemes
forall a b. (a -> b) -> a -> b
$ [Lexeme]
ws' [Lexeme] -> [Lexeme] -> [Lexeme]
forall a. Semigroup a => a -> a -> a
<> t [Lexeme] -> [Lexeme]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat t [Lexeme]
wss, b
a))

moptional :: f a -> f a
moptional f a
p = f a
p f a -> f a -> f a
forall a. f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> f a
forall a. Monoid a => a
mempty

delimiter, operator :: (LexicalParsing (Parser g Text)) => Text -> Parser g Text ()

delimiter :: forall (g :: (* -> *) -> *).
LexicalParsing (Parser g Text) =>
Text -> Parser g Text ()
delimiter Text
s = Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. LexicalParsing m => m a -> m a
lexicalToken (Fixed (ParserT ((,) [[Lexeme]])) g Text Text
 -> Fixed (ParserT ((,) [[Lexeme]])) g Text Text)
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a b. (a -> b) -> a -> b
$ ParserInput (Parser g Text)
-> Fixed
     (ParserT ((,) [[Lexeme]])) g Text (ParserInput (Parser g Text))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string Text
ParserInput (Parser g Text)
s) Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> String -> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> String -> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> (String
"delimiter " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
s)
operator :: forall (g :: (* -> *) -> *).
LexicalParsing (Parser g Text) =>
Text -> Parser g Text ()
operator Text
s = Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. LexicalParsing m => m a -> m a
lexicalToken (Fixed (ParserT ((,) [[Lexeme]])) g Text Text
 -> Fixed (ParserT ((,) [[Lexeme]])) g Text Text)
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
-> Fixed (ParserT ((,) [[Lexeme]])) g Text Text
forall a b. (a -> b) -> a -> b
$ ParserInput (Parser g Text)
-> Fixed
     (ParserT ((,) [[Lexeme]])) g Text (ParserInput (Parser g Text))
forall (m :: * -> *).
InputParsing m =>
ParserInput m -> m (ParserInput m)
string Text
ParserInput (Parser g Text)
s) Fixed (ParserT ((,) [[Lexeme]])) g Text ()
-> String -> Fixed (ParserT ((,) [[Lexeme]])) g Text ()
forall a.
Fixed (ParserT ((,) [[Lexeme]])) g Text a
-> String -> Fixed (ParserT ((,) [[Lexeme]])) g Text a
forall (m :: * -> *) a. Parsing m => m a -> String -> m a
<?> (String
"operator " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Text -> String
forall a. Show a => a -> String
show Text
s)

reservedWords :: [Text]
reservedWords :: [Text]
reservedWords = [Text
"AND", Text
"ARRAY", Text
"BEGIN", Text
"BY",
                 Text
"CASE", Text
"CONST", Text
"DEFINITION", Text
"DIV", Text
"DO",
                 Text
"ELSE", Text
"ELSIF", Text
"END", Text
"EXIT", Text
"EXPORT", Text
"FOR", Text
"FROM",
                 Text
"IF", Text
"IMPLEMENTATION", Text
"IMPORT", Text
"IN", Text
"LOOP",
                 Text
"MOD", Text
"MODULE", Text
"NOT",
                 Text
"OF", Text
"OR", Text
"POINTER", Text
"PROCEDURE",
                 Text
"QUALIFIED", Text
"RECORD", Text
"REPEAT", Text
"RETURN",
                 Text
"SET", Text
"THEN", Text
"TO", Text
"TYPE",
                 Text
"UNTIL", Text
"VAR", Text
"WHILE", Text
"WITH"]