Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type CF = CFG RFun
- data CFG function = CFG {
- cfgPragmas :: [Pragma]
- cfgUsedCats :: Set Cat
- cfgLiterals :: [Literal]
- cfgSymbols :: [Symbol]
- cfgKeywords :: [KeyWord]
- cfgReversibleCats :: [Cat]
- cfgRules :: [Rul function]
- cfgSignature :: Signature
- type Rule = Rul RFun
- data Rul function = Rule {}
- npRule :: Fun -> Cat -> SentForm -> InternalRule -> Rule
- valCat :: Rul fun -> Cat
- lookupRule :: Eq f => f -> [Rul f] -> Maybe (Cat, SentForm)
- data InternalRule
- data Pragma
- data Exp
- data Base
- data Type = FunT [Base] Base
- type Signature = Map String (WithPosition Type)
- type Literal = String
- type Symbol = String
- type KeyWord = String
- data Position
- noPosition :: a -> WithPosition a
- prettyPosition :: Position -> String
- npIdentifier :: String -> Identifier
- data WithPosition a = WithPosition {
- wpPosition :: Position
- wpThing :: a
- blendInPosition :: RString -> String
- type RString = WithPosition String
- type RCat = WithPosition Cat
- data Cat
- strToCat :: String -> Cat
- catToStr :: Cat -> String
- type BaseCat = String
- type TokenCat = String
- catString :: TokenCat
- catInteger :: TokenCat
- catDouble :: TokenCat
- catChar :: TokenCat
- catIdent :: TokenCat
- type NonTerminal = Cat
- type SentForm = [Either Cat String]
- type Fun = String
- type RFun = RString
- class IsFun a where
- type Data = (Cat, [(String, [Cat])])
- cf2data :: CF -> [Data]
- cf2dataLists :: CF -> [Data]
- getAbstractSyntax :: CF -> [Data]
- firstEntry :: CF -> Cat
- baseTokenCatNames :: [TokenCat]
- specialCats :: CF -> [TokenCat]
- specialCatsP :: [TokenCat]
- specialData :: CF -> [Data]
- isCoercion :: IsFun a => a -> Bool
- isDefinedRule :: IsFun a => a -> Bool
- isProperLabel :: IsFun a => a -> Bool
- allCats :: (InternalRule -> Bool) -> CFG f -> [Cat]
- allParserCats :: CFG f -> [Cat]
- allParserCatsNorm :: CFG f -> [Cat]
- reallyAllCats :: CFG f -> [Cat]
- allCatsNorm :: CF -> [Cat]
- allCatsIdNorm :: CF -> [RString]
- allEntryPoints :: CFG f -> List1 Cat
- reservedWords :: CFG f -> [String]
- cfTokens :: CFG f -> [(String, Int)]
- literals :: CFG f -> [TokenCat]
- findAllReversibleCats :: CF -> [Cat]
- identCat :: Cat -> String
- isParsable :: Rul f -> Bool
- rulesForCat :: CF -> Cat -> [Rule]
- rulesForNormalizedCat :: CF -> Cat -> [Rule]
- ruleGroups :: CF -> [(Cat, [Rule])]
- ruleGroupsInternals :: CF -> [(Cat, [Rule])]
- allNames :: CF -> [RString]
- filterNonUnique :: Ord a => [a] -> [a]
- isList :: Cat -> Bool
- isTokenCat :: Cat -> Bool
- maybeTokenCat :: Cat -> Maybe TokenCat
- baseCat :: Cat -> Either BaseCat TokenCat
- sameCat :: Cat -> Cat -> Bool
- isNilFun :: IsFun a => a -> Bool
- isOneFun :: IsFun a => a -> Bool
- hasOneFunc :: [Rule] -> Bool
- getCons :: [Rule] -> String
- getSeparatorByPrecedence :: [Rule] -> [(Integer, String)]
- isConsFun :: IsFun a => a -> Bool
- isNilCons :: IsFun a => a -> Bool
- isEmptyListCat :: CF -> Cat -> Bool
- revSepListRule :: Rul f -> Rul f
- normCat :: Cat -> Cat
- isDataCat :: Cat -> Bool
- isDataOrListCat :: Cat -> Bool
- normCatOfList :: Cat -> Cat
- catOfList :: Cat -> Cat
- comments :: CF -> ([(String, String)], [String])
- numberOfBlockCommentForms :: CF -> Int
- tokenPragmas :: CFG f -> [(TokenCat, Reg)]
- tokenNames :: CFG f -> [String]
- precCat :: Cat -> Integer
- precRule :: Rul f -> Integer
- isUsedCat :: CFG f -> Cat -> Bool
- isPositionCat :: CFG f -> TokenCat -> Bool
- hasPositionTokens :: CFG g -> Bool
- hasIdent :: CFG f -> Bool
- hasIdentLikeTokens :: CFG g -> Bool
- hasLayout :: CF -> Bool
- layoutPragmas :: CF -> (Bool, [String], [String])
- sigLookup :: IsFun a => a -> CF -> Maybe (WithPosition Type)
Documentation
A context free grammar consists of a set of rules and some extended information (e.g. pragmas, literals, symbols, keywords).
Type of context-free grammars (GFG).
CFG | |
|
A rule consists of a function name, a main category and a sequence of terminals and non-terminals.
function_name . Main_Cat ::= sequence
Polymorphic rule type.
Rule | |
|
data InternalRule Source #
Instances
Eq InternalRule Source # | |
Defined in BNFC.CF (==) :: InternalRule -> InternalRule -> Bool # (/=) :: InternalRule -> InternalRule -> Bool # |
Pragmas.
Expressions for function definitions.
type Signature = Map String (WithPosition Type) Source #
Types of the rule labels, together with the position of the rule label.
Source positions.
noPosition :: a -> WithPosition a Source #
prettyPosition :: Position -> String Source #
npIdentifier :: String -> Identifier Source #
data WithPosition a Source #
WithPosition | |
|
Instances
blendInPosition :: RString -> String Source #
Prefix string with pretty-printed position information.
type RString = WithPosition String Source #
A "ranged string" (terminology from Agda code base).
type RCat = WithPosition Cat Source #
Categories are the non-terminals of the grammar.
Cat String | Ordinary non-terminal. |
TokenCat TokenCat | Token types (like |
ListCat Cat | List non-terminals, e.g., |
CoercCat String Integer | E.g. |
strToCat :: String -> Cat Source #
Reads a string into a category. This should only need to handle the case of simple categories (with or without coercion) since list categories are parsed in the grammar already. To be on the safe side here, we still call the parser function that parses categries.
type NonTerminal = Cat Source #
type SentForm = [Either Cat String] Source #
A sentential form is a sequence of non-terminals or terminals.
cf2dataLists :: CF -> [Data] Source #
getAbstractSyntax :: CF -> [Data] Source #
Return the abstract syntax of the grammar. All categories are normalized, so a rule like: EAdd . Exp2 ::= Exp2 "+" Exp3 ; Will give the following signature: EAdd : Exp -> Exp -> Exp
firstEntry :: CF -> Cat Source #
firstEntry
returns the first of the entrypoints
,
or (if none), the first parsable Cat
egory appearing in the grammar.
baseTokenCatNames :: [TokenCat] Source #
Token categories corresponding to base types.
specialCats :: CF -> [TokenCat] Source #
Categories corresponding to tokens. These end up in the
AST. (unlike tokens returned by cfTokens
)
specialCatsP :: [TokenCat] Source #
specialData :: CF -> [Data] Source #
isCoercion :: IsFun a => a -> Bool Source #
Is this function just a coercion? (I.e. the identity)
isDefinedRule :: IsFun a => a -> Bool Source #
isProperLabel :: IsFun a => a -> Bool Source #
allCats :: (InternalRule -> Bool) -> CFG f -> [Cat] Source #
Get all categories of a grammar matching the filter. (No Cat w/o production returned; no duplicates.)
allParserCats :: CFG f -> [Cat] Source #
allParserCatsNorm :: CFG f -> [Cat] Source #
Get all normalized Cat
reallyAllCats :: CFG f -> [Cat] Source #
Get all categories of a grammar. (No Cat w/o production returned; no duplicates.)
allCatsNorm :: CF -> [Cat] Source #
Get all normalized Cat
allCatsIdNorm :: CF -> [RString] Source #
Gets all normalized identified Categories
allEntryPoints :: CFG f -> List1 Cat Source #
Categories that are entry points to the parser.
These are either the declared entrypoints
(in the original order),
or, if no entrypoints
were declared explicitly,
all parsable categories (in the order of declaration in the grammar file).
reservedWords :: CFG f -> [String] Source #
Get the keywords of a grammar.
cfTokens :: CFG f -> [(String, Int)] Source #
Canonical, numbered list of symbols and reserved words. (These do not end up in the AST.)
findAllReversibleCats :: CF -> [Cat] Source #
identCat :: Cat -> String Source #
When given a list Cat, i.e. '[C]', it removes the square
brackets, and adds the prefix List, i.e. ListC
. (for Happy and
Latex)
isParsable :: Rul f -> Bool Source #
Checks if the rule is parsable.
rulesForCat :: CF -> Cat -> [Rule] Source #
Returns all parseable rules that construct the given Cat. Whitespace separators have been removed.
rulesForNormalizedCat :: CF -> Cat -> [Rule] Source #
Like rulesForCat but for normalized value categories. I.e., `rulesForCat (Cat Exp)` will return rules for category Exp but also Exp1, Exp2... in case of coercion
ruleGroups :: CF -> [(Cat, [Rule])] Source #
Group all parsable categories with their rules. Deletes whitespace separators, as they will not become part of the parsing rules.
ruleGroupsInternals :: CF -> [(Cat, [Rule])] Source #
Group all categories with their rules including internal rules.
filterNonUnique :: Ord a => [a] -> [a] Source #
Get all elements with more than one occurrence.
isTokenCat :: Cat -> Bool Source #
sameCat :: Cat -> Cat -> Bool Source #
Categories C1, C2,... (one digit at the end) are variants of C. This function returns true if two category are variants of the same abstract category. E.g.
>>>
sameCat (Cat "Abc") (CoercCat "Abc" 44)
True
hasOneFunc :: [Rule] -> Bool Source #
Checks if the list has a non-empty rule.
getSeparatorByPrecedence :: [Rule] -> [(Integer, String)] Source #
Helper function that gets the list separator by precedence level
revSepListRule :: Rul f -> Rul f Source #
isDataOrListCat :: Cat -> Bool Source #
normCatOfList :: Cat -> Cat Source #
catOfList :: Cat -> Cat Source #
Unwraps the list constructor from the category name.
E.g. [C1] => C1
.
comments :: CF -> ([(String, String)], [String]) Source #
Comments can be defined by the comment
pragma
numberOfBlockCommentForms :: CF -> Int Source #
Number of block comment forms defined in the grammar file.
tokenNames :: CFG f -> [String] Source #
The names of all user-defined tokens.
precCat :: Cat -> Integer Source #
Returns the precedence of a category symbol. E.g. >>> precCat (CoercCat Abc 4) 4
isUsedCat :: CFG f -> Cat -> Bool Source #
Is the category is used on an rhs? Includes internal rules.
hasPositionTokens :: CFG g -> Bool Source #
Is there a position token
declaration in the grammar?
hasIdentLikeTokens :: CFG g -> Bool Source #
Defines or uses the grammar token types like Ident
?
Excludes position tokens.