on master help sign in
Add error messages for parse errors in parentheses
c26f262Evan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+157−15
@@ -261,14 +261,14 @@ data Record
261
261
262
262
263data Tuple
263data Tuple
264− = TupleOpen Row Col
265− | TupleExpr Expr Row Col
264+ = TupleExpr Expr Row Col
266 | TupleSpace Space Row Col
265 | TupleSpace Space Row Col
267 | TupleEnd Row Col
266 | TupleEnd Row Col
268 | TupleOperatorClose Row Col
267 | TupleOperatorClose Row Col
269 | TupleOperatorReserved Operator Row Col
268 | TupleOperatorReserved Operator Row Col
270 --
269 --
271− | TupleIndentExpr Row Col
270+ | TupleIndentExpr1 Row Col
271+ | TupleIndentExprN Row Col
272 | TupleIndentEnd Row Col
272 | TupleIndentEnd Row Col
273
273
274
274
@@ -810,8 +810,8 @@ toExprReport source name expr _ _ =
810 Update _ _ _ ->
810 Update _ _ _ ->
811 error "TODO Update"
811 error "TODO Update"
812
812
813− Tuple _ _ _ ->
813+ Tuple tuple row col ->
814− error "TODO Tuple"
814+ toTupleReport source name tuple row col
815
815
816 Func func row col ->
816 Func func row col ->
817 toFuncReport source name func row col
817 toFuncReport source name func row col
@@ -856,21 +856,44 @@ toExprReport source name expr _ _ =
856 Report.toCodeSnippet source region Nothing
856 Report.toCodeSnippet source region Nothing
857 (
857 (
858 D.reflow $
858 D.reflow $
859− "I need to see an expression after this " ++ Name.toChars op ++ " operator:"
859+ "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
860 ,
860 ,
861+ D.stack
861− D.fillSep $
862+ [ D.fillSep $
862− ["You","can","just","put","anything","for","now,","like"
863+ ["You","can","just","put","anything","for","now,","like"
863− ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
864+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
864− ,"Once","there","is","something","there,","I","can","give","more"
865+ ,"Once","there","is","something","there,","I","can","give","more"
865− ,"specific","hints","about","what","type","of","value","is","needed!"
866+ ,"specific","hints","about","what","type","of","value","is","needed!"
867+ ]
868+ , D.toSimpleNote $
869+ "This can happen if see reserved words like `let` or `as` unexpectedly.\
870+ \ I can get confused and not understand what is going on very well!"
866 ]
871 ]
867 )
872 )
868
873
869 OperatorReserved operator row col ->
874 OperatorReserved operator row col ->
870 toOperatorReport source name operator row col
875 toOperatorReport source name operator row col
871
876
872− Start _ _ ->
877+ Start row col ->
873− error "TODO Start"
878+ let region = toRegion row col in
879+ Report.Report "MISSING EXPRESSION" region [] $
880+ Report.toCodeSnippet source region Nothing
881+ (
882+ D.reflow $
883+ "I was expecting to see an expression next:"
884+ ,
885+ D.stack
886+ [ D.fillSep $
887+ ["You","can","just","put","anything","for","now,","like"
888+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
889+ ,"Once","there","is","something","there,","I","can","give","more"
890+ ,"specific","hints","about","what","type","of","value","is","needed!"
891+ ]
892+ , D.toSimpleNote $
893+ "This can happen if see reserved words like `let` or `as` unexpectedly.\
894+ \ I can get confused and not understand what is going on very well!"
895+ ]
896+ )
874
897
875 Char char row col ->
898 Char char row col ->
876 toCharReport source char row col
899 toCharReport source char row col
@@ -1327,9 +1350,128 @@ toOperatorReport source name operator row col =
1327 )
1350 )
1328
1351
1329
1352
1353+toTupleReport :: Code.Source -> Name.Name -> Tuple -> Row -> Col -> Report.Report
1354+toTupleReport source name tuple startRow startCol =
1355+ case tuple of
1356+ TupleExpr expr row col ->
1357+ toExprReport source name expr row col
1358+
1359+ TupleSpace space row col ->
1360+ toSpaceReport source space row col
1361+
1362+ TupleEnd row col ->
1363+ let
1364+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1365+ region = toRegion row col
1366+ in
1367+ Report.Report "UNFINISHED PARENTHESES" region [] $
1368+ Report.toCodeSnippet source surroundings (Just region)
1369+ (
1370+ D.reflow $
1371+ "I was expecting to see a closing parenthesis next:"
1372+ ,
1373+ D.stack
1374+ [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
1375+ , D.toSimpleNote $
1376+ "This can happen if I see reserved words like `let` or `as` unexpectedly.\
1377+ \ So I could be stuck on some other problem, which is not letting me get to\
1378+ \ the closing parenthesis I am expecting to see."
1379+ ]
1380+ )
1381+
1382+ TupleOperatorClose row col ->
1383+ let
1384+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1385+ region = toRegion row col
1386+ in
1387+ Report.Report "UNFINISHED OPERATOR FUNCTION" region [] $
1388+ Report.toCodeSnippet source surroundings (Just region)
1389+ (
1390+ D.reflow "I was expecting a closing parenthesis here:"
1391+ ,
1392+ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
1393+ )
1394+
1395+ TupleOperatorReserved operator row col ->
1396+ let
1397+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1398+ region = toRegion row col
1399+ in
1400+ Report.Report "UNEXPECTED SYMBOL" region [] $
1401+ Report.toCodeSnippet source surroundings (Just region)
1402+ (
1403+ D.reflow $
1404+ "I ran into an unexpected symbol here:"
1405+ ,
1406+ D.fillSep $
1407+ case operator of
1408+ OpDot -> ["Maybe","you","wanted","a","record","accessor","like",D.dullyellow ".x","or",D.dullyellow ".name","instead?"]
1409+ OpPipe -> ["Try",D.dullyellow "(||)","instead?","To","turn","boolean","OR","into","a","function?"]
1410+ OpArrow -> ["Maybe","you","wanted",D.dullyellow "(>)","or",D.dullyellow "(>=)","instead?"]
1411+ OpEquals -> ["Try",D.dullyellow "(==)","instead?","To","make","a","function","that","checks","equality?"]
1412+ OpHasType -> ["Try",D.dullyellow "(::)","instead?","To","add","values","to","the","front","of","lists?"]
1413+ )
1414+
1415+ TupleIndentExpr1 row col ->
1416+ let
1417+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1418+ region = toRegion row col
1419+ in
1420+ Report.Report "UNFINISHED PARENTHESES" region [] $
1421+ Report.toCodeSnippet source surroundings (Just region)
1422+ (
1423+ D.reflow $
1424+ "I just saw an open parenthesis, so I was expecting to see an expression next."
1425+ ,
1426+ D.stack
1427+ [ D.fillSep $
1428+ ["Something","like",D.dullyellow "(4 + 5)","or"
1429+ ,D.dullyellow "(String.reverse \"desserts\")" <> "."
1430+ ,"Anything","where","you","are","putting","parentheses","around","normal","expressions."
1431+ ]
1432+ , D.toSimpleNote
1433+ "If you are trying to use the (+) syntax for referring to operators as functions (or\
1434+ \ the () syntax for the unit value) the issue may be that no spaces are allowed between\
1435+ \ the parentheses."
1436+ ]
1437+ )
1438+
1439+ TupleIndentExprN row col ->
1440+ let
1441+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1442+ region = toRegion row col
1443+ in
1444+ Report.Report "UNFINISHED TUPLE" region [] $
1445+ Report.toCodeSnippet source surroundings (Just region)
1446+ (
1447+ D.reflow $
1448+ "I just saw a comma, so I was expecting to see another expression in this tuple."
1449+ ,
1450+ D.fillSep $
1451+ ["A","tuple","looks","like",D.dullyellow "(3,4)","or"
1452+ ,D.dullyellow "(\"Tom\",42)" <> ","
1453+ ,"so","I","think","there","is","an","expression","missing","here?"
1454+ ]
1455+ )
1456+
1457+ TupleIndentEnd row col ->
1458+ let
1459+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1460+ region = toRegion row col
1461+ in
1462+ Report.Report "UNFINISHED PARENTHESES" region [] $
1463+ Report.toCodeSnippet source surroundings (Just region)
1464+ (
1465+ D.reflow $
1466+ "I was expecting to see a closing parenthesis next:"
1467+ ,
1468+ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
1469+ )
1470+
1471+
1330toListReport :: Code.Source -> Name.Name -> List -> Row -> Col -> Report.Report
1472toListReport :: Code.Source -> Name.Name -> List -> Row -> Col -> Report.Report
1331−toListReport source name func startRow startCol =
1473+toListReport source name list startRow startCol =
1332− case func of
1474+ case list of
1333 ListSpace space row col ->
1475 ListSpace space row col ->
1334 toSpaceReport source space row col
1476 toSpaceReport source space row col
1335
1477