Normalize recent changes to fit the overall design
This commit is contained in:
parent
74e1812f74
commit
2468bf6826
|
@ -16,14 +16,14 @@ import Prelude hiding (elem)
|
||||||
|
|
||||||
-- | The lexer for this parser is defined in 'Nix.Parser.Library'.
|
-- | The lexer for this parser is defined in 'Nix.Parser.Library'.
|
||||||
nixApp :: Parser NExpr
|
nixApp :: Parser NExpr
|
||||||
nixApp = go <$>
|
nixApp = go <$> someTill (whiteSpace *> nixExpr True) (try (lookAhead stop))
|
||||||
someTill (whiteSpace *> nixExpr True)
|
|
||||||
(try (lookAhead (() <$ oneOf "=,;])}" <|> reserved "then" <|> reserved "else" <|> eof)))
|
|
||||||
where
|
where
|
||||||
go [] = error "some has failed us"
|
go [] = error "some has failed us"
|
||||||
go [x] = x
|
go [x] = x
|
||||||
go (f:xs) = Fix (NApp f (go xs))
|
go (f:xs) = Fix (NApp f (go xs))
|
||||||
|
|
||||||
|
stop = () <$ oneOf "=,;])}" <|> eof
|
||||||
|
|
||||||
nixExpr :: Bool -> Parser NExpr
|
nixExpr :: Bool -> Parser NExpr
|
||||||
nixExpr = buildExpressionParser table . nixTerm
|
nixExpr = buildExpressionParser table . nixTerm
|
||||||
where
|
where
|
||||||
|
@ -51,13 +51,13 @@ nixExpr = buildExpressionParser table . nixTerm
|
||||||
nixTerm :: Bool -> Parser NExpr
|
nixTerm :: Bool -> Parser NExpr
|
||||||
nixTerm allowLambdas = choice
|
nixTerm allowLambdas = choice
|
||||||
[ nixInt
|
[ nixInt
|
||||||
, nixBool
|
|
||||||
, nixNull
|
|
||||||
, nixParens
|
, nixParens
|
||||||
, nixList
|
, nixList
|
||||||
, nixPath
|
|
||||||
, nixLet
|
, nixLet
|
||||||
, nixIf
|
, nixIf
|
||||||
|
, nixBool
|
||||||
|
, nixNull
|
||||||
|
, nixPath -- can be expensive due to back-tracking
|
||||||
, setLambdaStringOrSym allowLambdas
|
, setLambdaStringOrSym allowLambdas
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -85,10 +85,10 @@ nixLet = (Fix .) . NLet
|
||||||
<*> (whiteSpace *> reserved "in" *> nixApp)
|
<*> (whiteSpace *> reserved "in" *> nixApp)
|
||||||
|
|
||||||
nixIf :: Parser NExpr
|
nixIf :: Parser NExpr
|
||||||
nixIf = Fix <$> (NIf
|
nixIf = ((Fix .) .) . NIf
|
||||||
<$> (reserved "if" *> nixApp)
|
<$> (reserved "if" *> nixExpr False)
|
||||||
<*> (reserved "then" *> nixApp)
|
<*> (whiteSpace *> reserved "then" *> nixApp)
|
||||||
<*> (reserved "else" *> nixApp))
|
<*> (whiteSpace *> reserved "else" *> nixApp)
|
||||||
|
|
||||||
-- | This is a bit tricky because we don't know whether we're looking at a set
|
-- | This is a bit tricky because we don't know whether we're looking at a set
|
||||||
-- or a lambda until we've looked ahead a bit. And then it may be neither,
|
-- or a lambda until we've looked ahead a bit. And then it may be neither,
|
||||||
|
@ -96,14 +96,15 @@ nixIf = Fix <$> (NIf
|
||||||
setLambdaStringOrSym :: Bool -> Parser NExpr
|
setLambdaStringOrSym :: Bool -> Parser NExpr
|
||||||
setLambdaStringOrSym allowLambdas = do
|
setLambdaStringOrSym allowLambdas = do
|
||||||
trace "setLambdaStringOrSym" $ return ()
|
trace "setLambdaStringOrSym" $ return ()
|
||||||
isSetOrArgs <- try (lookAhead (reserved "rec") *> pure True) <|>
|
isSetOrArgs <- try (lookAhead (reserved "rec") *> pure True)
|
||||||
try (lookAhead (singleton <$> char '{') *> pure True)
|
<|> try (lookAhead (singleton <$> char '{') *> pure True)
|
||||||
<|> pure False
|
<|> pure False
|
||||||
if isSetOrArgs
|
if isSetOrArgs
|
||||||
then setOrArgs
|
then setOrArgs
|
||||||
else do
|
else do
|
||||||
trace "might still have a lambda" $ return ()
|
trace "might still have a lambda" $ return ()
|
||||||
y <- try (lookAhead (True <$ (identifier *> whiteSpace *> symbolic ':')))
|
y <- try (lookAhead (True <$ (identifier *> whiteSpace
|
||||||
|
*> symbolic ':')))
|
||||||
<|> return False
|
<|> return False
|
||||||
trace ("results are = " ++ show y) $ return ()
|
trace ("results are = " ++ show y) $ return ()
|
||||||
if y
|
if y
|
||||||
|
|
Loading…
Reference in New Issue