{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
-- | This module implements a specialized s-expression parser
--
-- The parser in s-cargot is very general, but that also makes it a bit
-- inefficient.  This module implements a drop-in replacement parser for the one
-- in What4.Serialize.Parser using megaparsec.  It is completely specialized to
-- the types in this library.
module What4.Serialize.FastSExpr (
  parseSExpr
  ) where

import           Control.Applicative
import qualified Control.Monad.Fail as MF
import qualified Data.Parameterized.NatRepr as PN
import           Data.Parameterized.Some ( Some(..) )
import           Data.Ratio ( (%) )
import qualified Data.SCargot.Repr.WellFormed as SC
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified LibBF as BF
import           Numeric.Natural ( Natural )
import qualified Text.Megaparsec as TM
import qualified Text.Megaparsec.Char as TMC
import qualified Text.Megaparsec.Char.Lexer as TMCL
import qualified What4.BaseTypes as WT
import qualified What4.Serialize.SETokens as WST

-- | Parse 'T.Text' into the well-formed s-expression type from s-cargot.
parseSExpr :: T.Text -> Either String (SC.WellFormedSExpr WST.Atom)
parseSExpr :: Text -> Either [Char] (WellFormedSExpr Atom)
parseSExpr Text
t =
  case forall e s a.
Parsec e s a -> [Char] -> s -> Either (ParseErrorBundle s e) a
TM.runParser (Parser ()
ws forall (m :: Type -> Type) a b. Monad m => m a -> m b -> m b
>> ParsecT What4ParseError Text Identity (WellFormedSExpr Atom)
parse) [Char]
"<input>" Text
t of
    Left ParseErrorBundle Text What4ParseError
errBundle -> forall a b. a -> Either a b
Left (forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> [Char]
TM.errorBundlePretty ParseErrorBundle Text What4ParseError
errBundle)
    Right WellFormedSExpr Atom
a -> forall a b. b -> Either a b
Right WellFormedSExpr Atom
a

data What4ParseError = ErrorParsingHexFloat String
                     | InvalidExponentOrSignificandSize Natural Natural
  deriving (Int -> What4ParseError -> ShowS
[What4ParseError] -> ShowS
What4ParseError -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [What4ParseError] -> ShowS
$cshowList :: [What4ParseError] -> ShowS
show :: What4ParseError -> [Char]
$cshow :: What4ParseError -> [Char]
showsPrec :: Int -> What4ParseError -> ShowS
$cshowsPrec :: Int -> What4ParseError -> ShowS
Show, What4ParseError -> What4ParseError -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: What4ParseError -> What4ParseError -> Bool
$c/= :: What4ParseError -> What4ParseError -> Bool
== :: What4ParseError -> What4ParseError -> Bool
$c== :: What4ParseError -> What4ParseError -> Bool
Eq, Eq What4ParseError
What4ParseError -> What4ParseError -> Bool
What4ParseError -> What4ParseError -> Ordering
What4ParseError -> What4ParseError -> What4ParseError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: What4ParseError -> What4ParseError -> What4ParseError
$cmin :: What4ParseError -> What4ParseError -> What4ParseError
max :: What4ParseError -> What4ParseError -> What4ParseError
$cmax :: What4ParseError -> What4ParseError -> What4ParseError
>= :: What4ParseError -> What4ParseError -> Bool
$c>= :: What4ParseError -> What4ParseError -> Bool
> :: What4ParseError -> What4ParseError -> Bool
$c> :: What4ParseError -> What4ParseError -> Bool
<= :: What4ParseError -> What4ParseError -> Bool
$c<= :: What4ParseError -> What4ParseError -> Bool
< :: What4ParseError -> What4ParseError -> Bool
$c< :: What4ParseError -> What4ParseError -> Bool
compare :: What4ParseError -> What4ParseError -> Ordering
$ccompare :: What4ParseError -> What4ParseError -> Ordering
Ord)

instance TM.ShowErrorComponent What4ParseError where
  showErrorComponent :: What4ParseError -> [Char]
showErrorComponent What4ParseError
e =
    case What4ParseError
e of
      ErrorParsingHexFloat [Char]
hf -> [Char]
"Error parsing hex float literal: " forall a. [a] -> [a] -> [a]
++ [Char]
hf
      InvalidExponentOrSignificandSize Natural
ex Natural
s ->
        forall (t :: Type -> Type) a. Foldable t => t [a] -> [a]
concat [ [Char]
"Invalid exponent or significand size: exponent size = "
               , forall a. Show a => a -> [Char]
show Natural
ex
               , [Char]
", significand size = "
               , forall a. Show a => a -> [Char]
show Natural
s
               ]

type Parser a = TM.Parsec What4ParseError T.Text a

parse :: Parser (SC.WellFormedSExpr WST.Atom)
parse :: ParsecT What4ParseError Text Identity (WellFormedSExpr Atom)
parse = ParsecT What4ParseError Text Identity (WellFormedSExpr Atom)
parseList forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> (forall atom. atom -> WellFormedSExpr atom
SC.WFSAtom forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Parser a -> Parser a
lexeme Parser Atom
parseAtom)

parseList :: Parser (SC.WellFormedSExpr WST.Atom)
parseList :: ParsecT What4ParseError Text Identity (WellFormedSExpr Atom)
parseList = do
  Token Text
_ <- forall a. Parser a -> Parser a
lexeme (forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'(')
  [WellFormedSExpr Atom]
items <- forall (m :: Type -> Type) a. MonadPlus m => m a -> m [a]
TM.many ParsecT What4ParseError Text Identity (WellFormedSExpr Atom)
parse
  Token Text
_ <- forall a. Parser a -> Parser a
lexeme (forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
')')
  forall (m :: Type -> Type) a. Monad m => a -> m a
return (forall atom. [WellFormedSExpr atom] -> WellFormedSExpr atom
SC.WFSList [WellFormedSExpr Atom]
items)

parseId :: Parser T.Text
parseId :: Parser Text
parseId = [Char] -> Text
T.pack forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> ((:) forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT What4ParseError Text Identity (Token Text)
first forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall (m :: Type -> Type) a. MonadPlus m => m a -> m [a]
TM.many ParsecT What4ParseError Text Identity (Token Text)
rest)
  where
    w4symbol :: Char -> Bool
w4symbol Char
c =  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
'.'
    first :: ParsecT What4ParseError Text Identity (Token Text)
first = forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
TMC.letterChar forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
TM.satisfy Char -> Bool
w4symbol
    rest :: ParsecT What4ParseError Text Identity (Token Text)
rest = forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
TMC.alphaNumChar forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
TM.satisfy Char -> Bool
w4symbol

parseNat :: Parser Natural
parseNat :: Parser Natural
parseNat = do
  Tokens Text
_ <- forall e s (m :: Type -> Type).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
TMC.string Tokens Text
"#u"
  forall e s (m :: Type -> Type) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
TMCL.decimal

parseInt :: Parser Integer
parseInt :: Parser Integer
parseInt = forall e s (m :: Type -> Type) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
TMCL.decimal forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> (forall a. Num a => a -> a
negate forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'-' forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f b
*> forall e s (m :: Type -> Type) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
TMCL.decimal))

