@@ -231,8 +231,7 @@ data Expr
232 | Dot Row Col
232 | Dot Row Col
233 | Access Row Col
233 | Access Row Col
234− | OperatorRHS Row Col
235− | OperatorRight Row Col
234+ | OperatorRight Name.Name Row Col
236 | OperatorReserved Operator Row Col
235 | OperatorReserved Operator Row Col
238 | Start Row Col
237 | Start Row Col
@@ -242,7 +241,7 @@ data Expr
242 | Space Space Row Col
241 | Space Space Row Col
243 | EndlessShader Row Col
242 | EndlessShader Row Col
244 | ShaderProblem [Char.Char] Row Col
243 | ShaderProblem [Char.Char] Row Col
245− | IndentOperatorRight Row Col
244+ | IndentOperatorRight Name.Name Row Col
246 | IndentMoreExpr Row Col
245 | IndentMoreExpr Row Col
@@ -791,7 +790,7 @@ toDeclDefReport source name declDef _ _ =
793toExprReport :: Code.Source -> Name.Name -> Expr -> Row -> Col -> Report.Report
792toExprReport :: Code.Source -> Name.Name -> Expr -> Row -> Col -> Report.Report
794−toExprReport source _ expr _ _ =
793+toExprReport source name expr _ _ =
795 case expr of
794 case expr of
796 Let _ _ _ ->
795 Let _ _ _ ->
797 error "TODO Let"
796 error "TODO Let"
@@ -817,20 +816,58 @@ toExprReport source _ expr _ _ =
817 Func _ _ _ ->
816 Func _ _ _ ->
818 error "TODO Func"
817 error "TODO Func"
820− Dot _ _ ->
819+ Dot row col ->
821− error "TODO Dot"
820+ let region = toRegion row col in
822−
821+ Report.Report "EXPECTING RECORD ACCESSOR" region [] $
823− Access _ _ ->
822+ Report.toCodeSnippet source region Nothing
824− error "TODO Access"
823+ (
825+ "I was expecting to see a record accessor here:"
828+ ["Something","like",D.dullyellow".name","or",D.dullyellow".price"
829+ ,"that","accesses","a","value","from","a","record."
826− OperatorRHS _ _ ->
833+ Access row col ->
827− error "TODO OperatorRHS"
834+ let region = toRegion row col in
835+ Report.Report "EXPECTING RECORD ACCESSOR" region [] $
836+ Report.toCodeSnippet source region Nothing
839+ "I am trying to parse a record accessor here:"
844+ ["Something","like",D.dullyellow".name","or",D.dullyellow".price"
845+ ,"that","accesses","a","value","from","a","record."
849+ "Record field names must start with a lower case letter!"
829− OperatorRight _ _ ->
853+ OperatorRight op row col ->
830− error "TODO OperatorRight"
854+ let region = toRegion row col in
855+ Report.Report "MISSING EXPRESSION" region [] $
856+ Report.toCodeSnippet source region Nothing
859+ "I need to see an expression after this " ++ Name.toChars op ++ " operator:"
862+ ["You","can","just","put","anything","for","now,","like"
863+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
864+ ,"Once","there","is","something","there,","I","can","give","more"
865+ ,"specific","hints","about","what","type","of","value","is","needed!"
832− OperatorReserved _ _ _ ->
869+ OperatorReserved operator row col ->
833− error "TODO OperatorReserved"
870+ toOperatorReport source name operator row col
835 Start _ _ ->
872 Start _ _ ->
836 error "TODO Start"
873 error "TODO Start"
@@ -877,8 +914,29 @@ toExprReport source _ expr _ _ =
880− IndentOperatorRight _ _ ->
917+ IndentOperatorRight op row col ->
881− error "TODO IndentOperatorRight"
918+ let region = toRegion row col in
919+ Report.Report "MISSING EXPRESSION" region [] $
920+ Report.toCodeSnippet source region Nothing
923+ "I need to see an expression after this " ++ Name.toChars op ++ " operator:"
928+ ["You","can","just","put","anything","for","now,","like"
929+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
930+ ,"Once","there","is","something","there,","I","can","give","more"
931+ ,"specific","hints","about","what","type","of","value","is","needed!"
935+ "I may be getting confused by your indentation? The easiest way to make sure\
936+ \ this is not an indentation problem is to put the expression on the right of\
937+ \ the " ++ Name.toChars op ++ " operator on the same line."
883 IndentMoreExpr _ _ ->
941 IndentMoreExpr _ _ ->
884 error "TODO IndentMoreExpr"
942 error "TODO IndentMoreExpr"
@@ -1145,6 +1203,129 @@ toNumberReport source number row col =
1206+toOperatorReport :: Code.Source -> Name.Name -> Operator -> Row -> Col -> Report.Report
1207+toOperatorReport source name operator row col =
1211+ region = toRegion row col
1213+ Report.Report "UNEXPECTED SYMBOL" region [] $
1214+ Report.toCodeSnippet source region Nothing
1216+ "I was not expecting this dot:"
1219+ "Dots are for record access and decimal points, so\
1220+ \ they cannot float around on their own. Maybe\
1221+ \ there is some extra whitespace?"
1226+ region = toRegion row col
1228+ Report.Report "UNEXPECTED SYMBOL" region [] $
1229+ Report.toCodeSnippet source region Nothing
1232+ "I was not expecting this vertical bar:"
1235+ "Vertical bars should only appear in custom type declarations. Maybe you want || instead?"
1240+ region = toWiderRegion row col 2
1242+ Report.Report "UNEXPECTED ARROW" region [] $
1243+ Report.toCodeSnippet source region Nothing $
1244+ if error "TODO inCase" then
1247+ "I was not expecting to see an arrow here:"
1252+ "I think I am parsing a `case` expression right now, so it makes sense to\
1253+ \ see arrows around here. This one is confusing me though!"
1256+ "I may be getting confused by the indentation. Every pattern in a `case` must be\
1257+ \ exactly aligned (with exactly the same amount of indentation) so maybe this arrow\
1258+ \ appears after the next `case` pattern (correctly!) but the pattern itself is\
1259+ \ indented too far?"
1266+ "I was not expecting an arrow here:"
1269+ "Arrows should only appear in `case` expressions and anonymous functions. Maybe\
1270+ \ you want > or >= instead?"
1275+ region = toRegion row col
1277+ Report.Report "UNEXPECTED EQUALS" region [] $
1278+ Report.toCodeSnippet source region Nothing
1281+ "I was not expecting to see this equals sign:"
1285+ D.reflow "Maybe you want == instead? To check if two values are equal?"
1288+ if error "TODO is within record?" then
1289+ "Records look like { x = 3, y = 4 } with the equals sign right\
1290+ \ after the field name. So maybe you forgot a comma?"
1292+ "I may be getting confused by your indentation. Is this supposed to be part of\
1293+ \ a definition AFTER the `" ++ Name.toChars name ++ "` definition? If so,\
1294+ \ the problem may be a bit before the equals sign. I need all definitions to\
1295+ \ be exactly aligned (with exactly the same indentation) so the problem may be that\
1296+ \ this new definition is indented a bit too much."
1302+ region = toRegion row col
1304+ Report.Report "UNEXPECTED SYMBOL" region [] $
1305+ Report.toCodeSnippet source region Nothing $
1308+ "I was not expecting to run into the \"has type\" symbol here:"
1313+ ["Maybe","you","want",D.green "::","instead?"
1314+ ,"To","put","something","on","the","front","of","a","list?"
1317+ "The single colon is reserved for type annotations and record types, but I think\
1318+ \ I am parsing the definition of `" ++ Name.toChars name ++ "` right now."
1321+ "I may be getting confused by your indentation. Is this supposed to be part of\
1322+ \ a type annotation AFTER the `" ++ Name.toChars name ++ "` definition? If so,\
1323+ \ the problem may be a bit before the \"has type\" symbol. I need all definitions to\
1324+ \ be exactly aligned (with exactly the same indentation) so the problem may be that\
1325+ \ this new definition is indented a bit too much."
1150 case err of
1331 case err of
@@ -1471,52 +1652,6 @@ problemToDocs problem =
1471 "Delete the underscore and it shoulld be fine!"
1652 "Delete the underscore and it shoulld be fine!"
1477− badOp stack "A" "\"has type\" operator"
1478− "type annotations and record types"
1479− "Maybe you want :: instead? Or maybe something is indented too much?"
1483− "I was not expecting this equals sign"
1484− <> contextToString " here" " while parsing " stack <> "."
1486− toBadEqualsHint stack
1490− if isCaseRelated stack then
1492− "I ran into a stray arrow while parsing this `case` expression."
1495− "All branches in a `case` must be indented the exact\
1496− \ same amount, so the patterns are vertically\
1497− \ aligned. Maybe this branch is indented too much?"
1501− badOp stack "An" "arrow"
1502− "cases expressions and anonymous functions"
1503− "Maybe you want > or >= instead?"
1506− badOp stack "A" "vertical bar"
1507− "type declarations"
1508− "Maybe you want || instead?"
1512− "I was not expecting this dot."
1515− "Dots are for record access and decimal points, so\
1516− \ they cannot float around on their own. Maybe\
1517− \ there is some extra whitespace?"
1520 Theories stack allTheories ->
1655 Theories stack allTheories ->
1522 D.reflow $
1657 D.reflow $
@@ -1548,60 +1683,6 @@ problemToDocs problem =
1554−badOp :: ContextStack -> String -> String -> String -> String -> ( D.Doc, D.Doc )
1555−badOp stack article opName setting hint =
1558− "I was not expecting this " <> opName
1559− <> contextToString " here" " while parsing " stack <> "."
1562− article <> " " <> opName <> " should only appear in "
1563− <> setting <> ". " <> hint
1567−toBadEqualsHint :: ContextStack -> D.Doc
1568−toBadEqualsHint stack =
1572− "Maybe you want == instead? Or maybe something is indented too much?"
1574− (ExprRecord, _) : _ ->
1576− "Records look like { x = 3, y = 4 } with the equals sign right\
1577− \ after the field name. Maybe you forgot a comma?"
1579− (Definition _, _) : rest ->
1581− "Maybe this is supposed to be a separate definition? If so, it\
1582− \ is indented too far. "
1584− if any ((==) ExprLet . fst) rest then
1585− "All definitions in a `let` expression must be vertically aligned."
1587− "Spaces are not allowed before top-level definitions."
1590− toBadEqualsHint rest
1594−isCaseRelated :: ContextStack -> Bool
1595−isCaseRelated stack =
1600− (context, _) : rest ->
1601− context == ExprCase || isCaseRelated rest
1605-- CONTEXT
1686-- CONTEXT