little-earley-0.2.0.0: Simple implementation of Earley parsing

Little.Earley.Examples

Contents

Description

Some examples of grammars.

Synopsis

# Grammars

Grammar of arithmetic expressions.

SUM     ::= PRODUCT | SUM [+-] PRODUCT
PRODUCT ::= FACTOR | PRODUCT [*/] FACTOR
FACTOR  ::= NUMBER | [(] NUMBER [)]
NUMBER  ::= [0-9] | [0-9] NUMBER

### Example

pparse arithG SUM "1+2*3"


Ambiguous grammar of arithmetic expressions.

SUM     ::= PRODUCT | SUM [+-] SUM
PRODUCT ::= FACTOR | PRODUCT [*/] PRODUCT
FACTOR  ::= NUMBER | [(] NUMBER [)]
NUMBER  ::= [0-9] | [0-9] NUMBER

### Example

pparse aArithG SUM "1+2-3"


Grammar of lambda expressions.

LAMBDA ::= VAR | [\] VAR [.] LAMBDA | [(] LAMBDA [)] LAMBDA
VAR    ::= [a-z]

### Example

pparse lambdaG LAMBDA "\\x.x"
pparse lambdaG LAMBDA "(\\x.(x)x)\\x.(x)x"


ML-like syntax.

TERM ::= ATOMS
| "fun" VAR "->" TERM
| "let" VAR "=" TERM "in" TERM
| "if" TERM "then" TERM
| "if" TERM "then" TERM "else" TERM
ATOMS ::= ATOM | ATOMS ATOM
ATOM ::= VAR
| "(" TERM ")"
VAR ::= "a" | "b" | "c" | ...

### Example

Featuring the if-then-else ambiguity.

pparse mlG TERM (words "if a then if b then c else d")


JSON grammar.

JSON   ::= "null" | "true" | "false" | (number) | (string) | "{" OBJECT "}" | "[" ARRAY "]"
OBJECT ::= (string) ":" JSON | (string) ":" JSON "," OBJECT
ARRAY ::= JSON | JSON "," ARRAY

### Example

pparse jsonG JSON (words "{ \"key\" : \"answer\" , \"contents\" : 42 }")


# Symbols

data ArithN Source #

Non-terminals for arithmetic expressions.

Constructors

 SUM PRODUCT FACTOR NUMBER

#### Instances

Instances details
 Source # Instance detailsDefined in Little.Earley.Examples Methods Source # Instance detailsDefined in Little.Earley.Examples MethodstoEnum :: Int -> ArithN #enumFrom :: ArithN -> [ArithN] #enumFromThen :: ArithN -> ArithN -> [ArithN] #enumFromTo :: ArithN -> ArithN -> [ArithN] #enumFromThenTo :: ArithN -> ArithN -> ArithN -> [ArithN] # Source # Instance detailsDefined in Little.Earley.Examples Methods(==) :: ArithN -> ArithN -> Bool #(/=) :: ArithN -> ArithN -> Bool # Source # Instance detailsDefined in Little.Earley.Examples Methods(<) :: ArithN -> ArithN -> Bool #(<=) :: ArithN -> ArithN -> Bool #(>) :: ArithN -> ArithN -> Bool #(>=) :: ArithN -> ArithN -> Bool #max :: ArithN -> ArithN -> ArithN #min :: ArithN -> ArithN -> ArithN # Source # Instance detailsDefined in Little.Earley.Examples MethodsshowsPrec :: Int -> ArithN -> ShowS #showList :: [ArithN] -> ShowS #

data LambdaN Source #

Non-terminals for lambda expressions.

Constructors

 LAMBDA VAR

#### Instances

Instances details
 Source # Instance detailsDefined in Little.Earley.Examples Methods Source # Instance detailsDefined in Little.Earley.Examples MethodsenumFrom :: LambdaN -> [LambdaN] #enumFromThen :: LambdaN -> LambdaN -> [LambdaN] #enumFromTo :: LambdaN -> LambdaN -> [LambdaN] #enumFromThenTo :: LambdaN -> LambdaN -> LambdaN -> [LambdaN] # Source # Instance detailsDefined in Little.Earley.Examples Methods(==) :: LambdaN -> LambdaN -> Bool #(/=) :: LambdaN -> LambdaN -> Bool # Source # Instance detailsDefined in Little.Earley.Examples Methods(<) :: LambdaN -> LambdaN -> Bool #(<=) :: LambdaN -> LambdaN -> Bool #(>) :: LambdaN -> LambdaN -> Bool #(>=) :: LambdaN -> LambdaN -> Bool # Source # Instance detailsDefined in Little.Earley.Examples MethodsshowList :: [LambdaN] -> ShowS #

