Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type List1 = NonEmpty
- type CF = CFG RFun
- type Rule = Rul RFun
- data Rul function = Rule {}
- data InternalRule
- type SentForm = [Either Cat String]
- data CFG function = CFG {
- cfgPragmas :: [Pragma]
- cfgUsedCats :: Set Cat
- cfgLiterals :: [Literal]
- cfgSymbols :: [Symbol]
- cfgKeywords :: [KeyWord]
- cfgReversibleCats :: [Cat]
- cfgRules :: [Rul function]
- cfgSignature :: Signature
- type Signature = Map String (WithPosition Type)
- data Base
- data Type = FunT [Base] Base
- dummyBase :: Base
- dummyType :: Type
- data Exp' f
- type Exp = Exp' String
- data Pragma
- data Define = Define {}
- type Telescope = [(String, Base)]
- isFunDef :: Pragma -> Either Pragma Define
- definitions :: CFG f -> [Define]
- type LayoutKeyWords = [(KeyWord, Delimiters)]
- data Delimiters = Delimiters {}
- tokenPragmas :: CFG f -> [(TokenCat, Reg)]
- tokenNames :: CFG f -> [String]
- layoutPragmas :: CF -> (Maybe Symbol, LayoutKeyWords, [KeyWord])
- hasLayout_ :: (Maybe Symbol, LayoutKeyWords, [KeyWord]) -> Bool
- hasLayout :: CF -> Bool
- type Literal = String
- type Symbol = String
- type KeyWord = String
- data Position
- prettyPosition :: Position -> String
- data WithPosition a = WithPosition {
- wpPosition :: Position
- wpThing :: a
- noPosition :: a -> WithPosition a
- type RString = WithPosition String
- blendInPosition :: RString -> String
- type RCat = WithPosition Cat
- valCat :: Rul fun -> Cat
- npRule :: Fun -> Cat -> SentForm -> InternalRule -> Rule
- npIdentifier :: String -> Identifier
- data Cat
- type TokenCat = String
- type BaseCat = String
- type NonTerminal = Cat
- catToStr :: Cat -> String
- strToCat :: String -> Cat
- catString :: TokenCat
- catInteger :: TokenCat
- catDouble :: TokenCat
- catChar :: TokenCat
- catIdent :: TokenCat
- baseTokenCatNames :: [TokenCat]
- specialCatsP :: [TokenCat]
- isDataCat :: Cat -> Bool
- isDataOrListCat :: Cat -> Bool
- sameCat :: Cat -> Cat -> Bool
- normCat :: Cat -> Cat
- normCatOfList :: Cat -> Cat
- identCat :: Cat -> String
- identType :: Base -> String
- catOfType :: [TokenCat] -> Base -> Cat
- isList :: Cat -> Bool
- baseCat :: Cat -> Either BaseCat TokenCat
- isTokenCat :: Cat -> Bool
- maybeTokenCat :: Cat -> Maybe TokenCat
- catOfList :: Cat -> Cat
- type Fun = String
- type RFun = RString
- class IsFun a where
- funNameSatisfies :: IsFun a => (String -> Bool) -> a -> Bool
- isDefinedRule :: IsFun a => a -> Bool
- isProperLabel :: IsFun a => a -> Bool
- isNilCons :: IsFun a => a -> Bool
- type Data = (Cat, [(String, [Cat])])
- firstEntry :: CF -> Cat
- allNames :: CF -> [RString]
- filterNonUnique :: Ord a => [a] -> [a]
- commentPragmas :: [Pragma] -> [Pragma]
- lookupRule :: Eq f => f -> [Rul f] -> Maybe (Cat, SentForm)
- rulesForCat :: CF -> Cat -> [Rule]
- removeWhiteSpaceSeparators :: Rul f -> Rul f
- mapRhs :: (SentForm -> SentForm) -> Rul f -> Rul f
- rulesForNormalizedCat :: CF -> Cat -> [Rule]
- rulesForCat' :: CF -> Cat -> [Rule]
- allCats :: (InternalRule -> Bool) -> CFG f -> [Cat]
- reallyAllCats :: CFG f -> [Cat]
- allParserCats :: CFG f -> [Cat]
- allCatsIdNorm :: CF -> [RString]
- allCatsNorm :: CF -> [Cat]
- allParserCatsNorm :: CFG f -> [Cat]
- isUsedCat :: CFG f -> Cat -> Bool
- ruleGroups :: CF -> [(Cat, [Rule])]
- ruleGroupsInternals :: CF -> [(Cat, [Rule])]
- literals :: CFG f -> [TokenCat]
- reservedWords :: CFG f -> [String]
- cfTokens :: CFG f -> [(String, Int)]
- comments :: CF -> ([(String, String)], [String])
- numberOfBlockCommentForms :: CF -> Int
- hasIdent :: CFG f -> Bool
- specialCats :: CF -> [TokenCat]
- getAbstractSyntax :: CF -> [Data]
- cf2data' :: (Cat -> Bool) -> CF -> [Data]
- cf2data :: CF -> [Data]
- cf2dataLists :: CF -> [Data]
- specialData :: CF -> [Data]
- sigLookup :: IsFun a => a -> CF -> Maybe (WithPosition Type)
- isParsable :: Rul f -> Bool
- hasNilRule :: [Rule] -> Maybe Rule
- hasSingletonRule :: [Rule] -> Maybe Rule
- sortRulesByPrecedence :: [Rule] -> [(Integer, Rule)]
- isEmptyListCat :: CF -> Cat -> Bool
- isNonterm :: Either Cat String -> Bool
- revSepListRule :: Rul f -> Rul f
- findAllReversibleCats :: CF -> [Cat]
- isEmptyNilRule :: IsFun a => Rul a -> Bool
- precCat :: Cat -> Integer
- precRule :: Rul f -> Integer
- hasIdentLikeTokens :: CFG g -> Bool
- hasTextualTokens :: CFG g -> Bool
- hasPositionTokens :: CFG g -> Bool
- isPositionCat :: CFG f -> TokenCat -> Bool
- allEntryPoints :: CFG f -> List1 Cat
Documentation
A context free grammar consists of a set of rules and some extended information (e.g. pragmas, literals, symbols, keywords).
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 # |
type SentForm = [Either Cat String] Source #
A sentential form is a sequence of non-terminals or terminals.
Type of context-free grammars (GFG).
CFG | |
|
type Signature = Map String (WithPosition Type) Source #
Types of the rule labels, together with the position of the rule label.
Expressions for function definitions.
Pragmas.
definitions :: CFG f -> [Define] Source #
All define
pragmas of the grammar.
type LayoutKeyWords = [(KeyWord, Delimiters)] Source #
data Delimiters Source #
List delimiters.
Instances
Show Delimiters Source # | |
Defined in BNFC.CF showsPrec :: Int -> Delimiters -> ShowS # show :: Delimiters -> String # showList :: [Delimiters] -> ShowS # |
tokenNames :: CFG f -> [String] Source #
The names of all user-defined tokens.
layoutPragmas :: CF -> (Maybe Symbol, LayoutKeyWords, [KeyWord]) Source #
hasLayout_ :: (Maybe Symbol, LayoutKeyWords, [KeyWord]) -> Bool Source #
Source positions.
prettyPosition :: Position -> String Source #
data WithPosition a Source #
WithPosition | |
|
Instances
noPosition :: a -> WithPosition a Source #
type RString = WithPosition String Source #
A "ranged string" (terminology from Agda code base).
blendInPosition :: RString -> String Source #
Prefix string with pretty-printed position information.
type RCat = WithPosition Cat Source #
npIdentifier :: String -> Identifier 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. |
type NonTerminal = Cat Source #
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.
baseTokenCatNames :: [TokenCat] Source #
Token categories corresponding to base types.
specialCatsP :: [TokenCat] Source #
isDataOrListCat :: 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
normCatOfList :: Cat -> 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)
catOfType :: [TokenCat] -> Base -> Cat Source #
Reconstruct (non-coercion) category from a type, given a list of what should be the token categories.
isTokenCat :: Cat -> Bool Source #
catOfList :: Cat -> Cat Source #
Unwraps the list constructor from the category name.
E.g. [C1] => C1
.
funName :: a -> String Source #
:: a | |
-> Bool | Is this the constructor for empty lists? |
:: a | |
-> Bool | Is this the constructor for singleton lists? |
:: a | |
-> Bool | Is this the list constructor? |
:: a | |
-> Bool | Is this list concatenation? |
isCoercion :: a -> Bool Source #
Is this function just a coercion? (I.e. the identity)
Instances
IsFun String Source # | |
IsFun a => IsFun (WithPosition a) Source # | |
Defined in BNFC.CF funName :: WithPosition a -> String Source # isNilFun :: WithPosition a -> Bool Source # isOneFun :: WithPosition a -> Bool Source # isConsFun :: WithPosition a -> Bool Source # isConcatFun :: WithPosition a -> Bool Source # isCoercion :: WithPosition a -> Bool Source # | |
IsFun a => IsFun (Rul a) Source # | |
IsFun a => IsFun (k, a) Source # | |
isDefinedRule :: IsFun a => a -> Bool Source #
isProperLabel :: IsFun a => a -> Bool Source #
firstEntry :: CF -> Cat Source #
firstEntry
returns the first of the entrypoints
,
or (if none), the first parsable Cat
egory appearing in the grammar.
filterNonUnique :: Ord a => [a] -> [a] Source #
Get all elements with more than one occurrence.
commentPragmas :: [Pragma] -> [Pragma] Source #
Extract the comment pragmas.
rulesForCat :: CF -> Cat -> [Rule] Source #
Returns all parseable rules that construct the given Cat. Whitespace separators have been removed.
removeWhiteSpaceSeparators :: Rul f -> Rul f Source #
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
rulesForCat' :: CF -> Cat -> [Rule] Source #
As rulesForCat, but this version doesn't exclude internal rules.
allCats :: (InternalRule -> Bool) -> CFG f -> [Cat] Source #
Get all categories of a grammar matching the filter. (No Cat w/o production returned; no duplicates.)
reallyAllCats :: CFG f -> [Cat] Source #
Get all categories of a grammar. (No Cat w/o production returned; no duplicates.)
allParserCats :: CFG f -> [Cat] Source #
allCatsIdNorm :: CF -> [RString] Source #
Gets all normalized identified Categories
allCatsNorm :: CF -> [Cat] Source #
Get all normalized Cat
allParserCatsNorm :: CFG f -> [Cat] Source #
Get all normalized Cat
isUsedCat :: CFG f -> Cat -> Bool Source #
Is the category is used on an rhs? Includes internal rules.
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.
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.)
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.
specialCats :: CF -> [TokenCat] Source #
Categories corresponding to tokens. These end up in the
AST. (unlike tokens returned by cfTokens
)
abstract syntax trees: data type definitions
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
cf2data' :: (Cat -> Bool) -> CF -> [Data] Source #
All the functions below implement the idea of getting the
abstract syntax of the grammar with some variation but they seem to do a
poor job at handling corner cases involving coercions.
Use getAbstractSyntax
instead if possible.
cf2dataLists :: CF -> [Data] Source #
specialData :: CF -> [Data] Source #
isParsable :: Rul f -> Bool Source #
Checks if the rule is parsable.
hasSingletonRule :: [Rule] -> Maybe Rule Source #
Gets the singleton rule out of the rules for a list.
isEmptyListCat :: CF -> Cat -> Bool Source #
Is the given category a list category parsing also empty lists?
revSepListRule :: Rul f -> Rul f Source #
findAllReversibleCats :: CF -> [Cat] Source #
precCat :: Cat -> Integer Source #
Returns the precedence of a category symbol. E.g. >>> precCat (CoercCat Abc 4) 4
hasIdentLikeTokens :: CFG g -> Bool Source #
Defines or uses the grammar token types like Ident
?
Excludes position tokens.
hasTextualTokens :: CFG g -> Bool Source #
Defines or uses the grammar token
types or Ident
?
hasPositionTokens :: CFG g -> Bool Source #
Is there a position token
declaration in the grammar?