@@ -49,7 +49,7 @@ import Prelude hiding (Char, String)
49import qualified Data.Char as Char
49import qualified Data.Char as Char
50import qualified Data.Name as Name
50import qualified Data.Name as Name
51import Data.Word (Word16)
51import Data.Word (Word16)
52−--import Numeric (showHex)
52+import Numeric (showHex)
54import qualified Elm.ModuleName as ModuleName
54import qualified Elm.ModuleName as ModuleName
55import Parse.Primitives (Row, Col)
55import Parse.Primitives (Row, Col)
@@ -470,7 +470,7 @@ data TTuple
471 = CharEndless
471 = CharEndless
472 | CharEscape Escape
472 | CharEscape Escape
473− | CharNotString Int
473+ | CharNotString Word16
476data String
476data String
@@ -480,10 +480,10 @@ data String
482data Escape
482data Escape
483− = EscapeUnknown Word16 Word16
483+ = EscapeUnknown
484− | BadUnicodeFormat Word16 Word16
484+ | BadUnicodeFormat Word16
485− | BadUnicodeCode Word16 Word16
485+ | BadUnicodeCode Word16
486− | BadUnicodeLength Word16 Word16 Int Int
486+ | BadUnicodeLength Word16 Int Int
489data Number
489data Number
@@ -550,7 +550,7 @@ toReport source err =
550 ++ ModuleName.toChars expectedName
550 ++ ModuleName.toChars expectedName
551 ++ "` here. Make the following change, and you should be all set!"
551 ++ "` here. Make the following change, and you should be all set!"
552 , D.indent 4 $
552 , D.indent 4 $
553− D.red (D.fromName actualName) <> " -> " <> D.green (D.fromName expectedName)
553+ D.dullyellow (D.fromName actualName) <> " -> " <> D.green (D.fromName expectedName)
554 , D.toSimpleNote $
554 , D.toSimpleNote $
555 "I require that module names correspond to file paths. This makes it much\
555 "I require that module names correspond to file paths. This makes it much\
556 \ easier to explore unfamiliar codebases! So if you want to keep the current\
556 \ easier to explore unfamiliar codebases! So if you want to keep the current\
@@ -835,11 +835,11 @@ toExprReport source _ expr _ _ =
835 Start _ _ ->
835 Start _ _ ->
836 error "TODO Start"
836 error "TODO Start"
838− Char _ _ _ ->
838+ Char char row col ->
839− error "TODO Char"
839+ toCharReport source char row col
841− String _ _ _ ->
841+ String string row col ->
842− error "TODO String"
842+ toStringReport source string row col
844 Number number row col ->
844 Number number row col ->
845 toNumberReport source number row col
845 toNumberReport source number row col
@@ -884,6 +884,196 @@ toExprReport source _ expr _ _ =
884 error "TODO IndentMoreExpr"
884 error "TODO IndentMoreExpr"
887+toCharReport :: Code.Source -> Char -> Row -> Col -> Report.Report
888+toCharReport source char row col =
892+ region = toRegion row col
894+ Report.Report "MISSING SINGLE QUOTE" region [] $
895+ Report.toCodeSnippet source region Nothing
898+ "I thought I was parsing a character, but I got to the end of\
899+ \ the line without seeing the closing single quote:"
902+ "Add a closing single quote here!"
905+ CharEscape escape ->
906+ toEscapeReport source escape row col
908+ CharNotString width ->
910+ region = toWiderRegion row col width
912+ Report.Report "NEEDS DOUBLE QUOTES" region [] $
913+ Report.toCodeSnippet source region Nothing
915+ "The following string uses single quotes:"
918+ [ "Please switch to double quotes instead:"
920+ D.dullyellow "'this'" <> " => " <> D.green "\"this\""
922+ "Elm uses double quotes for strings like \"hello\", whereas it uses single\
923+ \ quotes for individual characters like 'a' and 'ø'. This distinction helps with\
924+ \ code like (String.any (\\c -> c == 'X') \"90210\") where you are inspecting\
925+ \ individual characters."
930+toStringReport :: Code.Source -> String -> Row -> Col -> Report.Report
931+toStringReport source string row col =
933+ StringEndless_Single ->
935+ region = toRegion row col
937+ Report.Report "ENDLESS STRING" region [] $
938+ Report.toCodeSnippet source region Nothing
941+ "I got to the end of the line without seeing the closing double quote:"
945+ ["Strings","look","like",D.green "\"this\"","with","double"
946+ ,"quotes","on","each","end.","Is","the","closing","double"
947+ ,"quote","missing","in","your","code?"
949+ , D.link "Note" "Read" "TODO" "if you want a string that spans multiple lines."
953+ StringEndless_Multi ->
955+ region = toWiderRegion row col 3
957+ Report.Report "ENDLESS STRING" region [] $
958+ Report.toCodeSnippet source region Nothing
961+ "I cannot find the end of this multi-line string:"
964+ [ D.reflow "Add a \"\"\" somewhere after this to end the string."
965+ , D.link "Hint" "Read" "TODO" "for more information on strings and multi-line strings."
969+ StringEscape escape ->
970+ toEscapeReport source escape row col
973+toEscapeReport :: Code.Source -> Escape -> Row -> Col -> Report.Report
974+toEscapeReport source escape row col =
978+ region = toWiderRegion row col 2
980+ Report.Report "UNKNOWN ESCAPE" region [] $
981+ Report.toCodeSnippet source region Nothing
984+ "Backslashes always start escaped characters, but I do not recognize this one:"
988+ "Valid escape characters include:"
989+ , D.dullyellow $ D.indent 4 $ D.vcat $
999+ "Do you want one of those instead? Maybe you need \\\\ to escape a backslash?"
1001+ "The last style lets encode ANY character by its Unicode code\
1002+ \ point. That means \\u{0009} and \\t are the same. You can use\
1003+ \ that style for anything not covered by the other six escapes!"
1007+ BadUnicodeFormat width ->
1009+ region = toWiderRegion row col width
1011+ Report.Report "BAD UNICODE ESCAPE" region [] $
1012+ Report.toCodeSnippet source region Nothing
1015+ "I ran into an invalid Unicode escape:"
1019+ "Here are some examples of valid Unicode escapes:"
1020+ , D.dullyellow $ D.indent 4 $ D.vcat $
1027+ "Notice that the code point is always surrounded by curly braces.\
1028+ \ Maybe you are missing the opening or closing curly brace?"
1031+ BadUnicodeCode width ->
1033+ region = toWiderRegion row col width
1035+ Report.Report "BAD UNICODE ESCAPE" region [] $
1036+ Report.toCodeSnippet source region Nothing
1039+ "This is not a valid code point:"
1042+ "The valid code points are between 0 and 10FFFF inclusive."
1045+ BadUnicodeLength width numDigits badCode ->
1047+ region = toWiderRegion row col width
1049+ Report.Report "BAD UNICODE ESCAPE" region [] $
1050+ Report.toCodeSnippet source region Nothing $
1051+ if numDigits < 4 then
1054+ "Every code point needs at least four digits:"
1057+ goodCode = replicate (4 - numDigits) '0' ++ map Char.toUpper (showHex badCode "")
1058+ suggestion = "\\u{" <> D.fromChars goodCode <> "}"
1060+ D.fillSep ["Try",D.green suggestion,"instead?"]
1066+ "This code point has too many digits:"
1069+ ["Valid","code","points","are","between"
1070+ ,D.green "\\u{0000}","and",D.green "\\u{10FFFF}" <> ","
1071+ ,"so","try","trimming","any","leading","zeros","until"
1072+ ,"you","have","between","four","and","six","digits."
887toNumberReport :: Code.Source -> Number -> Row -> Col -> Report.Report
1077toNumberReport :: Code.Source -> Number -> Row -> Col -> Report.Report
888toNumberReport source number row col =
1078toNumberReport source number row col =
@@ -1051,233 +1241,6 @@ toNumberReport source number row col =
1051 "I need a single digit between 0 and 9 inclusive."
1241 "I need a single digit between 0 and 9 inclusive."
1057− Report.Report "EXPECTING A CHARACTER" region [] $
1058− Report.toCodeSnippet source region Nothing
1061− "I was expecting a character here:"
1065− "Characters start and end with single quotes, like this:"
1066− , D.indent 4 $ D.vcat $
1074− "That last style lets you encode characters by their unicode\
1075− \ code point, so 'a' is equivalent to '\\u{0061}', 'ø' is\
1076− \ equivalent to '\\u{00F8}', and so on for all code points."
1081− Report.Report "MISSING SINGLE QUOTE" region [] $
1082− Report.toCodeSnippet source region Nothing
1085− "I thought I was parsing a character, but I got to the end of\
1086− \ the line without seeing the closing single quote:"
1090− "Characters start and end with single quotes, like this:"
1091− , D.indent 4 $ D.vcat $
1099− "That last style lets you encode characters by their unicode\
1100− \ code point, so 'a' is equivalent to '\\u{0061}', 'ø' is\
1101− \ equivalent to '\\u{00F8}', and so on for all code points."
1105− CharNotString startRow startCol ->
1108− A.Region (A.Position startRow startCol) pos
1110− Report.Report "NEEDS DOUBLE QUOTES" stringRegion [] $
1111− Report.toCodeSnippet source stringRegion Nothing
1113− "The following string uses single quotes:"
1116− [ "Please switch to double quotes instead:"
1118− D.dullyellow "'this'" <> " => " <> D.green "\"this\""
1120− "Elm uses double quotes for strings like \"hello\", whereas it uses single\
1121− \ quotes for individual characters like 'a' and 'ø'. This distinction helps with\
1122− \ code like (String.any (\\c -> c == 'X') \"90210\") where you are inspecting\
1123− \ individual characters."
1128− Report.Report "EXPECTING A STRING" region [] $
1129− Report.toCodeSnippet source region Nothing
1132− "I was expecting a string here:"
1135− ["Something","like"
1136− ,D.green "\"this\""
1138− ,D.green "\"that\""
1139− ,"with","double","quotes."
1143− StringEnd_Single ->
1144− Report.Report "ENDLESS STRING" region [] $
1145− Report.toCodeSnippet source region Nothing
1148− "I got to the end of the line without seeing the closing double quote:"
1152− ["Strings","look","like",D.green "\"this\"","with","double"
1153− ,"quotes","on","each","end.","Is","the","closing","double"
1154− ,"quote","missing","in","your","code?"
1156− , D.link "Note" "Read" "TODO" "if you want a string that spans multiple lines."
1160− StringEnd_Multi startRow startCol ->
1164− (A.Position startRow startCol)
1165− (A.Position startRow (startCol + 3))
1167− Report.Report "ENDLESS STRING" startRegion [] $
1168− Report.toCodeSnippet source startRegion Nothing
1171− "I cannot find the end of this multi-line string:"
1174− [ D.reflow "Add a \"\"\" somewhere after this to end the string."
1175− , D.link "Hint" "Read" "TODO" "for more information on strings and multi-line strings."
1179− EscapeUnknown startCol endCol ->
1182− A.Region (A.Position row startCol) (A.Position row endCol)
1184− Report.Report "UNKNOWN ESCAPE" escapeRegion [] $
1185− Report.toCodeSnippet source escapeRegion Nothing
1188− "Backslashes always start escaped characters, but I do not recognize this one:"
1192− "Valid escape characters include:"
1193− , D.indent 4 $ D.vcat $
1203− "The last one lets encode ANY character by its Unicode code\
1204− \ point, so use that for anything outside the ordinary six."
1208− BadUnicodeFormat startCol endCol ->
1211− A.Region (A.Position row startCol) (A.Position row endCol)
1213− Report.Report "BAD UNICODE ESCAPE" escapeRegion [] $
1214− Report.toCodeSnippet source escapeRegion Nothing
1217− "I ran into an invalid Unicode escape:"
1221− "Here are some examples of valid Unicode escapes:"
1222− , D.green $ D.indent 4 $ D.vcat $
1229− "Notice that the code point is always surrounded by curly\
1230− \ braces. They are required!"
1234− BadUnicodeCode startCol endCol ->
1237− A.Region (A.Position row startCol) (A.Position row endCol)
1239− Report.Report "BAD UNICODE ESCAPE" escapeRegion [] $
1240− Report.toCodeSnippet source escapeRegion Nothing
1243− "This is not a valid code point:"
1246− "The valid code points are between 0 and 10FFFF inclusive."
1249− BadUnicodeLength startCol endCol numDigits badCode ->
1252− A.Region (A.Position row startCol) (A.Position row endCol)
1254− Report.Report "BAD UNICODE ESCAPE" escapeRegion [] $
1255− Report.toCodeSnippet source escapeRegion Nothing $
1256− if numDigits < 4 then
1259− "Every code point needs at least four digits:"
1262− goodCode = replicate (4 - numDigits) '0' ++ showHex badCode ""
1263− escape = "\\u{" <> D.fromChars goodCode <> "}"
1265− D.fillSep ["Try",D.green escape,"instead?"]
1271− "This code point has too many digits:"
1274− ["Valid","code","points","are","between"
1275− ,D.green "\\u{0000}","and",D.green "\\u{10FFFF}" <> ","
1276− ,"so","try","trimming","any","leading","zeros","until"
1277− ,"you","have","between","four","and","six","digits."
1281 Operator ->
1244 Operator ->
1282 Report.Report "EXPECTING AN OPERATOR" region [] $
1245 Report.Report "EXPECTING AN OPERATOR" region [] $
1283 Report.toCodeSnippet source region Nothing
1246 Report.toCodeSnippet source region Nothing