{-# language CPP #-}
{-# language DeriveAnyClass #-}

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

-- | Main module for parsing Nix expressions.
module Nix.Parser
  ( parseNixFile
  , parseNixFileLoc
  , parseNixText
  , parseNixTextLoc
  , parseExpr
  , parseFromFileEx
  , Parser
  , parseFromText
  , Result
  , reservedNames
  , NAssoc(..)
  , NOpPrecedence(..)
  , NOpName(..)
  , NSpecialOp(..)
  , NOperatorDef(..)
  , nixExpr
  , nixExprAlgebra
  , nixSet
  , nixBinders
  , nixSelector
  , nixSym
  , nixPath
  , nixString
  , nixUri
  , nixSearchPath
  , nixFloat
  , nixInt
  , nixBool
  , nixNull
  , whiteSpace

  --  2022-01-26: NOTE: Try to hide it after OperatorInfo is removed
  , NOp(..)
  , appOpDef
  )
where

import           Nix.Prelude             hiding ( (<|>)
                                                , some
                                                , many
                                                )
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.List.Extra                ( groupSort )
import           Data.Fix                       ( Fix(..) )
import qualified Data.HashSet                  as HashSet
import qualified Data.Text                     as Text
import           Nix.Expr.Types
import           Nix.Expr.Shorthands     hiding ( ($>) )
import           Nix.Expr.Types.Annotated
import           Nix.Expr.Strings               ( escapeCodes
                                                , stripIndent
                                                , mergePlain
                                                , removeEmptyPlains
                                                )
import           Nix.Render                     ( MonadFile() )
import           Prettyprinter                  ( Doc
                                                , pretty
                                                )
-- `parser-combinators` ships performance enhanced & MonadPlus-aware combinators.
-- For example `some` and `many` impoted here.
import           Text.Megaparsec         hiding ( (<|>)
                                                , State
                                                )
import           Text.Megaparsec.Char           ( space1
                                                , letterChar
                                                , char
                                                )
import qualified Text.Megaparsec.Char.Lexer    as Lexer


type Parser = ParsecT Void Text (State SourcePos)

-- * Utils

-- | 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 #-}

-- | Alternative "<|>" with additional preservation of 'MonadPlus' constraint.
infixl 3 <|>
(<|>) :: MonadPlus m => m a -> m a -> m a
<|> :: forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
(<|>) = m a -> m a -> m a
forall a. m a -> m a -> m a
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
mplus

-- ** Annotated

annotateLocation1 :: Parser a -> Parser (AnnUnit SrcSpan a)
annotateLocation1 :: forall a. Parser a -> Parser (AnnUnit SrcSpan a)
annotateLocation1 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 -> AnnUnit SrcSpan a
forall ann expr. ann -> expr -> AnnUnit ann expr
AnnUnit (NSourcePos -> NSourcePos -> SrcSpan
SrcSpan (SourcePos -> NSourcePos
toNSourcePos SourcePos
begin) (SourcePos -> NSourcePos
toNSourcePos SourcePos
end)) a
res

annotateLocation :: Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation :: Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateLocation = (AnnUnit SrcSpan (NExprF NExprLoc) -> NExprLoc
forall ann (f :: * -> *). AnnUnit ann (f (Ann ann f)) -> Ann ann f
annUnitToAnn (AnnUnit SrcSpan (NExprF NExprLoc) -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NExprF NExprLoc))
-> ParsecT Void Text (State SourcePos) NExprLoc
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>) (ParsecT
   Void Text (State SourcePos) (AnnUnit SrcSpan (NExprF NExprLoc))
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> (Parser (NExprF NExprLoc)
    -> ParsecT
         Void Text (State SourcePos) (AnnUnit SrcSpan (NExprF NExprLoc)))
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Parser (NExprF NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NExprF NExprLoc))
forall a. Parser a -> Parser (AnnUnit SrcSpan a)
annotateLocation1

annotateNamedLocation :: String -> Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateNamedLocation :: String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
name = Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateLocation (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc))
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
name


-- ** Grammar

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

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 a. Parser a -> Parser a
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)
chunk Text
Tokens Text
n ParsecT Void Text (State SourcePos) (Tokens Text)
-> Parser () -> Parser ()
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser () -> Parser ()
forall a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (ParsecT Void Text (State SourcePos) (Token Text) -> 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 (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof)

exprAfterSymbol :: Char -> Parser NExprLoc
exprAfterSymbol :: Char -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterSymbol Char
p = Char -> Parser Char
symbol Char
p Parser Char
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) NExprLoc
nixExpr

exprAfterReservedWord :: Text -> Parser NExprLoc
exprAfterReservedWord :: Text -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterReservedWord Text
word = Text -> Parser ()
reserved Text
word Parser ()
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) NExprLoc
nixExpr

-- | A literal copy of @megaparsec@ one but with addition of the @\r@ for Windows EOL case (@\r\n@).
-- Overall, parser should simply @\r\n -> \n@.
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)
chunk Tokens Text
prefix ParsecT Void Text (State SourcePos) (Tokens Text)
-> Parser () -> Parser ()
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) (Tokens 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 a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure String
"character") ((Token Text -> Bool)
 -> ParsecT Void Text (State SourcePos) (Tokens Text))
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Tokens Text)
forall a b. (a -> b) -> a -> b
$ \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' Text
Tokens Text
"#"
  blockCmnt :: Parser ()
blockCmnt = Tokens Text -> Tokens Text -> Parser ()
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> Tokens s -> m ()
Lexer.skipBlockComment Tokens Text
"/*" Tokens Text
"*/"

-- | Lexeme is a unit of the language.
-- Convention is that after lexeme an arbitrary amount of empty entities (space, comments, line breaks) are allowed.
-- This lexeme definition just skips over superflous @megaparsec: lexeme@ abstraction.
lexeme :: Parser a -> Parser a
lexeme :: forall a. Parser a -> Parser a
lexeme Parser a
p = Parser a
p Parser a -> Parser () -> Parser a
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
whiteSpace

symbol :: Char -> Parser Char
symbol :: Char -> Parser Char
symbol = Parser Char -> Parser Char
forall a. Parser a -> Parser a
lexeme (Parser Char -> Parser Char)
-> (Char -> Parser Char) -> Char -> Parser Char
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Char -> Parser 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

symbols :: Text -> Parser Text
symbols :: Text -> ParsecT Void Text (State SourcePos) Text
symbols = ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a. Parser a -> Parser a
lexeme (ParsecT Void Text (State SourcePos) Text
 -> ParsecT Void Text (State SourcePos) Text)
-> (Text -> ParsecT Void Text (State SourcePos) Text)
-> Text
-> ParsecT Void Text (State SourcePos) Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> ParsecT Void Text (State SourcePos) Text
Tokens Text -> ParsecT Void Text (State SourcePos) (Tokens Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Tokens s -> m (Tokens s)
chunk

-- 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 :: forall f. Parser (NExprF f) -> Parser (NExprF f)
parens   = (Parser Char
 -> Parser Char -> Parser (NExprF f) -> Parser (NExprF f))
-> (Char -> Parser Char)
-> Char
-> Char
-> Parser (NExprF f)
-> Parser (NExprF f)
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Parser Char
-> Parser Char -> Parser (NExprF f) -> Parser (NExprF f)
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between Char -> Parser Char
symbol Char
'(' Char
')'

braces :: Parser a -> Parser a
braces :: forall a. Parser a -> Parser a
braces   = (Parser Char -> Parser Char -> Parser a -> Parser a)
-> (Char -> Parser Char) -> Char -> Char -> Parser a -> Parser a
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Parser Char -> Parser Char -> Parser a -> Parser a
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between Char -> Parser Char
symbol Char
'{' Char
'}'

brackets :: Parser (NExprF f) -> Parser (NExprF f)
brackets :: forall f. Parser (NExprF f) -> Parser (NExprF f)
brackets = (Parser Char
 -> Parser Char -> Parser (NExprF f) -> Parser (NExprF f))
-> (Char -> Parser Char)
-> Char
-> Char
-> Parser (NExprF f)
-> Parser (NExprF f)
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Parser Char
-> Parser Char -> Parser (NExprF f) -> Parser (NExprF f)
forall (m :: * -> *) open close a.
Applicative m =>
m open -> m close -> m a -> m a
between Char -> Parser Char
symbol Char
'[' Char
']'

antiquotedIsHungryForTrailingSpaces :: Bool -> Parser (Antiquoted v NExprLoc)
antiquotedIsHungryForTrailingSpaces :: forall v. Bool -> Parser (Antiquoted v NExprLoc)
antiquotedIsHungryForTrailingSpaces Bool
hungry = NExprLoc -> Antiquoted v NExprLoc
forall v r. r -> Antiquoted v r
Antiquoted (NExprLoc -> Antiquoted v NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) (Antiquoted v NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ParsecT Void Text (State SourcePos) Text
antiStart ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) NExprLoc
nixExpr ParsecT Void Text (State SourcePos) NExprLoc
-> Parser Char -> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Char
antiEnd)
 where
  antiStart :: Parser Text
  antiStart :: ParsecT Void Text (State SourcePos) Text
antiStart = String
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"${" (ParsecT Void Text (State SourcePos) Text
 -> ParsecT Void Text (State SourcePos) Text)
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a b. (a -> b) -> a -> b
$ Text -> ParsecT Void Text (State SourcePos) Text
symbols Text
"${"

  antiEnd :: Parser Char
  antiEnd :: Parser Char
antiEnd = String -> Parser Char -> Parser Char
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"}" (Parser Char -> Parser Char) -> Parser Char -> Parser Char
forall a b. (a -> b) -> a -> b
$
    (Parser Char -> Parser Char)
-> (Parser Char -> Parser Char)
-> Bool
-> Parser Char
-> Parser Char
forall a. a -> a -> Bool -> a
bool
      Parser Char -> Parser Char
forall a. a -> a
id
      Parser Char -> Parser Char
forall a. Parser a -> Parser a
lexeme
      Bool
hungry
      (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
'}')

antiquotedLexeme :: Parser (Antiquoted v NExprLoc)
antiquotedLexeme :: forall v. Parser (Antiquoted v NExprLoc)
antiquotedLexeme = Bool -> Parser (Antiquoted v NExprLoc)
forall v. Bool -> Parser (Antiquoted v NExprLoc)
antiquotedIsHungryForTrailingSpaces Bool
True

antiquoted :: Parser (Antiquoted v NExprLoc)
antiquoted :: forall v. Parser (Antiquoted v NExprLoc)
antiquoted = Bool -> Parser (Antiquoted v NExprLoc)
forall v. Bool -> Parser (Antiquoted v NExprLoc)
antiquotedIsHungryForTrailingSpaces Bool
False

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

-- * Parser parts

-- ** Constrants

nixNull :: Parser NExprLoc
nixNull :: ParsecT Void Text (State SourcePos) NExprLoc
nixNull =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"null" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    NExprF NExprLoc
forall a. NExprF a
mkNullF NExprF NExprLoc -> Parser () -> Parser (NExprF NExprLoc)
forall a b.
a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser ()
reserved Text
"null"

nixBool :: Parser NExprLoc
nixBool :: ParsecT Void Text (State SourcePos) NExprLoc
nixBool =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"bool" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    (Parser (NExprF NExprLoc)
 -> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc))
-> ((Bool, Text) -> Parser (NExprF NExprLoc))
-> (Bool, Text)
-> (Bool, Text)
-> Parser (NExprF NExprLoc)
forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
on Parser (NExprF NExprLoc)
-> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
(<|>) (Bool, Text) -> Parser (NExprF NExprLoc)
forall {a}.
(Bool, Text) -> ParsecT Void Text (State SourcePos) (NExprF a)
lmkBool (Bool
True, Text
"true") (Bool
False, Text
"false")
 where
  lmkBool :: (Bool, Text) -> ParsecT Void Text (State SourcePos) (NExprF a)
lmkBool (Bool
b, Text
txt) = Bool -> NExprF a
forall a. Bool -> NExprF a
mkBoolF Bool
b NExprF a
-> Parser () -> ParsecT Void Text (State SourcePos) (NExprF a)
forall a b.
a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> Parser ()
reserved Text
txt

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

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

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

nixFloat :: Parser NExprLoc
nixFloat :: ParsecT Void Text (State SourcePos) NExprLoc
nixFloat =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"float" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a. Parser a -> Parser a
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
$
      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)
-> Parser Double -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Double
float

nixUri :: Parser NExprLoc
nixUri :: ParsecT Void Text (State SourcePos) NExprLoc
nixUri =
  ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a. Parser a -> Parser a
