aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2017-05-25 17:38:35 +0200
committertomsmeding <tom.smeding@gmail.com>2017-05-25 17:38:35 +0200
commit624c3db6f493edfb458ee262c4dd691915c46567 (patch)
treebf6614b3cc6a2d042d7bcade64992d3c2bb9882b
parent03b3893fc87c35edabc33a2c533e479e69da76fe (diff)
Add string mode
-rw-r--r--README.md1
-rw-r--r--rip.hs7
2 files changed, 8 insertions, 0 deletions
diff --git a/README.md b/README.md
index bb466e0..6d95c58 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,7 @@ All stack items are signed bigints.
- `$`: outputs a stackdump
- whitespace: nop
- `'c`: pushes the ascii value of c
+- `"abcde"`: `'a'b'c'd'e`
- `#<file.rip>`: literally includes contents of 'file.rip' in-place
diff --git a/rip.hs b/rip.hs
index 0ad0ed0..34d6647 100644
--- a/rip.hs
+++ b/rip.hs
@@ -331,6 +331,13 @@ rip' code@(x:xs) fns conns st = do
'\'' -> rip' (tail xs) fns conns $ ordI (head xs) : st
+ '"' ->
+ let str = takeWhile (/='"') xs
+ rest = drop (length str + 1) xs
+ in if length str == length xs
+ then riperror "No closing quote in \"string\""
+ else rip' rest fns conns $ reverse (map (fromIntegral . fromEnum) str) ++ st
+
'$' -> do
putStrLn $ '[' : ((intercalate " " . map show . reverse) st) ++ "]"
rip' xs fns conns st