context-free-grammar-0.0.1: Basic algorithms on context-free grammars

Safe HaskellNone
LanguageHaskell2010

Data.Cfg.Bnf

Description

A simple, concrete instance of Cfg that can be parsed from source.

The grammar of Bnf source is:

grammar ::= (production)+.
production ::= LOWER_CASE_STRING "::=" right_hand_sides ".".
right_hand_sides ::= right_hand_side ("|" right_hand_side)*.
right_hand_side ::= term*.
term ::= UPPER_CASE_STRING | LOWER_CASE_STRING.

where * means zero or more repetitions and + means one or more repetitions. Terminals are indicated by strings of upper-case characters and underscores; nonterminals by strings of lower-case characters and underscores. Quoted strings are literal tokens.

Synopsis

Documentation

newtype Grammar t nt Source

A simple, concrete instance of Cfg. The terminal and nonterminal symbols of a Grammar are defined to be exactly those appearing the productions. The start symbol is defined to be the head of the first of the productions.

Constructors

Grammar 

Fields

grammarProductions :: [Production t nt]

the productions of the Grammar

Instances

(Ord nt, Ord t) => Cfg Grammar t nt 
(Data t, Data nt) => Data (Grammar t nt) 
Typeable (* -> * -> *) Grammar 

bnf :: QuasiQuoter Source

QuasiQuoter for BNF source. Generates a value of type Grammar. Not usable in pattern, type or declaration positions.

parse :: String -> Grammar String String Source

Parses Bnf source into a Grammar.