lexeme (ParsecT Void Text (State SourcePos) NExprLoc
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateLocation (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
      Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a. Parser a -> Parser a
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    <- Parser Char
ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
(MonadParsec e s m, Token s ~ Char) =>
m (Token s)
letterChar
          Text
protocol <-
            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 ((Token Text -> Bool)
 -> ParsecT Void Text (State SourcePos) (Tokens Text))
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Tokens 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
          Token Text
_       <- Token Text -> ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *).
MonadParsec e s m =>
Token s -> m (Token s)
single Char
Token Text
':'
          Text
address <-
            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)
takeWhile1P Maybe String
forall a. Monoid a => a
mempty ((Token Text -> Bool)
 -> ParsecT Void Text (State SourcePos) (Tokens Text))
-> (Token Text -> Bool)
-> ParsecT Void Text (State SourcePos) (Tokens 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
          NExprF NExprLoc -> Parser (NExprF NExprLoc)
forall a. a -> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (NExprF NExprLoc -> Parser (NExprF NExprLoc))
-> (Text -> NExprF NExprLoc) -> Text -> Parser (NExprF NExprLoc)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NString NExprLoc -> NExprF NExprLoc
forall r. NString r -> NExprF r
NStr (NString NExprLoc -> NExprF NExprLoc)
-> (Text -> NString NExprLoc) -> Text -> NExprF NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Antiquoted Text NExprLoc] -> NString NExprLoc
forall r. [Antiquoted Text r] -> NString r
DoubleQuoted ([Antiquoted Text NExprLoc] -> NString NExprLoc)
-> (Text -> [Antiquoted Text NExprLoc]) -> Text -> NString NExprLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OneItem [Antiquoted Text NExprLoc] -> [Antiquoted Text NExprLoc]
Antiquoted Text NExprLoc -> [Antiquoted Text NExprLoc]
forall x. One x => OneItem x -> x
one (Antiquoted Text NExprLoc -> [Antiquoted Text NExprLoc])
-> (Text -> Antiquoted Text NExprLoc)
-> Text
-> [Antiquoted Text NExprLoc]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Antiquoted Text NExprLoc
forall v r. v -> Antiquoted v r
Plain (Text -> Parser (NExprF NExprLoc))
-> Text -> Parser (NExprF NExprLoc)
forall a b. (a -> b) -> a -> b
$ Char
start Char -> Text -> Text
`Text.cons` Text
protocol Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
":" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
address


-- ** Strings

nixAntiquoted :: Parser a -> Parser (Antiquoted a NExprLoc)
nixAntiquoted :: forall a. Parser a -> Parser (Antiquoted a NExprLoc)
nixAntiquoted Parser a
p =
  String
-> ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"anti-quotation" (ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
 -> ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc))
-> ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
forall a b. (a -> b) -> a -> b
$
    ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
forall v. Parser (Antiquoted v NExprLoc)
antiquotedLexeme
    ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
-> ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
-> ParsecT Void Text (State SourcePos) (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
-> ParsecT Void Text (State SourcePos) (Antiquoted a NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser a
p

escapeCode :: Parser Char
escapeCode :: Parser Char
escapeCode =
  [Parser Char] -> Parser Char
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, MonadPlus m) =>
t (m a) -> m a
msum
    [ Char
c Char -> Parser Char -> Parser Char
forall a b.
a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
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 ]
  Parser Char -> Parser Char -> Parser Char
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> Parser Char
ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
anySingle

stringChar
  :: Parser ()
  -> Parser ()
  -> Parser (Antiquoted Text NExprLoc)
  -> Parser (Antiquoted Text NExprLoc)
stringChar :: Parser ()
-> Parser ()
-> Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
stringChar Parser ()
end Parser ()
escStart Parser (Antiquoted Text NExprLoc)
esc =
  Parser (Antiquoted Text NExprLoc)
forall v. Parser (Antiquoted v NExprLoc)
antiquoted
  Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
-> Parser (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
OneItem Text -> Text
forall x. One x => OneItem x -> x
one (Char -> Antiquoted Text NExprLoc)
-> Parser Char -> Parser (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
'$'
  Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> Parser (Antiquoted Text NExprLoc)
esc
  Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
-> Parser (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. IsString a => String -> a
fromString (String -> Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) String
-> Parser (Antiquoted Text NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Char -> ParsecT Void Text (State SourcePos) String
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some Parser Char
plainChar
  where
  plainChar :: Parser Char
  plainChar :: Parser Char
plainChar =
    Parser () -> Parser ()
forall a. ParsecT Void Text (State SourcePos) a -> 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
<|> Parser 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 () -> Parser Char -> Parser Char
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Char
ParsecT Void Text (State SourcePos) (Token Text)
forall e s (m :: * -> *). MonadParsec e s m => m (Token s)
anySingle

doubleQuoted :: Parser (NString NExprLoc)
doubleQuoted :: Parser (NString NExprLoc)
doubleQuoted =
  String -> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"double quoted string" (Parser (NString NExprLoc) -> Parser (NString NExprLoc))
-> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a b. (a -> b) -> a -> b
$
    [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]
removeEmptyPlains ([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
<$>
      ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall a. Parser a -> Parser a
inQuotationMarks (Parser (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many (Parser (Antiquoted Text NExprLoc)
 -> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc])
-> Parser (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall a b. (a -> b) -> a -> b
$ Parser ()
-> Parser ()
-> Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
stringChar Parser ()
quotationMark (Parser Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Char -> Parser ()) -> Parser 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
'\\') Parser (Antiquoted Text NExprLoc)
forall r. Parser (Antiquoted Text r)
doubleEscape)
  where
  inQuotationMarks :: Parser a -> Parser a
  inQuotationMarks :: forall a. Parser a -> Parser a
inQuotationMarks Parser a
expr = Parser ()
quotationMark Parser () -> Parser a -> Parser a
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a
expr Parser a -> Parser () -> Parser a
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
quotationMark

  quotationMark :: Parser ()
  quotationMark :: Parser ()
quotationMark = Parser Char -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (Parser Char -> Parser ()) -> Parser 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 :: Parser (Antiquoted Text r)
  doubleEscape :: forall r. Parser (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
OneItem Text -> Text
forall x. One x => OneItem x -> x
one (Char -> Antiquoted Text r)
-> Parser 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
'\\' Parser Char -> Parser Char -> Parser Char
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser Char
escapeCode)


indented :: Parser (NString NExprLoc)
indented :: Parser (NString NExprLoc)
indented =
  String -> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"indented string" (Parser (NString NExprLoc) -> Parser (NString NExprLoc))
-> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a b. (a -> b) -> a -> b
$
    [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
<$>
      ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall a. Parser a -> Parser a
inIndentedQuotation (Parser (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many (Parser (Antiquoted Text NExprLoc)
 -> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc])
-> Parser (Antiquoted Text NExprLoc)
-> ParsecT Void Text (State SourcePos) [Antiquoted Text NExprLoc]
forall a b. (a -> b) -> a -> b
$ (Parser ()
 -> Parser ()
 -> Parser (Antiquoted Text NExprLoc)
 -> Parser (Antiquoted Text NExprLoc))
-> Parser ()
-> Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join Parser ()
-> Parser ()
-> Parser (Antiquoted Text NExprLoc)
-> Parser (Antiquoted Text NExprLoc)
stringChar Parser ()
indentedQuotationMark Parser (Antiquoted Text NExprLoc)
forall r. Parser (Antiquoted Text r)
indentedEscape)
 where
  -- | Read escaping inside of the "'' <expr> ''"
  indentedEscape :: Parser (Antiquoted Text r)
  indentedEscape :: forall r. Parser (Antiquoted Text r)
indentedEscape =
    ParsecT Void Text (State SourcePos) (Antiquoted Text r)
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
forall a. Parser a -> Parser a
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 ()
indentedQuotationMark
        Text -> Antiquoted Text r
forall v r. v -> Antiquoted v r
Plain (Text -> Antiquoted Text r)
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) (Antiquoted Text r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Text
"''" Text -> Parser Char -> ParsecT Void Text (State SourcePos) Text
forall a b.
a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
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) Text
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> Text
"$" Text -> Parser Char -> ParsecT Void Text (State SourcePos) Text
forall a b.
a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
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
c <- 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 Char -> Parser Char -> Parser Char
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser 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
$ OneItem Text -> Text
forall x. One x => OneItem x -> x
one Char
OneItem Text
c)
                  (Char
'\n' Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
c)

  -- | Enclosed into indented quatation "'' <expr> ''"
  inIndentedQuotation :: Parser a -> Parser a
  inIndentedQuotation :: forall a. Parser a -> Parser a
inIndentedQuotation Parser a
expr = Parser ()
indentedQuotationMark Parser () -> Parser a -> Parser a
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser a
expr Parser a -> Parser () -> Parser a
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
indentedQuotationMark

  -- | Symbol "''"
  indentedQuotationMark :: Parser ()
  indentedQuotationMark :: Parser ()
indentedQuotationMark = String -> Parser () -> Parser ()
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"\"''\"" (Parser () -> Parser ())
-> (ParsecT Void Text (State SourcePos) (Tokens Text) -> Parser ())
-> ParsecT Void Text (State SourcePos) (Tokens Text)
-> Parser ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT Void Text (State SourcePos) (Tokens Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Void Text (State SourcePos) (Tokens Text) -> Parser ())
-> ParsecT Void Text (State SourcePos) (Tokens Text) -> 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)
chunk Tokens Text
"''"


nixString' :: Parser (NString NExprLoc)
nixString' :: Parser (NString NExprLoc)
nixString' = String -> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"string" (Parser (NString NExprLoc) -> Parser (NString NExprLoc))
-> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a b. (a -> b) -> a -> b
$ Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a. Parser a -> Parser a
lexeme (Parser (NString NExprLoc) -> Parser (NString NExprLoc))
-> Parser (NString NExprLoc) -> Parser (NString NExprLoc)
forall a b. (a -> b) -> a -> b
$ 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

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


-- ** Names (variables aka symbols)

identifier :: Parser VarName
identifier :: Parser VarName
identifier =
  Parser VarName -> Parser VarName
forall a. Parser a -> Parser a
lexeme (Parser VarName -> Parser VarName)
-> Parser VarName -> Parser VarName
forall a b. (a -> b) -> a -> b
$
    Parser VarName -> Parser VarName
forall a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser VarName -> Parser VarName)
-> Parser VarName -> Parser VarName
forall a b. (a -> b) -> a -> b
$
      do
        (Text -> VarName
forall a b. Coercible a b => a -> b
coerce -> VarName
iD) <-
          (Char -> Text -> Text)
-> Parser Char
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Char -> Text -> 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
$ VarName
iD VarName -> HashSet VarName -> Bool
forall a. (Eq a, Hashable a) => a -> HashSet a -> Bool
`HashSet.member` HashSet VarName
reservedNames
        pure VarName
iD
 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
'-'

nixSym :: Parser NExprLoc
nixSym :: ParsecT Void Text (State SourcePos) NExprLoc
nixSym = Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateLocation (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$ Text -> NExprF NExprLoc
forall a. Text -> NExprF a
mkSymF (Text -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) Text
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser VarName -> ParsecT Void Text (State SourcePos) Text
forall a b. Coercible a b => a -> b
coerce Parser VarName
identifier


-- ** ( ) parens

-- | 'nixExpr' 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 :: ParsecT Void Text (State SourcePos) NExprLoc
nixParens =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"parens" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall f. Parser (NExprF f) -> Parser (NExprF f)
parens (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc))
-> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a b. (a -> b) -> a -> b
$ AnnF SrcSpan NExprF NExprLoc -> NExprF NExprLoc
forall ann (f :: * -> *) r. AnnF ann f r -> f r
stripAnnF (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)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text (State SourcePos) NExprLoc
nixExpr


-- ** [ ] list

nixList :: Parser NExprLoc
nixList :: ParsecT Void Text (State SourcePos) NExprLoc
nixList =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"list" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall f. Parser (NExprF f) -> Parser (NExprF f)
brackets (Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc))
-> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a b. (a -> b) -> a -> b
$ [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
<$> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) [NExprLoc]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many ParsecT Void Text (State SourcePos) NExprLoc
nixTerm


-- ** { } set

nixBinders :: Parser [Binding NExprLoc]
nixBinders :: Parser [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 Char -> Parser [Binding NExprLoc]
forall (m :: * -> *) a sep. MonadPlus m => m a -> m sep -> m [a]
`endBy` Char -> Parser Char
symbol Char
';' 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 a. Parser a -> Parser a
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)
chunk Tokens Text
"inherit" ParsecT Void Text (State SourcePos) (Tokens Text)
-> Parser () -> Parser ()
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser () -> Parser ()
forall a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead (ParsecT Void Text (State SourcePos) (Token Text) -> Parser ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (ParsecT Void Text (State SourcePos) (Token Text) -> Parser ())
-> ParsecT Void Text (State SourcePos) (Token Text) -> Parser ()
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
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 a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional ParsecT Void Text (State SourcePos) NExprLoc
scope
      String
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"inherited binding" (ParsecT Void Text (State SourcePos) (Binding NExprLoc)
 -> ParsecT Void Text (State SourcePos) (Binding NExprLoc))
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall a b. (a -> b) -> a -> b
$
        ([VarName] -> NSourcePos -> Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) [VarName]
-> ParsecT Void Text (State SourcePos) NSourcePos
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (Maybe NExprLoc -> [VarName] -> NSourcePos -> Binding NExprLoc
forall r. Maybe r -> [VarName] -> NSourcePos -> Binding r
Inherit Maybe NExprLoc
x)
          (Parser VarName -> ParsecT Void Text (State SourcePos) [VarName]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
many Parser VarName
identifier)
          (NSourcePos -> ParsecT Void Text (State SourcePos) NSourcePos
forall a. a -> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SourcePos -> NSourcePos
toNSourcePos SourcePos
p))
  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
      String
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"variable binding" (ParsecT Void Text (State SourcePos) (Binding NExprLoc)
 -> ParsecT Void Text (State SourcePos) (Binding NExprLoc))
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) (Binding NExprLoc)
forall a b. (a -> b) -> a -> b
$
        (NAttrPath NExprLoc -> NExprLoc -> NSourcePos -> Binding NExprLoc)
-> ParsecT Void Text (State SourcePos) (NAttrPath NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NSourcePos
-> 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 -> NSourcePos -> Binding NExprLoc
forall r. NAttrPath r -> r -> NSourcePos -> Binding r
NamedVar
          (AnnUnit SrcSpan (NAttrPath NExprLoc) -> NAttrPath NExprLoc
forall ann expr. AnnUnit ann expr -> expr
annotated (AnnUnit SrcSpan (NAttrPath NExprLoc) -> NAttrPath NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
-> ParsecT Void Text (State SourcePos) (NAttrPath NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
nixSelector)
          (Char -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterSymbol Char
'=')
          (NSourcePos -> ParsecT Void Text (State SourcePos) NSourcePos
forall a. a -> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SourcePos -> NSourcePos
toNSourcePos SourcePos
p))
  scope :: ParsecT Void Text (State SourcePos) NExprLoc
scope = String
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"inherit scope" ParsecT Void Text (State SourcePos) NExprLoc
nixParens

nixSet :: Parser NExprLoc
nixSet :: ParsecT Void Text (State SourcePos) NExprLoc
nixSet =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"set" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    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)
-> Parser [Binding NExprLoc] -> Parser (NExprF NExprLoc)
forall a b.
ParsecT Void Text (State SourcePos) (a -> b)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser [Binding NExprLoc] -> Parser [Binding NExprLoc]
forall a. Parser a -> Parser a
braces Parser [Binding NExprLoc]
nixBinders
 where
  isRec :: ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
isRec =
    String
-> ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
-> ParsecT Void Text (State SourcePos) ([Binding r] -> NExprF r)
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"recursive set" (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
$> Recursivity -> [Binding r] -> NExprF r
forall r. Recursivity -> [Binding r] -> NExprF r
NSet Recursivity
Recursive)
    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 a. a -> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Recursivity -> [Binding r] -> NExprF r
forall r. Recursivity -> [Binding r] -> NExprF r
NSet Recursivity
forall a. Monoid a => a
mempty)

-- ** /x/y/z literal Path

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 :: Parser Char
slash =
  String -> Parser Char -> Parser Char
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"slash " (Parser Char -> Parser Char) -> Parser Char -> Parser Char
forall a b. (a -> b) -> a -> b
$
    Parser Char -> Parser Char
forall a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Parser Char -> Parser Char) -> Parser Char -> Parser Char
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
'/' Parser Char -> Parser () -> Parser Char
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Void Text (State SourcePos) (Token Text) -> Parser ()
forall a. ParsecT Void Text (State SourcePos) a -> 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 -> 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
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)

