git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix some bad parser error messages caused by too many 'try's
5b44a8ePhil Freeman
purescript.cabal+4−4
@@ -1,5 +1,5 @@
1name: purescript
1name: purescript
2−version: 0.1.3
2+version: 0.1.4
3cabal-version: >=1.8
3cabal-version: >=1.8
4build-type: Simple
4build-type: Simple
5license: MIT
5license: MIT
@@ -12,7 +12,7 @@ description: A small compile-to-JS language with extensible records and type-saf
12category: Language
12category: Language
13author: Phil Freeman <paf31@cantab.net>
13author: Phil Freeman <paf31@cantab.net>
14data-dir: ""
14data-dir: ""
15−
15+
16library
16library
17 build-depends: base >=4 && <5, syb -any, cmdtheline -any,
17 build-depends: base >=4 && <5, syb -any, cmdtheline -any,
18 containers -any, mtl -any, transformers -any, parsec -any,
18 containers -any, mtl -any, transformers -any, parsec -any,
@@ -39,7 +39,7 @@ library
39 exposed: True
39 exposed: True
40 buildable: True
40 buildable: True
41 hs-source-dirs: src
41 hs-source-dirs: src
42−
42+
43executable psc
43executable psc
44 build-depends: base >=4 && <5, cmdtheline -any, containers -any,
44 build-depends: base >=4 && <5, cmdtheline -any, containers -any,
45 mtl -any, transformers -any, parsec -any, utf8-string -any,
45 mtl -any, transformers -any, parsec -any, utf8-string -any,
@@ -48,7 +48,7 @@ executable psc
48 buildable: True
48 buildable: True
49 hs-source-dirs: src
49 hs-source-dirs: src
50 other-modules: Language.PureScript.Optimize
50 other-modules: Language.PureScript.Optimize
51−
51+
52test-suite tests
52test-suite tests
53 build-depends: base >=4 && <5, syb -any, directory -any,
53 build-depends: base >=4 && <5, syb -any, directory -any,
54 filepath -any, containers -any, mtl -any, transformers -any,
54 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
148 return $ foldl combine a bs
148 return $ foldl combine a bs
149
149
150buildPostfixParser :: P.Stream s m t => [P.ParsecT s u m (a -> a)] -> P.ParsecT s u m a -> P.ParsecT s u m a
150buildPostfixParser :: 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 ($))
152
152
153parseIdent :: P.Parsec String u Ident
153parseIdent :: P.Parsec String u Ident
154parseIdent = (Ident <$> identifier) <|> (Op <$> parens operator)
154parseIdent = (Ident <$> identifier) <|> (Op <$> parens operator)
src/Language/PureScript/Parser/Declarations.hs+11−11
@@ -48,31 +48,31 @@ parseDataDeclaration = do
48
48
49parseTypeDeclaration :: P.Parsec String ParseState Declaration
49parseTypeDeclaration :: P.Parsec String ParseState Declaration
50parseTypeDeclaration =
50parseTypeDeclaration =
51− TypeDeclaration <$> parseIdent
51+ TypeDeclaration <$> P.try (parseIdent <* lexeme (indented *> P.string "::"))
52− <*> (lexeme (indented *> P.string "::") *> parsePolyType)
52+ <*> parsePolyType
53
53
54parseTypeSynonymDeclaration :: P.Parsec String ParseState Declaration
54parseTypeSynonymDeclaration :: P.Parsec String ParseState Declaration
55parseTypeSynonymDeclaration =
55parseTypeSynonymDeclaration =
56− TypeSynonymDeclaration <$> (reserved "type" *> indented *> properName)
56+ TypeSynonymDeclaration <$> (P.try (reserved "type") *> indented *> properName)
57 <*> many (indented *> identifier)
57 <*> many (indented *> identifier)
58 <*> (lexeme (indented *> P.char '=') *> parseType)
58 <*> (lexeme (indented *> P.char '=') *> parseType)
59
59
60parseValueDeclaration :: P.Parsec String ParseState Declaration
60parseValueDeclaration :: P.Parsec String ParseState Declaration
61parseValueDeclaration =
61parseValueDeclaration =
62− ValueDeclaration <$> parseIdent
62+ ValueDeclaration <$> P.try (parseIdent <* lexeme (indented *> P.char '='))
63− <*> (lexeme (indented *> P.char '=') *> parseValue)
63+ <*> parseValue
64
64
65parseExternDeclaration :: P.Parsec String ParseState Declaration
65parseExternDeclaration :: P.Parsec String ParseState Declaration
66−parseExternDeclaration = reserved "extern" *> indented *>
66+parseExternDeclaration = P.try (reserved "extern") *> indented *>
67− (ExternDataDeclaration <$> (reserved "data" *> indented *> properName)
67+ (ExternDataDeclaration <$> (P.try (reserved "data") *> indented *> properName)
68 <*> (lexeme (indented *> P.string "::") *> parseKind)
68 <*> (lexeme (indented *> P.string "::") *> parseKind)
69 <|> ExternDeclaration <$> parseIdent
69 <|> ExternDeclaration <$> parseIdent
70 <*> (lexeme (indented *> P.string "::") *> parsePolyType))
70 <*> (lexeme (indented *> P.string "::") *> parsePolyType))
71
71
72parseAssociativity :: P.Parsec String ParseState Associativity
72parseAssociativity :: P.Parsec String ParseState Associativity
73parseAssociativity =
73parseAssociativity =
74− (reserved "infixl" >> return Infixl) <|>
74+ (P.try (reserved "infixl") >> return Infixl) <|>
75− (reserved "infixr" >> return Infixr)
75+ (P.try (reserved "infixr") >> return Infixr)
76
76
77parseFixity :: P.Parsec String ParseState Fixity
77parseFixity :: P.Parsec String ParseState Fixity
78parseFixity = Fixity <$> parseAssociativity <*> (indented *> natural)
78parseFixity = Fixity <$> parseAssociativity <*> (indented *> natural)
@@ -88,13 +88,13 @@ parseFixityDeclaration = do
88 return $ FixityDeclaration fixity name
88 return $ FixityDeclaration fixity name
89
89
90parseDeclaration :: P.Parsec String ParseState Declaration
90parseDeclaration :: P.Parsec String ParseState Declaration
91−parseDeclaration = P.choice (map P.try
91+parseDeclaration = P.choice
92 [ parseDataDeclaration
92 [ parseDataDeclaration
93 , parseTypeDeclaration
93 , parseTypeDeclaration
94 , parseTypeSynonymDeclaration
94 , parseTypeSynonymDeclaration
95 , parseValueDeclaration
95 , parseValueDeclaration
96 , parseExternDeclaration
96 , parseExternDeclaration
97− , parseFixityDeclaration ]) P.<?> "declaration"
97+ , parseFixityDeclaration ] P.<?> "declaration"
98
98
99parseDeclarations :: P.Parsec String ParseState [Declaration]
99parseDeclarations :: P.Parsec String ParseState [Declaration]
100parseDeclarations = whiteSpace *> mark (same *> P.many parseDeclaration) <* P.eof
100parseDeclarations = 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
74parseType = (P.buildExpressionParser operators . buildPostfixParser postfixTable $ parseTypeAtom) P.<?> "type"
74parseType = (P.buildExpressionParser operators . buildPostfixParser postfixTable $ parseTypeAtom) P.<?> "type"
75 where
75 where
76 postfixTable :: [P.Parsec String ParseState (Type -> Type)]
76 postfixTable :: [P.Parsec String ParseState (Type -> Type)]
77− postfixTable = [ flip TypeApp <$> (indented *> parseTypeAtom) ]
77+ postfixTable = [ flip TypeApp <$> P.try (indented *> parseTypeAtom) ]
78 operators = [ [ P.Infix (lexeme (P.try (P.string "->")) >> return (\t1 t2 -> Function [t1] t2)) P.AssocRight ] ]
78 operators = [ [ P.Infix (lexeme (P.try (P.string "->")) >> return (\t1 t2 -> Function [t1] t2)) P.AssocRight ] ]
79
79
80parseNameAndType :: P.Parsec String ParseState (String, Type)
80parseNameAndType :: P.Parsec String ParseState (String, Type)
src/Language/PureScript/Parser/Values.hs+14−15
@@ -75,7 +75,7 @@ parseConstructor :: P.Parsec String ParseState Value
75parseConstructor = Constructor <$> C.properName
75parseConstructor = Constructor <$> C.properName
76
76
77parseCase :: P.Parsec String ParseState Value
77parseCase :: 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
79 <*> (C.indented *> C.mark (P.many (C.same *> C.mark parseCaseAlternative)))
79 <*> (C.indented *> C.mark (P.many (C.same *> C.mark parseCaseAlternative)))
80
80
81parseCaseAlternative :: P.Parsec String ParseState (Binder, Value)
81parseCaseAlternative :: P.Parsec String ParseState (Binder, Value)
@@ -84,30 +84,30 @@ parseCaseAlternative = (,) <$> (parseGuardedBinder <* C.lexeme (P.string "->"))
84 P.<?> "case alternative"
84 P.<?> "case alternative"
85
85
86parseIfThenElse :: P.Parsec String ParseState Value
86parseIfThenElse :: 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)
88 <*> (C.indented *> C.reserved "then" *> C.indented *> parseValue)
88 <*> (C.indented *> C.reserved "then" *> C.indented *> parseValue)
89 <*> (C.indented *> C.reserved "else" *> C.indented *> parseValue)
89 <*> (C.indented *> C.reserved "else" *> C.indented *> parseValue)
90
90
91parseBlock :: P.Parsec String ParseState Value
91parseBlock :: P.Parsec String ParseState Value
92−parseBlock = Block <$> (C.reserved "do" *> parseManyStatements)
92+parseBlock = Block <$> (P.try (C.reserved "do") *> parseManyStatements)
93
93
94parseManyStatements :: P.Parsec String ParseState [Statement]
94parseManyStatements :: P.Parsec String ParseState [Statement]
95parseManyStatements = C.indented *> C.mark (P.many (C.same *> C.mark parseStatement)) P.<?> "block"
95parseManyStatements = C.indented *> C.mark (P.many (C.same *> C.mark parseStatement)) P.<?> "block"
96
96
97parseValueAtom :: P.Parsec String ParseState Value
97parseValueAtom :: P.Parsec String ParseState Value
98−parseValueAtom = C.indented *> P.choice (map P.try
98+parseValueAtom = C.indented *> P.choice
99− [ parseNumericLiteral
99+ [ P.try parseNumericLiteral
100− , parseStringLiteral
100+ , P.try parseStringLiteral
101− , parseBooleanLiteral
101+ , P.try parseBooleanLiteral
102 , parseArrayLiteral
102 , parseArrayLiteral
103 , parseObjectLiteral
103 , parseObjectLiteral
104 , parseAbs
104 , parseAbs
105− , parseVar
105+ , P.try parseVar
106− , parseConstructor
106+ , P.try parseConstructor
107 , parseBlock
107 , parseBlock
108 , parseCase
108 , parseCase
109 , parseIfThenElse
109 , parseIfThenElse
110− , C.parens parseValue ])
110+ , C.parens parseValue ]
111
111
112parsePropertyUpdate :: P.Parsec String ParseState (String, Value)
112parsePropertyUpdate :: P.Parsec String ParseState (String, Value)
113parsePropertyUpdate = do
113parsePropertyUpdate = do
@@ -125,10 +125,10 @@ parseValue = do
125 where
125 where
126 indexersAndAccessors = C.buildPostfixParser postfixTable1 parseValueAtom
126 indexersAndAccessors = C.buildPostfixParser postfixTable1 parseValueAtom
127 postfixTable1 = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
127 postfixTable1 = [ Accessor <$> (C.indented *> C.dot *> C.indented *> C.identifier)
128− , Indexer <$> (C.indented *> C.squares parseValue)
128+ , P.try $ Indexer <$> (C.indented *> C.squares parseValue)
129− , flip ObjectUpdate <$> (C.indented *> C.braces ((C.indented *> parsePropertyUpdate) `P.sepBy1` (C.indented *> C.comma))) ]
129+ , P.try $ 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])
130+ postfixTable2 = [ P.try (C.indented *> indexersAndAccessors >>= \t2 -> return (\t1 -> App t1 [t2]))
131− , flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
131+ , P.try $ flip App <$> (C.indented *> C.parens (parseValue `P.sepBy` (C.indented *> C.comma)))
132 , flip TypedValue <$> (P.try (C.lexeme (C.indented *> P.string "::")) *> parsePolyType) ]
132 , flip TypedValue <$> (P.try (C.lexeme (C.indented *> P.string "::")) *> parsePolyType) ]
133 operators user =
133 operators user =
134 [ [ Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (Unary Not)
134 [ [ Prefix $ C.lexeme (P.try $ C.indented *> C.reservedOp "!") >> return (Unary Not)
@@ -174,7 +174,6 @@ customOperatorTable fixities =
174 return $ \t1 t2 -> App (App (Var (Op name)) [t1]) [t2])
174 return $ \t1 t2 -> App (App (Var (Op name)) [t1]) [t2])
175 levels
175 levels
176
176
177−
178toAssoc :: Associativity -> Assoc
177toAssoc :: Associativity -> Assoc
179toAssoc Infixl = AssocLeft
178toAssoc Infixl = AssocLeft
180toAssoc Infixr = AssocRight
179toAssoc Infixr = AssocRight