commit
bb26529c73
|
@ -81,7 +81,7 @@ import Nix.Expr.Types.Annotated
|
|||
import Nix.Frames
|
||||
import Nix.Normal
|
||||
import Nix.Options
|
||||
import Nix.Parser
|
||||
import Nix.Parser hiding (nixPath)
|
||||
import Nix.Render
|
||||
import Nix.Scope
|
||||
import Nix.Thunk
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{-# LANGUAGE CPP #-}
|
||||
{-# LANGUAGE DeriveAnyClass #-}
|
||||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{-# LANGUAGE DeriveFunctor #-}
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
@ -14,6 +15,7 @@ module Nix.Parser
|
|||
, parseNixText
|
||||
, parseNixTextLoc
|
||||
, parseFromFileEx
|
||||
, Parser
|
||||
, parseFromText
|
||||
, Result(..)
|
||||
, reservedNames
|
||||
|
@ -24,6 +26,24 @@ module Nix.Parser
|
|||
, getUnaryOperator
|
||||
, getBinaryOperator
|
||||
, getSpecialOperator
|
||||
|
||||
, nixToplevelForm
|
||||
, nixExpr
|
||||
, nixSet
|
||||
, nixBinders
|
||||
, nixSelector
|
||||
|
||||
, nixSym
|
||||
, nixPath
|
||||
, nixString
|
||||
, nixUri
|
||||
, nixSearchPath
|
||||
, nixFloat
|
||||
, nixInt
|
||||
, nixBool
|
||||
, nixNull
|
||||
, symbol
|
||||
, whiteSpace
|
||||
) where
|
||||
|
||||
import Control.Applicative hiding (many, some)
|
||||
|
@ -60,8 +80,8 @@ infixl 3 <+>
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
nixExprLoc :: Parser NExprLoc
|
||||
nixExprLoc = makeExprParser nixTerm $ map (map snd) (nixOperators nixSelector)
|
||||
nixExpr :: Parser NExprLoc
|
||||
nixExpr = makeExprParser nixTerm $ map (map snd) (nixOperators nixSelector)
|
||||
|
||||
antiStart :: Parser Text
|
||||
antiStart = symbol "${" <?> show ("${" :: String)
|
||||
|
@ -112,10 +132,10 @@ nixTerm = do
|
|||
'(' -> nixSelect nixParens
|
||||
'{' -> nixSelect nixSet
|
||||
'[' -> nixList
|
||||
'<' -> nixSPath
|
||||
'<' -> nixSearchPath
|
||||
'/' -> nixPath
|
||||
'"' -> nixStringExpr
|
||||
'\'' -> nixStringExpr
|
||||
'"' -> nixString
|
||||
'\'' -> nixString
|
||||
_ -> msum $
|
||||
[ nixSelect nixSet | c == 'r' ] ++
|
||||
[ nixPath | pathChar c ] ++
|
||||
|
@ -128,7 +148,7 @@ nixTerm = do
|
|||
[ nixSelect nixSym ]
|
||||
|
||||
nixToplevelForm :: Parser NExprLoc
|
||||
nixToplevelForm = keywords <+> nixLambda <+> nixExprLoc
|
||||
nixToplevelForm = keywords <+> nixLambda <+> nixExpr
|
||||
where
|
||||
keywords = nixLet <+> nixIf <+> nixAssert <+> nixWith
|
||||
|
||||
|
@ -164,8 +184,8 @@ slash = try (char '/' <* notFollowedBy (satisfy (\x -> x == '/' || x == '*' || i
|
|||
|
||||
-- | A path surrounded by angle brackets, indicating that it should be
|
||||
-- looked up in the NIX_PATH environment variable at evaluation.
|
||||
nixSPath :: Parser NExprLoc
|
||||
nixSPath = annotateLocation1
|
||||
nixSearchPath :: Parser NExprLoc
|
||||
nixSearchPath = annotateLocation1
|
||||
(mkPathF True <$> try (char '<' *> many (satisfy pathChar <+> slash) <* symbol ">")
|
||||
<?> "spath")
|
||||
|
||||
|
@ -191,14 +211,14 @@ nixLet = annotateLocation1 (reserved "let"
|
|||
|
||||
nixIf :: Parser NExprLoc
|
||||
nixIf = annotateLocation1 (NIf
|
||||
<$> (reserved "if" *> nixExprLoc)
|
||||
<$> (reserved "if" *> nixExpr)
|
||||
<*> (reserved "then" *> nixToplevelForm)
|
||||
<*> (reserved "else" *> nixToplevelForm)
|
||||
<?> "if")
|
||||
|
||||
nixAssert :: Parser NExprLoc
|
||||
nixAssert = annotateLocation1 (NAssert
|
||||
<$> (reserved "assert" *> nixExprLoc)
|
||||
<$> (reserved "assert" *> nixExpr)
|
||||
<*> (semi *> nixToplevelForm)
|
||||
<?> "assert")
|
||||
|
||||
|
@ -211,8 +231,8 @@ nixWith = annotateLocation1 (NWith
|
|||
nixLambda :: Parser NExprLoc
|
||||
nixLambda = nAbs <$> annotateLocation (try argExpr) <*> nixToplevelForm
|
||||
|
||||
nixStringExpr :: Parser NExprLoc
|
||||
nixStringExpr = nStr <$> annotateLocation nixString
|
||||
nixString :: Parser NExprLoc
|
||||
nixString = nStr <$> annotateLocation nixString'
|
||||
|
||||
nixUri :: Parser NExprLoc
|
||||
nixUri = annotateLocation1 $ lexeme $ try $ do
|
||||
|
@ -225,8 +245,8 @@ nixUri = annotateLocation1 $ lexeme $ try $ do
|
|||
return $ NStr $
|
||||
DoubleQuoted [Plain $ pack $ start : protocol ++ ':' : address]
|
||||
|
||||
nixString :: Parser (NString NExprLoc)
|
||||
nixString = lexeme (doubleQuoted <+> indented <?> "string")
|
||||
nixString' :: Parser (NString NExprLoc)
|
||||
nixString' = lexeme (doubleQuoted <+> indented <?> "string")
|
||||
where
|
||||
doubleQuoted :: Parser (NString NExprLoc)
|
||||
doubleQuoted = DoubleQuoted . removePlainEmpty . mergePlain
|
||||
|
@ -330,7 +350,7 @@ nixBinders = (inherit <+> namedVar) `endBy` semi where
|
|||
keyName :: Parser (NKeyName NExprLoc)
|
||||
keyName = dynamicKey <+> staticKey where
|
||||
staticKey = StaticKey <$> identifier
|
||||
dynamicKey = DynamicKey <$> nixAntiquoted nixString
|
||||
dynamicKey = DynamicKey <$> nixAntiquoted nixString'
|
||||
|
||||
nixSet :: Parser NExprLoc
|
||||
nixSet = annotateLocation1 ((isRec <*> braces nixBinders) <?> "set") where
|
||||
|
@ -417,7 +437,7 @@ reservedNames = HashSet.fromList
|
|||
|
||||
type Parser = ParsecT Void Text Identity
|
||||
|
||||
data Result a = Success a | Failure Doc deriving Show
|
||||
data Result a = Success a | Failure Doc deriving (Show, Functor)
|
||||
|
||||
parseFromFileEx :: MonadIO m => Parser a -> FilePath -> m (Result a)
|
||||
parseFromFileEx p path = do
|
||||
|
|
Loading…
Reference in a new issue