| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Nanopass.Internal.Parser
Description
This module contains functions that translate Haskell quasiquotes into internal representations of languages and passes as defined in Nanopass.Internal.Representation. This is done by first parsing an s-expression with Text.SExpression, and then recursively recognizing the components of that s-expression.
The primary entry points are parseLanguage and TODO parsePass.
Other recognizers are exported to serve as the promary source for
documentation about the grammar used in these quasiquotes.
Synopsis
- type ParseResult = Either (Language 'Unvalidated UpName) LangMod
- parseLanguage :: (Loc, String) -> Either Error ParseResult
- parseBaseLanguage :: String -> SExpr -> Either Error (Language 'Unvalidated UpName)
- parseNonterm :: SExpr -> Either Error (Nonterm 'Unvalidated)
- parseProduction :: SExpr -> Either Error (Production 'Unvalidated)
- parseLangMod :: String -> SExpr -> Either Error LangMod
- parseNontermsEdit :: SExpr -> Either Error NontermsEdit
- parseProductionsEdit :: SExpr -> Either Error ProductionsEdit
- parseLangLHS :: SExpr -> Either Error (UpName, [LowName])
- parseNontermBody :: UpName -> [SExpr] -> Either Error (Nonterm 'Unvalidated)
- parseProductionBody :: UpName -> [SExpr] -> Either Error (Production 'Unvalidated)
- parseType :: SExpr -> Either Error (TypeDesc 'Unvalidated)
- parsePass :: (Loc, String) -> Either Error Pass
- getSexpr :: (Loc, String) -> Either Error SExpr
- data Loc = Loc {}
- toUpColonName :: String -> Maybe UpDotName
Recognizers
type ParseResult Source #
Arguments
| = Either (Language 'Unvalidated UpName) LangMod | modifications to a language |
parseLanguage :: (Loc, String) -> Either Error ParseResult Source #
Language ::= <BaseLang> | <LangMod>
- for
BaseLang, seeparseBaseLanguage - for
LangMod, seeparseLangMod
Base Languages
parseBaseLanguage :: String -> SExpr -> Either Error (Language 'Unvalidated UpName) Source #
BaseLang ::=
(<LangLHS> language name and type variables
<string…> documentation
<Nonterm…>) syntactic categories
- for
LangLHS, seeparseLangLHS - for
Nonterm, seeparseNonterm
parseNonterm :: SExpr -> Either Error (Nonterm 'Unvalidated) Source #
Nonterm ::=
(<UpCase> type name
<string…> documentation
<Production…>) constructor arguments
- for
UpCase, seetoUpName - for
Production, seeparseProduction
parseProduction :: SExpr -> Either Error (Production 'Unvalidated) Source #
Language Modification
parseLangMod :: String -> SExpr -> Either Error LangMod Source #
LangMod ::=
(<LangLHS> new language name and type variables
'from' keyword
<UpColon> base language name
<string…> documentation
<NontermsEdit…>) changes to the base language's syntactic categories
- for
LangLHS, seeparseLangLHS - for
UpColon, seetoUpColonName - for
NontermsEdit, seeparseNontermsEdit
parseNontermsEdit :: SExpr -> Either Error NontermsEdit Source #
NontermsEdit
::= ('+' add a syntactic category
<UpCase> new non-terminal name
<string…> documentation
<Production…>) constructors
| ('-' <UpCase>) remove a syntactic category by name
| ('*' modify a syntactic category's productions
<UpCase name> name of non-terminal to edit
<ProductionsEdit…>) changes to the base language's non-terminal
- for
UpCase, seetoUpName - for
Production, seeparseProduction - for
ProductionsEdit, seeparseProductionsEdit
Shared Recognizers
parseNontermBody :: UpName -> [SExpr] -> Either Error (Nonterm 'Unvalidated) Source #
Separated out from parseNonterm because it is useful in parseNontermsEdit as well.
parseProductionBody :: UpName -> [SExpr] -> Either Error (Production 'Unvalidated) Source #
Separated out from parseProduction because it is useful in parseProductionsEdit as well.
parseType :: SExpr -> Either Error (TypeDesc 'Unvalidated) Source #
Type ::= <lowCase name> type parameter
| <UpColonName> plain Haskell type (kind *)
or non-terminal (language parameters already applied)
| (<UpColonName> <Type…>) plain Haskell type application
| ('?' <Type>) Maybe type
| ('*' <Type>) List type
| ('+' <Type>) NonEmpty type
| () | ('&') unit type
| ('&' <Type>) Only type TODO
| ('&' <Type> <Type> <Type…>) tuple types
- for
UpCase, seetoUpName - for
LowCase, seetoLowName - for
UpColonCase, seetoUpColonName
Passes
parsePass :: (Loc, String) -> Either Error Pass Source #
Pass
::= ('from' <UpColonCase> source lagnuage name
'to' <UpColonCase> target lagnuage name
<string…> documentation
- for
UpColonCase, seetoUpColonName
S-Expressions
getSexpr :: (Loc, String) -> Either Error SExpr Source #
This serves as an adapter between Template Haskell and whatever s-expression parser I decide to use.
This is a location type that should be sufficient to describe the start of a Template Haskell quasiquote.
It is used in getSexpr so that it can report errors from the actual source code location.