pathStr :: Parser Path
pathStr :: Parser Path
pathStr =
  Parser Path -> Parser Path
forall a. Parser a -> Parser a
lexeme (Parser Path -> Parser Path) -> Parser Path -> Parser Path
forall a b. (a -> b) -> a -> b
$ String -> Path
forall a b. Coercible a b => a -> b
coerce (String -> Path) -> (Text -> String) -> Text -> Path
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
forall a. ToString a => a -> String
toString (Text -> Path)
-> ParsecT Void Text (State SourcePos) Text -> Parser Path
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    (Text -> Text -> Text)
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
(<>)
      (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
pathChar)
      ([Text] -> Text
Text.concat ([Text] -> Text)
-> ParsecT Void Text (State SourcePos) [Text]
-> ParsecT Void Text (State SourcePos) Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
        ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) [Text]
forall (m :: * -> *) a. MonadPlus m => m a -> m [a]
some
          ((Char -> Text -> Text)
-> Parser Char
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 Char -> Text -> Text
Text.cons
            Parser Char
slash
            (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)
takeWhile1P Maybe String
forall a. Monoid a => a
mempty Char -> Bool
Token Text -> Bool
pathChar)
          )
      )

nixPath :: Parser NExprLoc
nixPath :: ParsecT Void Text (State SourcePos) NExprLoc
nixPath =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"path" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a. Parser a -> Parser a
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
$ 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
<$> Parser Path -> ParsecT Void Text (State SourcePos) String
forall a b. Coercible a b => a -> b
coerce Parser Path
pathStr


-- ** <<x>> environment path

-- | 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 :: ParsecT Void Text (State SourcePos) NExprLoc
nixSearchPath =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"spath" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    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 a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (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
$ 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 Char
-> ParsecT Void Text (State SourcePos) String
-> ParsecT Void Text (State SourcePos) String
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser 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 Parser Char -> Parser Char -> Parser Char
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> Parser Char
slash) ParsecT Void Text (State SourcePos) String
-> Parser Char -> ParsecT Void Text (State SourcePos) String
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
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
'>')


-- ** Operators

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

instance IsString NOpName where
  fromString :: String -> NOpName
fromString = Text -> NOpName
forall a b. Coercible a b => a -> b
coerce (Text -> NOpName) -> (String -> Text) -> String -> NOpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
fromString @Text

instance ToString NOpName where
  toString :: NOpName -> String
toString = forall a. ToString a => a -> String
toString @Text (Text -> String) -> (NOpName -> Text) -> NOpName -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NOpName -> Text
forall a b. Coercible a b => a -> b
coerce

operator :: NOpName -> Parser Text
operator :: NOpName -> ParsecT Void Text (State SourcePos) Text
operator (NOpName -> Text
forall a b. Coercible a b => a -> b
coerce -> Text
op) =
  case Text
op of
    c :: Text
c@Text
"-" -> Text
c Text -> Char -> ParsecT Void Text (State SourcePos) Text
`without` Char
'>'
    c :: Text
c@Text
"/" -> Text
c Text -> Char -> ParsecT Void Text (State SourcePos) Text
`without` Char
'/'
    c :: Text
c@Text
"<" -> Text
c Text -> Char -> ParsecT Void Text (State SourcePos) Text
`without` Char
'='
    c :: Text
c@Text
">" -> Text
c Text -> Char -> ParsecT Void Text (State SourcePos) Text
`without` Char
'='
    Text
n   -> Text -> ParsecT Void Text (State SourcePos) Text
symbols Text
n
 where
  without :: Text -> Char -> Parser Text
  without :: Text -> Char -> ParsecT Void Text (State SourcePos) Text
without Text
opChar Char
noNextChar =
    ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a. Parser a -> Parser a
lexeme (ParsecT Void Text (State SourcePos) Text
 -> ParsecT Void Text (State SourcePos) Text)
-> (ParsecT Void Text (State SourcePos) Text
    -> ParsecT Void Text (State SourcePos) Text)
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) Text
forall a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (ParsecT Void Text (State SourcePos) Text
 -> ParsecT Void Text (State SourcePos) Text)
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) 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)
chunk Text
Tokens Text
opChar ParsecT Void Text (State SourcePos) Text
-> Parser () -> ParsecT Void Text (State SourcePos) Text
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser Char -> Parser ()
forall a. ParsecT Void Text (State SourcePos) a -> 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 :: (AnnUnit SrcSpan o -> a) -> o -> NOpName -> Parser a
opWithLoc :: forall o a. (AnnUnit SrcSpan o -> a) -> o -> NOpName -> Parser a
opWithLoc AnnUnit SrcSpan o -> a
f o
op NOpName
name = AnnUnit SrcSpan o -> a
f (AnnUnit SrcSpan o -> a)
-> (AnnUnit SrcSpan Text -> AnnUnit SrcSpan o)
-> AnnUnit SrcSpan Text
-> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (o
op o -> AnnUnit SrcSpan Text -> AnnUnit SrcSpan o
forall a b. a -> AnnUnit SrcSpan b -> AnnUnit SrcSpan a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$) (AnnUnit SrcSpan Text -> a)
-> ParsecT Void Text (State SourcePos) (AnnUnit SrcSpan Text)
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text (State SourcePos) Text
-> ParsecT Void Text (State SourcePos) (AnnUnit SrcSpan Text)
forall a. Parser a -> Parser (AnnUnit SrcSpan a)
annotateLocation1 (NOpName -> ParsecT Void Text (State SourcePos) Text
operator NOpName
name)

--  2022-01-26: NOTE: Make presedence free and type safe by moving it into type level:
--  https://youtu.be/qaPdg0mZavM?t=1757
--  https://wiki.haskell.org/The_Monad.Reader/Issue5/Number_Param_Types
newtype NOpPrecedence = NOpPrecedence Int
  deriving (NOpPrecedence -> NOpPrecedence -> Bool
(NOpPrecedence -> NOpPrecedence -> Bool)
-> (NOpPrecedence -> NOpPrecedence -> Bool) -> Eq NOpPrecedence
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NOpPrecedence -> NOpPrecedence -> Bool
== :: NOpPrecedence -> NOpPrecedence -> Bool
$c/= :: NOpPrecedence -> NOpPrecedence -> Bool
/= :: NOpPrecedence -> NOpPrecedence -> Bool
Eq, Eq NOpPrecedence
Eq NOpPrecedence =>
(NOpPrecedence -> NOpPrecedence -> Ordering)
-> (NOpPrecedence -> NOpPrecedence -> Bool)
-> (NOpPrecedence -> NOpPrecedence -> Bool)
-> (NOpPrecedence -> NOpPrecedence -> Bool)
-> (NOpPrecedence -> NOpPrecedence -> Bool)
-> (NOpPrecedence -> NOpPrecedence -> NOpPrecedence)
-> (NOpPrecedence -> NOpPrecedence -> NOpPrecedence)
-> Ord NOpPrecedence
NOpPrecedence -> NOpPrecedence -> Bool
NOpPrecedence -> NOpPrecedence -> Ordering
NOpPrecedence -> NOpPrecedence -> NOpPrecedence
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
$ccompare :: NOpPrecedence -> NOpPrecedence -> Ordering
compare :: NOpPrecedence -> NOpPrecedence -> Ordering
$c< :: NOpPrecedence -> NOpPrecedence -> Bool
< :: NOpPrecedence -> NOpPrecedence -> Bool
$c<= :: NOpPrecedence -> NOpPrecedence -> Bool
<= :: NOpPrecedence -> NOpPrecedence -> Bool
$c> :: NOpPrecedence -> NOpPrecedence -> Bool
> :: NOpPrecedence -> NOpPrecedence -> Bool
$c>= :: NOpPrecedence -> NOpPrecedence -> Bool
>= :: NOpPrecedence -> NOpPrecedence -> Bool
$cmax :: NOpPrecedence -> NOpPrecedence -> NOpPrecedence
max :: NOpPrecedence -> NOpPrecedence -> NOpPrecedence
$cmin :: NOpPrecedence -> NOpPrecedence -> NOpPrecedence
min :: NOpPrecedence -> NOpPrecedence -> NOpPrecedence
Ord, (forall x. NOpPrecedence -> Rep NOpPrecedence x)
-> (forall x. Rep NOpPrecedence x -> NOpPrecedence)
-> Generic NOpPrecedence
forall x. Rep NOpPrecedence x -> NOpPrecedence
forall x. NOpPrecedence -> Rep NOpPrecedence x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NOpPrecedence -> Rep NOpPrecedence x
from :: forall x. NOpPrecedence -> Rep NOpPrecedence x
$cto :: forall x. Rep NOpPrecedence x -> NOpPrecedence
to :: forall x. Rep NOpPrecedence x -> NOpPrecedence
Generic, NOpPrecedence
NOpPrecedence -> NOpPrecedence -> Bounded NOpPrecedence
forall a. a -> a -> Bounded a
$cminBound :: NOpPrecedence
minBound :: NOpPrecedence
$cmaxBound :: NOpPrecedence
maxBound :: NOpPrecedence
Bounded, Typeable, Typeable NOpPrecedence
Typeable NOpPrecedence =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> NOpPrecedence -> c NOpPrecedence)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NOpPrecedence)
-> (NOpPrecedence -> Constr)
-> (NOpPrecedence -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NOpPrecedence))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c NOpPrecedence))
-> ((forall b. Data b => b -> b) -> NOpPrecedence -> NOpPrecedence)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r)
-> (forall u. (forall d. Data d => d -> u) -> NOpPrecedence -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NOpPrecedence -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence)
-> Data NOpPrecedence
NOpPrecedence -> Constr
NOpPrecedence -> DataType
(forall b. Data b => b -> b) -> NOpPrecedence -> NOpPrecedence
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) -> NOpPrecedence -> u
forall u. (forall d. Data d => d -> u) -> NOpPrecedence -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOpPrecedence
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOpPrecedence -> c NOpPrecedence
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NOpPrecedence)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOpPrecedence)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOpPrecedence -> c NOpPrecedence
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOpPrecedence -> c NOpPrecedence
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOpPrecedence
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOpPrecedence
$ctoConstr :: NOpPrecedence -> Constr
toConstr :: NOpPrecedence -> Constr
$cdataTypeOf :: NOpPrecedence -> DataType
dataTypeOf :: NOpPrecedence -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NOpPrecedence)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NOpPrecedence)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOpPrecedence)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOpPrecedence)
$cgmapT :: (forall b. Data b => b -> b) -> NOpPrecedence -> NOpPrecedence
gmapT :: (forall b. Data b => b -> b) -> NOpPrecedence -> NOpPrecedence
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NOpPrecedence -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NOpPrecedence -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NOpPrecedence -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NOpPrecedence -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NOpPrecedence -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOpPrecedence -> m NOpPrecedence
Data, Int -> NOpPrecedence -> String -> String
[NOpPrecedence] -> String -> String
NOpPrecedence -> String
(Int -> NOpPrecedence -> String -> String)
-> (NOpPrecedence -> String)
-> ([NOpPrecedence] -> String -> String)
-> Show NOpPrecedence
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> NOpPrecedence -> String -> String
showsPrec :: Int -> NOpPrecedence -> String -> String
$cshow :: NOpPrecedence -> String
show :: NOpPrecedence -> String
$cshowList :: [NOpPrecedence] -> String -> String
showList :: [NOpPrecedence] -> String -> String
Show, NOpPrecedence -> ()
(NOpPrecedence -> ()) -> NFData NOpPrecedence
forall a. (a -> ()) -> NFData a
$crnf :: NOpPrecedence -> ()
rnf :: NOpPrecedence -> ()
NFData)

