-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCode.hs
More file actions
31 lines (25 loc) · 808 Bytes
/
Copy pathCode.hs
File metadata and controls
31 lines (25 loc) · 808 Bytes
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
module Code where
import ParserC
data Code = Token String | Indent String
loadTokens :: FilePath -> IO [Code]
loadTokens source = do
f <- readFile source
case runParser tokenise f of
Right r -> return r
Left err -> print err >> return []
runParser :: ParserC () a -> String -> Either ParserError a
runParser p s = execP p st
where st = ParserState {
remaining = s,
location = (1, 0),
indent = 0,
reserved = [],
extension = ()
}
-- Parsing stuff
token :: ParserC () Code
token = Token <$> some (noneOf " \t\n")
indentation :: ParserC () Code
indentation = Indent <$> some whitespace
tokenise :: ParserC () [Code]
tokenise = many $ token +++ indentation