1
1
mirror of https://github.com/github/semantic.git synced 2024-11-24 08:54:07 +03:00

Clean up need for splice

This commit is contained in:
Timothy Clem 2018-08-16 16:57:06 -07:00
parent f674e2dad1
commit 0cd96954d9
2 changed files with 29 additions and 23 deletions

View File

@ -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")

View File

@ -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 :)