From 0cd96954d9311b9f222935f110383592209208cc Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 16 Aug 2018 16:57:06 -0700 Subject: [PATCH] Clean up need for splice --- src/Language/JSON/Translate.hs | 21 ++++++++++++--------- src/Reprinting/Translate.hs | 31 +++++++++++++++++-------------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src/Language/JSON/Translate.hs b/src/Language/JSON/Translate.hs index 89093e3e9..f39943f8b 100644 --- a/src/Language/JSON/Translate.hs +++ b/src/Language/JSON/Translate.hs @@ -8,16 +8,19 @@ import Reprinting.Translate instance Translation 'JSON where translation _ content context = case (content, context) of - (Fragment f, _) -> emit $ splice f - (Truth t, _) -> emit . splice $ if t then "true" else "false" - (Nullity, _) -> emit . splice $ "null" + (Fragment f, _) -> emit f - (Open, List:_) -> emit $ splice "[" - (Open, Associative:_) -> emit $ splice "{" + (Truth t, _) -> emit $ if t then "true" else "false" + (Nullity, _) -> emit "null" - (Close, List:_) -> emit $ splice "]" - (Close, Associative:_) -> emit $ splice "}" + (Open, List:_) -> emit "[" + (Open, Associative:_) -> emit "{" + + (Close, List:_) -> emit "]" + (Close, Associative:_) -> emit "}" + + (Separator, List:_) -> emit "," + (Separator, Associative:_) -> emit "," + (Separator, Pair:_) -> emit ":" - (Separator, List:_) -> emit $ splice "," - (Separator, Associative:_) -> emit $ splice ":" _ -> Exc.throwError (Unexpected "invalid context") diff --git a/src/Reprinting/Translate.hs b/src/Reprinting/Translate.hs index 11cb401f8..1f842e844 100644 --- a/src/Reprinting/Translate.hs +++ b/src/Reprinting/Translate.hs @@ -49,31 +49,34 @@ translate :: forall lang . (Translation lang) => Seq Token -> Translator () translate = traverse_ step where step :: Token -> Translator () step t = case t of - Chunk source -> emit $ splice (Source.toText source) - - TControl ctl -> case ctl of + Chunk source -> emit (Source.toText source) + TElement content -> get >>= translation @lang defaultTranslation content + TControl ctl -> case ctl of Log _ -> pure mempty Enter c -> enterContext c Exit c -> exitContext c - TElement content -> get >>= translation @lang defaultTranslation content - defaultTranslation :: Element -> [Context] -> Translator () defaultTranslation content context = case (content, context) of - (Fragment f, _) -> emit $ splice f + (Fragment f, _) -> emit f - (Open, List:_) -> emit $ splice "[" - (Open, Associative:_) -> emit $ splice "{" + (Truth t, _) -> emit $ if t then "true" else "false" + (Nullity, _) -> emit "null" - (Close, List:_) -> emit $ splice "]" - (Close, Associative:_) -> emit $ splice "}" + (Open, List:_) -> emit "[" + (Open, Associative:_) -> emit "{" + + (Close, List:_) -> emit "]" + (Close, Associative:_) -> emit "}" + + (Separator, List:_) -> emit "," + (Separator, Associative:_) -> emit "," + (Separator, Pair:_) -> emit ":" - (Separator, List:_) -> emit $ splice "," - (Separator, Associative:_) -> emit $ splice ":" _ -> Exc.throwError (Unexpected "invalid context") -emit :: Seq Splice -> Translator () -emit = tell +emit :: Text -> Translator () +emit = tell . splice enterContext :: Context -> Translator () enterContext c = modify' (c :)