Safe Haskell | None |
---|---|
Language | Haskell2010 |
We define a simple domain-specific language for context-free languages.
TODO we still need to make sure to handle NTs correctly. It should be that
we write [X,Y]
in multidim cases and then we check in rules if [X,Y]
is
available ... of course for [X,eps]
we then need to check if eps
is an
epsilon symbol.
Synopsis
- data GrammarEnv = GrammarEnv {}
- type Stately m a = (TokenParsing m, MonadState GrammarEnv m, MonadPlus m) => m a
- type Parse' a = StateT GrammarEnv Parser a
- type Parse m a = (TokenParsing m, MonadState GrammarEnv m, MonadPlus m) => m a
- data EvalReq
- current :: Lens' GrammarEnv Grammar
- emit :: Lens' GrammarEnv (Seq Grammar)
- env :: Lens' GrammarEnv (Map String Grammar)
- verbose :: Lens' GrammarEnv Bool
- test :: IO ()
- parse :: String -> Result (Seq Grammar)
- parseEverything :: Parse m () -> Parse m (Seq Grammar)
- parseGrammar :: Parse m ()
- setIndices :: Parse m [Index]
- parseEmitGrammar :: Parse m ()
- parseNormStartEps :: Parse m ()
- parseOutside :: Parse m ()
- parseCommands :: Parse m ()
- fgIdents :: TokenParsing m => IdentifierStyle m
- newGrammarName :: Parse m String
- knownGrammarName :: Parse m Grammar
- parseSyntacticDecl :: EvalReq -> Parse m SynTermEps
- parseSynTermDecl :: EvalReq -> Parse m SynTermEps
- parseTermDecl :: Parse m SynTermEps
- parseStartSym :: Parse m Symbol
- knownSynVar :: EvalReq -> Stately m Symbol
- knownSynTerm :: EvalReq -> Stately m Symbol
- parseIndex :: EvalReq -> Stately m [Index]
- knownTermVar :: EvalReq -> Stately m Symbol
- knownSymbol :: EvalReq -> Stately m Symbol
- parseRule :: Parse m [Rule]
- updateSplitCounts :: [Symbol] -> [Symbol]
- expandIndexed :: Rule -> Parse m [Rule]
- data Result a
Documentation
data GrammarEnv Source #
The environment captures both the current grammar we work with
(current
) as well as everything we have parsed until now (env
).
Instances
Show GrammarEnv Source # | |
Defined in FormalLanguage.CFG.Parser showsPrec :: Int -> GrammarEnv -> ShowS # show :: GrammarEnv -> String # showList :: [GrammarEnv] -> ShowS # | |
Default GrammarEnv Source # | |
Defined in FormalLanguage.CFG.Parser def :: GrammarEnv # |
type Stately m a = (TokenParsing m, MonadState GrammarEnv m, MonadPlus m) => m a Source #
type Parse m a = (TokenParsing m, MonadState GrammarEnv m, MonadPlus m) => m a Source #
EvalFull | Happens when we actually emit a grammar product (in development) |
EvalRule | Happens when we work through the rules |
EvalSymb | Happens when we encounter |
EvalGrammar | Happens when we define grammar-global parameters |
parseEverything :: Parse m () -> Parse m (Seq Grammar) Source #
Parse everything in the grammar source. The additional argument, normally
empty :: Alternative f a
, allows for providing additional parsing
capabilities -- e.g. for grammar products..
parseGrammar :: Parse m () Source #
The basic parser, which generates a grammar from a description.
setIndices :: Parse m [Index] Source #
Collect all indices and set them as active
parseEmitGrammar :: Parse m () Source #
Which of the intermediate grammar to actually emit as code or text in
TeX. Single line: Emit: KnownGrammarName
parseNormStartEps :: Parse m () Source #
Normalize start and epsilon rules in a known Source:
, thereby
generating a new grammar.
parseOutside :: Parse m () Source #
Try to generate an outside grammar from an inside grammar. The From:
name is looked up in the environment.
Outside: NAME From: (inside)NAME //
parseCommands :: Parse m () Source #
Some additional commands that change the parsing state.
TODO MonoidOfPairs
should generate an adapter function that turns any
2-tape eval function into its k-tape version. This means collecting all
name pairs, then emitting the corresponding adapter. We'll also need
a monoidal function for combining pairs. (this is along the lines of
sum-of-pairs).
fgIdents :: TokenParsing m => IdentifierStyle m Source #
newGrammarName :: Parse m String Source #
knownGrammarName :: Parse m Grammar Source #
parseSyntacticDecl :: EvalReq -> Parse m SynTermEps Source #
Parses a syntactic (or non-terminal) symbol (for the corresponding
index type). Cf. parseSynTermDecl
.
parseSynTermDecl :: EvalReq -> Parse m SynTermEps Source #
Parses a syntactic terminal declaration; an inside syntactic variable in an outside context.
parseTermDecl :: Parse m SynTermEps Source #
parseStartSym :: Parse m Symbol Source #
The syntactic variable here needs to either have no index at all, have a grammar-based index, or have a fully calculated index.
parseIndex :: EvalReq -> Stately m [Index] Source #
Parses indices { ... }
within curly brackets (braces
).
When parsing the EvalSymb
case, indexed symbols are being created.
Parsing in rules is handled via EvalRule
and actually requires us
saying which explicit index we use.
knownSymbol :: EvalReq -> Stately m Symbol Source #
Parses an already known symbol, either syntactic or terminal.
TODO Correctly parse inside-syntactics in outside grammars? Do we want this explicitly?
updateSplitCounts :: [Symbol] -> [Symbol] Source #
For split syntactic variables used in split manner (i.e. @S -> X Y X Y)
TODO error control!
expandIndexed :: Rule -> Parse m [Rule] Source #
Once we have parsed a rule, we still need to extract all active indices in the rule, and enumerate over them. This will finally generate the set of rules we are interested in.
The result of parsing. Either we succeeded or something went wrong.
Instances
Monad Result | |
Functor Result | |
Applicative Result | |
Foldable Result | |
Defined in Text.Trifecta.Result fold :: Monoid m => Result m -> m # foldMap :: Monoid m => (a -> m) -> Result a -> m # foldr :: (a -> b -> b) -> b -> Result a -> b # foldr' :: (a -> b -> b) -> b -> Result a -> b # foldl :: (b -> a -> b) -> b -> Result a -> b # foldl' :: (b -> a -> b) -> b -> Result a -> b # foldr1 :: (a -> a -> a) -> Result a -> a # foldl1 :: (a -> a -> a) -> Result a -> a # elem :: Eq a => a -> Result a -> Bool # maximum :: Ord a => Result a -> a # minimum :: Ord a => Result a -> a # | |
Traversable Result | |
Alternative Result | |
Show a => Show (Result a) | |
Show a => Pretty (Result a) | |
Defined in Text.Trifecta.Result | |
AsResult (Result a) (Result b) a b | |