BNFC-2.9.0: A compiler front-end generator.
Safe HaskellNone
LanguageHaskell2010

BNFC.CF

Synopsis

Documentation

type CF = CFG RFun Source #

A context free grammar consists of a set of rules and some extended information (e.g. pragmas, literals, symbols, keywords).

data CFG function Source #

Type of context-free grammars (GFG).

Constructors

CFG 

Fields

Instances

Instances details
Functor CFG Source # 
Instance details

Defined in BNFC.CF

Methods

fmap :: (a -> b) -> CFG a -> CFG b #

(<$) :: a -> CFG b -> CFG a #

Show function => Show (CFG function) Source # 
Instance details

Defined in BNFC.CF

Methods

showsPrec :: Int -> CFG function -> ShowS #

show :: CFG function -> String #

showList :: [CFG function] -> ShowS #

type Rule = Rul RFun Source #

A rule consists of a function name, a main category and a sequence of terminals and non-terminals.

  function_name . Main_Cat ::= sequence

data Rul function Source #

Polymorphic rule type.

Constructors

Rule 

Fields

  • funRule :: function

    The function (semantic action) of a rule. In order to be able to generate data types this must be a constructor (or an identity function).

  • valRCat :: RCat

    The value category, i.e., the defined non-terminal.

  • rhsRule :: SentForm

    The sentential form, i.e., the list of (non)terminals in the right-hand-side of a rule.

  • internal :: InternalRule

    Is this an "internal" rule only for the AST and printing, not for parsing?

Instances

Instances details
Functor Rul Source # 
Instance details

Defined in BNFC.CF

Methods

fmap :: (a -> b) -> Rul a -> Rul b #

(<$) :: a -> Rul b -> Rul a #

Eq function => Eq (Rul function) Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Rul function -> Rul function -> Bool #

(/=) :: Rul function -> Rul function -> Bool #

Show function => Show (Rul function) Source # 
Instance details

Defined in BNFC.CF

Methods

showsPrec :: Int -> Rul function -> ShowS #

show :: Rul function -> String #

showList :: [Rul function] -> ShowS #

valCat :: Rul fun -> Cat Source #

lookupRule :: Eq f => f -> [Rul f] -> Maybe (Cat, SentForm) Source #

data InternalRule Source #

Constructors

Internal

internal rule (only for AST & printer)

Parsable

ordinary rule (also for parser)

Instances

Instances details
Eq InternalRule Source # 
Instance details

Defined in BNFC.CF

data Pragma Source #

Pragmas.

Constructors

CommentS String

for single line comments

CommentM (String, String)

for multiple-line comments.

TokenReg RString Bool Reg

for tokens

EntryPoints [RCat] 
Layout [String] 
LayoutStop [String] 
LayoutTop 
FunDef RFun [String] Exp 

Instances

Instances details
Show Pragma Source # 
Instance details

Defined in BNFC.CF

data Exp Source #

Expressions for function definitions.

Constructors

App String [Exp]

(Possibly defined) label applied to expressions.

Var String

Function parameter.

LitInt Integer 
LitDouble Double 
LitChar Char 
LitString String 

Instances

Instances details
Eq Exp Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Exp -> Exp -> Bool #

(/=) :: Exp -> Exp -> Bool #

Show Exp Source # 
Instance details

Defined in BNFC.CF

Methods

showsPrec :: Int -> Exp -> ShowS #

show :: Exp -> String #

showList :: [Exp] -> ShowS #

data Base Source #

Type of a non-terminal.

Constructors

BaseT String 
ListT Base 

Instances

Instances details
Eq Base Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Base -> Base -> Bool #

(/=) :: Base -> Base -> Bool #

Ord Base Source # 
Instance details

Defined in BNFC.CF

Methods

compare :: Base -> Base -> Ordering #

(<) :: Base -> Base -> Bool #

(<=) :: Base -> Base -> Bool #

(>) :: Base -> Base -> Bool #

