]> Git — Sourcephile - haskell/symantic-parser.git/blob - parsers/Parsers/Tiny.hs
change ShowLetName into HideableName
[haskell/symantic-parser.git] / parsers / Parsers / Tiny.hs
1 {-# LANGUAGE NoMonomorphismRestriction #-}
2 {-# LANGUAGE Rank2Types #-}
3 {-# LANGUAGE TemplateHaskell #-}
4 {-# LANGUAGE UnboxedTuples #-}
5 module Parsers.Tiny where
6
7 import Control.Monad (Monad(..))
8 import Data.Char (Char)
9 import Data.Either (Either(..))
10 import Data.Function (($))
11 import Data.Semigroup (Semigroup(..))
12 import Data.String (String, IsString(..))
13 import Data.Text (Text)
14 import Data.Text.IO (readFile)
15 import System.IO (IO, FilePath)
16 import Test.Tasty
17 import Test.Tasty.Golden
18 import Text.Show (Show(..))
19 import qualified Data.ByteString.Lazy as BSL
20 import qualified Data.IORef as IORef
21 import qualified Data.Text.Lazy as TL
22 import qualified Data.Text.Lazy.Encoding as TL
23 import qualified Language.Haskell.TH.Syntax as TH
24
25 import qualified Symantic.Parser as P
26 --import Golden.Utils
27
28
29 p_Tiny = p_CmdSeq P.<* P.eof -- (!. / %{eof})
30 p_CmdSeq = P.some (p_Cmd p_SEMICOLON{-^cmdSeq-})
31 p_Cmd = p_IfCmd <|> p_RepeatCmd / p_ReadCmd / p_WriteCmd / p_AssignCmd
32
33 -- conditional :: Eq a => [Production (a -> Bool)] -> [repr b] -> repr a -> repr b -> repr b
34 p_Cmd = P.conditional
35 []
36 [p_IfCmd, p_RepeatCmd, p_ReadCmd, p_WriteCmd, p_AssignCmd]
37
38 empty
39
40 ((\c -> haskell c [||c||]) Prelude.<$> ["", ])
41 (look anyChar) op empty
42
43
44 p_IfCmd = p_IF p_Exp^ifExp p_THEN^ifThen p_CmdSeq^ifThenCmdSeq (p_ELSE p_CmdSeq^ifElseCmdSeq / '') p_END^ifEnd
45 p_RepeatCmd = p_REPEAT p_CmdSeq^repeatCmdSeq p_UNTIL^repeatUntil p_Exp^repeatExp
46 p_AssignCmd = p_NAME p_ASSIGNMENT^assignOp p_Exp^assignExp
47 p_ReadCmd = p_READ p_NAME^readName
48 p_WriteCmd = p_WRITE p_Exp^writeExp
49 p_Exp = p_SimpleExp ((p_LESS / p_EQUAL) p_SimpleExp^simpleExp / '')
50 p_SimpleExp = p_Term ((p_ADD / p_SUB) p_Term^term)*
51 p_Term = p_Factor ((p_MUL / p_DIV) p_Factor^factor)*
52 p_Factor = p_OPENPAR p_Exp^openParExp p_CLOSEPAR^closePar / p_NUMBER / p_NAME
53 p_ADD = lex "+"
54 p_ASSIGNMENT = lex ":="
55 p_CLOSEPAR = lex ")"
56 p_DIV = lex "/"
57 p_IF = lex "if"
58 p_ELSE = lex "else"
59 p_END = lex "end"
60 p_EQUAL = lex "="
61 p_LESS = lex "<"
62 p_MUL = lex "*"
63 p_NAME = !p_RESERVED lex (some (oneOf ['a' .. 'z']))
64 p_NUMBER = lex (some (oneOf ['0' .. '9']))
65 p_OPENPAR = lex "("
66 p_READ = lex "read"
67 p_REPEAT = lex "repeat"
68 p_SEMICOLON = lex ";"
69 p_SUB = lex "-"
70 p_THEN = lex "then"
71 p_UNTIL = lex "until"
72 p_WRITE = lex "write"
73 p_RESERVED = (p_IF / p_ELSE / p_END / p_READ / p_REPEAT / p_THEN / p_UNTIL / p_WRITE) ![a-z]+
74 p_Sp = (" " P.<|> "\n")*
75 lex = (p_Sp *>)