{-# LANGUAGE OverloadedStrings #-}
module Data.SCargot.Language.Basic
(
basicParser
, basicPrinter
, locatedBasicParser
, locatedBasicPrinter
) where
import Control.Applicative ((<$>))
import Data.Char (isAlphaNum)
import Text.Parsec (many1, satisfy)
import Data.Text (Text, pack)
import Data.Functor.Identity (Identity)
import Text.Parsec.Prim (ParsecT)
import Data.SCargot.Common (Located(..), located)
import Data.SCargot.Repr.Basic (SExpr)
import Data.SCargot ( SExprParser
, SExprPrinter
, mkParser
, flatPrint
)
isAtomChar :: Char -> Bool
isAtomChar :: Char -> Bool
isAtomChar Char
c = Char -> Bool
isAlphaNum Char
c
Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'-' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'*' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'/'
Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'+' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'<' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'>'
Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'=' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'!' Bool -> Bool -> Bool
|| Char
c forall a. Eq a => a -> a -> Bool
== Char
'?'
pToken :: ParsecT Text a Identity Text
pToken :: forall a. ParsecT Text a Identity Text
pToken = String -> Text
pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 (forall s (m :: * -> *) u.
Stream s m Char =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isAtomChar)
basicParser :: SExprParser Text (SExpr Text)
basicParser :: SExprParser Text (SExpr Text)
basicParser = forall atom. Parser atom -> SExprParser atom (SExpr atom)
mkParser forall a. ParsecT Text a Identity Text
pToken
locatedBasicParser :: SExprParser (Located Text) (SExpr (Located Text))
locatedBasicParser :: SExprParser (Located Text) (SExpr (Located Text))
locatedBasicParser = forall atom. Parser atom -> SExprParser atom (SExpr atom)
mkParser forall a b. (a -> b) -> a -> b
$ forall a. Parser a -> Parser (Located a)
located forall a. ParsecT Text a Identity Text
pToken
basicPrinter :: SExprPrinter Text (SExpr Text)
basicPrinter :: SExprPrinter Text (SExpr Text)
basicPrinter = forall atom. (atom -> Text) -> SExprPrinter atom (SExpr atom)
flatPrint forall a. a -> a
id
locatedBasicPrinter :: SExprPrinter (Located Text) (SExpr (Located Text))
locatedBasicPrinter :: SExprPrinter (Located Text) (SExpr (Located Text))
locatedBasicPrinter = forall atom. (atom -> Text) -> SExprPrinter atom (SExpr atom)
flatPrint forall {a}. Located a -> a
unLoc
where unLoc :: Located a -> a
unLoc (At Location
_loc a
e) = a
e