(>=) :: Base -> Base -> Bool #

max :: Base -> Base -> Base #

min :: Base -> Base -> Base #

Show Base Source # 
Instance details

Defined in BNFC.CF

Methods

showsPrec :: Int -> Base -> ShowS #

show :: Base -> String #

showList :: [Base] -> ShowS #

data Type Source #

Type of a rule label.

Constructors

FunT [Base] Base 

Instances

Instances details
Eq Type Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Type -> Type -> Bool #

(/=) :: Type -> Type -> Bool #

Ord Type Source # 
Instance details

Defined in BNFC.CF

Methods

compare :: Type -> Type -> Ordering #

(<) :: Type -> Type -> Bool #

(<=) :: Type -> Type -> Bool #

(>) :: Type -> Type -> Bool #

(>=) :: Type -> Type -> Bool #

max :: Type -> Type -> Type #

min :: Type -> Type -> Type #

Show Type Source # 
Instance details

Defined in BNFC.CF

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

type Signature = Map String (WithPosition Type) Source #

Types of the rule labels, together with the position of the rule label.

type Literal = String Source #

Literal: builtin-token types Char, String, Ident, Integer, Double.

data Position Source #

Source positions.

Constructors

NoPosition 
Position 

Fields

Instances

Instances details
Eq Position Source # 
Instance details

Defined in BNFC.CF

Ord Position Source # 
Instance details

Defined in BNFC.CF

Show Position Source # 
Instance details

Defined in BNFC.CF

data WithPosition a Source #

Constructors

WithPosition 

Fields

Instances

Instances details
Functor WithPosition Source # 
Instance details

Defined in BNFC.CF

Methods

fmap :: (a -> b) -> WithPosition a -> WithPosition b #

(<$) :: a -> WithPosition b -> WithPosition a #

IsString RFun Source # 
Instance details

Defined in BNFC.CF

Methods

fromString :: String -> RFun #

Foldable WithPosition Source # 
Instance details

Defined in BNFC.CF

Methods

fold :: Monoid m => WithPosition m -> m #

foldMap :: Monoid m => (a -> m) -> WithPosition a -> m #

foldMap' :: Monoid m => (a -> m) -> WithPosition a -> m #

foldr :: (a -> b -> b) -> b -> WithPosition a -> b #

foldr' :: (a -> b -> b) -> b -> WithPosition a -> b #

foldl :: (b -> a -> b) -> b -> WithPosition a -> b #

foldl' :: (b -> a -> b) -> b -> WithPosition a -> b #

foldr1 :: (a -> a -> a) -> WithPosition a -> a #

foldl1 :: (a -> a -> a) -> WithPosition a -> a #

toList :: WithPosition a -> [a] #

null :: WithPosition a -> Bool #

length :: WithPosition a -> Int #

elem :: Eq a => a -> WithPosition a -> Bool #

maximum :: Ord a => WithPosition a -> a #

minimum :: Ord a => WithPosition a -> a #

sum :: Num a => WithPosition a -> a #

product :: Num a => WithPosition a -> a #

Traversable WithPosition Source # 
Instance details

Defined in BNFC.CF

Methods

traverse :: Applicative f => (a -> f b) -> WithPosition a -> f (WithPosition b) #

sequenceA :: Applicative f => WithPosition (f a) -> f (WithPosition a) #

mapM :: Monad m => (a -> m b) -> WithPosition a -> m (WithPosition b) #

sequence :: Monad m => WithPosition (m a) -> m (WithPosition a) #

Eq a => Eq (WithPosition a) Source #

Ignore position in equality and ordering.

Instance details

Defined in BNFC.CF

Ord a => Ord (WithPosition a) Source # 
Instance details

Defined in BNFC.CF

Show a => Show (WithPosition a) Source # 
Instance details

Defined in BNFC.CF

IsFun a => IsFun (WithPosition a) Source # 
Instance details

Defined in BNFC.CF

blendInPosition :: RString -> String Source #