data MlN Source #

Non-terminals for an ML-like language.

Constructors

 TERM ATOMS ATOM VAR'

#### Instances

Instances details
 Source # Instance detailsDefined in Little.Earley.Examples Methods Source # Instance detailsDefined in Little.Earley.Examples Methodssucc :: MlN -> MlN #pred :: MlN -> MlN #toEnum :: Int -> MlN #fromEnum :: MlN -> Int #enumFrom :: MlN -> [MlN] #enumFromThen :: MlN -> MlN -> [MlN] #enumFromTo :: MlN -> MlN -> [MlN] #enumFromThenTo :: MlN -> MlN -> MlN -> [MlN] # Source # Instance detailsDefined in Little.Earley.Examples Methods(==) :: MlN -> MlN -> Bool #(/=) :: MlN -> MlN -> Bool # Source # Instance detailsDefined in Little.Earley.Examples Methodscompare :: MlN -> MlN -> Ordering #(<) :: MlN -> MlN -> Bool #(<=) :: MlN -> MlN -> Bool #(>) :: MlN -> MlN -> Bool #(>=) :: MlN -> MlN -> Bool #max :: MlN -> MlN -> MlN #min :: MlN -> MlN -> MlN # Source # Instance detailsDefined in Little.Earley.Examples MethodsshowsPrec :: Int -> MlN -> ShowS #show :: MlN -> String #showList :: [MlN] -> ShowS #

data JsonN Source #

Non-terminals for JSON.

Constructors

 JSON OBJECT ARRAY

#### Instances

Instances details
 Source # Instance detailsDefined in Little.Earley.Examples Methods Source # Instance detailsDefined in Little.Earley.Examples Methodssucc :: JsonN -> JsonN #pred :: JsonN -> JsonN #toEnum :: Int -> JsonN #enumFrom :: JsonN -> [JsonN] #enumFromThen :: JsonN -> JsonN -> [JsonN] #enumFromTo :: JsonN -> JsonN -> [JsonN] #enumFromThenTo :: JsonN -> JsonN -> JsonN -> [JsonN] # Source # Instance detailsDefined in Little.Earley.Examples Methods(==) :: JsonN -> JsonN -> Bool #(/=) :: JsonN -> JsonN -> Bool # Source # Instance detailsDefined in Little.Earley.Examples Methods(<) :: JsonN -> JsonN -> Bool #(<=) :: JsonN -> JsonN -> Bool #(>) :: JsonN -> JsonN -> Bool #(>=) :: JsonN -> JsonN -> Bool #max :: JsonN -> JsonN -> JsonN #min :: JsonN -> JsonN -> JsonN # Source # Instance detailsDefined in Little.Earley.Examples MethodsshowsPrec :: Int -> JsonN -> ShowS #show :: JsonN -> String #showList :: [JsonN] -> ShowS #

data CharT Source #

Basic character classes.

Constructors

 Digit Alpha OneOf [Char]

#### Instances

Instances details
 Source # Instance detailsDefined in Little.Earley.Examples Methods(==) :: CharT -> CharT -> Bool #(/=) :: CharT -> CharT -> Bool # Source # Instance detailsDefined in Little.Earley.Examples Methods(<) :: CharT -> CharT -> Bool #(<=) :: CharT -> CharT -> Bool #(>) :: CharT -> CharT -> Bool #(>=) :: CharT -> CharT -> Bool #max :: CharT -> CharT -> CharT #min :: CharT -> CharT -> CharT # Source # Instance detailsDefined in Little.Earley.Examples MethodsshowsPrec :: Int -> CharT -> ShowS #show :: CharT -> String #showList :: [CharT] -> ShowS #

Membership function for character classes.