parseReal :: Parser Rational
parseReal :: Parser Rational
parseReal = do
  Tokens Text
_ <- forall e s (m :: Type -> Type).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
TMC.string Tokens Text
"#r"
  Integer
n <- forall e s (m :: Type -> Type) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
TMCL.decimal
  Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'/'
  Integer
d <- forall e s (m :: Type -> Type) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
TMCL.decimal
  forall (m :: Type -> Type) a. Monad m => a -> m a
return (Integer
n forall a. Integral a => a -> a -> Ratio a
% Integer
d)

parseBV :: Parser (Int, Integer)
parseBV :: Parser (Int, Integer)
parseBV = do
  Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'#'
  Char
t <- forall e s (m :: Type -> Type). MonadParsec e s m => m (Token s)
TM.anySingle
  case Char
t of
    Char
'b' -> Int -> Integer -> Parser (Int, Integer)
parseBin Int
0 Integer
0
    Char
'x' -> Parser (Int, Integer)
parseHex
    Char
_ -> forall (m :: Type -> Type) a. MonadFail m => [Char] -> m a
MF.fail ([Char]
"Invalid bitvector class: " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Char
t)
  where
    parseBin :: Int -> Integer -> Parser (Int, Integer)
    parseBin :: Int -> Integer -> Parser (Int, Integer)
parseBin !Int
nBits !Integer
value= do
      Maybe Char
mb <- forall (f :: Type -> Type) a. Alternative f => f a -> f (Maybe a)
TM.optional forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
TMC.binDigitChar
      case Maybe Char
mb of
        Maybe Char
Nothing -> forall (m :: Type -> Type) a. Monad m => a -> m a
return (Int
nBits, Integer
value)
        Just Char
bitChar -> Int -> Integer -> Parser (Int, Integer)
parseBin (Int
nBits forall a. Num a => a -> a -> a
+ Int
1) (Integer
value forall a. Num a => a -> a -> a
* Integer
2 forall a. Num a => a -> a -> a
+ if Char
bitChar forall a. Eq a => a -> a -> Bool
== Char
'1' then Integer
1 else Integer
0)
    parseHex :: Parser (Int, Integer)
    parseHex :: Parser (Int, Integer)
