Safe Haskell | Safe-Infered |
---|

- type Grammar a = Gram (P (Str Char String LineColPos)) a
- run_demos :: IO ()
- pA, pC, pB :: Grammar String
- pNat :: Grammar Int
- pDigit' :: (ListLike state Char, IsLocationUpdatedBy loc Char) => Gram (P (Str Char state loc)) Char
- two :: Applicative f => f [a] -> f [a]
- three :: Applicative f => f a -> f (a, a, a)
- pABC :: Gram (P (Str Char String LineColPos)) Char
- pABC' :: Grammar String

# Documentation

By running the function `show_demos`

you will get a demonstration of the merging parsers.

`>>>`

Result: ("aa",("b","b","b"),["c","c","c","c"]) Correcting steps: The token 'c' was not consumed by the parsing process.`run ((,,) <$> two pA <||> three pB <||> pBetween 2 4 pC ) "cababbcccc"`

`>>>`

Result: [([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]),([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]), ([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]),([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]), ([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]),([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]), ([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]),([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]), ([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]),([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]), ([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"]),([("a","c"),("a","c"),("a","c"),("a","c")],["b","b","b","b"])]`run (amb (mkParserM ((,) <$> pmMany ((,) <$> pA <*> pC) <||> pmMany pB))) "aabbcaabbccc"`

`>>>`

Result: ["2a","1a","3a"]`run (pmMany(pABC)) "a2a1b1b2c2a3b3c1c3"`

`>>>`

Result: (["a","a"],["b","b"])`run ((,) <$> pBetween 2 3 pA <||> pBetween 1 2 pB) "abba"`

`>>>`

Result: (["a","a"],["b","b"]) Correcting steps: Inserted 'a' at position LineColPos 0 3 3 expecting 'a'`run ((,) <$> pBetween 2 3 pA <||> pBetween 1 2 pB) "bba"`

`>>>`

Result: [(["a","a"],["a"]),(["a","a"],["a"]),(["a","a"],["a"])]`run (amb (mkParserM( ((,) <$> pBetween 2 3 pA <||> pBetween 1 2 pA)))) "aaa"`

The `a`

at the right hand side can b any of the three `a`

-s in the input:

`>>>`

Result: (["a","a","a"],["b","b","b"]) Correcting steps: Deleted 'b' at position LineColPos 0 5 5 expecting 'a' Inserted 'a' at position LineColPos 0 6 6 expecting 'a'`run ((,) <$> pAtLeast 3 pA <||> pAtMost 3 pB) "aabbbb"`

`>>>`

Result: (["a","a"],["b","b"])`run ((,) <$> pSome pA <||> pMany pB) "abba"`

`>>>`

Result: (["a","a"],["b","b"])`run ((,) <$> pSome pA <||> pMany pB) "abba"`

`>>>`

Result: (["a"],[]) Correcting steps: Inserted 'a' at position LineColPos 0 0 0 expecting one of ['a', 'b']`run ((,) <$> pSome pA <||> pMany pB) ""`

`>>>`

Result: (["b","b"],["c","c"])`run ((,) <$> pMany pB <||> pSome pC) "bcbc"`

`>>>`

Result: (["b","b"],["c","c"])`run ((,) <$> pSome pB <||> pMany pC) "bcbc"`

`>>>`

Result: (["a"],["b","b"],"c",45)`run ((,,,) <$> pSome pA <||> pMany pB <||> pC <||> (pNat `opt` 5) ) "bcab45"`

`>>>`

Result: (["a","b","a","a","b"],[1,12,14])`run ((,) <$> pMany (pA <|> pB) <||> pSome pNat) "1ab12aab14"`

`>>>`

Result: (["a","a","a","a","b","b"],"c")`run ( (,) <$> ((++) <$> pMany pA <||> pMany pB) <||> pC) "abcaaab"`

`>>>`

Result: (["a","a"],["b","b"])`run (pc `mkParserS` ((,) <$> pMany pA <||> pMany pB)) "acbcacb"`

pDigit' :: (ListLike state Char, IsLocationUpdatedBy loc Char) => Gram (P (Str Char state loc)) CharSource

two :: Applicative f => f [a] -> f [a]Source

`two`

recognises two instance of p as part of the input sequence

three :: Applicative f => f a -> f (a, a, a)Source

`three`

recognises two instance of p as part of the input sequence and concatenates the results

pABC :: Gram (P (Str Char String LineColPos)) CharSource

`pABC`

minimcs a series of events (here an `a`

, a `b`

and a `c`

), which belong to the same transaction.
The transaction is identified by a digit: hence a full transaction is a string like "a5b5c5".
The third element in the body of `show_demos`

below shows how the different transactions can be recovered from
a log-file which contains all events generated by a collection of concurrently running transactions.