blob: 1cdfcf63989a13f72ce39249103ee256e7a2633e (
plain) (
blame)
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 snug
import StdEnv
import StdMaybe
import System.CommandLine
import Snug.Parse
Start w
# ([prog:args],w) = getCommandLine w
| length args <> 1 = abort ("Usage: " +++ prog +++ " INPUT\n")
# input = hd args
# (mbInput,w) = readFile input w
input = fromJust mbInput
| isNone mbInput = abort "Failed to read input\n"
| otherwise = parseSnug input
readFile :: !String !*World -> (!?[Char], !*World)
readFile path w
# (ok,f,w) = fopen path FReadData w
| not ok = (?None, w)
# (contents,f) = read [] f
# (_,w) = fclose f w
= (?Just contents, w)
where
read :: ![Char] !*File -> (![Char], !*File)
read acc f
# (ok,c,f) = freadc f
| not ok = (reverse acc, f)
| otherwise = read [c:acc] f
|