diff options
Diffstat (limited to 'Smurf.icl')
-rw-r--r-- | Smurf.icl | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -172,6 +172,7 @@ where etl (Lit s) = Text s etl (Var v) = Math False [Raw v] etl (ECat a b) = List [etl a, etl b] + //etl (ECat a b) = List [etl a, Raw "+(", etl b, Raw ")"] etl (EHead e) = List [Command "textit" [Text "hd"], Raw "(", etl e, Raw ")"] etl (ETail e) = List [Command "textit" [Text "tl"], Raw "(", etl e, Raw ")"] etl (EQuotify e) = List [Command "textit" [Text "q"], Raw "(", etl e, Raw ")"] @@ -260,7 +261,7 @@ step [Get:p] st io _ = (pop st.stack >>= \(var,stk) -> pure (p, { st & stack = push (get var st.store) stk }), io) step [Exec:p] st io _ - = (pop st.stack >>= \(pgm,_) -> pure (let vcs = eToVarChars pgm in fromJust $ parsev $ trace (printToString vcs +++ "\n") vcs, zero), io) + = (pop st.stack >>= \(pgm,_) -> pure (let vcs = eToVarChars (trace pgm pgm) in fromJust $ parsev $ trace (printToString vcs +++ "\n") vcs, zero), io) push :: Expr Stack -> Stack push s st = [s:st] @@ -272,6 +273,7 @@ pop [s:ss] = pure (s, ss) head :: Expr -> Maybe Expr head (Lit "") = empty head (Lit s) = pure $ Lit $ s % (0,0) +head (ECat a b) = head a <|> head b head e = pure $ EHead e tail :: Expr -> Maybe Expr @@ -288,20 +290,22 @@ get var store = case filter ((==)var o fst) store of [(_,val):_] = val quotify :: Expr -> Expr -quotify (Lit s) = Lit $ flip (+++) "\"" $ (+++)"\"" $ toString $ quot $ fromString s +quotify e = ECat (Lit "\"") (ECat (quotify` e) (Lit "\"")) where - quot :: [Char] -> [Char] - quot [] = [] - quot ['\\':cs] = ['\\':'\\':quot cs] - quot ['\n':cs] = ['\\':'n':quot cs] - quot ['\r':cs] = ['\\':'r':quot cs] - quot ['\t':cs] = ['\\':'t':quot cs] - quot ['"':cs] = ['\\':'"':quot cs] - quot [c:cs] = [c:quot cs] -quotify (ECat a b) = ECat (quotify a) (quotify b) -quotify (EHead a) = EHead (quotify a) -quotify (ETail a) = ETail (quotify a) -quotify (Var v) = EQuotify (Var v) + quotify` (Lit s) = Lit $ toString $ quot $ fromString s + where + quot :: [Char] -> [Char] + quot [] = [] + quot ['\\':cs] = ['\\':'\\':quot cs] + quot ['\n':cs] = ['\\':'n':quot cs] + quot ['\r':cs] = ['\\':'r':quot cs] + quot ['\t':cs] = ['\\':'t':quot cs] + quot ['"':cs] = ['\\':'"':quot cs] + quot [c:cs] = [c:quot cs] + quotify` (ECat a b) = ECat (quotify` a) (quotify` b) + quotify` (EHead a) = EHead (quotify` a) + quotify` (ETail a) = ETail (quotify` a) + quotify` (Var v) = EQuotify (Var v) listIO :: IO ListIO listIO = IO read write |