1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- {-# 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 c = isAlphaNum c
- || c == '-' || c == '*' || c == '/'
- || c == '+' || c == '<' || c == '>'
- || c == '=' || c == '!' || c == '?'
- pToken :: ParsecT Text a Identity Text
- pToken = pack <$> many1 (satisfy isAtomChar)
- basicParser :: SExprParser Text (SExpr Text)
- basicParser = mkParser pToken
- locatedBasicParser :: SExprParser (Located Text) (SExpr (Located Text))
- locatedBasicParser = mkParser $ located pToken
- basicPrinter :: SExprPrinter Text (SExpr Text)
- basicPrinter = flatPrint id
- locatedBasicPrinter :: SExprPrinter (Located Text) (SExpr (Located Text))
- locatedBasicPrinter = flatPrint unLoc
- where unLoc (At _loc e) = e
|