| Safe Haskell | None | 
|---|---|
| Language | Haskell2010 | 
BNFC.CF
Description
The internal representation of LBNF grammars.
Pragmas have been desugared as far as possible.
Synopsis
- data LBNF = LBNF {- _lbnfSignature :: Signature
- _lbnfFunctions :: Functions
- _lbnfASTRules :: ASTRules
- _lbnfASTRulesAP :: ASTRulesAP
- _lbnfASTBuiltins :: UsedBuiltins
- _lbnfParserRules :: ParserRules
- _lbnfParserBuiltins :: UsedBuiltins
- _lbnfEntryPoints :: EntryPoints
- _lbnfTokenDefs :: TokenDefs
- _lbnfKeywords :: KeywordUses
- _lbnfSymbols :: SymbolUses
- _lbnfSymbolsKeywords :: SymbolsKeywords
- _lbnfLineComments :: LineComments
- _lbnfBlockComments :: BlockComments
- _lbnfLayoutStart :: LayoutKeywords
- _lbnfLayoutStop :: LayoutKeywords
- _lbnfLayoutTop :: Maybe Position
 
- type Signature = Map LabelName (WithPosition FunType)
- type Functions = Map LabelName (WithPosition Function)
- type ASTRules = Map Cat (Map Label (WithPosition ARuleRHS))
- type ASTRulesAP = Map Type (Map Label ([Type], (Integer, WithPosition ARHS)))
- type ParserRules = Map Cat (Map RHS (WithPosition RuleLabel))
- type EntryPoints = Map Cat (List1 Position)
- type UsedBuiltins = Map BuiltinCat (List1 Position)
- type TokenDefs = Map CatName (WithPosition TokenDef)
- type KeywordUses = Map Keyword (List1 Position)
- type SymbolUses = Map Symbol (List1 Position)
- type SymbolsKeywords = Map String1 Int
- type LineComments = Map Position LineComment
- type BlockComments = Map Position BlockComment
- type LayoutKeywords = Map Keyword Position
- initLBNF :: LBNF
- data TokenDef = TokenDef {}
- newtype Keyword = Keyword {- theKeyword :: List1 Char
 
- newtype Symbol = Symbol {}
- newtype LineComment = LineComment String1
- data BlockComment = BlockComment String1 String1
- type CatName = String1
- type Cat = Cat' BaseCat
- data Cat' a
- data BaseCat
- data BuiltinCat
- data IdentCat = BIdent
- data Type
- data FunType = FunType {- targetType :: Type
- argTypes :: [Type]
 
- data Exp
- data Parameter = Parameter {}
- type VarName = String1
- data Function = Function {}
- type LabelName = String1
- data Label
- data Item' a
- type AItem = Item' String1
- type Item = Item' Keyword
- type RHS' a = [Item' a]
- type ARHS = RHS' String1
- type RHS = RHS' Keyword
- data RuleOrigin
- data ARuleRHS = ARuleRHS {}
- data RuleLabel = RuleLabel {}
- data Separator' a- = Separator a
- | Terminator a
 
- type ASeparator = Separator' String1
- type Separator = Separator' Keyword
- data Parseable
- data PositionToken
- lbnfTokenDefs :: Lens' LBNF TokenDefs
- lbnfSymbolsKeywords :: Lens' LBNF SymbolsKeywords
- lbnfSymbols :: Lens' LBNF SymbolUses
- lbnfSignature :: Lens' LBNF Signature
- lbnfParserRules :: Lens' LBNF ParserRules
- lbnfParserBuiltins :: Lens' LBNF UsedBuiltins
- lbnfLineComments :: Lens' LBNF LineComments
- lbnfLayoutTop :: Lens' LBNF (Maybe Position)
- lbnfLayoutStop :: Lens' LBNF LayoutKeywords
- lbnfLayoutStart :: Lens' LBNF LayoutKeywords
- lbnfKeywords :: Lens' LBNF KeywordUses
- lbnfFunctions :: Lens' LBNF Functions
- lbnfEntryPoints :: Lens' LBNF EntryPoints
- lbnfBlockComments :: Lens' LBNF BlockComments
- lbnfASTRulesAP :: Lens' LBNF ASTRulesAP
- lbnfASTRules :: Lens' LBNF ASTRules
- lbnfASTBuiltins :: Lens' LBNF UsedBuiltins
- catToType :: Cat -> Type
- catToIdentifier :: Cat -> String1
- baseCatToIdentifier :: BaseCat -> String1
- printCatName :: Cat -> String
- printCatNamePrec :: Cat -> String
- printCatNamePrec' :: Cat -> String
- catToString :: Cat -> String
- printBaseCatName :: BaseCat -> String
- isCatCoerced :: Cat -> Bool
- isCatList :: Cat -> Bool
- isCatBuiltin :: Cat -> Bool
- getCatPrec :: Cat -> Integer
- identCat :: Cat -> String
- isBuiltin :: BaseCat -> Bool
- isIdentifier :: BaseCat -> Bool
- isToken :: BaseCat -> Bool
- builtinCats :: [(BuiltinCat, String1)]
- printBuiltinCat :: BuiltinCat -> String1
- printIdentCat :: IdentCat -> String1
- parseBuiltinCat :: String1 -> Maybe (Either IdentCat BuiltinCat)
- identBuiltinCats :: [(Either IdentCat BuiltinCat, String1)]
- tChar :: Type
- tDouble :: Type
- tInteger :: Type
- tString :: Type
- printTypeName :: Type -> String
- identType :: Type -> String
- isListType :: Type -> Bool
- isBuiltinType :: Type -> Bool
- isIdentType :: Type -> Bool
- isTokenType :: Type -> Bool
- labelFromIdentifier :: LabelName -> Label
- printLabelName :: Label -> String
- printRuleName :: Label -> String
- isDef :: Label -> Bool
- isCoercion :: Label -> Bool
- isList :: Label -> Bool
- isALabel :: Label -> Bool
- isPLabel :: Label -> Bool
- filterLabelsAST :: [String] -> [(Label, ([Type], (Integer, ARHS)))] -> [(Label, ([Type], (Integer, ARHS)))]
- filterLabelsPrinter :: [String] -> [(Label, ([Type], (Integer, ARHS)))] -> [(Label, ([Type], (Integer, ARHS)))]
- printRhsCats :: [Item' a] -> [String]
- printRHS :: [Item' Keyword] -> [String]
- getRhsCats :: [Item' a] -> [Cat]
- printItemName :: Item' String1 -> String
- isNTerminal :: Item' a -> Bool
- isItemListCat :: Item' a -> Bool
- isItemBuiltin :: Item' a -> Bool
- rhsCats :: RHS' a -> [Cat]
- rhsType :: RHS' a -> [Type]
- isNoPositionToken :: WithPosition TokenDef -> Bool
- isPositionToken :: WithPosition TokenDef -> Bool
- isPosToken :: TokenDef -> Bool
- hasIdentifier :: TokenDefs -> Bool
- printExp :: Bool -> String -> Exp -> String
- printExp1 :: Exp -> String
- printExp2 :: String -> Exp -> String
- isApp1 :: Exp -> Bool
- isApp2 :: Exp -> Bool
- getKeyword :: Separator -> Keyword
- parseKeyword :: String -> Maybe Keyword
- parseASeparator :: Separator' String -> Maybe ASeparator
- trimSeparator :: ASeparator -> Maybe Separator
- lookupRHS :: Cat -> RHS -> ParserRules -> Maybe (WithPosition RuleLabel)
- layoutsAreUsed :: LBNF -> Bool
Documentation
The internal representation of a LBNF grammar.
The name is an abbreviation of Context-Free (Grammar).
Rules are stored in:
- The signature: a map from rule names to their type (Id labels only). The signature is used for type-checking definitions and special rules (lists).
- The AST rules: a map from categories to labels to rhss. This representation is useful for generating the abstract syntax and the printer. Keywords are not trimmed here to allow the extra whitespace to be printed (see BNFC/bnfc#70).
- The parser rules: a map from categories to rhss to labels.
      internalrules are not contained in this map. This representation expresses that each parseable BNF rule can have at most one label. It is useful for detecting overlapping rules, e.g. coming from proper rules and list/coercion pragmas. The parser generation should start with these rules. Keywords are trimmed since BNFC-generated parsers are not whitespace-sensitive.
Constructors
| LBNF | |
| Fields 
 | |
type ParserRules = Map Cat (Map RHS (WithPosition RuleLabel)) Source #
type UsedBuiltins = Map BuiltinCat (List1 Position) Source #
type LineComments = Map Position LineComment Source #
type BlockComments = Map Position BlockComment Source #
A token category is defined by a regular expression.
Constructors
| TokenDef | |
| Fields 
 | |
Keywords are non-empty trimmed strings.
   Trimming happens since LBNF is a whitespace-insensitive formalism.
   Should a future version of BNFC become whitespace sensitive,
   we have to abstain from trimming keywords by default.
Constructors
| Keyword | |
| Fields 
 | |
Instances
| Eq Keyword Source # | |
| Ord Keyword Source # | |
| Show Keyword Source # | |
Instances
| Eq Symbol Source # | |
| Ord Symbol Source # | |
| Show Symbol Source # | |
newtype LineComment Source #
Constructors
| LineComment String1 | 
data BlockComment Source #
Constructors
| BlockComment String1 String1 | 
Categories
Categories (non-terminals).
Constructors
| Cat a | Base category, e.g.  | 
| ListCat (Cat' a) | List non-terminals, e.g.,  | 
| CoerceCat CatName Integer | E.g.  | 
Instances
| Eq a => Eq (Cat' a) Source # | |
| Ord a => Ord (Cat' a) Source # | |
| Show a => Show (Cat' a) Source # | |
| AddCategories (WithPosition ICat) Source # | Directly add to  | 
| Defined in BNFC.Check.Pass1 Methods addCategories :: WithPosition ICat -> ReaderT Parseable M () Source # | |
Constructors
| BuiltinCat BuiltinCat | 
 | 
| IdentCat IdentCat | Ident | 
| TokenCat CatName | User-defined  | 
| BaseCat CatName | Base category defined by CFG, like  | 
Instances
| Eq BaseCat Source # | |
| Ord BaseCat Source # | |
| Show BaseCat Source # | |
data BuiltinCat Source #
Built-in token categories with special token representation.
Instances
Built-in token Ident, treated as a string.
Constructors
| BIdent | Ident | 
Instances
| Eq IdentCat Source # | |
| Ord IdentCat Source # | |
| Defined in BNFC.CF | |
| Show IdentCat Source # | |
Types (categories in AST)
Types are categories without the precedences (CoerceCat).
Function type t(t₁,...,tₙ) or t₁ → ... → tₙ → t.
Constructors
| FunType | |
| Fields 
 | |
Instances
Expressions (for defined constructors)
Bodies of Function.
   For convenience, these are fully typed.
Bound variable.
Definition body of a constructor.
Labels
LBNF rule label (AST constructor).
Constructors
| LId LabelName | ordinary rule label (uppercase) | 
| LDef LabelName | defined label (lowercase) No representation in AST: | 
| LWild | coercion  | 
| LNil | empty list  | 
| LSg | singleton list  | 
| LCons | list constructor  | 
Rule definition
Element of a rule right hand side (rhs).
Constructors
| Terminal a | Keyword or symbol (not represented in AST). | 
| NTerminal Cat | Category (represented in AST). | 
Instances
| Functor Item' Source # | |
| Foldable Item' Source # | |
| Defined in BNFC.CF Methods fold :: Monoid m => Item' m -> m Source # foldMap :: Monoid m => (a -> m) -> Item' a -> m Source # foldMap' :: Monoid m => (a -> m) -> Item' a -> m Source # foldr :: (a -> b -> b) -> b -> Item' a -> b Source # foldr' :: (a -> b -> b) -> b -> Item' a -> b Source # foldl :: (b -> a -> b) -> b -> Item' a -> b Source # foldl' :: (b -> a -> b) -> b -> Item' a -> b Source # foldr1 :: (a -> a -> a) -> Item' a -> a Source # foldl1 :: (a -> a -> a) -> Item' a -> a Source # toList :: Item' a -> [a] Source # null :: Item' a -> Bool Source # length :: Item' a -> Int Source # elem :: Eq a => a -> Item' a -> Bool Source # maximum :: Ord a => Item' a -> a Source # minimum :: Ord a => Item' a -> a Source # | |
| Traversable Item' Source # | |
| Eq a => Eq (Item' a) Source # | |
| Ord a => Ord (Item' a) Source # | |
| Show a => Show (Item' a) Source # | |
data RuleOrigin Source #
The origin of a rule.
Constructors
| FromOrdinary | Ordinary LBNF rule. | 
| FromRules | Expanded from  | 
| FromCoercions | Expanded from  | 
| FromList | Expanded from list pragma:  | 
Instances
| Eq RuleOrigin Source # | |
| Defined in BNFC.CF Methods (==) :: RuleOrigin -> RuleOrigin -> Bool Source # (/=) :: RuleOrigin -> RuleOrigin -> Bool Source # | |
| Ord RuleOrigin Source # | |
| Defined in BNFC.CF Methods compare :: RuleOrigin -> RuleOrigin -> Ordering Source # (<) :: RuleOrigin -> RuleOrigin -> Bool Source # (<=) :: RuleOrigin -> RuleOrigin -> Bool Source # (>) :: RuleOrigin -> RuleOrigin -> Bool Source # (>=) :: RuleOrigin -> RuleOrigin -> Bool Source # max :: RuleOrigin -> RuleOrigin -> RuleOrigin Source # min :: RuleOrigin -> RuleOrigin -> RuleOrigin Source # | |
| Show RuleOrigin Source # | |
The AST-flavor representation of the rule rhs with meta information.
Constructors
| ARuleRHS | |
| Fields 
 | |
The parser-flavor representation of the rule label with meta information.
Constructors
| RuleLabel | |
| Fields 
 | |
List pragmas
data Separator' a Source #
Constructors
| Separator a | E.g.  | 
| Terminator a | E.g.  | 
Instances
type ASeparator = Separator' String1 Source #
type Separator = Separator' Keyword Source #
Flags etc.
Is a rule relevant for the parser or only for the AST/printer?
Instances
| Eq Parseable Source # | |
| Ord Parseable Source # | |
| Defined in BNFC.CF | |
| Show Parseable Source # | |
data PositionToken Source #
Does a token category carry position information?
Constructors
| PositionToken | from 'position token' pragma | 
| NoPositionToken | from ordinary  | 
Instances
| Eq PositionToken Source # | |
| Defined in BNFC.CF Methods (==) :: PositionToken -> PositionToken -> Bool Source # (/=) :: PositionToken -> PositionToken -> Bool Source # | |
| Ord PositionToken Source # | |
| Defined in BNFC.CF Methods compare :: PositionToken -> PositionToken -> Ordering Source # (<) :: PositionToken -> PositionToken -> Bool Source # (<=) :: PositionToken -> PositionToken -> Bool Source # (>) :: PositionToken -> PositionToken -> Bool Source # (>=) :: PositionToken -> PositionToken -> Bool Source # max :: PositionToken -> PositionToken -> PositionToken Source # min :: PositionToken -> PositionToken -> PositionToken Source # | |
| Show PositionToken Source # | |
Utilities
Categories
catToIdentifier :: Cat -> String1 Source #
baseCatToIdentifier :: BaseCat -> String1 Source #
printCatName :: Cat -> String Source #
Print CatName from Cat in AST generator.
printCatNamePrec :: Cat -> String Source #
printCatNamePrec' :: Cat -> String Source #
catToString :: Cat -> String Source #
printBaseCatName :: BaseCat -> String Source #
isCatCoerced :: Cat -> Bool Source #
is Cat coerced?
isCatBuiltin :: Cat -> Bool Source #
is Cat between used builtins.
getCatPrec :: Cat -> Integer Source #
get Cat coercion number, returns 0 if Cat is not coerced.
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)
isIdentifier :: BaseCat -> Bool Source #
Builtin categories
builtinCats :: [(BuiltinCat, String1)] Source #
printBuiltinCat :: BuiltinCat -> String1 Source #
printIdentCat :: IdentCat -> String1 Source #
parseBuiltinCat :: String1 -> Maybe (Either IdentCat BuiltinCat) Source #
identBuiltinCats :: [(Either IdentCat BuiltinCat, String1)] Source #
Types
printTypeName :: Type -> String Source #
identType :: Type -> String Source #
When given a list Type, i.e. '[C]', it removes the square
 brackets, and adds the prefix List, i.e. ListC.  (for Happy and
 Latex)
isListType :: Type -> Bool Source #
isBuiltinType :: Type -> Bool Source #
isIdentType :: Type -> Bool Source #
isTokenType :: Type -> Bool Source #
Labels
labelFromIdentifier :: LabelName -> Label Source #
printLabelName :: Label -> String Source #
Print Label name.
printRuleName :: Label -> String Source #
isCoercion :: Label -> Bool Source #
filterLabelsAST :: [String] -> [(Label, ([Type], (Integer, ARHS)))] -> [(Label, ([Type], (Integer, ARHS)))] Source #
Filter Labels that will be printed in the AST datatypes.
filterLabelsPrinter :: [String] -> [(Label, ([Type], (Integer, ARHS)))] -> [(Label, ([Type], (Integer, ARHS)))] Source #
Filter Labels that will be printed in the Pretty printer.
RHS
printRhsCats :: [Item' a] -> [String] Source #
Print names of Cat in a rhs.
getRhsCats :: [Item' a] -> [Cat] Source #
Get Cats in a rhs.
isNTerminal :: Item' a -> Bool Source #
isItemListCat :: Item' a -> Bool Source #
isItemBuiltin :: Item' a -> Bool Source #
Token definitions
isNoPositionToken :: WithPosition TokenDef -> Bool Source #
does a token definition contain a no position token.
isPositionToken :: WithPosition TokenDef -> Bool Source #
does a token definition contain (with position) a position token.
isPosToken :: TokenDef -> Bool Source #
does a token definition contain a position token.
hasIdentifier :: TokenDefs -> Bool Source #
Functions
Keywords
getKeyword :: Separator -> Keyword Source #
All-whitespace strings (in particular, empty strings) give Nothing.
trimSeparator :: ASeparator -> Maybe Separator Source #
Parser rules.
lookupRHS :: Cat -> RHS -> ParserRules -> Maybe (WithPosition RuleLabel) Source #
Layouts.
layoutsAreUsed :: LBNF -> Bool Source #