From 301a73c63b3fe5e8306e9e8d213269a720b7a089 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 23 Jan 2023 22:36:16 +0100 Subject: Add Clean parser for snug --- snug-clean/src/snug.icl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 snug-clean/src/snug.icl (limited to 'snug-clean/src/snug.icl') 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 -- cgit v1.2.3