diff options
author | Camil Staps | 2023-01-23 22:36:16 +0100 |
---|---|---|
committer | Camil Staps | 2023-01-23 22:36:16 +0100 |
commit | 301a73c63b3fe5e8306e9e8d213269a720b7a089 (patch) | |
tree | 0593001bc36302e0c759d85e98fcd78dfe87fcef /snug-clean/src/snug.icl | |
parent | Add example of small functional language and run time system (diff) |
Add Clean parser for snug
Diffstat (limited to 'snug-clean/src/snug.icl')
-rw-r--r-- | snug-clean/src/snug.icl | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/snug-clean/src/snug.icl b/snug-clean/src/snug.icl new file mode 100644 index 0000000..1cdfcf6 --- /dev/null +++ b/snug-clean/src/snug.icl @@ -0,0 +1,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 |