{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}

{-# OPTIONS_GHC -fno-warn-name-shadowing #-}

-- | Main module for parsing Nix expressions.
module Nix.Parser
  ( parseNixFile
  , parseNixFileLoc
  , parseNixText
  , parseNixTextLoc
  , parseFromFileEx
  , Parser
  , parseFromText
  , Result
  , reservedNames
  , OperatorInfo(..)
  , NSpecialOp(..)
  , NAssoc(..)
  , NOperatorDef
  , getUnaryOperator
  , getBinaryOperator
  , getSpecialOperator
  , nixToplevelForm
  , nixExpr
  , nixSet
  , nixBinders
  , nixSelector
  , nixSym
  , nixPath
  , nixString
  , nixUri
  , nixSearchPath
  , nixFloat
  , nixInt
  , nixBool
  , nixNull
  , symbol
  , whiteSpace
  )
where

import           Prelude                 hiding ( some
                                                , many
                                                , readFile
                                                )
import           Data.Foldable                  ( foldr1 )

import           Control.Monad                  ( msum )
import           Control.Monad.Combinators.Expr ( makeExprParser
                                                , Operator( Postfix
                                                          , InfixN
                                                          , InfixR
                                                          , Prefix
                                                          , InfixL
                                                          )
                                                )
import           Data.Char                      ( isAlpha
                                                , isDigit
                                                , isSpace
                                                )
import           Data.Data                      ( Data(..) )
import           Data.Fix                       ( Fix(..) )
import qualified Data.HashSet                  as HashSet
import qualified Data.Map                      as Map
import           Data.Text                      ( cons
                                                , singleton
                                                )
import           Nix.Expr                hiding ( ($>) )
import           Nix.Expr.Strings               ( escapeCodes
                                                , stripIndent
                                                , mergePlain
                                                , removePlainEmpty
                                                )
import           Nix.Render                     ( MonadFile(readFile) )
import           Prettyprinter                  ( Doc
                                                , pretty
                                                )
-- `parser-combinators` ships performance enhanced & MonadPlus-aware combinators.
-- For example `smome` and `many` impoted here.
import           Text.Megaparsec         hiding ( State )
import           Text.Megaparsec.Char           ( space1
                                                , string
                                                , letterChar
                                                , char
                                                )
import qualified Text.Megaparsec.Char.Lexer    as Lexer

-- | Different to @isAlphaNum@
isAlphanumeric :: Char -> Bool
isAlphanumeric :: Char -> Bool
isAlphanumeric Char
x = Char -> Bool
isAlpha Char
x Bool -> Bool -> Bool
|| Char -> Bool
isDigit Char
x
{-# inline isAlphanumeric #-}

infixl 3 <+>
(<+>) :: MonadPlus m => m a -> m a -> m a
<+> :: m a -> m a -> m a
(<+>) = m a -> m a -> m a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus

---------------------------------------------------------------------------------

nixExpr :: Parser NExprLoc
nixExpr :: Parser NExprLoc
nixExpr =
  Parser NExprLoc
-> [[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
-> Parser NExprLoc
forall (m :: * -> *) a.
MonadPlus m =>
m a -> [[Operator m a]] -> m a
makeExprParser
    Parser NExprLoc
nixTerm ([[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
 -> Parser NExprLoc)
-> [[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
-> Parser NExprLoc
forall a b. (a -> b) -> a -> b
$
      (NOperatorDef,
 Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a, b) -> b
snd ((NOperatorDef,
  Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
-> [[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
forall (f :: * -> *) (g :: * -> *) a b.
(Functor f, Functor g) =>
(a -> b) -> f (g a) -> f (g b)
<<$>>
        Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
nixOperators Parser (Ann SrcSpan (NAttrPath NExprLoc))
nixSelector

antiStart :: Parser Text
antiStart :: Parser Text
antiStart = Text -> Parser Text
symbol Text
"${" Parser Text -> String -> Parser Text
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"${"

nixAntiquoted :: Parser a -> Parser (Antiquoted a NExprLoc)
nixAntiquoted :: Parser a -> Parser (Antiquoted a NExprLoc)
nixAntiquoted Parser a
p =
  NExprLoc -> Antiquoted a NExprLoc
forall v r. r -> Antiquoted v r
Antiquoted (NExprLoc -> Antiquoted a NExprLoc)
-> Parser NExprLoc -> Parser (Antiquoted a NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Parser Text
antiStart Parser Text -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm Parser NExprLoc -> Parser Text -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> Parser Text
symbol Text
"}")
      Parser (Antiquoted a NExprLoc)
-> Parser (Antiquoted a NExprLoc) -> Parser (Antiquoted a NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> a -> Antiquoted a NExprLoc
forall v r. v -> Antiquoted v r
Plain (a -> Antiquoted a NExprLoc)
-> Parser a -> Parser (Antiquoted a NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        Parser a
p
      Parser (Antiquoted a NExprLoc)
-> String -> Parser (Antiquoted a NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"anti-quotation"

selDot :: Parser ()
selDot :: Parser ()
selDot = Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Text -> Parser Text
symbol Text
"." Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy Parser NExprLoc
nixPath) Parser () -> String -> Parser ()
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"."

nixSelect :: Parser NExprLoc -> Parser NExprLoc
nixSelect :: Parser NExprLoc -> Parser NExprLoc
nixSelect Parser NExprLoc
term =
  do
    NExprLoc
res <-
      (NExprLoc
 -> Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
 -> NExprLoc)
-> Parser NExprLoc
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc))
-> Parser NExprLoc
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 NExprLoc
-> Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
-> NExprLoc
build
        Parser NExprLoc
term
        (ParsecT
  Void
  Text
  (State SourcePos)
  (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT
   Void
   Text
   (State SourcePos)
   (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
 -> ParsecT
      Void
      Text
      (State SourcePos)
      (Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)))
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc))
forall a b. (a -> b) -> a -> b
$
          (Ann SrcSpan (NAttrPath NExprLoc)
 -> Maybe NExprLoc
 -> (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc))
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,)
            (Parser ()
selDot Parser ()
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser (Ann SrcSpan (NAttrPath NExprLoc))
nixSelector)
            (Parser NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser NExprLoc
 -> ParsecT Void Text (State SourcePos) (Maybe NExprLoc))
-> Parser NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall a b. (a -> b) -> a -> b
$ Text -> Parser ()
reserved Text
"or" Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixTerm)
        )
    Maybe ()
continues <- Parser () -> ParsecT Void Text (State SourcePos) (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser () -> ParsecT Void Text (State SourcePos) (Maybe ()))
-> Parser () -> ParsecT Void Text (State SourcePos) (Maybe ())
forall a b. (a -> b) -> a -> b
$ Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead Parser ()
selDot

    (Parser NExprLoc -> Parser NExprLoc)
-> (() -> Parser NExprLoc -> Parser NExprLoc)
-> Maybe ()
-> Parser NExprLoc
-> Parser NExprLoc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      Parser NExprLoc -> Parser NExprLoc
forall a. a -> a
id
      ((Parser NExprLoc -> Parser NExprLoc)
-> () -> Parser NExprLoc -> Parser NExprLoc
forall a b. a -> b -> a
const Parser NExprLoc -> Parser NExprLoc
nixSelect)
      Maybe ()
continues
      (NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a. Applicative f => a -> f a
pure NExprLoc
res)
 where
  build
    :: NExprLoc
    -> Maybe ( Ann SrcSpan (NAttrPath NExprLoc)
        , Maybe NExprLoc
        )
    -> NExprLoc
  build :: NExprLoc
-> Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
-> NExprLoc
build NExprLoc
t Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
mexpr =
    (NExprLoc -> NExprLoc)
-> ((Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
    -> NExprLoc -> NExprLoc)
-> Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
-> NExprLoc
-> NExprLoc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      NExprLoc -> NExprLoc
forall a. a -> a
id
      (\ (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
expr NExprLoc
t -> ((Ann SrcSpan (NAttrPath NExprLoc) -> Maybe NExprLoc -> NExprLoc)
-> (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc) -> NExprLoc
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry ((Ann SrcSpan (NAttrPath NExprLoc) -> Maybe NExprLoc -> NExprLoc)
 -> (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc) -> NExprLoc)
-> (Ann SrcSpan (NAttrPath NExprLoc) -> Maybe NExprLoc -> NExprLoc)
-> (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
-> NExprLoc
forall a b. (a -> b) -> a -> b
$ NExprLoc
-> Ann SrcSpan (NAttrPath NExprLoc) -> Maybe NExprLoc -> NExprLoc
nSelectLoc NExprLoc
t) (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
expr)
      Maybe (Ann SrcSpan (NAttrPath NExprLoc), Maybe NExprLoc)
mexpr
      NExprLoc
t

nixSelector :: Parser (Ann SrcSpan (NAttrPath NExprLoc))
nixSelector :: Parser (Ann SrcSpan (NAttrPath NExprLoc))
nixSelector =
  Parser (NAttrPath NExprLoc)
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
forall a. Parser a -> Parser (Ann SrcSpan a)
annotateLocation (Parser (NAttrPath NExprLoc)
 -> Parser (Ann SrcSpan (NAttrPath NExprLoc)))
-> Parser (NAttrPath NExprLoc)
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
forall a b. (a -> b) -> a -> b
$
    do
      (NKeyName NExprLoc
x : [NKeyName NExprLoc]
xs) <- Parser (NKeyName NExprLoc)
keyName Parser (NKeyName NExprLoc)
-> Parser ()
-> ParsecT Void Text (State SourcePos) [NKeyName NExprLoc]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`sepBy1` Parser ()
selDot
      NAttrPath NExprLoc -> Parser (NAttrPath NExprLoc)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NAttrPath NExprLoc -> Parser (NAttrPath NExprLoc))
-> NAttrPath NExprLoc -> Parser (NAttrPath NExprLoc)
forall a b. (a -> b) -> a -> b
$ NKeyName NExprLoc
x NKeyName NExprLoc -> [NKeyName NExprLoc] -> NAttrPath NExprLoc
forall a. a -> [a] -> NonEmpty a
:| [NKeyName NExprLoc]
xs

nixTerm :: Parser NExprLoc
nixTerm :: Parser NExprLoc
nixTerm = do
  Char
c <- ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT Void Text (State SourcePos) Char
 -> ParsecT Void Text (State SourcePos) Char)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (ParsecT Void Text (State SourcePos) Char
 -> ParsecT Void Text (State SourcePos) Char)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall a b. (a -> b) -> a -> b
$ (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy ((Token Text -> Bool)
 -> ParsecT Void Text (State SourcePos) (Token Text))
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall a b. (a -> b) -> a -> b
$ \Token Text
x ->
    Char -> Bool
pathChar Char
Token Text
x Bool -> Bool -> Bool
|| (Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` (String
"({[</\"'^" :: String)) Char
Token Text
x
  case Char
c of
    Char
'('  -> Parser NExprLoc -> Parser NExprLoc
nixSelect Parser NExprLoc
nixParens
    Char
'{'  -> Parser NExprLoc -> Parser NExprLoc
nixSelect Parser NExprLoc
nixSet
    Char
'['  -> Parser NExprLoc
nixList
    Char
'<'  -> Parser NExprLoc
nixSearchPath
    Char
'/'  -> Parser NExprLoc
nixPath
    Char
'"'  -> Parser NExprLoc
nixString
    Char
'\'' -> Parser NExprLoc
nixString
    Char
'^'  -> Parser NExprLoc
nixSynHole
    Char
_ ->
      [Parser NExprLoc] -> Parser NExprLoc
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
        ([Parser NExprLoc] -> Parser NExprLoc)
-> [Parser NExprLoc] -> Parser NExprLoc
forall a b. (a -> b) -> a -> b
$  [ Parser NExprLoc -> Parser NExprLoc
nixSelect Parser NExprLoc
nixSet | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'r' ]
        [Parser NExprLoc] -> [Parser NExprLoc] -> [Parser NExprLoc]
forall a. Semigroup a => a -> a -> a
<> [ Parser NExprLoc
nixPath | Char -> Bool
pathChar Char
c ]
        [Parser NExprLoc] -> [Parser NExprLoc] -> [Parser NExprLoc]
forall a. Semigroup a => a -> a -> a
<> if Char -> Bool
isDigit Char
c
             then [ Parser NExprLoc
nixFloat, Parser NExprLoc
nixInt ]
             else
               [ Parser NExprLoc
nixUri | Char -> Bool
isAlpha Char
c ]
               [Parser NExprLoc] -> [Parser NExprLoc] -> [Parser NExprLoc]
forall a. Semigroup a => a -> a -> a
<> [ Parser NExprLoc
nixBool | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
't' Bool -> Bool -> Bool
|| Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'f' ]
               [Parser NExprLoc] -> [Parser NExprLoc] -> [Parser NExprLoc]
forall a. Semigroup a => a -> a -> a
<> [ Parser NExprLoc
nixNull | Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'n' ]
               [Parser NExprLoc] -> [Parser NExprLoc] -> [Parser NExprLoc]
forall a. Semigroup a => a -> a -> a
<> [ Parser NExprLoc -> Parser NExprLoc
nixSelect Parser NExprLoc
nixSym ]

nixToplevelForm :: Parser NExprLoc
nixToplevelForm :: Parser NExprLoc
nixToplevelForm = Parser NExprLoc
keywords Parser NExprLoc -> Parser NExprLoc -> Parser NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser NExprLoc
nixLambda Parser NExprLoc -> Parser NExprLoc -> Parser NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser NExprLoc
nixExpr
 where
  keywords :: Parser NExprLoc
keywords = Parser NExprLoc
nixLet Parser NExprLoc -> Parser NExprLoc -> Parser NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser NExprLoc
nixIf Parser NExprLoc -> Parser NExprLoc -> Parser NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser NExprLoc
nixAssert Parser NExprLoc -> Parser NExprLoc -> Parser NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser NExprLoc
nixWith

nixSym :: Parser NExprLoc
nixSym :: Parser NExprLoc
nixSym = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser NExprLoc)
-> Parser (NExprF NExprLoc) -> Parser NExprLoc
forall a b. (a -> b) -> a -> b
$ Text -> NExprF NExprLoc
forall a. Text -> NExprF a
mkSymF (Text -> NExprF NExprLoc)
-> Parser Text -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
identifier

nixSynHole :: Parser NExprLoc
nixSynHole :: Parser NExprLoc
nixSynHole = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser NExprLoc)
-> Parser (NExprF NExprLoc) -> Parser NExprLoc
forall a b. (a -> b) -> a -> b
$ Text -> NExprF NExprLoc
forall a. Text -> NExprF a
mkSynHoleF (Text -> NExprF NExprLoc)
-> Parser Text -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'^' ParsecT Void Text (State SourcePos) Char
-> Parser Text -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text
identifier)

nixInt :: Parser NExprLoc
nixInt :: Parser NExprLoc
nixInt = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Integer -> NExprF NExprLoc
forall a. Integer -> NExprF a
mkIntF (Integer -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) Integer
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text (State SourcePos) Integer
integer Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"integer")

nixFloat :: Parser NExprLoc
nixFloat :: Parser NExprLoc
nixFloat =
  Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Float -> NExprF NExprLoc
forall a. Float -> NExprF a
mkFloatF (Float -> NExprF NExprLoc)
-> (Double -> Float) -> Double -> NExprF NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Float
forall a b. (Real a, Fractional b) => a -> b
realToFrac (Double -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) Double
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text (State SourcePos) Double
float) Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"float")

nixBool :: Parser NExprLoc
nixBool :: Parser NExprLoc
nixBool =
  Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Text -> Bool -> Parser (NExprF NExprLoc)
forall a.
Text -> Bool -> ParsecT Void Text (State SourcePos) (NExprF a)
bool Text
"true" Bool
True Parser (NExprF NExprLoc)
-> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Text -> Bool -> Parser (NExprF NExprLoc)
forall a.
Text -> Bool -> ParsecT Void Text (State SourcePos) (NExprF a)
bool Text
"false" Bool
False) Parser NExprLoc -> String -> Parser NExprLoc
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"bool"
 where
  bool :: Text -> Bool -> ParsecT Void Text (State SourcePos) (NExprF a)
bool Text
str Bool
b = Bool -> NExprF a
forall a. Bool -> NExprF a
mkBoolF Bool
b NExprF a
-> Parser () -> ParsecT Void Text (State SourcePos) (NExprF a)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser ()
reserved Text
str

nixNull :: Parser NExprLoc
nixNull :: Parser NExprLoc
nixNull = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (NExprF NExprLoc
forall a. NExprF a
mkNullF NExprF NExprLoc -> Parser () -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser ()
reserved Text
"null" Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"null")

-- | 'nixTopLevelForm' returns an expression annotated with a source position,
-- however this position doesn't include the parsed parentheses, so remove the
-- "inner" location annotateion and annotate again, including the parentheses.
nixParens :: Parser NExprLoc
nixParens :: Parser NExprLoc
nixParens = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall f. Parser (NExprF f) -> Parser (NExprF f)
parens (AnnF SrcSpan NExprF NExprLoc -> NExprF NExprLoc
forall ann (f :: * -> *) r. AnnF ann f r -> f r
stripAnn (AnnF SrcSpan NExprF NExprLoc -> NExprF NExprLoc)
-> (NExprLoc -> AnnF SrcSpan NExprF NExprLoc)
-> NExprLoc
-> NExprF NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NExprLoc -> AnnF SrcSpan NExprF NExprLoc
forall (f :: * -> *). Fix f -> f (Fix f)
unFix (NExprLoc -> NExprF NExprLoc)
-> Parser NExprLoc -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NExprLoc
nixToplevelForm) Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"parens")

nixList :: Parser NExprLoc
nixList :: Parser NExprLoc
nixList = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall f. Parser (NExprF f) -> Parser (NExprF f)
brackets ([NExprLoc] -> NExprF NExprLoc
forall r. [r] -> NExprF r
NList ([NExprLoc] -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) [NExprLoc]
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NExprLoc -> ParsecT Void Text (State SourcePos) [NExprLoc]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many Parser NExprLoc
nixTerm) Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"list")

pathChar :: Char -> Bool
pathChar :: Char -> Bool
pathChar Char
x =
  Char -> Bool
isAlphanumeric Char
x Bool -> Bool -> Bool
|| (Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` (String
"._-+~" :: String)) Char
x

slash :: Parser Char
slash :: ParsecT Void Text (State SourcePos) Char
slash =
  ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try
    (  Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'/'
    ParsecT Void Text (State SourcePos) Char
-> Parser () -> ParsecT Void Text (State SourcePos) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Void Text (State SourcePos) Char -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy ((Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy (\Token Text
x -> Char
Token Text
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'/' Bool -> Bool -> Bool
|| Char
Token Text
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'*' Bool -> Bool -> Bool
|| Char -> Bool
isSpace Char
Token Text
x))
    )
    ParsecT Void Text (State SourcePos) Char
-> String -> ParsecT Void Text (State SourcePos) Char
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"slash"

-- | A path surrounded by angle brackets, indicating that it should be
-- looked up in the NIX_PATH environment variable at evaluation.
nixSearchPath :: Parser NExprLoc
nixSearchPath :: Parser NExprLoc
nixSearchPath =
  Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1
    (Bool -> String -> NExprF NExprLoc
forall a. Bool -> String -> NExprF a
mkPathF Bool
True (String -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) String
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'<' ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many ((Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy Char -> Bool
Token Text -> Bool
pathChar ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> ParsecT Void Text (State SourcePos) Char
slash) ParsecT Void Text (State SourcePos) String
-> Parser Text -> ParsecT Void Text (State SourcePos) String
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> Parser Text
symbol Text
">")
      Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"spath"
    )

pathStr :: Parser FilePath
pathStr :: ParsecT Void Text (State SourcePos) String
pathStr =
  ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
forall a. Parser a -> Parser a
lexeme (ParsecT Void Text (State SourcePos) String
 -> ParsecT Void Text (State SourcePos) String)
-> ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
forall a b. (a -> b) -> a -> b
$
    (String -> String -> String)
-> ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 String -> String -> String
forall a. Semigroup a => a -> a -> a
(<>)
      (ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many (ParsecT Void Text (State SourcePos) Char
 -> ParsecT Void Text (State SourcePos) String)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall a b. (a -> b) -> a -> b
$ (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy Char -> Bool
Token Text -> Bool
pathChar)
      ([String] -> String
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([String] -> String)
-> ParsecT Void Text (State SourcePos) [String]
-> ParsecT Void Text (State SourcePos) String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) [String]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some
          ((Char -> String -> String)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (:)
            ParsecT Void Text (State SourcePos) Char
slash
            (ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some (ParsecT Void Text (State SourcePos) Char
 -> ParsecT Void Text (State SourcePos) String)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall a b. (a -> b) -> a -> b
$ (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy Char -> Bool
Token Text -> Bool
pathChar)
          )
      )

nixPath :: Parser NExprLoc
nixPath :: Parser NExprLoc
nixPath = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Bool -> String -> NExprF NExprLoc
forall a. Bool -> String -> NExprF a
mkPathF Bool
False (String -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) String
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text (State SourcePos) String
pathStr) Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"path")

nixLet :: Parser NExprLoc
nixLet :: Parser NExprLoc
nixLet = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1
  (Text -> Parser ()
reserved Text
"let" Parser () -> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> (Parser (NExprF NExprLoc)
letBody Parser (NExprF NExprLoc)
-> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser (NExprF NExprLoc)
letBinders) Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"let block")
 where
  letBinders :: Parser (NExprF NExprLoc)
letBinders =
    ([Binding NExprLoc] -> NExprLoc -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
-> Parser NExprLoc
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 [Binding NExprLoc] -> NExprLoc -> NExprF NExprLoc
forall r. [Binding r] -> r -> NExprF r
NLet
      ParsecT Void Text (State SourcePos) [Binding NExprLoc]
nixBinders
      (Text -> Parser ()
reserved Text
"in" Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
  -- Let expressions `let {..., body = ...}' are just desugared
  -- into `(rec {..., body = ...}).body'.
  letBody :: Parser (NExprF NExprLoc)
letBody    = (\NExprLoc
x -> NExprLoc -> NAttrPath NExprLoc -> Maybe NExprLoc -> NExprF NExprLoc
forall r. r -> NAttrPath r -> Maybe r -> NExprF r
NSelect NExprLoc
x (Text -> NKeyName NExprLoc
forall r. Text -> NKeyName r
StaticKey Text
"body" NKeyName NExprLoc -> [NKeyName NExprLoc] -> NAttrPath NExprLoc
forall a. a -> [a] -> NonEmpty a
:| [NKeyName NExprLoc]
forall a. Monoid a => a
mempty) Maybe NExprLoc
forall a. Maybe a
Nothing) (NExprLoc -> NExprF NExprLoc)
-> Parser NExprLoc -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser NExprLoc
aset
  aset :: Parser NExprLoc
aset       = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser NExprLoc)
-> Parser (NExprF NExprLoc) -> Parser NExprLoc
forall a b. (a -> b) -> a -> b
$ NRecordType -> [Binding NExprLoc] -> NExprF NExprLoc
forall r. NRecordType -> [Binding r] -> NExprF r
NSet NRecordType
NRecursive ([Binding NExprLoc] -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
-> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
forall a. Parser a -> Parser a
braces ParsecT Void Text (State SourcePos) [Binding NExprLoc]
nixBinders

nixIf :: Parser NExprLoc
nixIf :: Parser NExprLoc
nixIf = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1
  ((NExprLoc -> NExprLoc -> NExprLoc -> NExprF NExprLoc)
-> Parser NExprLoc
-> Parser NExprLoc
-> Parser NExprLoc
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 NExprLoc -> NExprLoc -> NExprLoc -> NExprF NExprLoc
forall r. r -> r -> r -> NExprF r
NIf
    (Text -> Parser ()
reserved Text
"if"   Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixExpr        )
    (Text -> Parser ()
reserved Text
"then" Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
    (Text -> Parser ()
reserved Text
"else" Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
  Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"if"
  )

nixAssert :: Parser NExprLoc
nixAssert :: Parser NExprLoc
nixAssert = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1
  ((NExprLoc -> NExprLoc -> NExprF NExprLoc)
-> Parser NExprLoc -> Parser NExprLoc -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 NExprLoc -> NExprLoc -> NExprF NExprLoc
forall r. r -> r -> NExprF r
NAssert
    (Text -> Parser ()
reserved Text
"assert" Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
    (Parser Text
semi              Parser Text -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
  Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"assert"
  )

nixWith :: Parser NExprLoc
nixWith :: Parser NExprLoc
nixWith = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1
  ((NExprLoc -> NExprLoc -> NExprF NExprLoc)
-> Parser NExprLoc -> Parser NExprLoc -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 NExprLoc -> NExprLoc -> NExprF NExprLoc
forall r. r -> r -> NExprF r
NWith
    (Text -> Parser ()
reserved Text
"with" Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
    (Parser Text
semi            Parser Text -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
  Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"with"
  )

nixLambda :: Parser NExprLoc
nixLambda :: Parser NExprLoc
nixLambda =
  (Ann SrcSpan (Params NExprLoc) -> NExprLoc -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (Ann SrcSpan (Params NExprLoc))
-> Parser NExprLoc
-> Parser NExprLoc
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Ann SrcSpan (Params NExprLoc) -> NExprLoc -> NExprLoc
nAbs
    (Parser (Params NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (Ann SrcSpan (Params NExprLoc))
forall a. Parser a -> Parser (Ann SrcSpan a)
annotateLocation (Parser (Params NExprLoc)
 -> ParsecT
      Void Text (State SourcePos) (Ann SrcSpan (Params NExprLoc)))
-> Parser (Params NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (Ann SrcSpan (Params NExprLoc))
forall a b. (a -> b) -> a -> b
$ Parser (Params NExprLoc) -> Parser (Params NExprLoc)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try Parser (Params NExprLoc)
argExpr)
    Parser NExprLoc
nixToplevelForm

nixString :: Parser NExprLoc
nixString :: Parser NExprLoc
nixString = Ann SrcSpan (NString NExprLoc) -> NExprLoc
nStr (Ann SrcSpan (NString NExprLoc) -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (Ann SrcSpan (NString NExprLoc))
-> Parser NExprLoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (NString NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (Ann SrcSpan (NString NExprLoc))
forall a. Parser a -> Parser (Ann SrcSpan a)
annotateLocation Parser (NString NExprLoc)
nixString'

nixUri :: Parser NExprLoc
nixUri :: Parser NExprLoc
nixUri = Parser NExprLoc -> Parser NExprLoc
forall a. Parser a -> Parser a
lexeme (Parser NExprLoc -> Parser NExprLoc)
-> Parser NExprLoc -> Parser NExprLoc
forall a b. (a -> b) -> a -> b
$ Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 (Parser (NExprF NExprLoc) -> Parser NExprLoc)
-> Parser (NExprF NExprLoc) -> Parser NExprLoc
forall a b. (a -> b) -> a -> b
$ Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc))
-> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a b. (a -> b) -> a -> b
$ do
  Char
start    <- ParsecT Void Text (State SourcePos) Char
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
letterChar
  String
protocol <- ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many (ParsecT Void Text (State SourcePos) Char
 -> ParsecT Void Text (State SourcePos) String)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall a b. (a -> b) -> a -> b
$
    (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy ((Token Text -> Bool)
 -> ParsecT Void Text (State SourcePos) (Token Text))
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall a b. (a -> b) -> a -> b
$
      \ Token Text
x ->
        Char -> Bool
isAlphanumeric Char
Token Text
x
        Bool -> Bool -> Bool
|| (Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` (String
"+-." :: String)) Char
Token Text
x
  Text
_       <- Tokens Text -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
":"
  String
address <-
    ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some (ParsecT Void Text (State SourcePos) Char
 -> ParsecT Void Text (State SourcePos) String)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall a b. (a -> b) -> a -> b
$
      (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy ((Token Text -> Bool)
 -> ParsecT Void Text (State SourcePos) (Token Text))
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall a b. (a -> b) -> a -> b
$
        \ Token Text
x ->
          Char -> Bool
isAlphanumeric Char
Token Text
x
          Bool -> Bool -> Bool
|| (Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` (String
"%/?:@&=+$,-_.!~*'" :: String)) Char
Token Text
x
  pure $ NString NExprLoc -> NExprF NExprLoc
forall r. NString r -> NExprF r
NStr (NString NExprLoc -> NExprF NExprLoc)
-> NString NExprLoc -> NExprF NExprLoc
forall a b. (a -> b) -> a -> b
$ [Antiquoted Text NExprLoc] -> NString NExprLoc
forall r. [Antiquoted Text r] -> NString r
DoubleQuoted
    [Text -> Antiquoted Text NExprLoc
forall v r. v -> Antiquoted v r
Plain (Text -> Antiquoted Text NExprLoc)
-> Text -> Antiquoted Text NExprLoc
forall a b. (a -> b) -> a -> b
$ String -> Text
forall a. ToText a => a -> Text
toText (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Char
start Char -> String -> String
forall a. a -> [a] -> [a]
: String
protocol String -> String -> String
forall a. [a] -> [a] -> [a]
++ Char
':' Char -> String -> String
forall a. a -> [a] -> [a]
: String
address]

nixString' :: Parser (NString NExprLoc)
nixString' :: Parser (NString NExprLoc)
nixString' = Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a. Parser a -> Parser a
lexeme (Parser (NString NExprLoc)
doubleQuoted Parser (NString NExprLoc)
-> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser (NString NExprLoc)
indented Parser (NString NExprLoc) -> String -> Parser (NString NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"string")
 where
  doubleQuoted :: Parser (NString NExprLoc)
  doubleQuoted :: Parser (NString NExprLoc)
doubleQuoted =
    [Antiquoted Text NExprLoc] -> NString NExprLoc
forall r. [Antiquoted Text r] -> NString r
DoubleQuoted
    ([Antiquoted Text NExprLoc] -> NString NExprLoc)
-> ([Antiquoted Text NExprLoc] -> [Antiquoted Text NExprLoc])
-> [Antiquoted Text NExprLoc]
-> NString NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Antiquoted Text NExprLoc] -> [Antiquoted Text NExprLoc]
forall r. [Antiquoted Text r] -> [Antiquoted Text r]
removePlainEmpty
    ([Antiquoted Text NExprLoc] -> [Antiquoted Text NExprLoc])
-> ([Antiquoted Text NExprLoc] -> [Antiquoted Text NExprLoc])
-> [Antiquoted Text NExprLoc]
-> [Antiquoted Text NExprLoc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Antiquoted Text NExprLoc] -> [Antiquoted Text NExprLoc]
forall r. [Antiquoted Text r] -> [Antiquoted Text r]
mergePlain ([Antiquoted Text NExprLoc] -> NString NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> Parser (NString NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      ( Parser ()
doubleQ
      Parser ()
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many (Parser ()
-> Parser ()
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
stringChar Parser ()
doubleQ (ParsecT Void Text (State SourcePos) Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Void Text (State SourcePos) Char -> Parser ())
-> ParsecT Void Text (State SourcePos) Char -> Parser ()
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'\\') ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall r. ParsecT Void Text (State SourcePos) (Antiquoted Text r)
doubleEscape)
      ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> Parser ()
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
doubleQ
      )
      Parser (NString NExprLoc) -> String -> Parser (NString NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"double quoted string"

  doubleQ :: Parser ()
doubleQ      = ParsecT Void Text (State SourcePos) Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Void Text (State SourcePos) Char -> Parser ())
-> ParsecT Void Text (State SourcePos) Char -> Parser ()
forall a b. (a -> b) -> a -> b
$ Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'"'
  doubleEscape :: ParsecT Void Text (State SourcePos) (Antiquoted Text r)
doubleEscape = Text -> Antiquoted Text r
forall v r. v -> Antiquoted v r
Plain (Text -> Antiquoted Text r)
-> (Char -> Text) -> Char -> Antiquoted Text r
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
singleton (Char -> Antiquoted Text r)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'\\' ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) Char
escapeCode)

  indented :: Parser (NString NExprLoc)
  indented :: Parser (NString NExprLoc)
indented =
    [Antiquoted Text NExprLoc] -> NString NExprLoc
forall r. [Antiquoted Text r] -> NString r
stripIndent ([Antiquoted Text NExprLoc] -> NString NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> Parser (NString NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      (Parser ()
indentedQ
      Parser ()
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many (Parser ()
-> Parser ()
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
stringChar Parser ()
indentedQ Parser ()
indentedQ ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall r. ParsecT Void Text (State SourcePos) (Antiquoted Text r)
indentedEscape)
      ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> Parser ()
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
indentedQ
      )
      Parser (NString NExprLoc) -> String -> Parser (NString NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"indented string"

  indentedQ :: Parser ()
indentedQ      = ParsecT Void Text (State SourcePos) (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Tokens Text -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"''" ParsecT Void Text (State SourcePos) (Tokens Text)
-> String -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"\"''\"")
  indentedEscape :: ParsecT Void Text (State SourcePos) (Antiquoted Text r)
indentedEscape =
    ParsecT Void Text (State SourcePos) (Antiquoted Text r)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT Void Text (State SourcePos) (Antiquoted Text r)
 -> ParsecT Void Text (State SourcePos) (Antiquoted Text r))
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
forall a b. (a -> b) -> a -> b
$
      do
        Parser ()
indentedQ
        (Text -> Antiquoted Text r
forall v r. v -> Antiquoted v r
Plain (Text -> Antiquoted Text r)
-> Parser Text
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text
"''" Text -> ParsecT Void Text (State SourcePos) Char -> Parser Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'\'' Parser Text -> Parser Text -> Parser Text
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Text
"$" Text -> ParsecT Void Text (State SourcePos) Char -> Parser Text
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'$')) ParsecT Void Text (State SourcePos) (Antiquoted Text r)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+>
          do
            Char
_ <- Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'\\'
            Char
c <- ParsecT Void Text (State SourcePos) Char
escapeCode

            pure $
              Antiquoted Text r -> Antiquoted Text r -> Bool -> Antiquoted Text r
forall a. a -> a -> Bool -> a
bool
                Antiquoted Text r
forall v r. Antiquoted v r
EscapedNewline
                (Text -> Antiquoted Text r
forall v r. v -> Antiquoted v r
Plain (Text -> Antiquoted Text r) -> Text -> Antiquoted Text r
forall a b. (a -> b) -> a -> b
$ Char -> Text
singleton Char
c)
                (Char
c Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n')

  stringChar :: Parser ()
-> Parser ()
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
stringChar Parser ()
end Parser ()
escStart ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
esc =
    NExprLoc -> Antiquoted Text NExprLoc
forall v r. r -> Antiquoted v r
Antiquoted (NExprLoc -> Antiquoted Text NExprLoc)
-> Parser NExprLoc
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
      (Parser Text
antiStart Parser Text -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm Parser NExprLoc
-> ParsecT Void Text (State SourcePos) Char -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'}')
        ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Text -> Antiquoted Text NExprLoc
forall v r. v -> Antiquoted v r
Plain (Text -> Antiquoted Text NExprLoc)
-> (Char -> Text) -> Char -> Antiquoted Text NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Text
singleton (Char -> Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'$' ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
esc ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Text -> Antiquoted Text NExprLoc
forall v r. v -> Antiquoted v r
Plain (Text -> Antiquoted Text NExprLoc)
-> (String -> Text) -> String -> Antiquoted Text NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
forall a. ToText a => a -> Text
toText (String -> Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) (Antiquoted Text NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
            ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some ParsecT Void Text (State SourcePos) Char
plainChar
   where
    plainChar :: ParsecT Void Text (State SourcePos) Char
plainChar =
      Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (Parser ()
end Parser () -> Parser () -> Parser ()
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> ParsecT Void Text (State SourcePos) Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
'$') Parser () -> Parser () -> Parser ()
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser ()
escStart) Parser ()
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) Char
forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
anySingle

  escapeCode :: ParsecT Void Text (State SourcePos) Char
escapeCode =
    [ParsecT Void Text (State SourcePos) Char]
-> ParsecT Void Text (State SourcePos) Char
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
      [ Char
c Char
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
e | (Char
c, Char
e) <- [(Char, Char)]
escapeCodes ]
    ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
-> ParsecT Void Text (State SourcePos) Char
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> ParsecT Void Text (State SourcePos) Char
forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
anySingle

-- | Gets all of the arguments for a function.
argExpr :: Parser (Params NExprLoc)
argExpr :: Parser (Params NExprLoc)
argExpr =
  [Parser (Params NExprLoc)] -> Parser (Params NExprLoc)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
    [ Parser (Params NExprLoc)
atLeft
    , Parser (Params NExprLoc)
forall r. ParsecT Void Text (State SourcePos) (Params r)
onlyname
    , Parser (Params NExprLoc)
atRight
    ]
  Parser (Params NExprLoc) -> Parser Text -> Parser (Params NExprLoc)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> Parser Text
symbol Text
":"
 where
  -- An argument not in curly braces. There's some potential ambiguity
  -- in the case of, for example `x:y`. Is it a lambda function `x: y`, or
  -- a URI `x:y`? Nix syntax says it's the latter. So we need to fail if
  -- there's a valid URI parse here.
  onlyname :: ParsecT Void Text (State SourcePos) (Params r)
onlyname =
    [ParsecT Void Text (State SourcePos) (Params r)]
-> ParsecT Void Text (State SourcePos) (Params r)
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
      [ Parser NExprLoc
nixUri Parser NExprLoc
-> ParsecT Void Text (State SourcePos) (Params r)
-> ParsecT Void Text (State SourcePos) (Params r)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ErrorItem (Token Text)
-> ParsecT Void Text (State SourcePos) (Params r)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
ErrorItem (Token s) -> m a
unexpected (NonEmpty Char -> ErrorItem Char
forall t. NonEmpty Char -> ErrorItem t
Label (Char
'v' Char -> String -> NonEmpty Char
forall a. a -> [a] -> NonEmpty a
:| String
"alid uri"))
      , Text -> Params r
forall r. Text -> Params r
Param (Text -> Params r)
-> Parser Text -> ParsecT Void Text (State SourcePos) (Params r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
identifier
      ]

  -- Parameters named by an identifier on the left (`args @ {x, y}`)
  atLeft :: Parser (Params NExprLoc)
atLeft =
    Parser (Params NExprLoc) -> Parser (Params NExprLoc)
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser (Params NExprLoc) -> Parser (Params NExprLoc))
-> Parser (Params NExprLoc) -> Parser (Params NExprLoc)
forall a b. (a -> b) -> a -> b
$
      do
        Text
name               <- Parser Text
identifier Parser Text -> Parser Text -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Text -> Parser Text
symbol Text
"@"
        ([(Text, Maybe NExprLoc)]
params, Bool
variadic) <- ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
params
        pure $ [(Text, Maybe NExprLoc)] -> Bool -> Maybe Text -> Params NExprLoc
forall r. ParamSet r -> Bool -> Maybe Text -> Params r
ParamSet [(Text, Maybe NExprLoc)]
params Bool
variadic (Maybe Text -> Params NExprLoc) -> Maybe Text -> Params NExprLoc
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text
forall (f :: * -> *) a. Applicative f => a -> f a
pure Text
name

  -- Parameters named by an identifier on the right, or none (`{x, y} @ args`)
  atRight :: Parser (Params NExprLoc)
atRight =
    do
      ([(Text, Maybe NExprLoc)]
params, Bool
variadic) <- ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
params
      Maybe Text
name               <- Parser Text -> ParsecT Void Text (State SourcePos) (Maybe Text)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser Text -> ParsecT Void Text (State SourcePos) (Maybe Text))
-> Parser Text -> ParsecT Void Text (State SourcePos) (Maybe Text)
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
symbol Text
"@" Parser Text -> Parser Text -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text
identifier
      pure $ [(Text, Maybe NExprLoc)] -> Bool -> Maybe Text -> Params NExprLoc
forall r. ParamSet r -> Bool -> Maybe Text -> Params r
ParamSet [(Text, Maybe NExprLoc)]
params Bool
variadic Maybe Text
name

  -- Return the parameters set.
  params :: ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
params = ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall a. Parser a -> Parser a
braces ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
getParams

  -- Collects the parameters within curly braces. Returns the parameters and
  -- a boolean indicating if the parameters are variadic.
  getParams :: Parser ([(Text, Maybe NExprLoc)], Bool)
  getParams :: ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
getParams = [(Text, Maybe NExprLoc)]
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
go [(Text, Maybe NExprLoc)]
forall a. Monoid a => a
mempty
   where
    -- Attempt to parse `...`. If this succeeds, stop and return True.
    -- Otherwise, attempt to parse an argument, optionally with a
    -- default. If this fails, then return what has been accumulated
    -- so far.
    go :: [(Text, Maybe NExprLoc)]
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
go [(Text, Maybe NExprLoc)]
acc = (([(Text, Maybe NExprLoc)]
acc, Bool
True) ([(Text, Maybe NExprLoc)], Bool)
-> Parser Text
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser Text
symbol Text
"...") ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
getMore
     where
      getMore :: ParsecT
  Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
getMore =
        -- Could be nothing, in which just return what we have so far.
        ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option ([(Text, Maybe NExprLoc)]
acc, Bool
False) (ParsecT
   Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
 -> ParsecT
      Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool))
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall a b. (a -> b) -> a -> b
$
          do
            -- Get an argument name and an optional default.
            (Text, Maybe NExprLoc)
pair <-
              (Text -> Maybe NExprLoc -> (Text, Maybe NExprLoc))
-> Parser Text
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
-> ParsecT Void Text (State SourcePos) (Text, Maybe NExprLoc)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,)
                Parser Text
identifier
                (Parser NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser NExprLoc
 -> ParsecT Void Text (State SourcePos) (Maybe NExprLoc))
-> Parser NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall a b. (a -> b) -> a -> b
$ Parser Text
question Parser Text -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)

            let args :: [(Text, Maybe NExprLoc)]
args = [(Text, Maybe NExprLoc)]
acc [(Text, Maybe NExprLoc)]
-> [(Text, Maybe NExprLoc)] -> [(Text, Maybe NExprLoc)]
forall a. Semigroup a => a -> a -> a
<> [(Text, Maybe NExprLoc)
pair]

            -- Either return this, or attempt to get a comma and restart.
            ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option ([(Text, Maybe NExprLoc)]
args, Bool
False) (ParsecT
   Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
 -> ParsecT
      Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool))
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall a b. (a -> b) -> a -> b
$ Parser Text
comma Parser Text
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> [(Text, Maybe NExprLoc)]
-> ParsecT
     Void Text (State SourcePos) ([(Text, Maybe NExprLoc)], Bool)
go [(Text, Maybe NExprLoc)]
args

nixBinders :: Parser [Binding NExprLoc]
nixBinders :: ParsecT Void Text (State SourcePos) [Binding NExprLoc]
nixBinders = (ParsecT Void Text (State SourcePos) (Binding NExprLoc)
inherit ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
namedVar) ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> Parser Text
-> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`endBy` Parser Text
semi where
  inherit :: ParsecT Void Text (State SourcePos) (Binding NExprLoc)
inherit =
    do
      -- We can't use 'reserved' here because it would consume the whitespace
      -- after the keyword, which is not exactly the semantics of C++ Nix.
      Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
"inherit" Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (ParsecT Void Text (State SourcePos) Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ((Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy Char -> Bool
Token Text -> Bool
reservedEnd))
      SourcePos
p <- ParsecT Void Text (State SourcePos) SourcePos
forall s e (m :: * -> *).
(TraversableStream s, MonadParsec e s m) =>
m SourcePos
getSourcePos
      Maybe NExprLoc
x <- Parser ()
whiteSpace Parser ()
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser NExprLoc
scope
      ([NKeyName NExprLoc] -> SourcePos -> Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) [NKeyName NExprLoc]
-> ParsecT Void Text (State SourcePos) SourcePos
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (Maybe NExprLoc
-> [NKeyName NExprLoc] -> SourcePos -> Binding NExprLoc
forall r. Maybe r -> [NKeyName r] -> SourcePos -> Binding r
Inherit Maybe NExprLoc
x)
        (Parser (NKeyName NExprLoc)
-> ParsecT Void Text (State SourcePos) [NKeyName NExprLoc]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many Parser (NKeyName NExprLoc)
keyName)
        (SourcePos -> ParsecT Void Text (State SourcePos) SourcePos
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourcePos
p)
        ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> String -> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"inherited binding"
  namedVar :: ParsecT Void Text (State SourcePos) (Binding NExprLoc)
namedVar =
    do
      SourcePos
p <- ParsecT Void Text (State SourcePos) SourcePos
forall s e (m :: * -> *).
(TraversableStream s, MonadParsec e s m) =>
m SourcePos
getSourcePos
      (NAttrPath NExprLoc -> NExprLoc -> SourcePos -> Binding NExprLoc)
-> Parser (NAttrPath NExprLoc)
-> Parser NExprLoc
-> ParsecT Void Text (State SourcePos) SourcePos
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall (f :: * -> *) a b c d.
Applicative f =>
(a -> b -> c -> d) -> f a -> f b -> f c -> f d
liftA3 NAttrPath NExprLoc -> NExprLoc -> SourcePos -> Binding NExprLoc
forall r. NAttrPath r -> r -> SourcePos -> Binding r
NamedVar
        (Ann SrcSpan (NAttrPath NExprLoc) -> NAttrPath NExprLoc
forall ann a. Ann ann a -> a
annotated (Ann SrcSpan (NAttrPath NExprLoc) -> NAttrPath NExprLoc)
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> Parser (NAttrPath NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Ann SrcSpan (NAttrPath NExprLoc))
nixSelector)
        (Parser Text
equals Parser Text -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm)
        (SourcePos -> ParsecT Void Text (State SourcePos) SourcePos
forall (f :: * -> *) a. Applicative f => a -> f a
pure SourcePos
p)
        ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> String -> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"variable binding"
  scope :: Parser NExprLoc
scope = Parser NExprLoc
nixParens Parser NExprLoc -> String -> Parser NExprLoc
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"inherit scope"

keyName :: Parser (NKeyName NExprLoc)
keyName :: Parser (NKeyName NExprLoc)
keyName = Parser (NKeyName NExprLoc)
dynamicKey Parser (NKeyName NExprLoc)
-> Parser (NKeyName NExprLoc) -> Parser (NKeyName NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> Parser (NKeyName NExprLoc)
forall r. ParsecT Void Text (State SourcePos) (NKeyName r)
staticKey
 where
  staticKey :: ParsecT Void Text (State SourcePos) (NKeyName r)
staticKey  = Text -> NKeyName r
forall r. Text -> NKeyName r
StaticKey (Text -> NKeyName r)
-> Parser Text -> ParsecT Void Text (State SourcePos) (NKeyName r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Text
identifier
  dynamicKey :: Parser (NKeyName NExprLoc)
dynamicKey = Antiquoted (NString NExprLoc) NExprLoc -> NKeyName NExprLoc
forall r. Antiquoted (NString r) r -> NKeyName r
DynamicKey (Antiquoted (NString NExprLoc) NExprLoc -> NKeyName NExprLoc)
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Antiquoted (NString NExprLoc) NExprLoc)
-> Parser (NKeyName NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (NString NExprLoc)
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Antiquoted (NString NExprLoc) NExprLoc)
forall a. Parser a -> Parser (Antiquoted a NExprLoc)
nixAntiquoted Parser (NString NExprLoc)
nixString'

nixSet :: Parser NExprLoc
nixSet :: Parser NExprLoc
nixSet = Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 ((ParsecT
  Void Text (State SourcePos) ([Binding NExprLoc] -> NExprF NExprLoc)
forall r.
ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
isRec ParsecT
  Void Text (State SourcePos) ([Binding NExprLoc] -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
-> ParsecT Void Text (State SourcePos) [Binding NExprLoc]
forall a. Parser a -> Parser a
braces ParsecT Void Text (State SourcePos) [Binding NExprLoc]
nixBinders) Parser (NExprF NExprLoc) -> String -> Parser (NExprF NExprLoc)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"set")
 where
  isRec :: ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
isRec = (Text -> Parser ()
reserved Text
"rec" Parser ()
-> ([Binding r] -> NExprF r)
-> ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> NRecordType -> [Binding r] -> NExprF r
forall r. NRecordType -> [Binding r] -> NExprF r
NSet NRecordType
NRecursive ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
-> String
-> ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
forall e s (m :: * -> *) a.
MonadParsec e s m =>
m a -> String -> m a
<?> String
"recursive set") ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
-> ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
-> ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<+> ([Binding r] -> NExprF r)
-> ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NRecordType -> [Binding r] -> NExprF r
forall r. NRecordType -> [Binding r] -> NExprF r
NSet NRecordType
NNonRecursive)

parseNixFile :: MonadFile m => FilePath -> m (Result NExpr)
parseNixFile :: String -> m (Result NExpr)
parseNixFile =
  Parser NExpr -> String -> m (Result NExpr)
forall (m :: * -> *) a.
MonadFile m =>
Parser a -> String -> m (Result a)
parseFromFileEx (Parser NExpr -> String -> m (Result NExpr))
-> Parser NExpr -> String -> m (Result NExpr)
forall a b. (a -> b) -> a -> b
$ NExprLoc -> NExpr
forall (f :: * -> *) ann. Functor f => Fix (AnnF ann f) -> Fix f
stripAnnotation (NExprLoc -> NExpr) -> Parser NExprLoc -> Parser NExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ()
whiteSpace Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm Parser NExprLoc -> Parser () -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof)

parseNixFileLoc :: MonadFile m => FilePath -> m (Result NExprLoc)
parseNixFileLoc :: String -> m (Result NExprLoc)
parseNixFileLoc = Parser NExprLoc -> String -> m (Result NExprLoc)
forall (m :: * -> *) a.
MonadFile m =>
Parser a -> String -> m (Result a)
parseFromFileEx (Parser ()
whiteSpace Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm Parser NExprLoc -> Parser () -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof)

parseNixText :: Text -> Result NExpr
parseNixText :: Text -> Result NExpr
parseNixText =
  Parser NExpr -> Text -> Result NExpr
forall a. Parser a -> Text -> Result a
parseFromText (Parser NExpr -> Text -> Result NExpr)
-> Parser NExpr -> Text -> Result NExpr
forall a b. (a -> b) -> a -> b
$ NExprLoc -> NExpr
forall (f :: * -> *) ann. Functor f => Fix (AnnF ann f) -> Fix f
stripAnnotation (NExprLoc -> NExpr) -> Parser NExprLoc -> Parser NExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Parser ()
whiteSpace Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm Parser NExprLoc -> Parser () -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof)

parseNixTextLoc :: Text -> Result NExprLoc
parseNixTextLoc :: Text -> Result NExprLoc
parseNixTextLoc = Parser NExprLoc -> Text -> Result NExprLoc
forall a. Parser a -> Text -> Result a
parseFromText (Parser ()
whiteSpace Parser () -> Parser NExprLoc -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser NExprLoc
nixToplevelForm Parser NExprLoc -> Parser () -> Parser NExprLoc
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof)

{- Parser.Library -}

skipLineComment' :: Tokens Text -> Parser ()
skipLineComment' :: Tokens Text -> Parser ()
skipLineComment' Tokens Text
prefix =
  Tokens Text -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Tokens Text
prefix Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Text -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Maybe String
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP (String -> Maybe String
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
"character") (\Token Text
x -> Char
Token Text
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n' Bool -> Bool -> Bool
&& Char
Token Text
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\r'))

whiteSpace :: Parser ()
whiteSpace :: Parser ()
whiteSpace = do
  SourcePos -> Parser ()
forall s (m :: * -> *). MonadState s m => s -> m ()
put (SourcePos -> Parser ())
-> ParsecT Void Text (State SourcePos) SourcePos -> Parser ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< ParsecT Void Text (State SourcePos) SourcePos
forall s e (m :: * -> *).
(TraversableStream s, MonadParsec e s m) =>
m SourcePos
getSourcePos
  Parser () -> Parser () -> Parser () -> Parser ()
forall e s (m :: * -> *).
MonadParsec e s m =>
m () -> m () -> m () -> m ()
Lexer.space Parser ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m ()
space1 Parser ()
lineCmnt Parser ()
blockCmnt
 where
  lineCmnt :: Parser ()
lineCmnt  = Tokens Text -> Parser ()
skipLineComment' Tokens Text
"#"
  blockCmnt :: Parser ()
blockCmnt = Tokens Text -> Tokens Text -> Parser ()
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Tokens s -> Tokens s -> m ()
Lexer.skipBlockComment Tokens Text
"/*" Tokens Text
"*/"

lexeme :: Parser a -> Parser a
lexeme :: Parser a -> Parser a
lexeme Parser a
p = Parser a
p Parser a -> Parser () -> Parser a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
whiteSpace

symbol :: Text -> Parser Text
symbol :: Text -> Parser Text
symbol = Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text)
-> (Text -> Parser Text) -> Text -> Parser Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Parser Text
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string

reservedEnd :: Char -> Bool
reservedEnd :: Char -> Bool
reservedEnd Char
x =
  Char -> Bool
isSpace Char
x Bool -> Bool -> Bool
|| (Char -> String -> Bool
forall (f :: * -> *) a.
(Foldable f, DisallowElem f, Eq a) =>
a -> f a -> Bool
`elem` (String
"{([})];:.\"'," :: String)) Char
x
{-# inline reservedEnd #-}

reserved :: Text -> Parser ()
reserved :: Text -> Parser ()
reserved Text
n =
  Parser () -> Parser ()
forall a. Parser a -> Parser a
lexeme (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Text
Tokens Text
n Parser Text -> Parser () -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser () -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (ParsecT Void Text (State SourcePos) Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void ((Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy Char -> Bool
Token Text -> Bool
reservedEnd) Parser () -> Parser () -> Parser ()
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof)

identifier :: Parser Text
identifier :: Parser Text
identifier = Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text) -> Parser Text -> Parser Text
forall a b. (a -> b) -> a -> b
$ Parser Text -> Parser Text
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser Text -> Parser Text) -> Parser Text -> Parser Text
forall a b. (a -> b) -> a -> b
$ do
  Text
ident <-
    (Char -> Text -> Text)
-> ParsecT Void Text (State SourcePos) Char
-> Parser Text
-> Parser Text
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Char -> Text -> Text
cons
      ((Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
(Token s -> Bool) -> m (Token s)
satisfy (\Token Text
x -> Char -> Bool
isAlpha Char
Token Text
x Bool -> Bool -> Bool
|| Char
Token Text
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_'))
      (Maybe String
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Maybe String -> (Token s -> Bool) -> m (Tokens s)
takeWhileP Maybe String
forall a. Monoid a => a
mempty Char -> Bool
Token Text -> Bool
identLetter)
  Bool -> Parser ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> Parser ()) -> Bool -> Parser ()
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ Text
ident Text -> HashSet Text -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`HashSet.member` HashSet Text
reservedNames
  pure Text
ident
 where
  identLetter :: Char -> Bool
identLetter Char
x = Char -> Bool
isAlphanumeric Char
x Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'_' Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'\'' Bool -> Bool -> Bool
|| Char
x Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
== Char
'-'

-- We restrict the type of 'parens' and 'brackets' here because if they were to
-- take a @Parser NExprLoc@ argument they would parse additional text which
-- wouldn't be captured in the source location annotation.
--
-- Braces and angles in hnix don't enclose a single expression so this type
-- restriction would not be useful.
parens :: Parser (NExprF f) -> Parser (NExprF f)
parens :: Parser (NExprF f) -> Parser (NExprF f)
parens   = Parser Text
-> Parser Text -> Parser (NExprF f) -> Parser (NExprF f)
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between (Text -> Parser Text
symbol Text
"(") (Text -> Parser Text
symbol Text
")")
braces :: ParsecT Void Text (State SourcePos) a -> ParsecT Void Text (State SourcePos) a
braces :: ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
braces   = Parser Text
-> Parser Text
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between (Text -> Parser Text
symbol Text
"{") (Text -> Parser Text
symbol Text
"}")
-- angles    = between (symbol "<") (symbol ">")
brackets :: Parser (NExprF f) -> Parser (NExprF f)
brackets :: Parser (NExprF f) -> Parser (NExprF f)
brackets = Parser Text
-> Parser Text -> Parser (NExprF f) -> Parser (NExprF f)
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between (Text -> Parser Text
symbol Text
"[") (Text -> Parser Text
symbol Text
"]")
semi :: Parser Text
semi :: Parser Text
semi     = Text -> Parser Text
symbol Text
";"
comma :: Parser Text
comma :: Parser Text
comma    = Text -> Parser Text
symbol Text
","
-- colon     = symbol ":"
-- dot       = symbol "."
equals :: Parser Text
equals :: Parser Text
equals   = Text -> Parser Text
symbol Text
"="
question :: Parser Text
question :: Parser Text
question = Text -> Parser Text
symbol Text
"?"

integer :: Parser Integer
integer :: ParsecT Void Text (State SourcePos) Integer
integer = ParsecT Void Text (State SourcePos) Integer
-> ParsecT Void Text (State SourcePos) Integer
forall a. Parser a -> Parser a
lexeme ParsecT Void Text (State SourcePos) Integer
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, Num a) =>
m a
Lexer.decimal

float :: Parser Double
float :: ParsecT Void Text (State SourcePos) Double
float = ParsecT Void Text (State SourcePos) Double
-> ParsecT Void Text (State SourcePos) Double
forall a. Parser a -> Parser a
lexeme ParsecT Void Text (State SourcePos) Double
forall e s (m :: * -> *) a.
(MonadParsec e s m, Token s ~ Char, RealFloat a) =>
m a
Lexer.float

reservedNames :: HashSet Text
reservedNames :: HashSet Text
reservedNames =
  [Text] -> HashSet Text
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList
    [Text
"let", Text
"in", Text
"if", Text
"then", Text
"else", Text
"assert", Text
"with", Text
"rec", Text
"inherit"]

type Parser = ParsecT Void Text (State SourcePos)

type Result a = Either (Doc Void) a

parseFromFileEx :: MonadFile m => Parser a -> FilePath -> m (Result a)
parseFromFileEx :: Parser a -> String -> m (Result a)
parseFromFileEx Parser a
parser String
file =
  do
    Text
input <- ByteString -> Text
forall a b. ConvertUtf8 a b => b -> a
decodeUtf8 (ByteString -> Text) -> m ByteString -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> m ByteString
forall (m :: * -> *). MonadFile m => String -> m ByteString
readFile String
file

    pure $
      (ParseErrorBundle Text Void -> Result a)
-> (a -> Result a)
-> Either (ParseErrorBundle Text Void) a
-> Result a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
        (Doc Void -> Result a
forall a b. a -> Either a b
Left (Doc Void -> Result a)
-> (ParseErrorBundle Text Void -> Doc Void)
-> ParseErrorBundle Text Void
-> Result a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc Void
forall a ann. Pretty a => a -> Doc ann
pretty (String -> Doc Void)
-> (ParseErrorBundle Text Void -> String)
-> ParseErrorBundle Text Void
-> Doc Void
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseErrorBundle Text Void -> String
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> String
errorBundlePretty)
        a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
        (Either (ParseErrorBundle Text Void) a -> Result a)
-> Either (ParseErrorBundle Text Void) a -> Result a
forall a b. (a -> b) -> a -> b
$ (State SourcePos (Either (ParseErrorBundle Text Void) a)
-> SourcePos -> Either (ParseErrorBundle Text Void) a
forall s a. State s a -> s -> a
`evalState` String -> SourcePos
initialPos String
file) (State SourcePos (Either (ParseErrorBundle Text Void) a)
 -> Either (ParseErrorBundle Text Void) a)
-> State SourcePos (Either (ParseErrorBundle Text Void) a)
-> Either (ParseErrorBundle Text Void) a
forall a b. (a -> b) -> a -> b
$ Parser a
-> String
-> Text
-> State SourcePos (Either (ParseErrorBundle Text Void) a)
forall (m :: * -> *) e s a.
Monad m =>
ParsecT e s m a
-> String -> s -> m (Either (ParseErrorBundle s e) a)
runParserT Parser a
parser String
file Text
input

parseFromText :: Parser a -> Text -> Result a
parseFromText :: Parser a -> Text -> Result a
parseFromText Parser a
parser Text
input =
  let stub :: String
stub = String
"<string>" in
  (ParseErrorBundle Text Void -> Result a)
-> (a -> Result a)
-> Either (ParseErrorBundle Text Void) a
-> Result a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
    (Doc Void -> Result a
forall a b. a -> Either a b
Left (Doc Void -> Result a)
-> (ParseErrorBundle Text Void -> Doc Void)
-> ParseErrorBundle Text Void
-> Result a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc Void
forall a ann. Pretty a => a -> Doc ann
pretty (String -> Doc Void)
-> (ParseErrorBundle Text Void -> String)
-> ParseErrorBundle Text Void
-> Doc Void
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParseErrorBundle Text Void -> String
forall s e.
(VisualStream s, TraversableStream s, ShowErrorComponent e) =>
ParseErrorBundle s e -> String
errorBundlePretty)
    a -> Result a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (Either (ParseErrorBundle Text Void) a -> Result a)
-> Either (ParseErrorBundle Text Void) a -> Result a
forall a b. (a -> b) -> a -> b
$ (State SourcePos (Either (ParseErrorBundle Text Void) a)
-> SourcePos -> Either (ParseErrorBundle Text Void) a
forall s a. State s a -> s -> a
`evalState` String -> SourcePos
initialPos String
stub) (State SourcePos (Either (ParseErrorBundle Text Void) a)
 -> Either (ParseErrorBundle Text Void) a)
-> State SourcePos (Either (ParseErrorBundle Text Void) a)
-> Either (ParseErrorBundle Text Void) a
forall a b. (a -> b) -> a -> b
$ (Parser a
-> String
-> Text
-> State SourcePos (Either (ParseErrorBundle Text Void) a)
forall (m :: * -> *) e s a.
Monad m =>
ParsecT e s m a
-> String -> s -> m (Either (ParseErrorBundle s e) a)
`runParserT` String
stub) Parser a
parser Text
input

{- Parser.Operators -}

data NSpecialOp = NHasAttrOp | NSelectOp
  deriving (NSpecialOp -> NSpecialOp -> Bool
(NSpecialOp -> NSpecialOp -> Bool)
-> (NSpecialOp -> NSpecialOp -> Bool) -> Eq NSpecialOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NSpecialOp -> NSpecialOp -> Bool
$c/= :: NSpecialOp -> NSpecialOp -> Bool
== :: NSpecialOp -> NSpecialOp -> Bool
$c== :: NSpecialOp -> NSpecialOp -> Bool
Eq, Eq NSpecialOp
Eq NSpecialOp
-> (NSpecialOp -> NSpecialOp -> Ordering)
-> (NSpecialOp -> NSpecialOp -> Bool)
-> (NSpecialOp -> NSpecialOp -> Bool)
-> (NSpecialOp -> NSpecialOp -> Bool)
-> (NSpecialOp -> NSpecialOp -> Bool)
-> (NSpecialOp -> NSpecialOp -> NSpecialOp)
-> (NSpecialOp -> NSpecialOp -> NSpecialOp)
-> Ord NSpecialOp
NSpecialOp -> NSpecialOp -> Bool
NSpecialOp -> NSpecialOp -> Ordering
NSpecialOp -> NSpecialOp -> NSpecialOp
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 :: NSpecialOp -> NSpecialOp -> NSpecialOp
$cmin :: NSpecialOp -> NSpecialOp -> NSpecialOp
max :: NSpecialOp -> NSpecialOp -> NSpecialOp
$cmax :: NSpecialOp -> NSpecialOp -> NSpecialOp
>= :: NSpecialOp -> NSpecialOp -> Bool
$c>= :: NSpecialOp -> NSpecialOp -> Bool
> :: NSpecialOp -> NSpecialOp -> Bool
$c> :: NSpecialOp -> NSpecialOp -> Bool
<= :: NSpecialOp -> NSpecialOp -> Bool
$c<= :: NSpecialOp -> NSpecialOp -> Bool
< :: NSpecialOp -> NSpecialOp -> Bool
$c< :: NSpecialOp -> NSpecialOp -> Bool
compare :: NSpecialOp -> NSpecialOp -> Ordering
$ccompare :: NSpecialOp -> NSpecialOp -> Ordering
$cp1Ord :: Eq NSpecialOp
Ord, (forall x. NSpecialOp -> Rep NSpecialOp x)
-> (forall x. Rep NSpecialOp x -> NSpecialOp) -> Generic NSpecialOp
forall x. Rep NSpecialOp x -> NSpecialOp
forall x. NSpecialOp -> Rep NSpecialOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NSpecialOp x -> NSpecialOp
$cfrom :: forall x. NSpecialOp -> Rep NSpecialOp x
Generic, Typeable, Typeable NSpecialOp
DataType
Constr
Typeable NSpecialOp
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NSpecialOp -> c NSpecialOp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NSpecialOp)
-> (NSpecialOp -> Constr)
-> (NSpecialOp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NSpecialOp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c NSpecialOp))
-> ((forall b. Data b => b -> b) -> NSpecialOp -> NSpecialOp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r)
-> (forall u. (forall d. Data d => d -> u) -> NSpecialOp -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NSpecialOp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp)
-> Data NSpecialOp
NSpecialOp -> DataType
NSpecialOp -> Constr
(forall b. Data b => b -> b) -> NSpecialOp -> NSpecialOp
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NSpecialOp -> c NSpecialOp
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NSpecialOp
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NSpecialOp -> u
forall u. (forall d. Data d => d -> u) -> NSpecialOp -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NSpecialOp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NSpecialOp -> c NSpecialOp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NSpecialOp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NSpecialOp)
$cNSelectOp :: Constr
$cNHasAttrOp :: Constr
$tNSpecialOp :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
gmapMp :: (forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
gmapM :: (forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
gmapQi :: Int -> (forall d. Data d => d -> u) -> NSpecialOp -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NSpecialOp -> u
gmapQ :: (forall d. Data d => d -> u) -> NSpecialOp -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NSpecialOp -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
gmapT :: (forall b. Data b => b -> b) -> NSpecialOp -> NSpecialOp
$cgmapT :: (forall b. Data b => b -> b) -> NSpecialOp -> NSpecialOp
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NSpecialOp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NSpecialOp)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c NSpecialOp)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NSpecialOp)
dataTypeOf :: NSpecialOp -> DataType
$cdataTypeOf :: NSpecialOp -> DataType
toConstr :: NSpecialOp -> Constr
$ctoConstr :: NSpecialOp -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NSpecialOp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NSpecialOp
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NSpecialOp -> c NSpecialOp
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NSpecialOp -> c NSpecialOp
$cp1Data :: Typeable NSpecialOp
Data, Int -> NSpecialOp -> String -> String
[NSpecialOp] -> String -> String
NSpecialOp -> String
(Int -> NSpecialOp -> String -> String)
-> (NSpecialOp -> String)
-> ([NSpecialOp] -> String -> String)
-> Show NSpecialOp
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [NSpecialOp] -> String -> String
$cshowList :: [NSpecialOp] -> String -> String
show :: NSpecialOp -> String
$cshow :: NSpecialOp -> String
showsPrec :: Int -> NSpecialOp -> String -> String
$cshowsPrec :: Int -> NSpecialOp -> String -> String
Show, NSpecialOp -> ()
(NSpecialOp -> ()) -> NFData NSpecialOp
forall a. (a -> ()) -> NFData a
rnf :: NSpecialOp -> ()
$crnf :: NSpecialOp -> ()
NFData)

data NAssoc = NAssocNone | NAssocLeft | NAssocRight
  deriving (NAssoc -> NAssoc -> Bool
(NAssoc -> NAssoc -> Bool)
-> (NAssoc -> NAssoc -> Bool) -> Eq NAssoc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NAssoc -> NAssoc -> Bool
$c/= :: NAssoc -> NAssoc -> Bool
== :: NAssoc -> NAssoc -> Bool
$c== :: NAssoc -> NAssoc -> Bool
Eq, Eq NAssoc
Eq NAssoc
-> (NAssoc -> NAssoc -> Ordering)
-> (NAssoc -> NAssoc -> Bool)
-> (NAssoc -> NAssoc -> Bool)
-> (NAssoc -> NAssoc -> Bool)
-> (NAssoc -> NAssoc -> Bool)
-> (NAssoc -> NAssoc -> NAssoc)
-> (NAssoc -> NAssoc -> NAssoc)
-> Ord NAssoc
NAssoc -> NAssoc -> Bool
NAssoc -> NAssoc -> Ordering
NAssoc -> NAssoc -> NAssoc
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 :: NAssoc -> NAssoc -> NAssoc
$cmin :: NAssoc -> NAssoc -> NAssoc
max :: NAssoc -> NAssoc -> NAssoc
$cmax :: NAssoc -> NAssoc -> NAssoc
>= :: NAssoc -> NAssoc -> Bool
$c>= :: NAssoc -> NAssoc -> Bool
> :: NAssoc -> NAssoc -> Bool
$c> :: NAssoc -> NAssoc -> Bool
<= :: NAssoc -> NAssoc -> Bool
$c<= :: NAssoc -> NAssoc -> Bool
< :: NAssoc -> NAssoc -> Bool
$c< :: NAssoc -> NAssoc -> Bool
compare :: NAssoc -> NAssoc -> Ordering
$ccompare :: NAssoc -> NAssoc -> Ordering
$cp1Ord :: Eq NAssoc
Ord, (forall x. NAssoc -> Rep NAssoc x)
-> (forall x. Rep NAssoc x -> NAssoc) -> Generic NAssoc
forall x. Rep NAssoc x -> NAssoc
forall x. NAssoc -> Rep NAssoc x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NAssoc x -> NAssoc
$cfrom :: forall x. NAssoc -> Rep NAssoc x
Generic, Typeable, Typeable NAssoc
DataType
Constr
Typeable NAssoc
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NAssoc -> c NAssoc)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NAssoc)
-> (NAssoc -> Constr)
-> (NAssoc -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NAssoc))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAssoc))
-> ((forall b. Data b => b -> b) -> NAssoc -> NAssoc)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NAssoc -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NAssoc -> r)
-> (forall u. (forall d. Data d => d -> u) -> NAssoc -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> NAssoc -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NAssoc -> m NAssoc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NAssoc -> m NAssoc)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NAssoc -> m NAssoc)
-> Data NAssoc
NAssoc -> DataType
NAssoc -> Constr
(forall b. Data b => b -> b) -> NAssoc -> NAssoc
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAssoc -> c NAssoc
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAssoc
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NAssoc -> u
forall u. (forall d. Data d => d -> u) -> NAssoc -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAssoc
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAssoc -> c NAssoc
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NAssoc)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAssoc)
$cNAssocRight :: Constr
$cNAssocLeft :: Constr
$cNAssocNone :: Constr
$tNAssoc :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
gmapMp :: (forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
gmapM :: (forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
gmapQi :: Int -> (forall d. Data d => d -> u) -> NAssoc -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NAssoc -> u
gmapQ :: (forall d. Data d => d -> u) -> NAssoc -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NAssoc -> [u]
gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
gmapT :: (forall b. Data b => b -> b) -> NAssoc -> NAssoc
$cgmapT :: (forall b. Data b => b -> b) -> NAssoc -> NAssoc
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAssoc)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAssoc)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c NAssoc)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NAssoc)
dataTypeOf :: NAssoc -> DataType
$cdataTypeOf :: NAssoc -> DataType
toConstr :: NAssoc -> Constr
$ctoConstr :: NAssoc -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAssoc
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAssoc
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAssoc -> c NAssoc
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAssoc -> c NAssoc
$cp1Data :: Typeable NAssoc
Data, Int -> NAssoc -> String -> String
[NAssoc] -> String -> String
NAssoc -> String
(Int -> NAssoc -> String -> String)
-> (NAssoc -> String)
-> ([NAssoc] -> String -> String)
-> Show NAssoc
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [NAssoc] -> String -> String
$cshowList :: [NAssoc] -> String -> String
show :: NAssoc -> String
$cshow :: NAssoc -> String
showsPrec :: Int -> NAssoc -> String -> String
$cshowsPrec :: Int -> NAssoc -> String -> String
Show, NAssoc -> ()
(NAssoc -> ()) -> NFData NAssoc
forall a. (a -> ()) -> NFData a
rnf :: NAssoc -> ()
$crnf :: NAssoc -> ()
NFData)

data NOperatorDef
  = NUnaryDef   Text NUnaryOp
  | NBinaryDef  Text NBinaryOp  NAssoc
  | NSpecialDef Text NSpecialOp NAssoc
  deriving (NOperatorDef -> NOperatorDef -> Bool
(NOperatorDef -> NOperatorDef -> Bool)
-> (NOperatorDef -> NOperatorDef -> Bool) -> Eq NOperatorDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NOperatorDef -> NOperatorDef -> Bool
$c/= :: NOperatorDef -> NOperatorDef -> Bool
== :: NOperatorDef -> NOperatorDef -> Bool
$c== :: NOperatorDef -> NOperatorDef -> Bool
Eq, Eq NOperatorDef
Eq NOperatorDef
-> (NOperatorDef -> NOperatorDef -> Ordering)
-> (NOperatorDef -> NOperatorDef -> Bool)
-> (NOperatorDef -> NOperatorDef -> Bool)
-> (NOperatorDef -> NOperatorDef -> Bool)
-> (NOperatorDef -> NOperatorDef -> Bool)
-> (NOperatorDef -> NOperatorDef -> NOperatorDef)
-> (NOperatorDef -> NOperatorDef -> NOperatorDef)
-> Ord NOperatorDef
NOperatorDef -> NOperatorDef -> Bool
NOperatorDef -> NOperatorDef -> Ordering
NOperatorDef -> NOperatorDef -> NOperatorDef
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 :: NOperatorDef -> NOperatorDef -> NOperatorDef
$cmin :: NOperatorDef -> NOperatorDef -> NOperatorDef
max :: NOperatorDef -> NOperatorDef -> NOperatorDef
$cmax :: NOperatorDef -> NOperatorDef -> NOperatorDef
>= :: NOperatorDef -> NOperatorDef -> Bool
$c>= :: NOperatorDef -> NOperatorDef -> Bool
> :: NOperatorDef -> NOperatorDef -> Bool
$c> :: NOperatorDef -> NOperatorDef -> Bool
<= :: NOperatorDef -> NOperatorDef -> Bool
$c<= :: NOperatorDef -> NOperatorDef -> Bool
< :: NOperatorDef -> NOperatorDef -> Bool
$c< :: NOperatorDef -> NOperatorDef -> Bool
compare :: NOperatorDef -> NOperatorDef -> Ordering
$ccompare :: NOperatorDef -> NOperatorDef -> Ordering
$cp1Ord :: Eq NOperatorDef
Ord, (forall x. NOperatorDef -> Rep NOperatorDef x)
-> (forall x. Rep NOperatorDef x -> NOperatorDef)
-> Generic NOperatorDef
forall x. Rep NOperatorDef x -> NOperatorDef
forall x. NOperatorDef -> Rep NOperatorDef x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NOperatorDef x -> NOperatorDef
$cfrom :: forall x. NOperatorDef -> Rep NOperatorDef x
Generic, Typeable, Typeable NOperatorDef
DataType
Constr
Typeable NOperatorDef
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> NOperatorDef -> c NOperatorDef)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NOperatorDef)
-> (NOperatorDef -> Constr)
-> (NOperatorDef -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NOperatorDef))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c NOperatorDef))
-> ((forall b. Data b => b -> b) -> NOperatorDef -> NOperatorDef)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r)
-> (forall u. (forall d. Data d => d -> u) -> NOperatorDef -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NOperatorDef -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef)
-> Data NOperatorDef
NOperatorDef -> DataType
NOperatorDef -> Constr
(forall b. Data b => b -> b) -> NOperatorDef -> NOperatorDef
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOperatorDef -> c NOperatorDef
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOperatorDef
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> NOperatorDef -> u
forall u. (forall d. Data d => d -> u) -> NOperatorDef -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOperatorDef
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOperatorDef -> c NOperatorDef
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NOperatorDef)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOperatorDef)
$cNSpecialDef :: Constr
$cNBinaryDef :: Constr
$cNUnaryDef :: Constr
$tNOperatorDef :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
gmapMp :: (forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
gmapM :: (forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
gmapQi :: Int -> (forall d. Data d => d -> u) -> NOperatorDef -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NOperatorDef -> u
gmapQ :: (forall d. Data d => d -> u) -> NOperatorDef -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NOperatorDef -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
gmapT :: (forall b. Data b => b -> b) -> NOperatorDef -> NOperatorDef
$cgmapT :: (forall b. Data b => b -> b) -> NOperatorDef -> NOperatorDef
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOperatorDef)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOperatorDef)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c NOperatorDef)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NOperatorDef)
dataTypeOf :: NOperatorDef -> DataType
$cdataTypeOf :: NOperatorDef -> DataType
toConstr :: NOperatorDef -> Constr
$ctoConstr :: NOperatorDef -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOperatorDef
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOperatorDef
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOperatorDef -> c NOperatorDef
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOperatorDef -> c NOperatorDef
$cp1Data :: Typeable NOperatorDef
Data, Int -> NOperatorDef -> String -> String
[NOperatorDef] -> String -> String
NOperatorDef -> String
(Int -> NOperatorDef -> String -> String)
-> (NOperatorDef -> String)
-> ([NOperatorDef] -> String -> String)
-> Show NOperatorDef
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [NOperatorDef] -> String -> String
$cshowList :: [NOperatorDef] -> String -> String
show :: NOperatorDef -> String
$cshow :: NOperatorDef -> String
showsPrec :: Int -> NOperatorDef -> String -> String
$cshowsPrec :: Int -> NOperatorDef -> String -> String
Show, NOperatorDef -> ()
(NOperatorDef -> ()) -> NFData NOperatorDef
forall a. (a -> ()) -> NFData a
rnf :: NOperatorDef -> ()
$crnf :: NOperatorDef -> ()
NFData)

