More corrections to the parser

This commit is contained in:
John Wiegley 2018-04-10 09:03:18 -07:00
parent 81c63a98d5
commit 12b1a79a2c
3 changed files with 23 additions and 20 deletions

View file

@ -69,49 +69,49 @@ nixSelector = annotateLocation $ keyName `sepBy1` selDot
-- | A self-contained unit.
nixTerm :: Parser NExprLoc
nixTerm = nixSelect $ choice
[ dbg "Path" nixPath
[ dbg "Parens" nixParens
, dbg "Set" nixSet
, dbg "List" nixList
, dbg "SPath" nixSPath
, dbg "StringExpr" nixStringExpr
, dbg "Path" nixPath
, dbg "Uri" nixUri
, dbg "Float" nixFloat
, dbg "Int" nixInt
, dbg "Bool" nixBool
, dbg "Null" nixNull
, dbg "Parens" nixParens
, dbg "List" nixList
, dbg "Uri" nixUri
, dbg "StringExpr" nixStringExpr
, dbg "Set" nixSet
, dbg "Sym" nixSym ]
nixToplevelForm :: Parser NExprLoc
nixToplevelForm = choice
[ dbg "Lambda" nixLambda
, dbg "Let" nixLet
[ dbg "Let" nixLet
, dbg "If" nixIf
, dbg "Assert" nixAssert
, dbg "With" nixWith ]
, dbg "With" nixWith
, dbg "Lambda" nixLambda ]
#else
nixTerm :: Parser NExprLoc
nixTerm = nixSelect $ choice
[ nixPath
[ nixParens
, nixSet
, nixList
, nixSPath
, nixStringExpr
, nixPath
, nixUri
, nixFloat
, nixInt
, nixBool
, nixNull
, nixParens
, nixList
, nixUri
, nixStringExpr
, nixSet
, nixSym ]
nixToplevelForm :: Parser NExprLoc
nixToplevelForm = choice
[ nixLambda
, nixLet
[ nixLet
, nixIf
, nixAssert
, nixWith ]
, nixWith
, nixLambda ]
#endif
nixSym :: Parser NExprLoc

View file

@ -40,7 +40,8 @@ reserved n = lexeme $ try $ do
_ <- string n <* lookAhead (satisfy endMarker)
return ()
where
endMarker x = isSpace x || x == '{' || x == '(' || x == ';'
endMarker x =
isSpace x || x == '{' || x == '(' || x == ';' || x == '"' || x == '\''
opStart :: Parser Char
opStart = satisfy $ \x ->

View file

@ -12,7 +12,7 @@ import Control.DeepSeq
import Data.Data (Data(..))
import Data.Foldable (concat)
import qualified Data.Map as Map
import Data.Text (Text, unpack)
import Data.Text (Text)
import Data.Typeable (Typeable)
import GHC.Generics hiding (Prefix)
import Nix.Expr
@ -45,6 +45,8 @@ manyUnaryOp f = foldr1 (.) <$> some f
operator "-" = lexeme . try $ string "-" <* notFollowedBy (char '>')
operator "/" = lexeme . try $ string "/" <* notFollowedBy (char '/')
operator "<" = lexeme . try $ string "<" <* notFollowedBy (char '=')
operator ">" = lexeme . try $ string ">" <* notFollowedBy (char '=')
operator n = symbol n
opWithLoc :: Text -> o -> (Ann SrcSpan o -> a) -> Parser a