Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Various examples of using rere
,
as used in the blog post.
Synopsis
- syntaxExamples :: IO ()
- ex1 :: RE Void
- ex1run1 :: IO ()
- ex2 :: RE Void
- ex2run1 :: IO ()
- ex3 :: RE Void
- ex3run1 :: IO ()
- ex4 :: RE Void
- ex4run1 :: IO ()
- ex5 :: RE Void
- ex5run1 :: IO ()
- ex6 :: RE Void
- ex6run1 :: IO ()
- exCfg :: Ord a => CFG Nat5 a
- exCfgN :: Vec Nat5 Name
- ex7 :: Ord a => RE a
- ex7run1 :: IO ()
- ex7run :: String -> IO ()
- ex7parsec :: Parser ()
- ex7parsecRun :: IO ()
Documentation
>>>
import Test.QuickCheck.Random (mkQCGen)
>>>
import Test.QuickCheck.Gen (unGen)
>>>
import Control.Monad.ST (runST)
>>>
import RERE
>>>
let runGen seed = maybe "<<null>>" (\g' -> unGen g' (mkQCGen seed) 10)
>>>
let showRef re = matchDebugR re ""
Syntax
syntaxExamples :: IO () Source #
Demonstrates how various constructors are pretty printed.
Example 1
>>>
match ex1 "abab"
True
>>>
match ex1 "ababa"
False
>>>
ex1
Star (App (Ch "a") (Ch "b"))
>>>
charClasses ex1
fromList "\NULabc"
>>>
showRef ex1
size: 4 show: Star (App (Ch "a") (Ch "b")) null: True
>>>
matchR ex1 "abab"
True
>>>
matchR ex1 "ababa"
False
>>>
runGen 43 (generate 10 20 ex1)
"abababababababababab"
>>>
runGen 44 (generate 10 20 ex1)
"ababab"
Example 2
>>>
match ex2 "aaa"
True
Note: how "sharing" is preserved.
>>>
showRef ex2
size: 5 show: App (Star (Ch "a")) (Star (Ch "a")) null: True
> matchR ex2 "aaa"
True
>>>
runGen 42 (generate 10 20 ex2)
"aaaaaa"
>>>
runGen 44 (generate 10 20 ex2)
"aaaaaaaaaa"
Example 3
>>>
match ex3 "abab"
True
>>>
match ex3 "ababa"
False
>>>
showRef ex3
size: 8 show: Ref 0 (Alt Eps (App (Ch "a") (App (Ch "b") (Ref 0 <<loop>>)))) null: True
>>>
matchR ex3 "abab"
True
>>>
matchR ex3 "ababa"
False
>>>
runGen 43 (generate 10 20 ex3)
"abababab"
>>>
runGen 44 (generate 10 20 ex3)
"abab"
Example 4
>>>
match ex4 "aaaabbbb"
True
>>>
showRef ex4
size: 8 show: Ref 0 (Alt Eps (App (Ch "a") (App (Ref 0 <<loop>>) (Ch "b")))) null: True
>>>
matchR ex4 "aaaabbbb"
True
>>>
runGen 43 (generate 10 20 ex4)
"ab"
>>>
runGen 47 (generate 10 20 ex4)
"aaaabbbb"
Example 5
>>>
match ex5 "abab"
True
>>>
match ex5 "ababa"
False
>>>
showRef ex5
size: 8 show: Ref 0 (Alt Eps (App (Ref 0 <<loop>>) (App (Ch "a") (Ch "b")))) null: True
>>>
matchR ex5 "abab"
True
>>>
matchR ex5 "ababa"
False
>>>
runGen 43 (generate 10 20 ex5)
"ab"
>>>
runGen 51 (generate 10 20 ex5)
"abab"
Example 6
Using fix-point operator:
fix expr = "(" expr ")" | "1" | "2" | ... | "9" | expr "+" expr | expr "*" expr
which in BNF is almost he same
expr ::= "(" expr ")" | "1" | "2" | ... | "9" | expr "+" expr | expr "*" expr
>>>
matchR ex6 "(1+2)*3"
True
>>>
runGen 43 (generate 5 5 ex6)
"74501+(534*19450)*(99050)"
Example 7
>>>
matchR ex7 "12"
True
>>>
matchR ex7 "(1+2)*3"
True
>>>
charClasses ex7
fromList "\NUL()*+,0:"
>>>
runGen 43 (generate 5 5 ex7)
"(3431*((0337+5+070346+4))+76848+((4126+350875)*98769+308194+270+03118)+888*(95+90904)+(301069+7+715835)+2809)"
ex7parsecRun :: IO () Source #