-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.hs
More file actions
47 lines (32 loc) · 1.2 KB
/
Copy pathParser.hs
File metadata and controls
47 lines (32 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Parser where
----------------- IMPORTS -------------------------------------
import Data.Char -- for using isDigit function
import Types
------------------ PARSER 1 -----------------------------------
data HoneycombLine = Plaster [String] deriving (Read, Show)
stringToHcLine :: String -> HoneycombLine
stringToHcLine s = read s :: HoneycombLine --read :: Read a => String -> a
hcLineToHc :: HoneycombLine -> Honeycomb
hcLineToHc (Plaster []) = []
hcLineToHc (Plaster (x:xs)) = (stringToRow x) : hcLineToHc (Plaster xs)
parseHc1 :: String ->Honeycomb
parseHc1 s = hcLineToHc (stringToHcLine s)
------------------ PARSER 2 -----------------------------------
--hcParser :: Parser Honeycomb
--hcParser = do
-- let row1 = [(Just 'B'),(Just 'B'),(Just 'B')]
-- let row2 = [Nothing,Nothing,(Just 'C')]
-- let ret = [row1,row2]
-- return ret
--beginParser :: Parser String
--beginParser
--parseHc2 :: Parser a -> String -> a
--parseHc2 p inp = p inp
-- primitive parsers
------------------ COMMON FUNCTIONS ---------------------------
charToHex :: Char -> Hex
charToHex '.' = Nothing
charToHex c = Just c
stringToRow :: String -> Row
stringToRow "" = []
stringToRow (x:xs) = (charToHex x) : stringToRow xs