instance Enum NOpPrecedence where
  toEnum :: Int -> NOpPrecedence
toEnum = Int -> NOpPrecedence
forall a b. Coercible a b => a -> b
coerce
  fromEnum :: NOpPrecedence -> Int
fromEnum = NOpPrecedence -> Int
forall a b. Coercible a b => a -> b
coerce

instance Num NOpPrecedence where
  + :: NOpPrecedence -> NOpPrecedence -> NOpPrecedence
(+) = (Int -> Int -> Int)
-> NOpPrecedence -> NOpPrecedence -> NOpPrecedence
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a -> a
(+) @Int)
  * :: NOpPrecedence -> NOpPrecedence -> NOpPrecedence
(*) = (Int -> Int -> Int)
-> NOpPrecedence -> NOpPrecedence -> NOpPrecedence
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a -> a
(*) @Int)
  abs :: NOpPrecedence -> NOpPrecedence
abs = (Int -> Int) -> NOpPrecedence -> NOpPrecedence
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
abs @Int)
  signum :: NOpPrecedence -> NOpPrecedence
signum = (Int -> Int) -> NOpPrecedence -> NOpPrecedence
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
signum @Int)
  fromInteger :: Integer -> NOpPrecedence
fromInteger = (Integer -> Int) -> Integer -> NOpPrecedence
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => Integer -> a
fromInteger @Int)
  negate :: NOpPrecedence -> NOpPrecedence
negate = (Int -> Int) -> NOpPrecedence -> NOpPrecedence
forall a b. Coercible a b => a -> b
coerce (forall a. Num a => a -> a
negate @Int)

--  2022-01-26: NOTE: This type belongs into 'Type.Expr' & be used in NExprF.
data NAppOp = NAppOp
  deriving (NAppOp -> NAppOp -> Bool
(NAppOp -> NAppOp -> Bool)
-> (NAppOp -> NAppOp -> Bool) -> Eq NAppOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NAppOp -> NAppOp -> Bool
== :: NAppOp -> NAppOp -> Bool
$c/= :: NAppOp -> NAppOp -> Bool
/= :: NAppOp -> NAppOp -> Bool
Eq, Eq NAppOp
Eq NAppOp =>
(NAppOp -> NAppOp -> Ordering)
-> (NAppOp -> NAppOp -> Bool)
-> (NAppOp -> NAppOp -> Bool)
-> (NAppOp -> NAppOp -> Bool)
-> (NAppOp -> NAppOp -> Bool)
-> (NAppOp -> NAppOp -> NAppOp)
-> (NAppOp -> NAppOp -> NAppOp)
-> Ord NAppOp
NAppOp -> NAppOp -> Bool
NAppOp -> NAppOp -> Ordering
NAppOp -> NAppOp -> NAppOp
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
$ccompare :: NAppOp -> NAppOp -> Ordering
compare :: NAppOp -> NAppOp -> Ordering
$c< :: NAppOp -> NAppOp -> Bool
< :: NAppOp -> NAppOp -> Bool
$c<= :: NAppOp -> NAppOp -> Bool
<= :: NAppOp -> NAppOp -> Bool
$c> :: NAppOp -> NAppOp -> Bool
> :: NAppOp -> NAppOp -> Bool
$c>= :: NAppOp -> NAppOp -> Bool
>= :: NAppOp -> NAppOp -> Bool
$cmax :: NAppOp -> NAppOp -> NAppOp
max :: NAppOp -> NAppOp -> NAppOp
$cmin :: NAppOp -> NAppOp -> NAppOp
min :: NAppOp -> NAppOp -> NAppOp
Ord, (forall x. NAppOp -> Rep NAppOp x)
-> (forall x. Rep NAppOp x -> NAppOp) -> Generic NAppOp
forall x. Rep NAppOp x -> NAppOp
forall x. NAppOp -> Rep NAppOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. NAppOp -> Rep NAppOp x
from :: forall x. NAppOp -> Rep NAppOp x
$cto :: forall x. Rep NAppOp x -> NAppOp
to :: forall x. Rep NAppOp x -> NAppOp
Generic, Typeable, Typeable NAppOp
Typeable NAppOp =>
(forall (c :: * -> *).
 (forall d b. Data d => c (d -> b) -> d -> c b)
 -> (forall g. g -> c g) -> NAppOp -> c NAppOp)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c NAppOp)
-> (NAppOp -> Constr)
-> (NAppOp -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c NAppOp))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAppOp))
-> ((forall b. Data b => b -> b) -> NAppOp -> NAppOp)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NAppOp -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NAppOp -> r)
-> (forall u. (forall d. Data d => d -> u) -> NAppOp -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> NAppOp -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> NAppOp -> m NAppOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NAppOp -> m NAppOp)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> NAppOp -> m NAppOp)
-> Data NAppOp
NAppOp -> Constr
NAppOp -> DataType
(forall b. Data b => b -> b) -> NAppOp -> NAppOp
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) -> NAppOp -> u
forall u. (forall d. Data d => d -> u) -> NAppOp -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NAppOp -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NAppOp -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAppOp
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAppOp -> c NAppOp
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NAppOp)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAppOp)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAppOp -> c NAppOp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAppOp -> c NAppOp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAppOp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAppOp
$ctoConstr :: NAppOp -> Constr
toConstr :: NAppOp -> Constr
$cdataTypeOf :: NAppOp -> DataType
dataTypeOf :: NAppOp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NAppOp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NAppOp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAppOp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAppOp)
$cgmapT :: (forall b. Data b => b -> b) -> NAppOp -> NAppOp
gmapT :: (forall b. Data b => b -> b) -> NAppOp -> NAppOp
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NAppOp -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NAppOp -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NAppOp -> r
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NAppOp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NAppOp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NAppOp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NAppOp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NAppOp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAppOp -> m NAppOp
Data, Int -> NAppOp -> String -> String
[NAppOp] -> String -> String
NAppOp -> String
(Int -> NAppOp -> String -> String)
-> (NAppOp -> String)
-> ([NAppOp] -> String -> String)
-> Show NAppOp
forall a.
(Int -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
$cshowsPrec :: Int -> NAppOp -> String -> String
showsPrec :: Int -> NAppOp -> String -> String
$cshow :: NAppOp -> String
show :: NAppOp -> String
$cshowList :: [NAppOp] -> String -> String
showList :: [NAppOp] -> String -> String
Show, NAppOp -> ()
(NAppOp -> ()) -> NFData NAppOp
forall a. (a -> ()) -> NFData a
$crnf :: NAppOp -> ()
rnf :: NAppOp -> ()
NFData)

