-
Notifications
You must be signed in to change notification settings - Fork 2
/
TersmuIRC.hs
48 lines (42 loc) · 1.55 KB
/
TersmuIRC.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
-- This file is part of tersmu
-- Copyright (C) 2014 Martin Bays <mbays@sdf.org>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of version 3 of the GNU General Public License as
-- published by the Free Software Foundation.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see http://www.gnu.org/licenses/.
module TersmuIRC (onelineParse) where
import ParseText (parseText)
import JboParse (evalText, evalStatement)
import JboSyntax
import ParseM (ParseStateM, evalParseStateM)
import JboShow
import Logic
import Bindful
import Morph
import Control.Monad.State
import Control.Monad.Identity
import Control.Applicative
import Data.Map (Map)
import qualified Data.Map as Map
import Data.List
import Data.Char
import Data.Either
onelineParse :: Bool -> String -> String
onelineParse jbo s =
case morph s of
Left errpos ->
"Morphology error at " ++ show errpos
Right text ->
evalParseStateM $ showParsedText jbo text $ parseText text
showParsedText :: Bool -> String -> Either Int Text -> ParseStateM String
showParsedText jbo s (Right text) = do
jboText <- mapStateT (return.runIdentity) $ JboParse.evalText text
return $ onelinify jbo $ evalBindful $ logjboshow jbo jboText
showParsedText jbo s (Left pos) = return $ "Parse error at " ++ show pos
onelinify :: Bool -> String -> String
onelinify jbo "" = ""
onelinify jbo ('\n':cs) = (if jbo then " " else "; ") ++ onelinify jbo cs
onelinify jbo (c:cs) = c:onelinify jbo cs