annotateLocation :: Parser a -> Parser (Ann SrcSpan a)
annotateLocation :: Parser a -> Parser (Ann SrcSpan a)
annotateLocation Parser a
p =
  do
    SourcePos
begin <- ParsecT Void Text (State SourcePos) SourcePos
forall s e (m :: * -> *).
(TraversableStream s, MonadParsec e s m) =>
m SourcePos
getSourcePos
    a
res <- Parser a
p
    SourcePos
end   <- ParsecT Void Text (State SourcePos) SourcePos
forall s (m :: * -> *). MonadState s m => m s
get -- The state set before the last whitespace

    pure $ SrcSpan -> a -> Ann SrcSpan a
forall ann a. ann -> a -> Ann ann a
Ann (SourcePos -> SourcePos -> SrcSpan
SrcSpan SourcePos
begin SourcePos
end) a
res

annotateLocation1 :: Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 :: Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 = (Ann SrcSpan (NExprF NExprLoc) -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (Ann SrcSpan (NExprF NExprLoc))
-> Parser NExprLoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Ann SrcSpan (NExprF NExprLoc) -> NExprLoc
forall ann (f :: * -> *).
Ann ann (f (Fix (AnnF ann f))) -> Fix (AnnF ann f)
annToAnnF (ParsecT
   Void Text (State SourcePos) (Ann SrcSpan (NExprF NExprLoc))
 -> Parser NExprLoc)
-> (Parser (NExprF NExprLoc)
    -> ParsecT
         Void Text (State SourcePos) (Ann SrcSpan (NExprF NExprLoc)))
-> Parser (NExprF NExprLoc)
-> Parser NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser (NExprF NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (Ann SrcSpan (NExprF NExprLoc))
forall a. Parser a -> Parser (Ann SrcSpan a)
annotateLocation

manyUnaryOp :: MonadPlus f => f (a -> a) -> f (a -> a)
manyUnaryOp :: f (a -> a) -> f (a -> a)
manyUnaryOp f (a -> a)
f = ((a -> a) -> (a -> a) -> a -> a) -> [a -> a] -> a -> a
forall (t :: * -> *) a. Foldable t => (a -> a -> a) -> t a -> a
foldr1 (a -> a) -> (a -> a) -> a -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) ([a -> a] -> a -> a) -> f [a -> a] -> f (a -> a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> f (a -> a) -> f [a -> a]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some f (a -> a)
f

operator :: Text -> Parser Text
operator :: Text -> Parser Text
operator Text
op =
  case Text
op of
    Text
"-" -> Text -> Char -> Parser Text
tuneLexer Text
"-" Char
'>'
    Text
"/" -> Text -> Char -> Parser Text
tuneLexer Text
"/" Char
'/'
    Text
"<" -> Text -> Char -> Parser Text
tuneLexer Text
"<" Char
'='
    Text
">" -> Text -> Char -> Parser Text
tuneLexer Text
">" Char
'='
    Text
n   -> Text -> Parser Text
symbol Text
n
 where
  tuneLexer :: Text -> Char -> Parser Text
tuneLexer Text
opchar Char
nonextchar =
    Parser Text -> Parser Text
forall a. Parser a -> Parser a
lexeme (Parser Text -> Parser Text)
-> (Parser Text -> Parser Text) -> Parser Text -> Parser Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser Text -> Parser Text
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser Text -> Parser Text) -> Parser Text -> Parser Text
forall a b. (a -> b) -> a -> b
$ Tokens Text -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
string Text
Tokens Text
opchar Parser Text -> Parser () -> Parser Text
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Void Text (State SourcePos) Char -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy (Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
Token s -> m (Token s)
char Char
Token Text
nonextchar)

opWithLoc :: Text -> o -> (Ann SrcSpan o -> a) -> Parser a
opWithLoc :: Text -> o -> (Ann SrcSpan o -> a) -> Parser a
opWithLoc Text
name o
op Ann SrcSpan o -> a
f =
  do
    Ann SrcSpan
ann Text
_ <-
      Parser Text -> Parser (Ann SrcSpan Text)
forall a. Parser a -> Parser (Ann SrcSpan a)
annotateLocation (Parser Text -> Parser (Ann SrcSpan Text))
-> Parser Text -> Parser (Ann SrcSpan Text)
forall a b. (a -> b) -> a -> b
$
        {- dbg (toString name) $ -}
        Text -> Parser Text
operator Text
name

    a -> Parser a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (a -> Parser a) -> a -> Parser a
forall a b. (a -> b) -> a -> b
$ Ann SrcSpan o -> a
f (Ann SrcSpan o -> a) -> Ann SrcSpan o -> a
forall a b. (a -> b) -> a -> b
$ SrcSpan -> o -> Ann SrcSpan o
forall ann a. ann -> a -> Ann ann a
Ann SrcSpan
ann o
op

binaryN :: Text -> NBinaryOp -> (NOperatorDef, Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryN :: Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryN Text
name NBinaryOp
op =
  (Text -> NBinaryOp -> NAssoc -> NOperatorDef
NBinaryDef Text
name NBinaryOp
op NAssoc
NAssocNone, ParsecT
  Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixN (ParsecT
   Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ Text
-> NBinaryOp
-> (Ann SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
forall o a. Text -> o -> (Ann SrcSpan o -> a) -> Parser a
opWithLoc Text
name NBinaryOp
op Ann SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc
nBinary)
binaryL :: Text -> NBinaryOp -> (NOperatorDef, Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL :: Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
name NBinaryOp
op =
  (Text -> NBinaryOp -> NAssoc -> NOperatorDef
NBinaryDef Text
name NBinaryOp
op NAssoc
NAssocLeft, ParsecT
  Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixL (ParsecT
   Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ Text
-> NBinaryOp
-> (Ann SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
forall o a. Text -> o -> (Ann SrcSpan o -> a) -> Parser a
opWithLoc Text
name NBinaryOp
op Ann SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc
nBinary)
binaryR :: Text -> NBinaryOp -> (NOperatorDef, Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryR :: Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryR Text
name NBinaryOp
op =
  (Text -> NBinaryOp -> NAssoc -> NOperatorDef
NBinaryDef Text
name NBinaryOp
op NAssoc
NAssocRight, ParsecT
  Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixR (ParsecT
   Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ Text
-> NBinaryOp
-> (Ann SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
forall o a. Text -> o -> (Ann SrcSpan o -> a) -> Parser a
opWithLoc Text
name NBinaryOp
op Ann SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc
nBinary)
prefix :: Text -> NUnaryOp -> (NOperatorDef, Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
prefix :: Text
-> NUnaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
prefix Text
name NUnaryOp
op =
  (Text -> NUnaryOp -> NOperatorDef
NUnaryDef Text
name NUnaryOp
op, ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a) -> Operator m a
Prefix (ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
forall (f :: * -> *) a. MonadPlus f => f (a -> a) -> f (a -> a)
manyUnaryOp (ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
 -> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc))
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
forall a b. (a -> b) -> a -> b
$ Text
-> NUnaryOp
-> (Ann SrcSpan NUnaryOp -> NExprLoc -> NExprLoc)
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
forall o a. Text -> o -> (Ann SrcSpan o -> a) -> Parser a
opWithLoc Text
name NUnaryOp
op Ann SrcSpan NUnaryOp -> NExprLoc -> NExprLoc
nUnary)
-- postfix name op = (NUnaryDef name op,
--                    Postfix (opWithLoc name op nUnary))

nixOperators
  :: Parser (Ann SrcSpan (NAttrPath NExprLoc))
  -> [[(NOperatorDef, Operator Parser NExprLoc)]]
nixOperators :: Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
nixOperators Parser (Ann SrcSpan (NAttrPath NExprLoc))
selector =
  [ -- This is not parsed here, even though technically it's part of the
    -- expression table. The problem is that in some cases, such as list
    -- membership, it's also a term. And since terms are effectively the
    -- highest precedence entities parsed by the expression parser, it ends up
    -- working out that we parse them as a kind of "meta-term".

    -- {-  1 -} [ (NSpecialDef "." NSelectOp NAssocLeft,
    --             Postfix $ do
    --                    sel <- seldot *> selector
    --                    mor <- optional (reserved "or" *> term)
    --                    pure $ \x -> nSelectLoc x sel mor) ]

    {-  2 -}
    [ ( Text -> NBinaryOp -> NAssoc -> NOperatorDef
NBinaryDef Text
" " NBinaryOp
NApp NAssoc
NAssocLeft
      ,
        -- Thanks to Brent Yorgey for showing me this trick!
        ParsecT
  Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixL (ParsecT
   Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ NExprLoc -> NExprLoc -> NExprLoc
nApp (NExprLoc -> NExprLoc -> NExprLoc)
-> Parser Text
-> ParsecT
     Void Text (State SourcePos) (NExprLoc -> NExprLoc -> NExprLoc)
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser Text
symbol Text
""
      )
    ]
  , {-  3 -}
    [ Text
-> NUnaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
prefix  Text
"-"  NUnaryOp
NNeg ]
  , {-  4 -}
    [ ( Text -> NSpecialOp -> NAssoc -> NOperatorDef
NSpecialDef Text
"?" NSpecialOp
NHasAttrOp NAssoc
NAssocLeft
      , ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a) -> Operator m a
Postfix (ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ Text -> Parser Text
symbol Text
"?" Parser Text
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((NExprLoc -> Ann SrcSpan (NAttrPath NExprLoc) -> NExprLoc)
-> Ann SrcSpan (NAttrPath NExprLoc) -> NExprLoc -> NExprLoc
forall a b c. (a -> b -> c) -> b -> a -> c
flip NExprLoc -> Ann SrcSpan (NAttrPath NExprLoc) -> NExprLoc
nHasAttr (Ann SrcSpan (NAttrPath NExprLoc) -> NExprLoc -> NExprLoc)
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> ParsecT Void Text (State SourcePos) (NExprLoc -> NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser (Ann SrcSpan (NAttrPath NExprLoc))
selector)
      )
    ]
  , {-  5 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryR Text
"++" NBinaryOp
NConcat ]
  , {-  6 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"*"  NBinaryOp
NMult
    , Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"/"  NBinaryOp
NDiv
    ]
  , {-  7 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"+"  NBinaryOp
NPlus
    , Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"-"  NBinaryOp
NMinus
    ]
  , {-  8 -}
    [ Text
-> NUnaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
prefix  Text
"!"  NUnaryOp
NNot ]
  , {-  9 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryR Text
"//" NBinaryOp
NUpdate ]
  , {- 10 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"<"  NBinaryOp
NLt
    , Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
">"  NBinaryOp
NGt
    , Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"<=" NBinaryOp
NLte
    , Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
">=" NBinaryOp
NGte
    ]
  , {- 11 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryN Text
"==" NBinaryOp
NEq
    , Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryN Text
"!=" NBinaryOp
NNEq
    ]
  , {- 12 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"&&" NBinaryOp
NAnd ]
  , {- 13 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryL Text
"||" NBinaryOp
NOr ]
  , {- 14 -}
    [ Text
-> NBinaryOp
-> (NOperatorDef,
    Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
binaryR Text
"->" NBinaryOp
NImpl ]
  ]

data OperatorInfo = OperatorInfo
  { OperatorInfo -> Int
precedence    :: Int
  , OperatorInfo -> NAssoc
associativity :: NAssoc
  , OperatorInfo -> Text
operatorName  :: Text
  } deriving (OperatorInfo -> OperatorInfo -> Bool
(OperatorInfo -> OperatorInfo -> Bool)
-> (OperatorInfo -> OperatorInfo -> Bool) -> Eq OperatorInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OperatorInfo -> OperatorInfo -> Bool
$c/= :: OperatorInfo -> OperatorInfo -> Bool
== :: OperatorInfo -> OperatorInfo -> Bool
$c== :: OperatorInfo -> OperatorInfo -> Bool
Eq, Eq OperatorInfo
Eq OperatorInfo
-> (OperatorInfo -> OperatorInfo -> Ordering)
-> (OperatorInfo -> OperatorInfo -> Bool)
-> (OperatorInfo -> OperatorInfo -> Bool)
-> (OperatorInfo -> OperatorInfo -> Bool)
-> (OperatorInfo -> OperatorInfo -> Bool)
-> (OperatorInfo -> OperatorInfo -> OperatorInfo)
-> (OperatorInfo -> OperatorInfo -> OperatorInfo)
-> Ord OperatorInfo
OperatorInfo -> OperatorInfo -> Bool
OperatorInfo -> OperatorInfo -> Ordering
OperatorInfo -> OperatorInfo -> OperatorInfo
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 :: OperatorInfo -> OperatorInfo -> OperatorInfo
$cmin :: OperatorInfo -> OperatorInfo -> OperatorInfo
max :: OperatorInfo -> OperatorInfo -> OperatorInfo
$cmax :: OperatorInfo -> OperatorInfo -> OperatorInfo
>= :: OperatorInfo -> OperatorInfo -> Bool
$c>= :: OperatorInfo -> OperatorInfo -> Bool
> :: OperatorInfo -> OperatorInfo -> Bool
$c> :: OperatorInfo -> OperatorInfo -> Bool
<= :: OperatorInfo -> OperatorInfo -> Bool
$c<= :: OperatorInfo -> OperatorInfo -> Bool
< :: OperatorInfo -> OperatorInfo -> Bool
$c< :: OperatorInfo -> OperatorInfo -> Bool
compare :: OperatorInfo -> OperatorInfo -> Ordering
$ccompare :: OperatorInfo -> OperatorInfo -> Ordering
$cp1Ord :: Eq OperatorInfo
Ord, (forall x. OperatorInfo -> Rep OperatorInfo x)
-> (forall x. Rep OperatorInfo x -> OperatorInfo)
-> Generic OperatorInfo
forall x. Rep OperatorInfo x -> OperatorInfo
forall x. OperatorInfo -> Rep OperatorInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep OperatorInfo x -> OperatorInfo
$cfrom :: forall x. OperatorInfo -> Rep OperatorInfo x
Generic, Typeable, Typeable OperatorInfo
DataType
Constr
Typeable OperatorInfo
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> OperatorInfo -> c OperatorInfo)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c OperatorInfo)
-> (OperatorInfo -> Constr)
-> (OperatorInfo -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c OperatorInfo))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c OperatorInfo))
-> ((forall b. Data b => b -> b) -> OperatorInfo -> OperatorInfo)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r)
-> (forall u. (forall d. Data d => d -> u) -> OperatorInfo -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> OperatorInfo -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo)
-> Data OperatorInfo
OperatorInfo -> DataType
OperatorInfo -> Constr
(forall b. Data b => b -> b) -> OperatorInfo -> OperatorInfo
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OperatorInfo -> c OperatorInfo
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OperatorInfo
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> OperatorInfo -> u
forall u. (forall d. Data d => d -> u) -> OperatorInfo -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OperatorInfo
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OperatorInfo -> c OperatorInfo
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OperatorInfo)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c OperatorInfo)
$cOperatorInfo :: Constr
$tOperatorInfo :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
gmapMp :: (forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
gmapM :: (forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> OperatorInfo -> m OperatorInfo
gmapQi :: Int -> (forall d. Data d => d -> u) -> OperatorInfo -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> OperatorInfo -> u
gmapQ :: (forall d. Data d => d -> u) -> OperatorInfo -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> OperatorInfo -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> OperatorInfo -> r
gmapT :: (forall b. Data b => b -> b) -> OperatorInfo -> OperatorInfo
$cgmapT :: (forall b. Data b => b -> b) -> OperatorInfo -> OperatorInfo
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c OperatorInfo)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c OperatorInfo)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c OperatorInfo)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c OperatorInfo)
dataTypeOf :: OperatorInfo -> DataType
$cdataTypeOf :: OperatorInfo -> DataType
toConstr :: OperatorInfo -> Constr
$ctoConstr :: OperatorInfo -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OperatorInfo
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c OperatorInfo
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OperatorInfo -> c OperatorInfo
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> OperatorInfo -> c OperatorInfo
$cp1Data :: Typeable OperatorInfo
Data, Int -> OperatorInfo -> String -> String
[OperatorInfo] -> String -> String
OperatorInfo -> String
(Int -> OperatorInfo -> String -> String)
-> (OperatorInfo -> String)
-> ([OperatorInfo] -> String -> String)
-> Show OperatorInfo
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [OperatorInfo] -> String -> String
$cshowList :: [OperatorInfo] -> String -> String
show :: OperatorInfo -> String
$cshow :: OperatorInfo -> String
showsPrec :: Int -> OperatorInfo -> String -> String
$cshowsPrec :: Int -> OperatorInfo -> String -> String
Show)

getUnaryOperator :: NUnaryOp -> OperatorInfo
getUnaryOperator :: NUnaryOp -> OperatorInfo
getUnaryOperator = (Map NUnaryOp OperatorInfo
m Map NUnaryOp OperatorInfo -> NUnaryOp -> OperatorInfo
forall k a. Ord k => Map k a -> k -> a
Map.!)
 where
  m :: Map NUnaryOp OperatorInfo
m =
    [(NUnaryOp, OperatorInfo)] -> Map NUnaryOp OperatorInfo
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(NUnaryOp, OperatorInfo)] -> Map NUnaryOp OperatorInfo)
-> [(NUnaryOp, OperatorInfo)] -> Map NUnaryOp OperatorInfo
forall a b. (a -> b) -> a -> b
$
      [[(NUnaryOp, OperatorInfo)]] -> [(NUnaryOp, OperatorInfo)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[(NUnaryOp, OperatorInfo)]] -> [(NUnaryOp, OperatorInfo)])
