]> Git — Sourcephile - haskell/symantic-parser.git/blob - test/Grammar.hs
rename Symantic.{Univariant => Typed}
[haskell/symantic-parser.git] / test / Grammar.hs
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE NoMonomorphismRestriction #-}
3 {-# LANGUAGE TypeApplications #-}
4 {-# LANGUAGE TypeFamilies #-}
5 {-# LANGUAGE TemplateHaskell #-}
6 {-# OPTIONS_GHC -Wno-missing-signatures #-}
7 module Grammar where
8 import Data.Char (Char)
9 import Data.String (String)
10 import Text.Show (Show(..))
11 import qualified Data.Functor as Functor
12 import qualified Parsers.Nandlang
13 import qualified Parsers.Brainfuck.SymanticParser.Grammar
14
15 import Symantic.Parser
16
17 rawGrammars :: Grammarable Char repr => [repr String]
18 rawGrammars =
19 [ production show [||show||] <$> g1
20 , production show [||show||] <$> g2
21 , production show [||show||] <$> g3
22 , production show [||show||] <$> g4
23 , production show [||show||] <$> g5
24 , production show [||show||] <$> g6
25 , production show [||show||] <$> g7
26 , production show [||show||] <$> g8
27 , production show [||show||] <$> g9
28 , production show [||show||] <$> g10
29 , production show [||show||] <$> g11
30 , production show [||show||] <$> g12
31 , production show [||show||] <$> g13
32 , production show [||show||] <$> g14
33 , production show [||show||] <$> g15
34 , production show [||show||] <$> g16
35 ]
36 grammars :: Grammarable Char repr => [repr String]
37 grammars = observeSharing Functor.<$> rawGrammars
38
39 g1 = char 'a'
40 g2 = string "abc"
41 g3 = many (char 'a')
42 g4 = some (string "abcd")
43 g5 = some (string "abcd") <* eof
44 g6 = traverse char "aa" <|> traverse char "ab"
45 g7 = string "aa" <|> string "ab"
46 g8 = many (char 'r') <* eof
47 g9 = eof
48 g10 = char 'a' <|> char 'b'
49 g11 = many (char 'a') <* char 'b'
50 g12 = many (oneOf ['a', 'b', 'c', 'd']) <* eof
51 g13 = Parsers.Brainfuck.SymanticParser.Grammar.grammar @Char @_
52 g14 = Parsers.Nandlang.grammar
53 g15 = (char 'a' <|> char 'b') <* char 'c'
54 g16 = (char 'a' <|> char 'b' <|> char 'c') <* char 'd'