parseHex = do
      [Char]
digits <- forall (m :: Type -> Type) a. MonadPlus m => m a -> m [a]
TM.some forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
TMC.hexDigitChar
      forall (m :: Type -> Type) a. Monad m => a -> m a
return (forall (t :: Type -> Type) a. Foldable t => t a -> Int
length [Char]
digits forall a. Num a => a -> a -> a
* Int
4, forall a. Read a => [Char] -> a
read ([Char]
"0x" forall a. [a] -> [a] -> [a]
++ [Char]
digits))

parseBool :: Parser Bool
parseBool :: Parser Bool
parseBool = do
  Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'#'
  forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (forall e s (m :: Type -> Type).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
TMC.string Tokens Text
"true" forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f b
*> forall (m :: Type -> Type) a. Monad m => a -> m a
return Bool
True) forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> (forall e s (m :: Type -> Type).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
TMC.string Tokens Text
"false" forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f b
*> forall (m :: Type -> Type) a. Monad m => a -> m a
return Bool
False)

parseStrInfo :: Parser (Some WT.StringInfoRepr)
parseStrInfo :: Parser (Some StringInfoRepr)
parseStrInfo = forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (forall e s (m :: Type -> Type).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
TMC.string Tokens Text
"#char16" forall (m :: Type -> Type) a b. Monad m => m a -> m b -> m b
>> forall (m :: Type -> Type) a. Monad m => a -> m a
return (forall k (f :: k -> Type) (x :: k). f x -> Some f
Some StringInfoRepr 'Char16
WT.Char16Repr))
           forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (forall e s (m :: Type -> Type).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
TMC.string Tokens Text
"#char8" forall (m :: Type -> Type) a b. Monad m => m a -> m b -> m b
>> forall (m :: Type -> Type) a. Monad m => a -> m a
return (forall k (f :: k -> Type) (x :: k). f x -> Some f
Some StringInfoRepr 'Char8
WT.Char8Repr))
           forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall (m :: Type -> Type) a. Monad m => a -> m a
return (forall k (f :: k -> Type) (x :: k). f x -> Some f
Some StringInfoRepr 'Unicode
WT.UnicodeRepr)

parseStr :: Parser (Some WT.StringInfoRepr, T.Text)
parseStr :: Parser (Some StringInfoRepr, Text)
parseStr = do
  Some StringInfoRepr
prefix <- Parser (Some StringInfoRepr)
parseStrInfo
  Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'"'
  [Char]
str <- forall (t :: Type -> Type) a. Foldable t => t [a] -> [a]
concat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: Type -> Type) a. MonadPlus m => m a -> m [a]
TM.many (ParsecT What4ParseError Text Identity [Char]
parseEscaped forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall (m :: Type -> Type) a. MonadPlus m => m a -> m [a]
TM.some (forall (f :: Type -> Type) e s (m :: Type -> Type).
(Foldable f, MonadParsec e s m) =>
f (Token s) -> m (Token s)
TM.noneOf (Char
'"'forall a. a -> [a] -> [a]
:[Char]
"\\")))
  Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'"'
  forall (m :: Type -> Type) a. Monad m => a -> m a
return (Some StringInfoRepr
prefix, [Char] -> Text
T.pack [Char]
str)
  where
    parseEscaped :: ParsecT What4ParseError Text Identity [Char]
parseEscaped = do
      Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'\\'
      Char
c <- forall e s (m :: Type -> Type). MonadParsec e s m => m (Token s)
TM.anySingle
      forall (m :: Type -> Type) a. Monad m => a -> m a
return [Char
'\\', Char
c]

parseFloat :: Parser (Some WT.FloatPrecisionRepr, BF.BigFloat)
parseFloat :: Parser (Some FloatPrecisionRepr, BigFloat)
parseFloat = do
  Tokens Text
_ <- forall e s (m :: Type -> Type).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
TMC.string Tokens Text
"#f#"
  -- We printed the nat reprs out in decimal
  Natural
eb :: Natural
     <- forall e s (m :: Type -> Type) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
TMCL.decimal
  Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'#'
  Natural
sb :: Natural
     <- forall e s (m :: Type -> Type) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
TMCL.decimal
  Token Text
_ <- forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
TMC.char Char
'#'

  -- The float value itself is printed out as a hex literal
  [Token Text]
hexDigits <- forall (m :: Type -> Type) a. MonadPlus m => m a -> m [a]
TM.some forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
TMC.hexDigitChar

  Some NatRepr x
ebRepr <- forall (m :: Type -> Type) a. Monad m => a -> m a
return (Natural -> Some NatRepr
PN.mkNatRepr Natural
eb)
  Some NatRepr x
