module Snail.ToText (toText) where

import Data.Text
import Snail.Lexer

toText :: SnailAst -> Text
toText :: SnailAst -> Text
toText = \case
    TextLiteral (SourcePos
_, Text
txt) -> Text
"\"" forall a. Semigroup a => a -> a -> a
<> Text
txt forall a. Semigroup a => a -> a -> a
<> Text
"\""
    Lexeme (SourcePos
_, Text
lexeme) -> Text
lexeme
    SExpression Maybe Char
Nothing [SnailAst]
exprs ->
        let txt :: Text
txt = [Text] -> Text
Data.Text.unwords forall a b. (a -> b) -> a -> b
$ SnailAst -> Text
toText forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [SnailAst]
exprs
         in Text
"(" forall a. Semigroup a => a -> a -> a
<> Text
txt forall a. Semigroup a => a -> a -> a
<> Text
")"
    SExpression (Just Char
c) [SnailAst]
exprs ->
        let txt :: Text
txt = [Text] -> Text
Data.Text.unwords forall a b. (a -> b) -> a -> b
$ SnailAst -> Text
toText forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [SnailAst]
exprs
         in Char -> Text
singleton Char
c forall a. Semigroup a => a -> a -> a
<> Text
"(" forall a. Semigroup a => a -> a -> a
<> Text
txt forall a. Semigroup a => a -> a -> a
<> Text
")"