aboutsummaryrefslogtreecommitdiff
path: root/snug-clean/src/snug.icl
diff options
context:
space:
mode:
authorCamil Staps2023-01-23 22:36:16 +0100
committerCamil Staps2023-01-23 22:36:16 +0100
commit301a73c63b3fe5e8306e9e8d213269a720b7a089 (patch)
tree0593001bc36302e0c759d85e98fcd78dfe87fcef /snug-clean/src/snug.icl
parentAdd 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.icl31
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