sbRepr <- forall (m :: Type -> Type) a. Monad m => a -> m a
return (Natural -> Some NatRepr
PN.mkNatRepr Natural
sb)
  case (forall (m :: Natural) (n :: Natural).
NatRepr m -> NatRepr n -> Maybe (LeqProof m n)
PN.testLeq (forall (n :: Natural). KnownNat n => NatRepr n
PN.knownNat @2) NatRepr x
ebRepr, forall (m :: Natural) (n :: Natural).
NatRepr m -> NatRepr n -> Maybe (LeqProof m n)
PN.testLeq (forall (n :: Natural). KnownNat n => NatRepr n
PN.knownNat @2) NatRepr x
sbRepr) of
    (Just LeqProof 2 x
PN.LeqProof, Just LeqProof 2 x
PN.LeqProof) -> do
      let rep :: FloatPrecisionRepr ('FloatingPointPrecision x x)
rep = forall (eb :: Natural) (sb :: Natural).
(2 <= eb, 2 <= sb) =>
NatRepr eb
-> NatRepr sb -> FloatPrecisionRepr ('FloatingPointPrecision eb sb)
WT.FloatingPointPrecisionRepr NatRepr x
ebRepr NatRepr x
sbRepr

      -- We know our format: it is determined by the exponent bits (eb) and the
      -- significand bits (sb) parsed above
      let fmt :: BFOpts
fmt = Word -> BFOpts
BF.precBits (forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
sb) forall a. Semigroup a => a -> a -> a
<> Int -> BFOpts
BF.expBits (forall a b. (Integral a, Num b) => a -> b
fromIntegral Natural
eb)
      let (BigFloat
bf, Status
status) = Int -> BFOpts -> [Char] -> (BigFloat, Status)
BF.bfFromString Int
16 BFOpts
fmt [Token Text]
hexDigits
      case Status
status of
        Status
BF.Ok -> forall (m :: Type -> Type) a. Monad m => a -> m a
return (forall k (f :: k -> Type) (x :: k). f x -> Some f
Some FloatPrecisionRepr ('FloatingPointPrecision x x)
rep, BigFloat
bf)
        Status
_ -> forall e s (m :: Type -> Type) a.
MonadParsec e s m =>
Set (ErrorFancy e) -> m a
TM.fancyFailure (forall a. a -> Set a
Set.singleton (forall e. e -> ErrorFancy e
TM.ErrorCustom ([Char] -> What4ParseError
ErrorParsingHexFloat [Token Text]
hexDigits)))
    (Maybe (LeqProof 2 x), Maybe (LeqProof 2 x))
_ -> forall e s (m :: Type -> Type) a.
MonadParsec e s m =>
Set (ErrorFancy e) -> m a
TM.fancyFailure (forall a. a -> Set a
Set.singleton (forall e. e -> ErrorFancy e
TM.ErrorCustom (Natural -> Natural -> What4ParseError
InvalidExponentOrSignificandSize Natural
eb Natural
sb)))


parseAtom :: Parser WST.Atom
parseAtom :: Parser Atom
parseAtom = forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> Integer -> Atom
WST.ABV forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Int, Integer)
parseBV)
        forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (Bool -> Atom
WST.ABool forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
parseBool)
        forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (Integer -> Atom
WST.AInt forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Integer
parseInt)
        forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (Text -> Atom
WST.AId forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
parseId)
        forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (Natural -> Atom
WST.ANat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Natural
parseNat)
        forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (Rational -> Atom
WST.AReal forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Rational
parseReal)
        forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Some StringInfoRepr -> Text -> Atom
WST.AStr forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Some StringInfoRepr, Text)
parseStr)
        forall (f :: Type -> Type) a. Alternative f => f a -> f a -> f a
<|> forall e s (m :: Type -> Type) a. MonadParsec e s m => m a -> m a
TM.try (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Some FloatPrecisionRepr -> BigFloat -> Atom
WST.AFloat forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Some FloatPrecisionRepr, BigFloat)
parseFloat)

ws :: Parser ()
ws :: Parser ()
ws = forall e s (m :: Type -> Type).
MonadParsec e s m =>
m () -> m () -> m () -> m ()
TMCL.space forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
m ()
TMC.space1 (forall e s (m :: Type -> Type).
(MonadParsec e s m, Token s ~ Char) =>
Tokens s -> m ()
TMCL.skipLineComment ([Char] -> Text
T.pack [Char]
";")) forall (f :: Type -> Type) a. Alternative f => f a
empty

lexeme :: Parser a -> Parser a
lexeme :: forall a. Parser a -> Parser a
lexeme = forall e s (m :: Type -> Type) a.
MonadParsec e s m =>
m () -> m a -> m a
TMCL.lexeme Parser ()
ws