Prefix string with pretty-printed position information.

type RString = WithPosition String Source #

A "ranged string" (terminology from Agda code base).

data Cat Source #

Categories are the non-terminals of the grammar.

Constructors

Cat String

Ordinary non-terminal.

TokenCat TokenCat

Token types (like Ident, Integer, ..., user-defined).

ListCat Cat

List non-terminals, e.g., [Ident], [Exp], [Exp1].

CoercCat String Integer

E.g. Exp1, Exp2.

Instances

Instances details
Eq Cat Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Cat -> Cat -> Bool #

(/=) :: Cat -> Cat -> Bool #

Ord Cat Source # 
Instance details

Defined in BNFC.CF

Methods

compare :: Cat -> Cat -> Ordering #

(<) :: Cat -> Cat -> Bool #

(<=) :: Cat -> Cat -> Bool #

(>) :: Cat -> Cat -> Bool #

(>=) :: Cat -> Cat -> Bool #

max :: Cat -> Cat -> Cat #

min :: Cat -> Cat -> Cat #

Show Cat Source # 
Instance details

Defined in BNFC.CF

Methods

showsPrec :: Int -> Cat -> ShowS #

show :: Cat -> String #

showList :: [Cat] -> ShowS #

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.

catToStr :: Cat -> String Source #

Render category symbols as strings

type SentForm = [Either Cat String] Source #

A sentential form is a sequence of non-terminals or terminals.

type Fun = String Source #

Fun is the function name of a rule.

class IsFun a where Source #

Methods

funName :: a -> String Source #

Instances

Instances details
IsFun String Source # 
Instance details

Defined in BNFC.CF

IsFun a => IsFun (WithPosition a) Source # 
Instance details

Defined in BNFC.CF

type Data = (Cat, [(String, [Cat])]) Source #

The abstract syntax of a grammar.

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 Category 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)

isCoercion :: IsFun a => a -> Bool Source #

Is this function just a coercion? (I.e. the identity)

allCats :: (InternalRule -> Bool) -> CFG f -> [Cat] Source #

Get all categories of a grammar matching the filter. (No Cat w/o production returned; no duplicates.)

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.)

literals :: CFG f -> [TokenCat] Source #

Get all literals of a grammar. (e.g. String, Double)

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.

allNames :: CF -> [RString] Source #

Constructors and categories.

filterNonUnique :: Ord a => [a] -> [a] Source #

Get all elements with more than one occurrence.

baseCat :: Cat -> Either BaseCat TokenCat Source #

Get the underlying category identifier.

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

isNilFun :: IsFun a => a -> Bool Source #

isOneFun :: IsFun a => a -> Bool Source #

hasOneFunc :: [Rule] -> Bool Source #

Checks if the list has a non-empty rule.

getCons :: [Rule] -> String Source #

Gets the separator for a list.

getSeparatorByPrecedence :: [Rule] -> [(Integer, String)] Source #

Helper function that gets the list separator by precedence level

isConsFun :: IsFun a => a -> Bool Source #

isNilCons :: IsFun a => a -> Bool Source #

normCat :: Cat -> Cat Source #

Removes precedence information. C1 => C, [C2] => [C]

isDataCat :: Cat -> Bool Source #

Does the category correspond to a data type?

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.

tokenPragmas :: CFG f -> [(TokenCat, Reg)] Source #

User-defined regular expression tokens

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.

isPositionCat :: CFG f -> TokenCat -> Bool Source #

Does the category have a position stored in AST?

hasPositionTokens :: CFG g -> Bool Source #

Is there a position token declaration in the grammar?

hasIdent :: CFG f -> Bool Source #

Whether the grammar uses the predefined Ident type.

hasIdentLikeTokens :: CFG g -> Bool Source #

Defines or uses the grammar token types like Ident? Excludes position tokens.

sigLookup :: IsFun a => a -> CF -> Maybe (WithPosition Type) Source #

Get the type of a rule label.