-> [[(NUnaryOp, OperatorInfo)]] -> [(NUnaryOp, OperatorInfo)]
forall a b. (a -> b) -> a -> b
$
        (Int
 -> [(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
 -> [(NUnaryOp, OperatorInfo)])
-> [Int]
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
-> [[(NUnaryOp, OperatorInfo)]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith
          Int
-> [(NOperatorDef,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NUnaryOp, OperatorInfo)]
forall (t :: * -> *) b.
Foldable t =>
Int -> t (NOperatorDef, b) -> [(NUnaryOp, OperatorInfo)]
buildEntry
          [Int
1 ..]
          (Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
nixOperators (Parser (Ann SrcSpan (NAttrPath NExprLoc))
 -> [[(NOperatorDef,
       Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]])
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
forall a b. (a -> b) -> a -> b
$ String -> Parser (Ann SrcSpan (NAttrPath NExprLoc))
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"unused")

  buildEntry :: Int -> t (NOperatorDef, b) -> [(NUnaryOp, OperatorInfo)]
buildEntry Int
i =
    ((NOperatorDef, b) -> [(NUnaryOp, OperatorInfo)])
-> t (NOperatorDef, b) -> [(NUnaryOp, OperatorInfo)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (((NOperatorDef, b) -> [(NUnaryOp, OperatorInfo)])
 -> t (NOperatorDef, b) -> [(NUnaryOp, OperatorInfo)])
-> ((NOperatorDef, b) -> [(NUnaryOp, OperatorInfo)])
-> t (NOperatorDef, b)
-> [(NUnaryOp, OperatorInfo)]
forall a b. (a -> b) -> a -> b
$
      \case
        (NUnaryDef Text
name NUnaryOp
op, b
_) -> [(NUnaryOp
op, Int -> NAssoc -> Text -> OperatorInfo
OperatorInfo Int
i NAssoc
NAssocNone Text
name)]
        (NOperatorDef, b)
_                      -> [(NUnaryOp, OperatorInfo)]
forall a. Monoid a => a
mempty

getBinaryOperator :: NBinaryOp -> OperatorInfo
getBinaryOperator :: NBinaryOp -> OperatorInfo
getBinaryOperator = (Map NBinaryOp OperatorInfo
m Map NBinaryOp OperatorInfo -> NBinaryOp -> OperatorInfo
forall k a. Ord k => Map k a -> k -> a
Map.!)
 where
  m :: Map NBinaryOp OperatorInfo
m =
    [(NBinaryOp, OperatorInfo)] -> Map NBinaryOp OperatorInfo
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(NBinaryOp, OperatorInfo)] -> Map NBinaryOp OperatorInfo)
-> [(NBinaryOp, OperatorInfo)] -> Map NBinaryOp OperatorInfo
forall a b. (a -> b) -> a -> b
$
      [[(NBinaryOp, OperatorInfo)]] -> [(NBinaryOp, OperatorInfo)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[(NBinaryOp, OperatorInfo)]] -> [(NBinaryOp, OperatorInfo)])
-> [[(NBinaryOp, OperatorInfo)]] -> [(NBinaryOp, OperatorInfo)]
forall a b. (a -> b) -> a -> b
$
        (Int
 -> [(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
 -> [(NBinaryOp, OperatorInfo)])
-> [Int]
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
-> [[(NBinaryOp, OperatorInfo)]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith
          Int
-> [(NOperatorDef,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NBinaryOp, OperatorInfo)]
forall (t :: * -> *) b.
Foldable t =>
Int -> t (NOperatorDef, b) -> [(NBinaryOp, OperatorInfo)]
buildEntry
          [Int
1 ..]
          (Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
nixOperators (Parser (Ann SrcSpan (NAttrPath NExprLoc))
 -> [[(NOperatorDef,
       Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]])
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
forall a b. (a -> b) -> a -> b
$ String -> Parser (Ann SrcSpan (NAttrPath NExprLoc))
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"unused")

  buildEntry :: Int -> t (NOperatorDef, b) -> [(NBinaryOp, OperatorInfo)]
buildEntry Int
i =
    ((NOperatorDef, b) -> [(NBinaryOp, OperatorInfo)])
-> t (NOperatorDef, b) -> [(NBinaryOp, OperatorInfo)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (((NOperatorDef, b) -> [(NBinaryOp, OperatorInfo)])
 -> t (NOperatorDef, b) -> [(NBinaryOp, OperatorInfo)])
-> ((NOperatorDef, b) -> [(NBinaryOp, OperatorInfo)])
-> t (NOperatorDef, b)
-> [(NBinaryOp, OperatorInfo)]
forall a b. (a -> b) -> a -> b
$
      \case
        (NBinaryDef Text
name NBinaryOp
op NAssoc
assoc, b
_) -> [(NBinaryOp
op, Int -> NAssoc -> Text -> OperatorInfo
OperatorInfo Int
i NAssoc
assoc Text
name)]
        (NOperatorDef, b)
_                             -> [(NBinaryOp, OperatorInfo)]
forall a. Monoid a => a
mempty

getSpecialOperator :: NSpecialOp -> OperatorInfo
getSpecialOperator :: NSpecialOp -> OperatorInfo
getSpecialOperator NSpecialOp
NSelectOp = Int -> NAssoc -> Text -> OperatorInfo
OperatorInfo Int
1 NAssoc
NAssocLeft Text
"."
getSpecialOperator NSpecialOp
o         = Map NSpecialOp OperatorInfo
m Map NSpecialOp OperatorInfo -> NSpecialOp -> OperatorInfo
forall k a. Ord k => Map k a -> k -> a
Map.! NSpecialOp
o
 where
  m :: Map NSpecialOp OperatorInfo
m =
    [(NSpecialOp, OperatorInfo)] -> Map NSpecialOp OperatorInfo
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(NSpecialOp, OperatorInfo)] -> Map NSpecialOp OperatorInfo)
-> [(NSpecialOp, OperatorInfo)] -> Map NSpecialOp OperatorInfo
forall a b. (a -> b) -> a -> b
$
      [[(NSpecialOp, OperatorInfo)]] -> [(NSpecialOp, OperatorInfo)]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[(NSpecialOp, OperatorInfo)]] -> [(NSpecialOp, OperatorInfo)])
-> [[(NSpecialOp, OperatorInfo)]] -> [(NSpecialOp, OperatorInfo)]
forall a b. (a -> b) -> a -> b
$
        (Int
 -> [(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
 -> [(NSpecialOp, OperatorInfo)])
-> [Int]
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
-> [[(NSpecialOp, OperatorInfo)]]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith
          Int
-> [(NOperatorDef,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NSpecialOp, OperatorInfo)]
forall (t :: * -> *) b.
Foldable t =>
Int -> t (NOperatorDef, b) -> [(NSpecialOp, OperatorInfo)]
buildEntry
          [Int
1 ..]
          (Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
nixOperators (Parser (Ann SrcSpan (NAttrPath NExprLoc))
 -> [[(NOperatorDef,
       Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]])
-> Parser (Ann SrcSpan (NAttrPath NExprLoc))
-> [[(NOperatorDef,
      Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]]
forall a b. (a -> b) -> a -> b
$ String -> Parser (Ann SrcSpan (NAttrPath NExprLoc))
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"unused")

  buildEntry :: Int -> t (NOperatorDef, b) -> [(NSpecialOp, OperatorInfo)]
buildEntry Int
i =
    ((NOperatorDef, b) -> [(NSpecialOp, OperatorInfo)])
-> t (NOperatorDef, b) -> [(NSpecialOp, OperatorInfo)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (((NOperatorDef, b) -> [(NSpecialOp, OperatorInfo)])
 -> t (NOperatorDef, b) -> [(NSpecialOp, OperatorInfo)])
-> ((NOperatorDef, b) -> [(NSpecialOp, OperatorInfo)])
-> t (NOperatorDef, b)
-> [(NSpecialOp, OperatorInfo)]
forall a b. (a -> b) -> a -> b
$
      \case
        (NSpecialDef Text
name NSpecialOp
op NAssoc
assoc, b
_) -> [(NSpecialOp
op, Int -> NAssoc -> Text -> OperatorInfo
OperatorInfo Int
i NAssoc
assoc Text
name)]
        (NOperatorDef, b)
_                              -> [(NSpecialOp, OperatorInfo)]
forall a. Monoid a => a
mempty