--  2022-01-26: NOTE: This type belongs into 'Type.Expr' & be used in NExprF.
data NSpecialOp
  = NHasAttrOp
  | NSelectOp
  | NTerm -- ^ For special handling of internal special cases.
  deriving (NSpecialOp -> NSpecialOp -> Bool
(NSpecialOp -> NSpecialOp -> Bool)
-> (NSpecialOp -> NSpecialOp -> Bool) -> Eq NSpecialOp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NSpecialOp -> NSpecialOp -> Bool
== :: NSpecialOp -> NSpecialOp -> Bool
$c/= :: NSpecialOp -> NSpecialOp -> Bool
/= :: 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
$ccompare :: NSpecialOp -> NSpecialOp -> Ordering
compare :: NSpecialOp -> NSpecialOp -> Ordering
$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
>= :: NSpecialOp -> NSpecialOp -> Bool
$cmax :: NSpecialOp -> NSpecialOp -> NSpecialOp
max :: NSpecialOp -> NSpecialOp -> NSpecialOp
$cmin :: NSpecialOp -> NSpecialOp -> NSpecialOp
min :: NSpecialOp -> NSpecialOp -> 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
$cfrom :: forall x. NSpecialOp -> Rep NSpecialOp x
from :: forall x. NSpecialOp -> Rep NSpecialOp x
$cto :: forall x. Rep NSpecialOp x -> NSpecialOp
to :: forall x. Rep NSpecialOp x -> NSpecialOp
Generic, Typeable, Typeable NSpecialOp
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 -> Constr
NSpecialOp -> DataType
(forall b. Data b => b -> b) -> NSpecialOp -> 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)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NSpecialOp -> c NSpecialOp
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NSpecialOp -> c NSpecialOp
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NSpecialOp
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NSpecialOp
$ctoConstr :: NSpecialOp -> Constr
toConstr :: NSpecialOp -> Constr
$cdataTypeOf :: NSpecialOp -> DataType
dataTypeOf :: NSpecialOp -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NSpecialOp)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NSpecialOp)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NSpecialOp)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NSpecialOp)
$cgmapT :: (forall b. Data b => b -> b) -> NSpecialOp -> NSpecialOp
gmapT :: (forall b. Data b => b -> b) -> NSpecialOp -> NSpecialOp
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
gmapQl :: forall r r'.
(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
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NSpecialOp -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NSpecialOp -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NSpecialOp -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NSpecialOp -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NSpecialOp -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NSpecialOp -> m NSpecialOp
gmapM :: forall (m :: * -> *).
Monad m =>
(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
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(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
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NSpecialOp -> m 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
$cshowsPrec :: Int -> NSpecialOp -> String -> String
showsPrec :: Int -> NSpecialOp -> String -> String
$cshow :: NSpecialOp -> String
show :: NSpecialOp -> String
$cshowList :: [NSpecialOp] -> String -> String
showList :: [NSpecialOp] -> String -> String
Show, NSpecialOp -> ()
(NSpecialOp -> ()) -> NFData NSpecialOp
forall a. (a -> ()) -> NFData a
$crnf :: NSpecialOp -> ()
rnf :: NSpecialOp -> ()
NFData)

data NAssoc
  = NAssocLeft
  -- Nota bene: @parser-combinators@ named "associative property" as 'InfixN' stating it as "non-associative property".
  -- Binary operators having some associativity is a basis property in mathematical algebras in use (for example, in Category theory). Having no associativity in operators makes theory mostly impossible in use and so non-associativity is not encountered in notations, therefore under 'InfixN' @parser-combinators@ meant "associative".
  -- | Bidirectional associativity, or simply: associative property.
  | NAssoc
  | NAssocRight
  deriving (NAssoc -> NAssoc -> Bool
(NAssoc -> NAssoc -> Bool)
-> (NAssoc -> NAssoc -> Bool) -> Eq NAssoc
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NAssoc -> NAssoc -> Bool
== :: NAssoc -> NAssoc -> Bool
$c/= :: NAssoc -> NAssoc -> Bool
/= :: 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
$ccompare :: NAssoc -> NAssoc -> Ordering
compare :: NAssoc -> NAssoc -> Ordering
$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
>= :: NAssoc -> NAssoc -> Bool
$cmax :: NAssoc -> NAssoc -> NAssoc
max :: NAssoc -> NAssoc -> NAssoc
$cmin :: NAssoc -> NAssoc -> NAssoc
min :: NAssoc -> NAssoc -> 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
$cfrom :: forall x. NAssoc -> Rep NAssoc x
from :: forall x. NAssoc -> Rep NAssoc x
$cto :: forall x. Rep NAssoc x -> NAssoc
to :: forall x. Rep NAssoc x -> NAssoc
Generic, Typeable, Typeable NAssoc
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 -> Constr
NAssoc -> DataType
(forall b. Data b => b -> b) -> NAssoc -> 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)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAssoc -> c NAssoc
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NAssoc -> c NAssoc
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAssoc
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NAssoc
$ctoConstr :: NAssoc -> Constr
toConstr :: NAssoc -> Constr
$cdataTypeOf :: NAssoc -> DataType
dataTypeOf :: NAssoc -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NAssoc)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NAssoc)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAssoc)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c NAssoc)
$cgmapT :: (forall b. Data b => b -> b) -> NAssoc -> NAssoc
gmapT :: (forall b. Data b => b -> b) -> NAssoc -> NAssoc
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
gmapQl :: forall r r'.
(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
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> NAssoc -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NAssoc -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NAssoc -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NAssoc -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NAssoc -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NAssoc -> m NAssoc
gmapM :: forall (m :: * -> *).
Monad m =>
(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
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(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
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NAssoc -> m 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
$cshowsPrec :: Int -> NAssoc -> String -> String
showsPrec :: Int -> NAssoc -> String -> String
$cshow :: NAssoc -> String
show :: NAssoc -> String
$cshowList :: [NAssoc] -> String -> String
showList :: [NAssoc] -> String -> String
Show, NAssoc -> ()
(NAssoc -> ()) -> NFData NAssoc
forall a. (a -> ()) -> NFData a
$crnf :: NAssoc -> ()
rnf :: NAssoc -> ()
NFData)

--  2022-01-31: NOTE: This type and related typeclasses & their design, probably need a refinement.
--
-- In the "Nix.Pretty", the code probably should be well-typed to the type of operations its processes.
-- Therefor splitting operation types into separate types there is probably needed.
--
-- After that:
--
-- > { NAssoc, NOpPrecedence, NOpName }
--
-- Can be formed into a type.
--
-- Also 'NAppDef' really has only 1 implementation, @{ NAssoc, NOpPrecedence, NOpName }@
-- were added there only to make type uniformal.
-- All impossible cases ideally should be unrepresentable.
-- | Single operator grammar entries.
data NOperatorDef
  = NAppDef     NAppOp     NAssoc NOpPrecedence NOpName
  | NUnaryDef   NUnaryOp   NAssoc NOpPrecedence NOpName
  | NBinaryDef  NBinaryOp  NAssoc NOpPrecedence NOpName
  | NSpecialDef NSpecialOp NAssoc NOpPrecedence NOpName
  --  2022-01-26: NOTE: Ord can be the order of evaluation of precedence (which 'Pretty' printing also accounts for).
  deriving (NOperatorDef -> NOperatorDef -> Bool
(NOperatorDef -> NOperatorDef -> Bool)
-> (NOperatorDef -> NOperatorDef -> Bool) -> Eq NOperatorDef
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: NOperatorDef -> NOperatorDef -> Bool
== :: NOperatorDef -> NOperatorDef -> Bool
$c/= :: NOperatorDef -> NOperatorDef -> Bool
/= :: 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
$ccompare :: NOperatorDef -> NOperatorDef -> Ordering
compare :: NOperatorDef -> NOperatorDef -> Ordering
$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
>= :: NOperatorDef -> NOperatorDef -> Bool
$cmax :: NOperatorDef -> NOperatorDef -> NOperatorDef
max :: NOperatorDef -> NOperatorDef -> NOperatorDef
$cmin :: NOperatorDef -> NOperatorDef -> NOperatorDef
min :: NOperatorDef -> NOperatorDef -> 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
$cfrom :: forall x. NOperatorDef -> Rep NOperatorDef x
from :: forall x. NOperatorDef -> Rep NOperatorDef x
$cto :: forall x. Rep NOperatorDef x -> NOperatorDef
to :: forall x. Rep NOperatorDef x -> NOperatorDef
Generic, Typeable, Typeable NOperatorDef
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 -> Constr
NOperatorDef -> DataType
(forall b. Data b => b -> b) -> NOperatorDef -> 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)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOperatorDef -> c NOperatorDef
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NOperatorDef -> c NOperatorDef
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOperatorDef
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c NOperatorDef
$ctoConstr :: NOperatorDef -> Constr
toConstr :: NOperatorDef -> Constr
$cdataTypeOf :: NOperatorDef -> DataType
dataTypeOf :: NOperatorDef -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NOperatorDef)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c NOperatorDef)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOperatorDef)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c NOperatorDef)
$cgmapT :: (forall b. Data b => b -> b) -> NOperatorDef -> NOperatorDef
gmapT :: (forall b. Data b => b -> b) -> NOperatorDef -> NOperatorDef
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
gmapQl :: forall r r'.
(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
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NOperatorDef -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> NOperatorDef -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> NOperatorDef -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NOperatorDef -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> NOperatorDef -> u
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> NOperatorDef -> m NOperatorDef
gmapM :: forall (m :: * -> *).
Monad m =>
(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
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(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
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> NOperatorDef -> m 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
$cshowsPrec :: Int -> NOperatorDef -> String -> String
showsPrec :: Int -> NOperatorDef -> String -> String
$cshow :: NOperatorDef -> String
show :: NOperatorDef -> String
$cshowList :: [NOperatorDef] -> String -> String
showList :: [NOperatorDef] -> String -> String
Show, NOperatorDef -> ()
(NOperatorDef -> ()) -> NFData NOperatorDef
forall a. (a -> ()) -> NFData a
$crnf :: NOperatorDef -> ()
rnf :: NOperatorDef -> ()
NFData)

-- Supplied since its definition gets called/used frequently.
-- | Functional application operator definition, left associative, high precedence.
appOpDef :: NOperatorDef
appOpDef :: NOperatorDef
appOpDef = NAppOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NAppDef NAppOp
NAppOp NAssoc
NAssocLeft NOpPrecedence
1 NOpName
" " -- This defined as "2" in Nix lang spec.

--  2022-01-26: NOTE: When total - make sure to hide & inline all these instances to get free solution.
-- | Class to get a private free construction to abstract away the gap between the Nix operation types
-- 'NUnaryOp', 'NBinaryOp', 'NSpecialOp'.
-- And in doing remove 'OperatorInfo' from existance.
class NOp a where
  {-# minimal getOpDef, getOpAssoc, getOpPrecedence, getOpName #-}

  getOpDef :: a -> NOperatorDef
  getOpAssoc :: a -> NAssoc
  getOpPrecedence :: a -> NOpPrecedence
  getOpName :: a -> NOpName

instance NOp NAppOp where
  getOpDef :: NAppOp -> NOperatorDef
getOpDef NAppOp
NAppOp = NOperatorDef
appOpDef
  getOpAssoc :: NAppOp -> NAssoc
getOpAssoc NAppOp
_op = NOperatorDef -> NAssoc
fun NOperatorDef
appOpDef
   where
    fun :: NOperatorDef -> NAssoc
fun (NAppDef NAppOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) = NAssoc
assoc
    fun NOperatorDef
_ = Text -> NAssoc
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, funapp operation should been matched."
  getOpPrecedence :: NAppOp -> NOpPrecedence
getOpPrecedence NAppOp
_op = NOperatorDef -> NOpPrecedence
fun NOperatorDef
appOpDef
   where
    fun :: NOperatorDef -> NOpPrecedence
fun (NAppDef NAppOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
    fun NOperatorDef
_ = Text -> NOpPrecedence
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, funapp operation should been matched."
  getOpName :: NAppOp -> NOpName
getOpName NAppOp
_ = NOperatorDef -> NOpName
fun NOperatorDef
appOpDef
   where
    fun :: NOperatorDef -> NOpName
fun (NAppDef NAppOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name
    fun NOperatorDef
_ = Text -> NOpName
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, funapp operation should been matched."

instance NOp NUnaryOp where
  getOpDef :: NUnaryOp -> NOperatorDef
getOpDef =
    \case
      NUnaryOp
NNeg -> NUnaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NUnaryDef NUnaryOp
NNeg NAssoc
NAssocRight NOpPrecedence
3 NOpName
"-"
      NUnaryOp
NNot -> NUnaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NUnaryDef NUnaryOp
NNot NAssoc
NAssocRight NOpPrecedence
8 NOpName
"!"
  getOpAssoc :: NUnaryOp -> NAssoc
getOpAssoc = NOperatorDef -> NAssoc
fun (NOperatorDef -> NAssoc)
-> (NUnaryOp -> NOperatorDef) -> NUnaryOp -> NAssoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NUnaryOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NAssoc
fun (NUnaryDef NUnaryOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) = NAssoc
assoc
    fun NOperatorDef
_ = Text -> NAssoc
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, unary operation should been matched."
  getOpPrecedence :: NUnaryOp -> NOpPrecedence
getOpPrecedence = NOperatorDef -> NOpPrecedence
fun (NOperatorDef -> NOpPrecedence)
-> (NUnaryOp -> NOperatorDef) -> NUnaryOp -> NOpPrecedence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NUnaryOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpPrecedence
fun (NUnaryDef NUnaryOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
    fun NOperatorDef
_ = Text -> NOpPrecedence
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, unary operation should been matched."
  getOpName :: NUnaryOp -> NOpName
getOpName = NOperatorDef -> NOpName
fun (NOperatorDef -> NOpName)
-> (NUnaryOp -> NOperatorDef) -> NUnaryOp -> NOpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NUnaryOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpName
fun (NUnaryDef NUnaryOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name
    fun NOperatorDef
_ = Text -> NOpName
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, unary operation should been matched."

instance NOp NBinaryOp where
  getOpDef :: NBinaryOp -> NOperatorDef
getOpDef =
    \case
      NBinaryOp
NConcat -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NConcat NAssoc
NAssocRight  NOpPrecedence
5 NOpName
"++"
      NBinaryOp
NMult   -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NMult   NAssoc
NAssocLeft   NOpPrecedence
6 NOpName
"*"
      NBinaryOp
NDiv    -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NDiv    NAssoc
NAssocLeft   NOpPrecedence
6 NOpName
"/"
      NBinaryOp
NPlus   -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NPlus   NAssoc
NAssocLeft   NOpPrecedence
7 NOpName
"+"
      NBinaryOp
NMinus  -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NMinus  NAssoc
NAssocLeft   NOpPrecedence
7 NOpName
"-"
      NBinaryOp
NUpdate -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NUpdate NAssoc
NAssocRight  NOpPrecedence
9 NOpName
"//"
      NBinaryOp
NLt     -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NLt     NAssoc
NAssocLeft  NOpPrecedence
10 NOpName
"<"
      NBinaryOp
NLte    -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NLte    NAssoc
NAssocLeft  NOpPrecedence
10 NOpName
"<="
      NBinaryOp
NGt     -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NGt     NAssoc
NAssocLeft  NOpPrecedence
10 NOpName
">"
      NBinaryOp
NGte    -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NGte    NAssoc
NAssocLeft  NOpPrecedence
10 NOpName
">="
      NBinaryOp
NEq     -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NEq     NAssoc
NAssoc      NOpPrecedence
11 NOpName
"=="
      NBinaryOp
NNEq    -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NNEq    NAssoc
NAssoc      NOpPrecedence
11 NOpName
"!="
      NBinaryOp
NAnd    -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NAnd    NAssoc
NAssocLeft  NOpPrecedence
12 NOpName
"&&"
      NBinaryOp
NOr     -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NOr     NAssoc
NAssocLeft  NOpPrecedence
13 NOpName
"||"
      NBinaryOp
NImpl   -> NBinaryOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NBinaryDef NBinaryOp
NImpl   NAssoc
NAssocRight NOpPrecedence
14 NOpName
"->"
  getOpAssoc :: NBinaryOp -> NAssoc
getOpAssoc = NOperatorDef -> NAssoc
fun (NOperatorDef -> NAssoc)
-> (NBinaryOp -> NOperatorDef) -> NBinaryOp -> NAssoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NBinaryOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NAssoc
fun (NBinaryDef NBinaryOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) = NAssoc
assoc
    fun NOperatorDef
_ = Text -> NAssoc
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, binary operation should been matched."
  getOpPrecedence :: NBinaryOp -> NOpPrecedence
getOpPrecedence = NOperatorDef -> NOpPrecedence
fun (NOperatorDef -> NOpPrecedence)
-> (NBinaryOp -> NOperatorDef) -> NBinaryOp -> NOpPrecedence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NBinaryOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpPrecedence
fun (NBinaryDef NBinaryOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
    fun NOperatorDef
_ = Text -> NOpPrecedence
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, binary operation should been matched."
  getOpName :: NBinaryOp -> NOpName
getOpName = NOperatorDef -> NOpName
fun (NOperatorDef -> NOpName)
-> (NBinaryOp -> NOperatorDef) -> NBinaryOp -> NOpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NBinaryOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpName
fun (NBinaryDef NBinaryOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name
    fun NOperatorDef
_ = Text -> NOpName
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, binary operation should been matched."

instance NOp NSpecialOp where
  getOpDef :: NSpecialOp -> NOperatorDef
getOpDef =
    \case
      NSpecialOp
NSelectOp  -> NSpecialOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NSpecialDef NSpecialOp
NSelectOp  NAssoc
NAssocLeft NOpPrecedence
1 NOpName
"."
      NSpecialOp
NHasAttrOp -> NSpecialOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NSpecialDef NSpecialOp
NHasAttrOp NAssoc
NAssocLeft NOpPrecedence
4 NOpName
"?"
      NSpecialOp
NTerm      -> NSpecialOp -> NAssoc -> NOpPrecedence -> NOpName -> NOperatorDef
NSpecialDef NSpecialOp
NTerm      NAssoc
NAssocLeft NOpPrecedence
1 NOpName
"???"
  getOpAssoc :: NSpecialOp -> NAssoc
getOpAssoc = NOperatorDef -> NAssoc
fun (NOperatorDef -> NAssoc)
-> (NSpecialOp -> NOperatorDef) -> NSpecialOp -> NAssoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NSpecialOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NAssoc
fun (NSpecialDef NSpecialOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) = NAssoc
assoc
    fun NOperatorDef
_ = Text -> NAssoc
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, special operation should been matched."
  getOpPrecedence :: NSpecialOp -> NOpPrecedence
getOpPrecedence = NOperatorDef -> NOpPrecedence
fun (NOperatorDef -> NOpPrecedence)
-> (NSpecialOp -> NOperatorDef) -> NSpecialOp -> NOpPrecedence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NSpecialOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpPrecedence
fun (NSpecialDef NSpecialOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
    fun NOperatorDef
_ = Text -> NOpPrecedence
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, special operation should been matched."
  getOpName :: NSpecialOp -> NOpName
getOpName = NOperatorDef -> NOpName
fun (NOperatorDef -> NOpName)
-> (NSpecialOp -> NOperatorDef) -> NSpecialOp -> NOpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NSpecialOp -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpName
fun (NSpecialDef NSpecialOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name
    fun NOperatorDef
_ = Text -> NOpName
forall a t. (HasCallStack, IsText t) => t -> a
error Text
"Impossible happened, special operation should been matched."

instance NOp NOperatorDef where
  getOpDef :: NOperatorDef -> NOperatorDef
getOpDef NOperatorDef
op = NOperatorDef
op
  getOpAssoc :: NOperatorDef -> NAssoc
getOpAssoc = \case
    (NAppDef     NAppOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) -> NAssoc
assoc
    (NUnaryDef   NUnaryOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) -> NAssoc
assoc
    (NBinaryDef  NBinaryOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) -> NAssoc
assoc
    (NSpecialDef NSpecialOp
_op NAssoc
assoc NOpPrecedence
_prec NOpName
_name) -> NAssoc
assoc
  getOpPrecedence :: NOperatorDef -> NOpPrecedence
getOpPrecedence = NOperatorDef -> NOpPrecedence
fun (NOperatorDef -> NOpPrecedence)
-> (NOperatorDef -> NOperatorDef) -> NOperatorDef -> NOpPrecedence
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NOperatorDef -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpPrecedence
fun (NAppDef     NAppOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
    fun (NUnaryDef   NUnaryOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
    fun (NBinaryDef  NBinaryOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
    fun (NSpecialDef NSpecialOp
_op NAssoc
_assoc NOpPrecedence
prec NOpName
_name) = NOpPrecedence
prec
  getOpName :: NOperatorDef -> NOpName
getOpName = NOperatorDef -> NOpName
fun (NOperatorDef -> NOpName)
-> (NOperatorDef -> NOperatorDef) -> NOperatorDef -> NOpName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NOperatorDef -> NOperatorDef
forall a. NOp a => a -> NOperatorDef
getOpDef
   where
    fun :: NOperatorDef -> NOpName
fun (NAppDef     NAppOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name
    fun (NUnaryDef   NUnaryOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name
    fun (NBinaryDef  NBinaryOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name
    fun (NSpecialDef NSpecialOp
_op NAssoc
_assoc NOpPrecedence
_prec NOpName
name) = NOpName
name

prefix :: NUnaryOp -> Operator Parser NExprLoc
prefix :: NUnaryOp -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
prefix NUnaryOp
op =
  Parser (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a) -> Operator m a
Prefix (Parser (NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> Parser (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ Parser (NExprLoc -> NExprLoc) -> Parser (NExprLoc -> NExprLoc)
forall (f :: * -> *) a. MonadPlus f => f (a -> a) -> f (a -> a)
manyUnaryOp (Parser (NExprLoc -> NExprLoc) -> Parser (NExprLoc -> NExprLoc))
-> Parser (NExprLoc -> NExprLoc) -> Parser (NExprLoc -> NExprLoc)
forall a b. (a -> b) -> a -> b
$ (AnnUnit SrcSpan NUnaryOp -> NExprLoc -> NExprLoc)
-> NUnaryOp -> NOpName -> Parser (NExprLoc -> NExprLoc)
forall o a. (AnnUnit SrcSpan o -> a) -> o -> NOpName -> Parser a
opWithLoc AnnUnit SrcSpan NUnaryOp -> NExprLoc -> NExprLoc
annNUnary NUnaryOp
op (NOpName -> Parser (NExprLoc -> NExprLoc))
-> NOpName -> Parser (NExprLoc -> NExprLoc)
forall a b. (a -> b) -> a -> b
$ NUnaryOp -> NOpName
forall a. NOp a => a -> NOpName
getOpName NUnaryOp
op
-- postfix name op = (NUnaryDef name op,
--                    Postfix (opWithLoc annNUnary op name))

manyUnaryOp :: MonadPlus f => f (a -> a) -> f (a -> a)
manyUnaryOp :: forall (f :: * -> *) a. MonadPlus f => f (a -> a) -> f (a -> a)
manyUnaryOp f (a -> a)
f = ((a -> a) -> (a -> a) -> a -> a) -> [a -> a] -> a -> a
forall 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

binary
  :: NBinaryOp
  -> Operator Parser NExprLoc
binary :: NBinaryOp
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
binary NBinaryOp
op =
  NAssoc
-> Parser (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. NAssoc -> m (a -> a -> a) -> Operator m a
mapAssocToInfix (NBinaryOp -> NAssoc
forall a. NOp a => a -> NAssoc
getOpAssoc NBinaryOp
op) (Parser (NExprLoc -> NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> Parser (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ (AnnUnit SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc)
-> NBinaryOp
-> NOpName
-> Parser (NExprLoc -> NExprLoc -> NExprLoc)
forall o a. (AnnUnit SrcSpan o -> a) -> o -> NOpName -> Parser a
opWithLoc AnnUnit SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc
annNBinary NBinaryOp
op (NBinaryOp -> NOpName
forall a. NOp a => a -> NOpName
getOpName NBinaryOp
op)

mapAssocToInfix :: NAssoc -> m (a -> a -> a) -> Operator m a
mapAssocToInfix :: forall (m :: * -> *) a. NAssoc -> m (a -> a -> a) -> Operator m a
mapAssocToInfix NAssoc
NAssocLeft  = m (a -> a -> a) -> Operator m a
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixL
mapAssocToInfix NAssoc
NAssoc      = m (a -> a -> a) -> Operator m a
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixN
mapAssocToInfix NAssoc
NAssocRight = m (a -> a -> a) -> Operator m a
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixR

-- ** x: y lambda function

-- | 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 Char -> Parser (Params NExprLoc)
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> Parser Char
symbol Char
':'
 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
      [ ParsecT Void Text (State SourcePos) NExprLoc
nixUri ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) (Params r)
-> ParsecT Void Text (State SourcePos) (Params r)
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
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 (Token Text)
forall t. NonEmpty Char -> ErrorItem t
Label (NonEmpty Char -> ErrorItem (Token Text))
-> NonEmpty Char -> ErrorItem (Token Text)
forall a b. (a -> b) -> a -> b
$ [Item (NonEmpty Char)] -> NonEmpty Char
forall l. IsList l => [Item l] -> l
fromList String
[Item (NonEmpty Char)]
"valid uri" )
      , VarName -> Params r
forall r. VarName -> Params r
Param (VarName -> Params r)
-> Parser VarName -> ParsecT Void Text (State SourcePos) (Params r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser VarName
identifier
      ]

  -- Parameters named by an identifier on the left (`args @ {x, y}`)
  atLeft :: Parser (Params NExprLoc)
atLeft =
    Parser (Params NExprLoc) -> Parser (Params NExprLoc)
forall a. Parser a -> Parser a
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
        VarName
name             <- Parser VarName
identifier Parser VarName -> Parser Char -> Parser VarName
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Char -> Parser Char
symbol Char
'@'
        (Variadic
variadic, [(VarName, Maybe NExprLoc)]
pset) <- ParsecT
  Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
params
        pure $ Maybe VarName
-> Variadic -> [(VarName, Maybe NExprLoc)] -> Params NExprLoc
forall r. Maybe VarName -> Variadic -> ParamSet r -> Params r
ParamSet (VarName -> Maybe VarName
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure VarName
name) Variadic
variadic [(VarName, Maybe NExprLoc)]
pset

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

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

  -- Collects the parameters within curly braces. Returns the parameters and
  -- an flag indication if the parameters are variadic.
  getParams :: Parser (Variadic, [(VarName, Maybe NExprLoc)])
  getParams :: ParsecT
  Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
getParams = [(VarName, Maybe NExprLoc)]
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
go [(VarName, 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 :: [(VarName, Maybe NExprLoc)] -> Parser (Variadic, [(VarName, Maybe NExprLoc)])
    go :: [(VarName, Maybe NExprLoc)]
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
go [(VarName, Maybe NExprLoc)]
acc = ((Variadic
Variadic, [(VarName, Maybe NExprLoc)]
acc) (Variadic, [(VarName, Maybe NExprLoc)])
-> ParsecT Void Text (State SourcePos) Text
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
forall a b.
a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> ParsecT Void Text (State SourcePos) Text
symbols Text
"...") ParsecT
  Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> ParsecT
  Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
getMore
     where
      getMore :: Parser (Variadic, [(VarName, Maybe NExprLoc)])
      getMore :: ParsecT
  Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
getMore =
        -- Could be nothing, in which just return what we have so far.
        (Variadic, [(VarName, Maybe NExprLoc)])
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
forall (m :: * -> *) a. Alternative m => a -> m a -> m a
option (Variadic
forall a. Monoid a => a
mempty, [(VarName, Maybe NExprLoc)]
acc) (ParsecT
   Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
 -> ParsecT
      Void
      Text
      (State SourcePos)
      (Variadic, [(VarName, Maybe NExprLoc)]))
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
-> ParsecT
     Void Text (State SourcePos) (Variadic, [(VarName, Maybe NExprLoc)])
forall a b. (a -> b) -> a -> b
$
          do
            -- Get an argument name and an optional default.
            (VarName, Maybe NExprLoc)
pair <-
              (VarName -> Maybe NExprLoc -> (VarName, Maybe NExprLoc))
-> Parser VarName
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
-> ParsecT Void Text (State SourcePos) (VarName, Maybe NExprLoc)
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 (,)
                Parser VarName
identifier
                (ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT Void Text (State SourcePos) NExprLoc
 -> ParsecT Void Text (State SourcePos) (Maybe NExprLoc))
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall a b. (a -> b) -> a -> b
$ Char -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterSymbol Char
'?')

            let args :: [(VarName, Maybe NExprLoc)]
args = [(VarName, Maybe NExprLoc)]
acc [(VarName, Maybe NExprLoc)]
-> [(VarName, Maybe NExprLoc)] -> [(VarName, Maybe NExprLoc)]
forall a. Semigroup a => a -> a -> a
<> OneItem [(VarName, Maybe NExprLoc)] -> [(VarName, Maybe NExprLoc)]
forall x. One x => OneItem x -> x
one (VarName, Maybe NExprLoc)
OneItem [(VarName, Maybe NExprLoc)]
pair

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

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


-- ** let expression

nixLet :: Parser NExprLoc
nixLet :: ParsecT Void Text (State SourcePos) NExprLoc
nixLet =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"let block" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    Text -> Parser ()
reserved Text
"let" Parser () -> Parser (NExprF NExprLoc) -> Parser (NExprF NExprLoc)
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
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)
 where
  -- | Expressions `let {..., body = ...}' are just desugared
  -- into `(rec {..., body = ...}).body'.
  letBody :: Parser (NExprF NExprLoc)
letBody    = (\ NExprLoc
expr -> Maybe NExprLoc -> NExprLoc -> NAttrPath NExprLoc -> NExprF NExprLoc
forall r. Maybe r -> r -> NAttrPath r -> NExprF r
NSelect Maybe NExprLoc
forall a. Maybe a
Nothing NExprLoc
expr (OneItem (NAttrPath NExprLoc) -> NAttrPath NExprLoc
forall x. One x => OneItem x -> x
one (OneItem (NAttrPath NExprLoc) -> NAttrPath NExprLoc)
-> OneItem (NAttrPath NExprLoc) -> NAttrPath NExprLoc
forall a b. (a -> b) -> a -> b
$ VarName -> NKeyName NExprLoc
forall r. VarName -> NKeyName r
StaticKey VarName
"body")) (NExprLoc -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT Void Text (State SourcePos) NExprLoc
attrset
   where
    attrset :: ParsecT Void Text (State SourcePos) NExprLoc
attrset       = Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateLocation (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$ Recursivity -> [Binding NExprLoc] -> NExprF NExprLoc
forall r. Recursivity -> [Binding r] -> NExprF r
NSet Recursivity
Recursive ([Binding NExprLoc] -> NExprF NExprLoc)
-> Parser [Binding NExprLoc] -> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser [Binding NExprLoc] -> Parser [Binding NExprLoc]
forall a. Parser a -> Parser a
braces Parser [Binding NExprLoc]
nixBinders
  -- | Regular `let`
  letBinders :: Parser (NExprF NExprLoc)
letBinders =
    ([Binding NExprLoc] -> NExprLoc -> NExprF NExprLoc)
-> Parser [Binding NExprLoc]
-> ParsecT Void Text (State SourcePos) NExprLoc
-> Parser (NExprF NExprLoc)
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
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
      Parser [Binding NExprLoc]
nixBinders
      (Text -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterReservedWord Text
"in")

-- ** if then else

nixIf :: Parser NExprLoc
nixIf :: ParsecT Void Text (State SourcePos) NExprLoc
nixIf =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"if" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    (NExprLoc -> NExprLoc -> NExprLoc -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) 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 ()
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) NExprLoc
nixExpr)
      (Text -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterReservedWord Text
"then")
      (Text -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterReservedWord Text
"else")

-- ** with

nixWith :: Parser NExprLoc
nixWith :: ParsecT Void Text (State SourcePos) NExprLoc
nixWith =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"with" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    (NExprLoc -> NExprLoc -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> Parser (NExprF NExprLoc)
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
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 -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterReservedWord Text
"with")
      (Char -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterSymbol       Char
';'   )


-- ** assert

nixAssert :: Parser NExprLoc
nixAssert :: ParsecT Void Text (State SourcePos) NExprLoc
nixAssert =
  String
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateNamedLocation String
"assert" (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$
    (NExprLoc -> NExprLoc -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> Parser (NExprF NExprLoc)
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
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 -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterReservedWord Text
"assert")
      (Char -> ParsecT Void Text (State SourcePos) NExprLoc
exprAfterSymbol       Char
';'     )

-- ** . - reference (selector) into attr

selectorDot :: Parser ()
selectorDot :: Parser ()
selectorDot = String -> Parser () -> Parser ()
forall a.
String
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) a
forall e s (m :: * -> *) a.
MonadParsec e s m =>
String -> m a -> m a
label String
"." (Parser () -> Parser ()) -> Parser () -> Parser ()
forall a b. (a -> b) -> a -> b
$ Parser () -> Parser ()
forall a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
try (Char -> Parser Char
symbol Char
'.' Parser Char -> Parser () -> Parser ()
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) NExprLoc -> Parser ()
forall a. ParsecT Void Text (State SourcePos) a -> Parser ()
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m ()
notFollowedBy ParsecT Void Text (State SourcePos) NExprLoc
nixPath)

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  = VarName -> NKeyName r
forall r. VarName -> NKeyName r
StaticKey (VarName -> NKeyName r)
-> Parser VarName
-> ParsecT Void Text (State SourcePos) (NKeyName r)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser VarName
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'

nixSelector :: Parser (AnnUnit SrcSpan (NAttrPath NExprLoc))
nixSelector :: ParsecT
  Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
nixSelector =
  ParsecT Void Text (State SourcePos) (NAttrPath NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
forall a. Parser a -> Parser (AnnUnit SrcSpan a)
annotateLocation1 (ParsecT Void Text (State SourcePos) (NAttrPath NExprLoc)
 -> ParsecT
      Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc)))
-> ParsecT Void Text (State SourcePos) (NAttrPath NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
forall a b. (a -> b) -> a -> b
$ [Item (NAttrPath NExprLoc)] -> NAttrPath NExprLoc
[NKeyName NExprLoc] -> NAttrPath NExprLoc
forall l. IsList l => [Item l] -> l
fromList ([NKeyName NExprLoc] -> NAttrPath NExprLoc)
-> ParsecT Void Text (State SourcePos) [NKeyName NExprLoc]
-> ParsecT Void Text (State SourcePos) (NAttrPath NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> 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 ()
selectorDot

nixSelect :: Parser NExprLoc -> Parser NExprLoc
nixSelect :: ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
nixSelect ParsecT Void Text (State SourcePos) NExprLoc
term =
  do
    NExprLoc
res <-
      (NExprLoc
 -> Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
 -> NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc)))
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 NExprLoc
-> Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
-> NExprLoc
builder
        ParsecT Void Text (State SourcePos) NExprLoc
term
        (ParsecT
  Void
  Text
  (State SourcePos)
  (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc)))
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT
   Void
   Text
   (State SourcePos)
   (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
 -> ParsecT
      Void
      Text
      (State SourcePos)
      (Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))))
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc)))
forall a b. (a -> b) -> a -> b
$
          (AnnUnit SrcSpan (NAttrPath NExprLoc)
 -> Maybe NExprLoc
 -> (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc)))
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
-> ParsecT
     Void
     Text
     (State SourcePos)
     (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
forall a b c.
(a -> b -> c)
-> ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 ((Maybe NExprLoc
 -> AnnUnit SrcSpan (NAttrPath NExprLoc)
 -> (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc)))
-> AnnUnit SrcSpan (NAttrPath NExprLoc)
-> Maybe NExprLoc
-> (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
forall a b c. (a -> b -> c) -> b -> a -> c
flip (,))
            (Parser ()
selectorDot Parser ()
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT
  Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
nixSelector)
            (ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (ParsecT Void Text (State SourcePos) NExprLoc
 -> ParsecT Void Text (State SourcePos) (Maybe NExprLoc))
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) (Maybe NExprLoc)
forall a b. (a -> b) -> a -> b
$ Text -> Parser ()
reserved Text
"or" Parser ()
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) 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 a. Parser a -> Parser a
forall e s (m :: * -> *) a. MonadParsec e s m => m a -> m a
lookAhead Parser ()
selectorDot

    (ParsecT Void Text (State SourcePos) NExprLoc
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> (()
    -> ParsecT Void Text (State SourcePos) NExprLoc
    -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Maybe ()
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a. a -> a
id
      ((ParsecT Void Text (State SourcePos) NExprLoc
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> ()
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. a -> b -> a
const ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
nixSelect)
      Maybe ()
continues
      (NExprLoc -> ParsecT Void Text (State SourcePos) NExprLoc
forall a. a -> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure NExprLoc
res)
 where
  builder
    :: NExprLoc
    -> Maybe
      ( Maybe NExprLoc
      , AnnUnit SrcSpan (NAttrPath NExprLoc)
      )
    -> NExprLoc
  builder :: NExprLoc
-> Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
-> NExprLoc
builder NExprLoc
t =
    NExprLoc
-> ((Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
    -> NExprLoc)
-> Maybe (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
-> NExprLoc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
      NExprLoc
t
      ((Maybe NExprLoc
 -> AnnUnit SrcSpan (NAttrPath NExprLoc) -> NExprLoc)
-> (Maybe NExprLoc, AnnUnit SrcSpan (NAttrPath NExprLoc))
-> NExprLoc
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry (Maybe NExprLoc
-> NExprLoc -> AnnUnit SrcSpan (NAttrPath NExprLoc) -> NExprLoc
`annNSelect` NExprLoc
t))


-- ** _ - syntax hole

nixSynHole :: Parser NExprLoc
nixSynHole :: ParsecT Void Text (State SourcePos) NExprLoc
nixSynHole =
  Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
annotateLocation (Parser (NExprF NExprLoc)
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Parser (NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b. (a -> b) -> a -> b
$ Text -> NExprF NExprLoc
forall a. Text -> NExprF a
mkSynHoleF (Text -> NExprF NExprLoc)
-> ParsecT Void Text (State SourcePos) Text
-> Parser (NExprF NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser VarName -> ParsecT Void Text (State SourcePos) Text
forall a b. Coercible a b => a -> b
coerce (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 Char -> Parser VarName -> Parser VarName
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Parser VarName
identifier)

-- List of Nix operation parsers with their precedence.
opParsers :: [(NOpPrecedence, Operator Parser NExprLoc)]
opParsers :: [(NOpPrecedence,
  Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
opParsers =
  -- 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 -> annNSelect x sel mor)
  -- ]

  -- NApp is left associative
  -- 2018-05-07: jwiegley: Thanks to Brent Yorgey for showing me this trick!
  NAppOp
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
forall t b. NOp t => t -> b -> [(NOpPrecedence, b)]
specialBuilder NAppOp
NAppOp (Parser (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a -> a) -> Operator m a
InfixL (Parser (NExprLoc -> NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> Parser (NExprLoc -> NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ NExprLoc -> NExprLoc -> NExprLoc
annNApp (NExprLoc -> NExprLoc -> NExprLoc)
-> ParsecT Void Text (State SourcePos) Text
-> Parser (NExprLoc -> NExprLoc -> NExprLoc)
forall a b.
a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Text -> ParsecT Void Text (State SourcePos) Text
symbols Text
forall a. Monoid a => a
mempty) [(NOpPrecedence,
  Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
forall a. Semigroup a => a -> a -> a
<>
  NSpecialOp
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
forall t b. NOp t => t -> b -> [(NOpPrecedence, b)]
specialBuilder NSpecialOp
NHasAttrOp (Parser (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall (m :: * -> *) a. m (a -> a) -> Operator m a
Postfix (Parser (NExprLoc -> NExprLoc)
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> Parser (NExprLoc -> NExprLoc)
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
forall a b. (a -> b) -> a -> b
$ Char -> Parser Char
symbol Char
'?' Parser Char
-> Parser (NExprLoc -> NExprLoc) -> Parser (NExprLoc -> NExprLoc)
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ((NExprLoc -> AnnUnit SrcSpan (NAttrPath NExprLoc) -> NExprLoc)
-> AnnUnit SrcSpan (NAttrPath NExprLoc) -> NExprLoc -> NExprLoc
forall a b c. (a -> b -> c) -> b -> a -> c
flip NExprLoc -> AnnUnit SrcSpan (NAttrPath NExprLoc) -> NExprLoc
annNHasAttr (AnnUnit SrcSpan (NAttrPath NExprLoc) -> NExprLoc -> NExprLoc)
-> ParsecT
     Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
-> Parser (NExprLoc -> NExprLoc)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
  Void Text (State SourcePos) (AnnUnit SrcSpan (NAttrPath NExprLoc))
nixSelector)) [(NOpPrecedence,
  Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
forall a. Semigroup a => a -> a -> a
<>
  (NUnaryOp
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
forall t b.
(Enum t, Bounded t, NOp t) =>
(t -> b) -> [(NOpPrecedence, b)]
builder NUnaryOp -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
prefix [(NOpPrecedence,
  Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
forall a. Semigroup a => a -> a -> a
<>
  (NBinaryOp
 -> Operator (ParsecT Void Text (State SourcePos)) NExprLoc)
-> [(NOpPrecedence,
     Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
forall t b.
(Enum t, Bounded t, NOp t) =>
(t -> b) -> [(NOpPrecedence, b)]
builder NBinaryOp
-> Operator (ParsecT Void Text (State SourcePos)) NExprLoc
binary
 where
  specialBuilder :: NOp t => t -> b -> [(NOpPrecedence, b)]
  specialBuilder :: forall t b. NOp t => t -> b -> [(NOpPrecedence, b)]
specialBuilder t
op b
parser = OneItem [(NOpPrecedence, b)] -> [(NOpPrecedence, b)]
forall x. One x => OneItem x -> x
one (t -> (t -> b) -> (NOpPrecedence, b)
forall t b. NOp t => t -> (t -> b) -> (NOpPrecedence, b)
entry t
op (b -> t -> b
forall a b. a -> b -> a
const b
parser))

  builder :: (Enum t, Bounded t, NOp t) => (t -> b) -> [(NOpPrecedence, b)]
  builder :: forall t b.
(Enum t, Bounded t, NOp t) =>
(t -> b) -> [(NOpPrecedence, b)]
builder t -> b
tp = (t -> (NOpPrecedence, b)) -> [t] -> [(NOpPrecedence, b)]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (t -> (t -> b) -> (NOpPrecedence, b)
forall t b. NOp t => t -> (t -> b) -> (NOpPrecedence, b)
`entry` t -> b
tp) [t]
forall a. (Bounded a, Enum a) => [a]
universe

  entry :: NOp t => t -> (t -> b) -> (NOpPrecedence, b)
  entry :: forall t b. NOp t => t -> (t -> b) -> (NOpPrecedence, b)
entry t
op t -> b
parser = (t -> NOpPrecedence
forall a. NOp a => a -> NOpPrecedence
getOpPrecedence t
op, t -> b
parser t
op)


-- ** Expr & its constituents (Language term, expr algebra)

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

-- | Bundles parsers into @[[]]@ based on precedence (form is required for `megaparsec`).
nixOperators :: [[ Operator Parser NExprLoc ]]
nixOperators :: [[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
nixOperators =
  (NOpPrecedence,
 [Operator (ParsecT Void Text (State SourcePos)) NExprLoc])
-> [Operator (ParsecT Void Text (State SourcePos)) NExprLoc]
forall a b. (a, b) -> b
snd ((NOpPrecedence,
  [Operator (ParsecT Void Text (State SourcePos)) NExprLoc])
 -> [Operator (ParsecT Void Text (State SourcePos)) NExprLoc])
-> [(NOpPrecedence,
     [Operator (ParsecT Void Text (State SourcePos)) NExprLoc])]
-> [[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
    [(NOpPrecedence,
  Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
-> [(NOpPrecedence,
     [Operator (ParsecT Void Text (State SourcePos)) NExprLoc])]
forall k v. Ord k => [(k, v)] -> [(k, [v])]
groupSort [(NOpPrecedence,
  Operator (ParsecT Void Text (State SourcePos)) NExprLoc)]
opParsers

-- | Nix expression algebra parser.
-- "Expression algebra" is to explain @megaparsec@ use of the term "Expression" (parser for language algebraic coperators without any statements (without @let@ etc.)), which is essentially an algebra inside the language.
nixExprAlgebra :: Parser NExprLoc
nixExprAlgebra :: ParsecT Void Text (State SourcePos) NExprLoc
nixExprAlgebra =
  ParsecT Void Text (State SourcePos) NExprLoc
-> [[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
-> ParsecT Void Text (State SourcePos) NExprLoc
forall (m :: * -> *) a.
MonadPlus m =>
m a -> [[Operator m a]] -> m a
makeExprParser
    ParsecT Void Text (State SourcePos) NExprLoc
nixTerm
    [[Operator (ParsecT Void Text (State SourcePos)) NExprLoc]]
nixOperators

nixExpr :: Parser NExprLoc
nixExpr :: ParsecT Void Text (State SourcePos) NExprLoc
nixExpr = ParsecT Void Text (State SourcePos) NExprLoc
keywords ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> ParsecT Void Text (State SourcePos) NExprLoc
nixLambda ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> ParsecT Void Text (State SourcePos) NExprLoc
nixExprAlgebra
 where
  keywords :: ParsecT Void Text (State SourcePos) NExprLoc
keywords = ParsecT Void Text (State SourcePos) NExprLoc
nixLet ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> ParsecT Void Text (State SourcePos) NExprLoc
nixIf ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> ParsecT Void Text (State SourcePos) NExprLoc
nixAssert ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall (m :: * -> *) a. MonadPlus m => m a -> m a -> m a
<|> ParsecT Void Text (State SourcePos) NExprLoc
nixWith


-- * Parse

type Result a = Either (Doc Void) a


parseWith
  :: Parser a
  -> Path
  -> Text
  -> Either (Doc Void) a
parseWith :: forall a. Parser a -> Path -> Text -> Either (Doc Void) a
parseWith Parser a
parser Path
file Text
input =
  (ParseErrorBundle Text Void -> Either (Doc Void) a)
-> (a -> Either (Doc Void) a)
-> Either (ParseErrorBundle Text Void) a
-> Either (Doc Void) a
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
    (Doc Void -> Either (Doc Void) a
forall a b. a -> Either a b
Left (Doc Void -> Either (Doc Void) a)
-> (ParseErrorBundle Text Void -> Doc Void)
-> ParseErrorBundle Text Void
-> Either (Doc Void) a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Doc Void
forall ann. String -> Doc ann
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 -> Either (Doc Void) a
forall a. a -> Either (Doc Void) a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (Either (ParseErrorBundle Text Void) a -> Either (Doc Void) a)
-> Either (ParseErrorBundle Text Void) a -> Either (Doc Void) 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 (Path -> String
forall a b. Coercible a b => a -> b
coerce Path
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` Path -> String
forall a b. Coercible a b => a -> b
coerce Path
file) Parser a
parser Text
input


parseFromFileEx :: MonadFile m => Parser a -> Path -> m (Result a)
parseFromFileEx :: forall (m :: * -> *) a.
MonadFile m =>
Parser a -> Path -> m (Result a)
parseFromFileEx Parser a
parser Path
file = Parser a -> Path -> Text -> Either (Doc Void) a
forall a. Parser a -> Path -> Text -> Either (Doc Void) a
parseWith Parser a
parser Path
file (Text -> Either (Doc Void) a) -> m Text -> m (Either (Doc Void) a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Path -> m Text
forall (m :: * -> *). MonadIO m => Path -> m Text
readFile Path
file

parseFromText :: Parser a -> Text -> Result a
parseFromText :: forall a. Parser a -> Text -> Result a
parseFromText = (Parser a -> Path -> Text -> Either (Doc Void) a
forall a. Parser a -> Path -> Text -> Either (Doc Void) a
`parseWith` Path
"<string>")

fullContent :: Parser NExprLoc
fullContent :: ParsecT Void Text (State SourcePos) NExprLoc
fullContent = Parser ()
whiteSpace Parser ()
-> ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Void Text (State SourcePos) NExprLoc
nixExpr ParsecT Void Text (State SourcePos) NExprLoc
-> Parser () -> ParsecT Void Text (State SourcePos) NExprLoc
forall a b.
ParsecT Void Text (State SourcePos) a
-> ParsecT Void Text (State SourcePos) b
-> ParsecT Void Text (State SourcePos) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser ()
forall e s (m :: * -> *). MonadParsec e s m => m ()
eof

parseNixFile' :: MonadFile m => (Parser NExprLoc -> Parser a) -> Path -> m (Result a)
parseNixFile' :: forall (m :: * -> *) a.
MonadFile m =>
(ParsecT Void Text (State SourcePos) NExprLoc -> Parser a)
-> Path -> m (Result a)
parseNixFile' ParsecT Void Text (State SourcePos) NExprLoc -> Parser a
f =
  Parser a -> Path -> m (Result a)
forall (m :: * -> *) a.
MonadFile m =>
Parser a -> Path -> m (Result a)
parseFromFileEx (Parser a -> Path -> m (Result a))
-> Parser a -> Path -> m (Result a)
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text (State SourcePos) NExprLoc -> Parser a
f ParsecT Void Text (State SourcePos) NExprLoc
fullContent

parseNixFile :: MonadFile m => Path -> m (Result NExpr)
parseNixFile :: forall (m :: * -> *). MonadFile m => Path -> m (Result NExpr)
parseNixFile =
  (ParsecT Void Text (State SourcePos) NExprLoc -> Parser NExpr)
-> Path -> m (Result NExpr)
forall (m :: * -> *) a.
MonadFile m =>
(ParsecT Void Text (State SourcePos) NExprLoc -> Parser a)
-> Path -> m (Result a)
parseNixFile' (NExprLoc -> NExpr
forall (f :: * -> *) ann. Functor f => Ann ann f -> Fix f
stripAnnotation (NExprLoc -> NExpr)
-> ParsecT Void Text (State SourcePos) NExprLoc -> Parser NExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>)

parseNixFileLoc :: MonadFile m => Path -> m (Result NExprLoc)
parseNixFileLoc :: forall (m :: * -> *). MonadFile m => Path -> m (Result NExprLoc)
parseNixFileLoc =
  (ParsecT Void Text (State SourcePos) NExprLoc
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Path -> m (Result NExprLoc)
forall (m :: * -> *) a.
MonadFile m =>
(ParsecT Void Text (State SourcePos) NExprLoc -> Parser a)
-> Path -> m (Result a)
parseNixFile' ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a. a -> a
id

parseNixText' :: (Parser NExprLoc -> Parser a) -> Text -> Result a
parseNixText' :: forall a.
(ParsecT Void Text (State SourcePos) NExprLoc -> Parser a)
-> Text -> Result a
parseNixText' ParsecT Void Text (State SourcePos) NExprLoc -> Parser a
f =
  Parser a -> Text -> Result a
forall a. Parser a -> Text -> Result a
parseFromText (Parser a -> Text -> Result a) -> Parser a -> Text -> Result a
forall a b. (a -> b) -> a -> b
$ ParsecT Void Text (State SourcePos) NExprLoc -> Parser a
f ParsecT Void Text (State SourcePos) NExprLoc
fullContent

parseNixText :: Text -> Result NExpr
parseNixText :: Text -> Result NExpr
parseNixText =
  (ParsecT Void Text (State SourcePos) NExprLoc -> Parser NExpr)
-> Text -> Result NExpr
forall a.
(ParsecT Void Text (State SourcePos) NExprLoc -> Parser a)
-> Text -> Result a
parseNixText' (NExprLoc -> NExpr
forall (f :: * -> *) ann. Functor f => Ann ann f -> Fix f
stripAnnotation (NExprLoc -> NExpr)
-> ParsecT Void Text (State SourcePos) NExprLoc -> Parser NExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>)

parseNixTextLoc :: Text -> Result NExprLoc
parseNixTextLoc :: Text -> Result NExprLoc
parseNixTextLoc =
  (ParsecT Void Text (State SourcePos) NExprLoc
 -> ParsecT Void Text (State SourcePos) NExprLoc)
-> Text -> Result NExprLoc
forall a.
(ParsecT Void Text (State SourcePos) NExprLoc -> Parser a)
-> Text -> Result a
parseNixText' ParsecT Void Text (State SourcePos) NExprLoc
-> ParsecT Void Text (State SourcePos) NExprLoc
forall a. a -> a
id

parseExpr :: MonadFail m => Text -> m NExpr
parseExpr :: forall (m :: * -> *). MonadFail m => Text -> m NExpr
parseExpr =
  (Doc Void -> m NExpr)
-> (NExpr -> m NExpr) -> Result NExpr -> m NExpr
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either
    (String -> m NExpr
forall a. String -> m a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> m NExpr) -> (Doc Void -> String) -> Doc Void -> m NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Doc Void -> String
forall b a. (Show a, IsString b) => a -> b
show)
    NExpr -> m NExpr
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (Result NExpr -> m NExpr)
-> (Text -> Result NExpr) -> Text -> m NExpr
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Result NExpr
parseNixText