BNFC3-3.0: A compiler front-end generator.
Safe HaskellNone
LanguageHaskell2010

BNFC.CF

Description

The internal representation of LBNF grammars.

Pragmas have been desugared as far as possible.

Synopsis

Documentation

data LBNF Source #

The internal representation of a LBNF grammar.

The name is an abbreviation of Context-Free (Grammar).

Rules are stored in:

  1. 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).
  2. 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).
  3. The parser rules: a map from categories to rhss to labels. internal rules 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

Instances

Instances details
Show LBNF Source # 
Instance details

Defined in BNFC.CF

data TokenDef Source #

A token category is defined by a regular expression.

Constructors

TokenDef 

Fields

Instances

Instances details
Show TokenDef Source # 
Instance details

Defined in BNFC.CF

newtype Keyword Source #

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

Instances details
Eq Keyword Source # 
Instance details

Defined in BNFC.CF

Ord Keyword Source # 
Instance details

Defined in BNFC.CF

Show Keyword Source # 
Instance details

Defined in BNFC.CF

newtype Symbol Source #

Constructors

Symbol 

Fields

Instances

Instances details
Eq Symbol Source # 
Instance details

Defined in BNFC.CF

Ord Symbol Source # 
Instance details

Defined in BNFC.CF

Show Symbol Source # 
Instance details

Defined in BNFC.CF

newtype LineComment Source #

Constructors

LineComment String1 

Instances

Instances details
Show LineComment Source # 
Instance details

Defined in BNFC.CF

data BlockComment Source #

Instances

Instances details
Show BlockComment Source # 
Instance details

Defined in BNFC.CF

Categories

data Cat' a Source #

Categories (non-terminals).

Constructors

Cat a

Base category, e.g. Ident, Exp.

