git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix some bad parser error messages caused by too many 'try's
commit5b44a8ed3fd7c2999901011e58538d5d5a694b1e authorPhil Freeman <paf31@cantab.net> dateMon 4 Nov 2013, 15:42 (13 years ago) parent4f6d82f
5 files changed+31−32
purescript.cabal+4−4 src/Language/PureScript/Parser/Common.hs+1−1 src/Language/PureScript/Parser/Declarations.hs+11−11 src/Language/PureScript/Parser/Types.hs+1−1 src/Language/PureScript/Parser/Values.hs+14−15
purescript.cabal+4−4
@@ -1,5 +1,5 @@
11name: purescript
2−version: 0.1.3
2+version: 0.1.4
33cabal-version: >=1.8
44build-type: Simple
55license: MIT
@@ -12,7 +12,7 @@ description: A small compile-to-JS language with extensible records and type-saf
1212category: Language
1313author: Phil Freeman <paf31@cantab.net>
1414data-dir: ""
15−
15+
1616library
1717 build-depends: base >=4 && <5, syb -any, cmdtheline -any,
1818 containers -any, mtl -any, transformers -any, parsec -any,
@@ -39,7 +39,7 @@ library
3939 exposed: True
4040 buildable: True
4141 hs-source-dirs: src
42−
42+
4343executable psc
4444 build-depends: base >=4 && <5, cmdtheline -any, containers -any,
4545 mtl -any, transformers -any, parsec -any, utf8-string -any,
@@ -48,7 +48,7 @@ executable psc
4848 buildable: True
4949 hs-source-dirs: src
5050 other-modules: Language.PureScript.Optimize
51−
51+
5252test-suite tests
5353 build-depends: base >=4 && <5, syb -any, directory -any,
5454 filepath -any, containers -any, mtl -any, transformers -any,
src/Language/PureScript/Parser/Common.hs+1−1
@@ -148,7 +148,7 @@ fold first more combine = do
148148 return $ foldl combine a bs
149149
150150buildPostfixParser :: P.Stream s m t => [P.ParsecT s u m (a -> a)] -> P.ParsecT s u m a -> P.ParsecT s u m a
151−buildPostfixParser f x = fold x (P.choice (map P.try f)) (flip ($))
151+buildPostfixParser f x = fold x (P.choice f) (flip ($))
152152
153153parseIdent :: P.Parsec String u Ident
154154parseIdent = (Ident <$> identifier) <|> (Op <$> parens operator)
src/Language/PureScript/Parser/Declarations.hs+11−11
@@ -48,31 +48,31 @@ parseDataDeclaration = do
4848
4949parseTypeDeclaration :: P.Parsec String ParseState Declaration
5050parseTypeDeclaration =
51− TypeDeclaration <$> parseIdent
52− <*> (lexeme (indented *> P.string "::") *> parsePolyType)
51+ TypeDeclaration <$> P.try (parseIdent <* lexeme (indented *> P.string "::"))
52+ <*> parsePolyType
5353
5454parseTypeSynonymDeclaration :: P.Parsec String ParseState Declaration
5555parseTypeSynonymDeclaration =
56− TypeSynonymDeclaration <$> (reserved "type" *> indented *> properName)
56+ TypeSynonymDeclaration <$> (P.try (reserved "type") *> indented *> properName)
5757 <*> many (indented *> identifier)
5858 <*> (lexeme (indented *> P.char '=') *> parseType)
5959
6060parseValueDeclaration :: P.Parsec String ParseState Declaration
6161parseValueDeclaration =
62− ValueDeclaration <$> parseIdent
63− <*> (lexeme (indented *> P.char '=') *> parseValue)
62+ ValueDeclaration <$> P.try (parseIdent <* lexeme (indented *> P.char '='))
63+ <*> parseValue
6464
6565parseExternDeclaration :: P.Parsec String ParseState Declaration
66−parseExternDeclaration = reserved "extern" *> indented *>
67− (ExternDataDeclaration <$> (reserved "data" *> indented *> properName)
66+parseExternDeclaration = P.try (reserved "extern") *> indented *>
67+ (ExternDataDeclaration <$> (P.try (reserved "data") *> indented *> properName)
6868 <*> (lexeme (indented *> P.string "::") *> parseKind)
6969 <|> ExternDeclaration <$> parseIdent
7070 <*> (lexeme (indented *> P.string "::") *> parsePolyType))
7171
7272parseAssociativity :: P.Parsec String ParseState Associativity
7373parseAssociativity =
74− (reserved "infixl" >> return Infixl) <|>
75− (reserved "infixr" >> return Infixr)
74+ (P.try (reserved "infixl") >> return Infixl) <|>
75+ (P.try (reserved "infixr") >> return Infixr)
7676
7777parseFixity :: P.Parsec String ParseState Fixity
7878parseFixity = Fixity <$> parseAssociativity <*> (indented *> natural)
@@ -88,13 +88,13 @@ parseFixityDeclaration = do
8888 return $ FixityDeclaration fixity name
8989
9090parseDeclaration :: P.Parsec String ParseState Declaration
91−parseDeclaration = P.choice (map P.try
91+parseDeclaration = P.choice
9292 [ parseDataDeclaration
9393 , parseTypeDeclaration
9494 , parseTypeSynonymDeclaration
9595 , parseValueDeclaration
9696 , parseExternDeclaration
97− , parseFixityDeclaration ]) P.<?> "declaration"
97+ , parseFixityDeclaration ] P.<?> "declaration"
9898
9999parseDeclarations :: P.Parsec String ParseState [Declaration]
100100parseDeclarations = whiteSpace *> mark (same *> P.many parseDeclaration) <* P.eof
src/Language/PureScript/Parser/Types.hs+1−1
@@ -74,7 +74,7 @@ parseType :: P.Parsec String ParseState Type
7474parseType = (P.buildExpressionParser operators . buildPostfixParser postfixTable $ parseTypeAtom) P.<?> "type"
7575 where
7676 postfixTable :: [P.Parsec String ParseState (Type -> Type)]
77− postfixTable = [ flip TypeApp <$> (indented *> parseTypeAtom) ]
77+ postfixTable = [ flip TypeApp <$> P.try (indented *> parseTypeAtom) ]
7878 operators = [ [ P.Infix (lexeme (P.try (P.string "->")) >> return (\t1 t2 -> Function [t1] t2)) P.AssocRight ] ]
7979
8080parseNameAndType :: P.Parsec String ParseState (String, Type)
src/Language/PureScript/Parser/Values.hs+14−15
@@ -75,7 +75,7 @@ parseConstructor :: P.Parsec String ParseState Value
7575parseConstructor = Constructor <$> C.properName
7676
7777parseCase :: P.Parsec String ParseState Value
78−parseCase = Case <$> P.between (C.reserved "case") (C.indented *> C.reserved "of") parseValue
78+parseCase = Case <$> P.between (P.try (C.reserved "case")) (C.indented *> C.reserved "of") parseValue
7979 <*> (C.indented *> C.mark (P.many (C.same *> C.mark parseCaseAlternative)))
8080
8181parseCaseAlternative :: P.Parsec String ParseState (Binder, Value)
@@ -84,30 +84,30 @@ parseCaseAlternative = (,) <$> (parseGuardedBinder <* C.lexeme (P.string "->"))
8484 P.<?> "case alternative"
8585
8686parseIfThenElse :: P.Parsec String ParseState Value
87−parseIfThenElse = IfThenElse <$> (C.reserved "if" *> C.indented *> parseValue)
87+parseIfThenElse = IfThenElse <$> (P.try (C.reserved "if") *> C.indented *> parseValue)
8888 <*> (C.indented *> C.reserved "then" *> C.indented *> parseValue)
8989 <*> (C.indented *> C.reserved "else" *> C.indented *> parseValue)
9090
9191parseBlock :: P.Parsec String ParseState Value
92−parseBlock = Block <$> (C.reserved "do" *> parseManyStatements)
92+parseBlock = Block <$> (P.try (C.reserved "do") *> parseManyStatements)
9393
9494parseManyStatements :: P.Parsec String ParseState [Statement]
9595parseManyStatements = C.indented *> C.mark (P.many (C.same *> C.mark parseStatement)) P.<?> "block"
9696
9797parseValueAtom :: P.Parsec String ParseState Value
98−parseValueAtom = C.indented *> P.choice (map P.try
99− [ parseNumericLiteral
100− , parseStringLiteral
101− , parseBooleanLiteral
98+parseValueAtom = C.indented *> P.choice
99+ [ P.try parseNumericLiteral
100+ , P.try parseStringLiteral
101+ , P.try parseBooleanLiteral
102102 , parseArrayLiteral
103103 , parseObjectLiteral
104104 , parseAbs
105− , parseVar
106− , parseConstructor
105+ , P.try parseVar
106+ , P.try parseConstructor
107107 , parseBlock
108108 , parseCase
109109 , parseIfThenElse
110− , C.parens parseValue ])
110+ , C.parens parseValue ]
111111
112112parsePropertyUpdate :: P.Parsec String ParseState (String, Value)
113113parsePropertyUpdate = do
@@ -125,10 +125,10 @@ parseValue = do
125125 where
126126 indexersAndAccessors = C.buildPostfixParser postfixTable1 parseValueAtom
127127 postfixTable1 = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
128− , Indexer <$> (C.indented *> C.squares parseValue)
129− , flip ObjectUpdate <$> (C.indented *> C.braces ((C.indented *> parsePropertyUpdate) `P.sepBy1` (C.indented *> C.comma))) ]
130− postfixTable2 = [ C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2])
131− , flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
128+ , P.try $ Indexer <$> (C.indented *> C.squares parseValue)
129+ , P.try $ flip ObjectUpdate <$> (C.indented *> C.braces ((C.indented *> parsePropertyUpdate) `P.sepBy1` (C.indented *> C.comma))) ]
130+ postfixTable2 = [ P.try (C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2]))
131+ , P.try $ flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
132132 , flip TypedValue <$> (P.try (C.lexeme (C.indented *> P.string "::")) *> parsePolyType) ]
133133 operators user =
134134 [ [ Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (Unary Not)
@@ -174,7 +174,6 @@ customOperatorTable fixities =
174174 return $ \t1 t2 -> App (App (Var (Op name)) [t1]) [t2])
175175 levels
176176
177−
178177toAssoc :: Associativity -> Assoc
179178toAssoc Infixl = AssocLeft
180179toAssoc Infixr = AssocRight