git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2559 from purescript/phil/parse-named-binders

Fix parsing for named binders

commit966386795014f75a700aa1bc4c12f9cd62ae26ec authorPhil Freeman <paf31@cantab.net> dateThu 12 Jan 2017, 21:09 (10 years ago) parent62a30ad82e609b
3 files changed+134−190
examples/passing/ParseNamedBinder.purs+9 src/Language/PureScript/Parser/Common.hs+49−73 src/Language/PureScript/Parser/Declarations.hs+76−117
examples/passing/ParseNamedBinder.pursnew file+9
@@ -0,0 +1,9 @@
1+module Main where
2+
3+import Control.Monad.Eff.Console (log)
4+
5+data X = X
6+
7+f a@X X = a
8+
9+main = log "Done"
src/Language/PureScript/Parser/Common.hs+49−73
@@ -1,52 +1,39 @@
1−-- |
2−-- Constants and utility functions to be used when parsing
3−--
1+-- | Useful common functions for building parsers
42module Language.PureScript.Parser.Common where
53
6−import Prelude.Compat
4+import Prelude.Compat
75
8−import Control.Applicative ((<|>))
9−import Control.Monad (guard)
10−import Data.Monoid ((<>))
11−import Data.Text (Text)
6+import Control.Applicative ((<|>))
7+import Control.Monad (guard)
8+import Data.Maybe (fromMaybe)
9+import Data.Monoid ((<>))
10+import Data.Text (Text)
1211import qualified Data.Text as T
13−
14−import Language.PureScript.AST.SourcePos
15−import Language.PureScript.Comments
16−import Language.PureScript.Names
17−import Language.PureScript.Parser.Lexer
18−import Language.PureScript.Parser.State
19−import Language.PureScript.PSString (PSString, mkString)
20−
12+import Language.PureScript.AST.SourcePos
13+import Language.PureScript.Comments
14+import Language.PureScript.Names
15+import Language.PureScript.Parser.Lexer
16+import Language.PureScript.Parser.State
17+import Language.PureScript.PSString (PSString, mkString)
2118import qualified Text.Parsec as P
2219
23−-- |
24−-- Parse a general proper name.
25−--
20+-- | Parse a general proper name.
2621properName :: TokenParser (ProperName a)
2722properName = ProperName <$> uname
2823
29−-- |
30−-- Parse a proper name for a type.
31−--
24+-- | Parse a proper name for a type.
3225typeName :: TokenParser (ProperName 'TypeName)
3326typeName = ProperName <$> tyname
3427
35−-- |
36−-- Parse a proper name for a kind.
37−--
28+-- | Parse a proper name for a kind.
3829kindName :: TokenParser (ProperName 'KindName)
3930kindName = ProperName <$> kiname
4031
41−-- |
42−-- Parse a proper name for a data constructor.
43−--
32+-- | Parse a proper name for a data constructor.
4433dataConstructorName :: TokenParser (ProperName 'ConstructorName)
4534dataConstructorName = ProperName <$> dconsname
4635
47−-- |
48−-- Parse a module name
49−--
36+-- | Parse a module name
5037moduleName :: TokenParser ModuleName
5138moduleName = part []
5239 where
@@ -55,9 +42,7 @@ moduleName = part []
5542 <|> (ModuleName . snoc path . ProperName <$> mname)
5643 snoc path name = path ++ [name]
5744
58−-- |
59−-- Parse a qualified name, i.e. M.name or just name
60−--
45+-- | Parse a qualified name, i.e. M.name or just name
6146parseQualified :: TokenParser a -> TokenParser (Qualified a)
6247parseQualified parser = part []
6348 where
@@ -67,42 +52,30 @@ parseQualified parser = part []
6752 updatePath path name = path ++ [name]
6853 qual path = if null path then Nothing else Just $ ModuleName path
6954
70−-- |
71−-- Parse an identifier.
72−--
55+-- | Parse an identifier.
7356parseIdent :: TokenParser Ident
7457parseIdent = Ident <$> identifier
7558
76−-- |
77−-- Parse a label, which may look like an identifier or a string
78−--
59+-- | Parse a label, which may look like an identifier or a string
7960parseLabel :: TokenParser PSString
8061parseLabel = (mkString <$> lname) <|> stringLiteral
8162
82−-- |
83−-- Parse an operator.
84−--
63+-- | Parse an operator.
8564parseOperator :: TokenParser (OpName a)
8665parseOperator = OpName <$> symbol
8766
88−-- |
89−-- Run the first parser, then match the second if possible, applying the specified function on a successful match
90−--
67+-- | Run the first parser, then match the second if possible, applying the specified function on a successful match
9168augment :: P.Stream s m t => P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
9269augment p q f = flip (maybe id $ flip f) <$> p <*> P.optionMaybe q
9370
94−-- |
95−-- Run the first parser, then match the second zero or more times, applying the specified function for each match
96−--
71+-- | Run the first parser, then match the second zero or more times, applying the specified function for each match
9772fold :: P.ParsecT s u m a -> P.ParsecT s u m b -> (a -> b -> a) -> P.ParsecT s u m a
9873fold first' more combine = do
9974 a <- first'
10075 bs <- P.many more
10176 return $ foldl combine a bs
10277
103−-- |
104−-- Build a parser from a smaller parser and a list of parsers for postfix operators
105−--
78+-- | Build a parser from a smaller parser and a list of parsers for postfix operators
10679buildPostfixParser :: P.Stream s m t => [a -> P.ParsecT s u m a] -> P.ParsecT s u m a -> P.ParsecT s u m a
10780buildPostfixParser fs first' = do
10881 a <- first'
@@ -114,9 +87,7 @@ buildPostfixParser fs first' = do
11487 Nothing -> return a
11588 Just a' -> go a'
11689
117−-- |
118−-- Mark the current indentation level
119−--
90+-- | Mark the current indentation level
12091mark :: P.Parsec s ParseState a -> P.Parsec s ParseState a
12192mark p = do
12293 current <- indentationLevel <$> P.getState
@@ -126,9 +97,7 @@ mark p = do
12697 P.modifyState $ \st -> st { indentationLevel = current }
12798 return a
12899
129−-- |
130−-- Check that the current identation level matches a predicate
131−--
100+-- | Check that the current identation level matches a predicate
132101checkIndentation
133102 :: (P.Column -> Text)
134103 -> (P.Column -> P.Column -> Bool)
@@ -138,32 +107,39 @@ checkIndentation mkMsg rel = do
138107 current <- indentationLevel <$> P.getState
139108 guard (col `rel` current) P.<?> T.unpack (mkMsg current)
140109
141−-- |
142−-- Check that the current indentation level is past the current mark
143−--
110+-- | Check that the current indentation level is past the current mark
144111indented :: P.Parsec s ParseState ()
145112indented = checkIndentation (("indentation past column " <>) . (T.pack . show)) (>)
146113
147−-- |
148−-- Check that the current indentation level is at the same indentation as the current mark
149−--
114+-- | Check that the current indentation level is at the same indentation as the current mark
150115same :: P.Parsec s ParseState ()
151116same = checkIndentation (("indentation at column " <>) . (T.pack . show)) (==)
152117
153−-- |
154−-- Read the comments from the the next token, without consuming it
155−--
118+-- | Read the comments from the the next token, without consuming it
156119readComments :: P.Parsec [PositionedToken] u [Comment]
157120readComments = P.lookAhead $ ptComments <$> P.anyToken
158121
159−-- |
160−-- Run a parser
161−--
122+-- | Run a parser
162123runTokenParser :: FilePath -> TokenParser a -> [PositionedToken] -> Either P.ParseError a
163124runTokenParser filePath p = P.runParser p (ParseState 0) filePath
164125
165−-- |
166−-- Convert from Parsec sourcepos
167−--
126+-- | Convert from Parsec sourcepos
168127toSourcePos :: P.SourcePos -> SourcePos
169128toSourcePos pos = SourcePos (P.sourceLine pos) (P.sourceColumn pos)
129+
130+-- | Read source position information and comments
131+withSourceSpan
132+ :: (SourceSpan -> [Comment] -> a -> b)
133+ -> P.Parsec [PositionedToken] u a
134+ -> P.Parsec [PositionedToken] u b
135+withSourceSpan f p = do
136+ start <- P.getPosition
137+ comments <- readComments
138+ x <- p
139+ end <- P.getPosition
140+ input <- P.getInput
141+ let end' = case input of
142+ pt:_ -> ptPrevEndPos pt
143+ _ -> Nothing
144+ let sp = SourceSpan (P.sourceName start) (toSourcePos start) (toSourcePos $ fromMaybe end end')
145+ return $ f sp comments x
src/Language/PureScript/Parser/Declarations.hs+76−117
@@ -1,6 +1,4 @@
1−-- |
2−-- Parsers for module definitions and declarations
3−--
1+-- | Parsers for module definitions and declarations
42module Language.PureScript.Parser.Declarations
53 ( parseDeclaration
64 , parseModule
@@ -15,53 +13,29 @@ module Language.PureScript.Parser.Declarations
1513 , toPositionedError
1614 ) where
1715
18−import Prelude hiding (lex)
19−
20−import Data.Functor (($>))
21−import Data.Maybe (fromMaybe)
22−import Data.Text (Text)
23−
24−import Control.Applicative
25−import Control.Arrow ((+++))
26−import Control.Monad.Error.Class (MonadError(..))
27−import Control.Parallel.Strategies (withStrategy, parList, rseq)
28−
29−import Language.PureScript.AST
30−import Language.PureScript.Comments
31−import Language.PureScript.Environment
32−import Language.PureScript.Errors
33−import Language.PureScript.Kinds
34−import Language.PureScript.Names
35−import Language.PureScript.Types
36−import Language.PureScript.PSString (PSString, mkString)
37−import Language.PureScript.Parser.Common
38−import Language.PureScript.Parser.Kinds
39−import Language.PureScript.Parser.Lexer
40−import Language.PureScript.Parser.Types
41−
42−import qualified Language.PureScript.Parser.Common as C
16+import Prelude hiding (lex)
17+
18+import Control.Applicative
19+import Control.Arrow ((+++))
20+import Control.Monad.Error.Class (MonadError(..))
21+import Control.Parallel.Strategies (withStrategy, parList, rseq)
22+import Data.Functor (($>))
23+import Data.Maybe (fromMaybe)
24+import Data.Text (Text)
25+import Language.PureScript.AST
26+import Language.PureScript.Environment
27+import Language.PureScript.Errors
28+import Language.PureScript.Kinds
29+import Language.PureScript.Names
30+import Language.PureScript.Parser.Common
31+import Language.PureScript.Parser.Kinds
32+import Language.PureScript.Parser.Lexer
33+import Language.PureScript.Parser.Types
34+import Language.PureScript.PSString (PSString, mkString)
35+import Language.PureScript.Types
4336import qualified Text.Parsec as P
4437import qualified Text.Parsec.Expr as P
4538
46−-- |
47−-- Read source position information
48−--
49−withSourceSpan
50− :: (SourceSpan -> [Comment] -> a -> a)
51− -> P.Parsec [PositionedToken] u a
52− -> P.Parsec [PositionedToken] u a
53−withSourceSpan f p = do
54− start <- P.getPosition
55− comments <- C.readComments
56− x <- p
57− end <- P.getPosition
58− input <- P.getInput
59− let end' = case input of
60− pt:_ -> ptPrevEndPos pt
61− _ -> Nothing
62− let sp = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos $ fromMaybe end end')
63− return $ f sp comments x
64−
6539kindedIdent :: TokenParser (Text, Maybe Kind)
6640kindedIdent = (, Nothing) <$> identifier
6741 <|> parens ((,) <$> identifier <*> (Just <$> (indented *> doubleColon *> indented *> parseKind)))
@@ -91,7 +65,7 @@ parseValueDeclaration :: TokenParser Declaration
9165parseValueDeclaration = do
9266 name <- parseIdent
9367 binders <- P.many parseBinderNoParens
94− value <- Left <$> (C.indented *>
68+ value <- Left <$> (indented *>
9569 P.many1 ((,) <$> parseGuard
9670 <*> (indented *> equals *> parseValueWithWhereClause)
9771 ))
@@ -100,13 +74,13 @@ parseValueDeclaration = do
10074 where
10175 parseValueWithWhereClause :: TokenParser Expr
10276 parseValueWithWhereClause = do
103− C.indented
77+ indented
10478 value <- parseValue
10579 whereClause <- P.optionMaybe $ do
106− C.indented
80+ indented
10781 reserved "where"
108− C.indented
109− C.mark $ P.many1 (C.same *> parseLocalDeclaration)
82+ indented
83+ mark $ P.many1 (same *> parseLocalDeclaration)
11084 return $ maybe value (`Let` value) whereClause
11185
11286parseExternDeclaration :: TokenParser Declaration
@@ -237,9 +211,7 @@ parseDerivingInstanceDeclaration = do
237211positioned :: TokenParser Declaration -> TokenParser Declaration
238212positioned = withSourceSpan PositionedDeclaration
239213
240−-- |
241−-- Parse a single declaration
242−--
214+-- | Parse a single declaration
243215parseDeclaration :: TokenParser Declaration
244216parseDeclaration = positioned (P.choice
245217 [ parseDataDeclaration
@@ -259,12 +231,10 @@ parseLocalDeclaration = positioned (P.choice
259231 , parseValueDeclaration
260232 ] P.<?> "local declaration")
261233
262−-- |
263−-- Parse a module header and a collection of declarations
264−--
234+-- | Parse a module header and a collection of declarations
265235parseModule :: TokenParser Module
266236parseModule = do
267− comments <- C.readComments
237+ comments <- readComments
268238 start <- P.getPosition
269239 reserved "module"
270240 indented
@@ -280,7 +250,7 @@ parseModule = do
280250 return (imports ++ decls)
281251 _ <- P.eof
282252 end <- P.getPosition
283− let ss = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos end)
253+ let ss = SourceSpan (P.sourceName start) (toSourcePos start) (toSourcePos end)
284254 return $ Module ss comments name decls exports
285255
286256-- | Parse a collection of modules in parallel
@@ -301,7 +271,6 @@ parseModulesFromFiles toFilePath input =
301271 inParallel :: [Either P.ParseError (k, a)] -> [Either P.ParseError (k, a)]
302272 inParallel = withStrategy (parList rseq)
303273
304−
305274-- | Parses a single module with FilePath for eventual parsing errors
306275parseModuleFromFile
307276 :: (k -> FilePath)
@@ -313,12 +282,12 @@ parseModuleFromFile toFilePath (k, content) = do
313282 m <- runTokenParser filename parseModule ts
314283 pure (k, m)
315284
316−-- | Converts a @ParseError@ into a @PositionedError@
285+-- | Converts a 'ParseError' into a 'PositionedError'
317286toPositionedError :: P.ParseError -> ErrorMessage
318287toPositionedError perr = ErrorMessage [ PositionedError (SourceSpan name start end) ] (ErrorParsingModule perr)
319288 where
320289 name = (P.sourceName . P.errorPos) perr
321− start = (C.toSourcePos . P.errorPos) perr
290+ start = (toSourcePos . P.errorPos) perr
322291 end = start
323292
324293booleanLiteral :: TokenParser Bool
@@ -345,18 +314,18 @@ parseObjectLiteral p = ObjectLiteral <$> braces (commaSep p)
345314parseIdentifierAndValue :: TokenParser (PSString, Expr)
346315parseIdentifierAndValue =
347316 do
348− name <- C.indented *> lname
317+ name <- indented *> lname
349318 b <- P.option (Var $ Qualified Nothing (Ident name)) rest
350319 return (mkString name, b)
351− <|> (,) <$> (C.indented *> stringLiteral) <*> rest
320+ <|> (,) <$> (indented *> stringLiteral) <*> rest
352321 where
353− rest = C.indented *> colon *> C.indented *> parseValue
322+ rest = indented *> colon *> indented *> parseValue
354323
355324parseAbs :: TokenParser Expr
356325parseAbs = do
357326 symbol' "\\"
358− args <- P.many1 (C.indented *> (Abs <$> (Left <$> C.parseIdent <|> Right <$> parseBinderNoParens)))
359− C.indented *> rarrow
327+ args <- P.many1 (indented *> (Abs <$> (Left <$> parseIdent <|> Right <$> parseBinderNoParens)))
328+ indented *> rarrow
360329 value <- parseValue
361330 return $ toFunction args value
362331 where
@@ -364,18 +333,18 @@ parseAbs = do
364333 toFunction args value = foldr ($) value args
365334
366335parseVar :: TokenParser Expr
367−parseVar = Var <$> C.parseQualified C.parseIdent
336+parseVar = Var <$> parseQualified parseIdent
368337
369338parseConstructor :: TokenParser Expr
370−parseConstructor = Constructor <$> C.parseQualified C.dataConstructorName
339+parseConstructor = Constructor <$> parseQualified dataConstructorName
371340
372341parseCase :: TokenParser Expr
373−parseCase = Case <$> P.between (reserved "case") (C.indented *> reserved "of") (commaSep1 parseValue)
374− <*> (C.indented *> C.mark (P.many1 (C.same *> C.mark parseCaseAlternative)))
342+parseCase = Case <$> P.between (reserved "case") (indented *> reserved "of") (commaSep1 parseValue)
343+ <*> (indented *> mark (P.many1 (same *> mark parseCaseAlternative)))
375344
376345parseCaseAlternative :: TokenParser CaseAlternative
377346parseCaseAlternative = CaseAlternative <$> commaSep1 parseBinder
378− <*> (Left <$> (C.indented *>
347+ <*> (Left <$> (indented *>
379348 P.many1 ((,) <$> parseGuard
380349 <*> (indented *> rarrow *> parseValue)
381350 ))
@@ -383,16 +352,16 @@ parseCaseAlternative = CaseAlternative <$> commaSep1 parseBinder
383352 P.<?> "case alternative"
384353
385354parseIfThenElse :: TokenParser Expr
386−parseIfThenElse = IfThenElse <$> (P.try (reserved "if") *> C.indented *> parseValue)
387− <*> (C.indented *> reserved "then" *> C.indented *> parseValue)
388− <*> (C.indented *> reserved "else" *> C.indented *> parseValue)
355+parseIfThenElse = IfThenElse <$> (P.try (reserved "if") *> indented *> parseValue)
356+ <*> (indented *> reserved "then" *> indented *> parseValue)
357+ <*> (indented *> reserved "else" *> indented *> parseValue)
389358
390359parseLet :: TokenParser Expr
391360parseLet = do
392361 reserved "let"
393− C.indented
394− ds <- C.mark $ P.many1 (C.same *> parseLocalDeclaration)
395− C.indented
362+ indented
363+ ds <- mark $ P.many1 (same *> parseLocalDeclaration)
364+ indented
396365 reserved "in"
397366 result <- parseValue
398367 return $ Let ds result
@@ -418,9 +387,7 @@ parseValueAtom = withSourceSpan PositionedValue $ P.choice
418387 , parseHole
419388 ]
420389
421−-- |
422−-- Parse an expression in backticks or an operator
423−--
390+-- | Parse an expression in backticks or an operator
424391parseInfixExpr :: TokenParser Expr
425392parseInfixExpr
426393 = P.between tick tick parseValue
@@ -432,25 +399,25 @@ parseHole = Hole <$> holeLit
432399parsePropertyUpdate :: TokenParser (PSString, Expr)
433400parsePropertyUpdate = do
434401 name <- parseLabel
435− _ <- C.indented *> equals
436− value <- C.indented *> parseValue
402+ _ <- indented *> equals
403+ value <- indented *> parseValue
437404 return (name, value)
438405
439406parseAccessor :: Expr -> TokenParser Expr
440407parseAccessor (Constructor _) = P.unexpected "constructor"
441−parseAccessor obj = P.try $ Accessor <$> (C.indented *> dot *> C.indented *> parseLabel) <*> pure obj
408+parseAccessor obj = P.try $ Accessor <$> (indented *> dot *> indented *> parseLabel) <*> pure obj
442409
443410parseDo :: TokenParser Expr
444411parseDo = do
445412 reserved "do"
446− C.indented
447− Do <$> C.mark (P.many1 (C.same *> C.mark parseDoNotationElement))
413+ indented
414+ Do <$> mark (P.many1 (same *> mark parseDoNotationElement))
448415
449416parseDoNotationLet :: TokenParser DoNotationElement
450−parseDoNotationLet = DoNotationLet <$> (reserved "let" *> C.indented *> C.mark (P.many1 (C.same *> parseLocalDeclaration)))
417+parseDoNotationLet = DoNotationLet <$> (reserved "let" *> indented *> mark (P.many1 (same *> parseLocalDeclaration)))
451418
452419parseDoNotationBind :: TokenParser DoNotationElement
453−parseDoNotationBind = DoNotationBind <$> P.try (parseBinder <* C.indented <* larrow) <*> parseValue
420+parseDoNotationBind = DoNotationBind <$> P.try (parseBinder <* indented <* larrow) <*> parseValue
454421
455422parseDoNotationElement :: TokenParser DoNotationElement
456423parseDoNotationElement = P.choice
@@ -461,33 +428,31 @@ parseDoNotationElement = P.choice
461428
462429-- | Expressions including indexers and record updates
463430indexersAndAccessors :: TokenParser Expr
464−indexersAndAccessors = C.buildPostfixParser postfixTable parseValueAtom
431+indexersAndAccessors = buildPostfixParser postfixTable parseValueAtom
465432 where
466433 postfixTable = [ parseAccessor
467434 , P.try . parseUpdaterBody
468435 ]
469436
470−-- |
471−-- Parse a value
472−--
437+-- | Parse an expression
473438parseValue :: TokenParser Expr
474439parseValue = withSourceSpan PositionedValue
475440 (P.buildExpressionParser operators
476− . C.buildPostfixParser postfixTable
441+ . buildPostfixParser postfixTable
477442 $ indexersAndAccessors) P.<?> "expression"
478443 where
479− postfixTable = [ \v -> P.try (flip App <$> (C.indented *> indexersAndAccessors)) <*> pure v
480− , \v -> flip (TypedValue True) <$> (C.indented *> doubleColon *> parsePolyType) <*> pure v
444+ postfixTable = [ \v -> P.try (flip App <$> (indented *> indexersAndAccessors)) <*> pure v
445+ , \v -> flip (TypedValue True) <$> (indented *> doubleColon *> parsePolyType) <*> pure v
481446 ]
482− operators = [ [ P.Prefix (C.indented *> symbol' "-" *> return UnaryMinus)
447+ operators = [ [ P.Prefix (indented *> symbol' "-" *> return UnaryMinus)
483448 ]
484− , [ P.Infix (P.try (C.indented *> parseInfixExpr P.<?> "infix expression") >>= \ident ->
449+ , [ P.Infix (P.try (indented *> parseInfixExpr P.<?> "infix expression") >>= \ident ->
485450 return (BinaryNoParens ident)) P.AssocRight
486451 ]
487452 ]
488453
489454parseUpdaterBody :: Expr -> TokenParser Expr
490−parseUpdaterBody v = ObjectUpdate v <$> (C.indented *> braces (commaSep1 (C.indented *> parsePropertyUpdate)))
455+parseUpdaterBody v = ObjectUpdate v <$> (indented *> braces (commaSep1 (indented *> parsePropertyUpdate)))
491456
492457parseAnonymousArgument :: TokenParser Expr
493458parseAnonymousArgument = underscore *> pure AnonymousArgument
@@ -501,21 +466,21 @@ parseNumberLiteral = LiteralBinder . NumericLiteral <$> (sign <*> number)
501466 <|> return id
502467
503468parseNullaryConstructorBinder :: TokenParser Binder
504−parseNullaryConstructorBinder = ConstructorBinder <$> C.parseQualified C.dataConstructorName <*> pure []
469+parseNullaryConstructorBinder = ConstructorBinder <$> parseQualified dataConstructorName <*> pure []
505470
506471parseConstructorBinder :: TokenParser Binder
507−parseConstructorBinder = ConstructorBinder <$> C.parseQualified C.dataConstructorName <*> many (C.indented *> parseBinderNoParens)
472+parseConstructorBinder = ConstructorBinder <$> parseQualified dataConstructorName <*> many (indented *> parseBinderNoParens)
508473
509474parseObjectBinder:: TokenParser Binder
510−parseObjectBinder = LiteralBinder <$> parseObjectLiteral (C.indented *> parseIdentifierAndBinder)
475+parseObjectBinder = LiteralBinder <$> parseObjectLiteral (indented *> parseIdentifierAndBinder)
511476
512477parseArrayBinder :: TokenParser Binder
513−parseArrayBinder = LiteralBinder <$> parseArrayLiteral (C.indented *> parseBinder)
478+parseArrayBinder = LiteralBinder <$> parseArrayLiteral (indented *> parseBinder)
514479
515480parseVarOrNamedBinder :: TokenParser Binder
516481parseVarOrNamedBinder = do
517− name <- C.parseIdent
518− let parseNamedBinder = NamedBinder name <$> (at *> C.indented *> parseBinderAtom)
482+ name <- parseIdent
483+ let parseNamedBinder = NamedBinder name <$> (at *> indented *> parseBinderNoParens)
519484 parseNamedBinder <|> return (VarBinder name)
520485
521486parseNullBinder :: TokenParser Binder
@@ -528,11 +493,9 @@ parseIdentifierAndBinder =
528493 return (mkString name, b)
529494 <|> (,) <$> stringLiteral <*> rest
530495 where
531− rest = C.indented *> colon *> C.indented *> parseBinder
496+ rest = indented *> colon *> indented *> parseBinder
532497
533−-- |
534−-- Parse a binder
535−--
498+-- | Parse a binder
536499parseBinder :: TokenParser Binder
537500parseBinder =
538501 withSourceSpan
@@ -543,7 +506,7 @@ parseBinder =
543506 )
544507 where
545508 operators =
546− [ [ P.Infix (P.try (C.indented *> parseOpBinder P.<?> "binder operator") >>= \op ->
509+ [ [ P.Infix (P.try (indented *> parseOpBinder P.<?> "binder operator") >>= \op ->
547510 return (BinaryNoParensBinder op)) P.AssocRight
548511 ]
549512 ]
@@ -569,9 +532,7 @@ parseBinderAtom = P.choice
569532 , ParensInBinder <$> parens parseBinder
570533 ] P.<?> "binder"
571534
572−-- |
573−-- Parse a binder as it would appear in a top level declaration
574−--
535+-- | Parse a binder as it would appear in a top level declaration
575536parseBinderNoParens :: TokenParser Binder
576537parseBinderNoParens = P.choice
577538 [ parseNullBinder
@@ -586,8 +547,6 @@ parseBinderNoParens = P.choice
586547 , ParensInBinder <$> parens parseBinder
587548 ] P.<?> "binder"
588549
589−-- |
590−-- Parse a guard
591−--
550+-- | Parse a guard
592551parseGuard :: TokenParser Guard
593−parseGuard = pipe *> C.indented *> parseValue
552+parseGuard = pipe *> indented *> parseValue