ListCat (Cat' a)

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

CoerceCat CatName Integer

E.g. Exp1, Exp2.

Instances

Instances details
Eq a => Eq (Cat' a) Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Cat' a -> Cat' a -> Bool Source #

(/=) :: Cat' a -> Cat' a -> Bool Source #

Ord a => Ord (Cat' a) Source # 
Instance details

Defined in BNFC.CF

Methods

compare :: Cat' a -> Cat' a -> Ordering Source #

(<) :: Cat' a -> Cat' a -> Bool Source #

(<=) :: Cat' a -> Cat' a -> Bool Source #

(>) :: Cat' a -> Cat' a -> Bool Source #

(>=) :: Cat' a -> Cat' a -> Bool Source #

max :: Cat' a -> Cat' a -> Cat' a Source #

min :: Cat' a -> Cat' a -> Cat' a Source #

Show a => Show (Cat' a) Source # 
Instance details

Defined in BNFC.CF

Methods

showsPrec :: Int -> Cat' a -> ShowS Source #

show :: Cat' a -> String Source #

showList :: [Cat' a] -> ShowS Source #

AddCategories (WithPosition ICat) Source #

Directly add to _stUsedCats.

Instance details

Defined in BNFC.Check.Pass1

data BaseCat Source #

Constructors

BuiltinCat BuiltinCat

Char, Double, Integer, String.

IdentCat IdentCat
Ident
TokenCat CatName

User-defined token category.

BaseCat CatName

Base category defined by CFG, like Exp.

Instances

Instances details
Eq BaseCat Source # 
Instance details

Defined in BNFC.CF

Ord BaseCat Source # 
Instance details

Defined in BNFC.CF

Show BaseCat Source # 
Instance details

Defined in BNFC.CF

data BuiltinCat Source #

Built-in token categories with special token representation.

Constructors

BChar
Char
BDouble
Double
BInteger
Integer
BString
String

data IdentCat Source #

Built-in token Ident, treated as a string.

Constructors

BIdent
Ident

Instances

Instances details
Eq IdentCat Source # 
Instance details

Defined in BNFC.CF

Ord IdentCat Source # 
Instance details

Defined in BNFC.CF

Show IdentCat Source # 
Instance details

Defined in BNFC.CF

Types (categories in AST)

data Type Source #

Types are categories without the precedences (CoerceCat).

Constructors

BaseType BaseCat

Base category.

ListType Type

List category.

Instances

Instances details
Eq Type Source # 
Instance details

Defined in BNFC.CF

Methods

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

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

Ord Type Source # 
Instance details

Defined in BNFC.CF

Show Type Source # 
Instance details

Defined in BNFC.CF

data FunType Source #

Function type t(t₁,...,tₙ) or t₁ → ... → tₙ → t.

Constructors

FunType 

Fields

Instances

Instances details
Eq FunType Source # 
Instance details

Defined in BNFC.CF

Show FunType Source # 
Instance details

Defined in BNFC.CF

Expressions (for defined constructors)

data Exp Source #

Bodies of Function. For convenience, these are fully typed.

Constructors

App Label FunType [Exp]

(Possibly defined) label with its type applied to the correct number of expressions.

Var Parameter

Use of function parameter.

LitInteger Integer 
LitDouble Double 
LitChar Char 
LitString String 

Instances

Instances details
Show Exp Source # 
Instance details

Defined in BNFC.CF

data Parameter Source #

Bound variable.

Constructors

Parameter 

Instances

Instances details
Show Parameter Source # 
Instance details

Defined in BNFC.CF

data Function Source #

Definition body of a constructor.

Constructors

Function 

Fields

Instances

Instances details
Show Function Source # 
Instance details

Defined in BNFC.CF

Labels

type LabelName = String1 Source #

Label names are nonempty strings.

data Label Source #

LBNF rule label (AST constructor).

Constructors

LId LabelName

ordinary rule label (uppercase)

LDef LabelName

defined label (lowercase) No representation in AST:

LWild

coercion _ List labels, mapped to the list constructors of the target language.

LNil

empty list []

LSg

singleton list (:[]) ("robot gorilla")

LCons

list constructor (:)

Instances

Instances details
Eq Label Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Label -> Label -> Bool Source #

(/=) :: Label -> Label -> Bool Source #

Ord Label Source # 
Instance details

Defined in BNFC.CF

Show Label Source # 
Instance details

Defined in BNFC.CF

Rule definition

data Item' a Source #

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

Instances details
Functor Item' Source # 
Instance details

Defined in BNFC.CF

Methods

fmap :: (a -> b) -> Item' a -> Item' b Source #

(<$) :: a -> Item' b -> Item' a Source #

Foldable Item' Source # 
Instance details

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 #

sum :: Num a => Item' a -> a Source #

product :: Num a => Item' a -> a Source #

Traversable Item' Source # 
Instance details

Defined in BNFC.CF

Methods

traverse :: Applicative f => (a -> f b) -> Item' a -> f (Item' b) Source #

sequenceA :: Applicative f => Item' (f a) -> f (Item' a) Source #

mapM :: Monad m => (a -> m b) -> Item' a -> m (Item' b) Source #

sequence :: Monad m => Item' (m a) -> m (Item' a) Source #

Eq a => Eq (Item' a) Source # 
Instance details

Defined in BNFC.CF

Methods

(==) :: Item' a -> Item' a -> Bool Source #

(/=) :: Item' a -> Item' a -> Bool Source #

Ord a => Ord (Item' a) Source # 
Instance details

Defined in BNFC.CF

Methods

compare :: Item' a -> Item' a -> Ordering Source #

(<) :: Item' a -> Item' a -> Bool Source #

(<=) :: Item' a -> Item' a -> Bool Source #

(>) :: Item' a -> Item' a -> Bool Source #

(>=) :: Item' a -> Item' a -> Bool Source #

max :: Item' a -> Item' a -> Item' a Source #

min :: Item' a -> Item' a -> Item' a Source #

Show a => Show (Item' a) Source # 
Instance details

Defined in BNFC.CF

type AItem Source #

Arguments

 = Item' String1

AST/printer flavor.

type Item Source #

Arguments

 = Item' Keyword

Parser flavor.

type RHS' a = [Item' a] Source #

The bare rhs of a rule.

data RuleOrigin Source #

The origin of a rule.

Constructors

FromOrdinary

Ordinary LBNF rule.

FromRules

Expanded from rules pragma.

FromCoercions

Expanded from coercions pragma.

FromList

Expanded from list pragma: separator or terminator.

data ARuleRHS Source #

The AST-flavor representation of the rule rhs with meta information.

Constructors

ARuleRHS 

Fields

Instances

Instances details
Eq ARuleRHS Source # 
Instance details

Defined in BNFC.CF

Show ARuleRHS Source # 
Instance details

Defined in BNFC.CF

data RuleLabel Source #

The parser-flavor representation of the rule label with meta information.

Constructors

RuleLabel 

Fields

Instances

Instances details
Eq RuleLabel Source # 
Instance details

Defined in BNFC.CF

Show RuleLabel Source # 
Instance details

Defined in BNFC.CF

List pragmas

data Separator' a Source #

Constructors

Separator a

E.g. separator _ ",".

Terminator a

E.g. terminator _ ";". The last case is better represented as Nothing. -- | NoSeparator -- -- ^ E.g. separator _ "" or terminator _ "".

Instances

Instances details
Functor Separator' Source # 
Instance details

Defined in BNFC.CF

Methods

fmap :: (a -> b) -> Separator' a -> Separator' b Source #

(<$) :: a -> Separator' b -> Separator' a Source #

Foldable Separator' Source # 
Instance details

Defined in BNFC.CF

Methods

fold :: Monoid m => Separator' m -> m Source #

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

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

foldr :: (a -> b -> b) -> b -> Separator' a -> b Source #

foldr' :: (a -> b -> b) -> b -> Separator' a -> b Source #

foldl :: (b -> a -> b) -> b -> Separator' a -> b Source #

foldl' :: (b -> a -> b) -> b -> Separator' a -> b Source #

foldr1 :: (a -> a -> a) -> Separator' a -> a Source #

foldl1 :: (a -> a -> a) -> Separator' a -> a Source #

toList :: Separator' a -> [a] Source #

null :: Separator' a -> Bool Source #

length :: Separator' a -> Int Source #

elem :: Eq a => a -> Separator' a -> Bool Source #

maximum :: Ord a => Separator' a -> a Source #

minimum :: Ord a => Separator' a -> a Source #

sum :: Num a => Separator' a -> a Source #

product :: Num a => Separator' a -> a Source #

Traversable Separator' Source # 
Instance details

Defined in BNFC.CF

Methods

traverse :: Applicative f => (a -> f b) -> Separator' a -> f (Separator' b) Source #

sequenceA :: Applicative f => Separator' (f a) -> f (Separator' a) Source #

mapM :: Monad m => (a -> m b) -> Separator' a -> m (Separator' b) Source #

sequence :: Monad m => Separator' (m a) -> m (Separator' a) Source #

Eq a => Eq (Separator' a) Source # 
Instance details

Defined in BNFC.CF

Ord a => Ord (Separator' a) Source # 
Instance details

Defined in BNFC.CF

Show a => Show (Separator' a) Source # 
Instance details

Defined in BNFC.CF

Flags etc.

data Parseable Source #

Is a rule relevant for the parser or only for the AST/printer?

Constructors

Internal

internal rule (only for AST & printer)

Parseable

ordinary rule (also for parser)

data PositionToken Source #

Does a token category carry position information?

Constructors

PositionToken

from 'position token' pragma

NoPositionToken

from ordinary token pragma

Utilities

Categories

catToType :: Cat -> Type Source #

Convert Cat to Type, converting CoerceCat to BaseCat.

printCatName :: Cat -> String Source #

Print CatName from Cat in AST generator.

isCatCoerced :: Cat -> Bool Source #

is Cat coerced?

isCatList :: Cat -> Bool Source #

is Cat list category?

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)

Builtin categories

Types

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)

Labels

printLabelName :: Label -> String Source #

Print Label name.

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.

printRHS :: [Item' Keyword] -> [String] Source #

Print rhs Items, both non terminals and terminals.

getRhsCats :: [Item' a] -> [Cat] Source #

Get Cats in a rhs.

rhsCats :: RHS' a -> [Cat] Source #

Get the non-terminals of a rhs in left-to-right order.

rhsType :: RHS' a -> [Type] Source #

Get the types of a rhs.

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.

Functions

printExp :: Bool -> String -> Exp -> String Source #

Print Exp (function body in define pragma).

Keywords

getKeyword :: Separator -> Keyword Source #

All-whitespace strings (in particular, empty strings) give Nothing.

Parser rules.

Layouts.