@@ -115,18 +115,11 @@ data Exposing
115115 | ExposingOperator Row Col
116116 | ExposingOperatorReserved BadOperator Row Col
117117 | ExposingOperatorRightParen Row Col
118− | ExposingEnd Row Col
119− --
120118 | ExposingTypePrivacy Row Col
121− | ExposingTypePrivacyDots Row Col
122− | ExposingTypePrivacyEnd Row Col
119+ | ExposingEnd Row Col
123120 --
124121 | ExposingIndentEnd Row Col
125122 | ExposingIndentValue Row Col
126− | ExposingIndentValueEnd Row Col
127− | ExposingIndentTypePrivacy Row Col
128− | ExposingIndentTypePrivacyDots Row Col
129− | ExposingIndentTypePrivacyEnd Row Col
130123
131124
132125
@@ -689,7 +682,7 @@ toParseErrorReport source modul =
689682 )
690683
691684 ModuleExposing exposing row col ->
692− error "TODO ModuleExposing" exposing row col
685+ toExposingReport source exposing row col
693686
694687 PortModuleProblem row col ->
695688 let
@@ -735,7 +728,7 @@ toParseErrorReport source modul =
735728 )
736729
737730 PortModuleExposing exposing row col ->
738− error "TODO PortModuleExposing" exposing row col
731+ toExposingReport source exposing row col
739732
740733 Effect row col ->
741734 let
@@ -855,7 +848,7 @@ toParseErrorReport source modul =
855848 toImportReport source row col
856849
857850 ImportExposingList exposing row col ->
858− error "TODO ImportExposingList" exposing row col
851+ toExposingReport source exposing row col
859852
860853 ImportEnd row col ->
861854 toImportReport source row col
@@ -940,6 +933,237 @@ toImportReport source row col =
940933
941934
942935
936+-- EXPOSING
937+
938+
939+toExposingReport :: Code.Source -> Exposing -> Row -> Col -> Report.Report
940+toExposingReport source exposing startRow startCol =
941+ case exposing of
942+ ExposingSpace space row col ->
943+ toSpaceReport source space row col
944+
945+ ExposingStart row col ->
946+ let
947+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
948+ region = toRegion row col
949+ in
950+ Report.Report "PROBLEM IN EXPOSING" region [] $
951+ Code.toSnippet source surroundings (Just region)
952+ (
953+ D.reflow $
954+ "I want to parse exposed values, but I am getting stuck here:"
955+ ,
956+ D.stack
957+ [ D.fillSep $
958+ ["Exposed","values","are","always","surrounded","by","parentheses."
959+ ,"So","try","adding","a",D.green "(","here?"
960+ ]
961+ , D.toSimpleNote "Here are some valid examples of `exposing` for reference:"
962+ , D.indent 4 $ D.vcat $
963+ [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
964+ , D.fillSep [D.cyan "import","Html",D.cyan "exposing","(Html, div, text)"]
965+ ]
966+ , D.reflow $
967+ "If you are getting tripped up, you can just expose everything for now. It should\
968+ \ get easier to make an explicit exposing list as you see more examples in the wild."
969+ ]
970+ )
971+
972+ ExposingValue row col ->
973+ case Code.whatIsNext source row col of
974+ Code.Keyword keyword ->
975+ let
976+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
977+ region = toKeywordRegion row col keyword
978+ in
979+ Report.Report "RESERVED WORD" region [] $
980+ Code.toSnippet source surroundings (Just region)
981+ (
982+ D.reflow $
983+ "I got stuck on this reserved word:"
984+ ,
985+ D.reflow $
986+ "It looks like you are trying to expose `" ++ keyword ++ "` but that is a reserved word. Is there a typo?"
987+ )
988+
989+ Code.Operator op ->
990+ let
991+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
992+ region = toKeywordRegion row col op
993+ in
994+ Report.Report "UNEXPECTED SYMBOL" region [] $
995+ Code.toSnippet source surroundings (Just region)
996+ (
997+ D.reflow $
998+ "I got stuck on this symbol:"
999+ ,
1000+ D.stack
1001+ [ D.reflow $
1002+ "If you are trying to expose an operator, add parentheses around it like this:"
1003+ , D.indent 4 $ D.dullyellow (D.fromChars op) <> " -> " <> D.green ("(" <> D.fromChars op <> ")")
1004+ ]
1005+ )
1006+
1007+ _ ->
1008+ let
1009+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1010+ region = toRegion row col
1011+ in
1012+ Report.Report "PROBLEM IN EXPOSING" region [] $
1013+ Code.toSnippet source surroundings (Just region)
1014+ (
1015+ D.reflow $
1016+ "I got stuck while parsing these exposed values:"
1017+ ,
1018+ D.stack
1019+ [ D.reflow $
1020+ "I do not have an exact recommendation, so here are some valid examples\
1021+ \ of `exposing` for reference:"
1022+ , D.indent 4 $ D.vcat $
1023+ [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
1024+ , D.fillSep [D.cyan "import","Basics",D.cyan "exposing","(Int, Float, Bool(..), (+), not, sqrt)"]
1025+ ]
1026+ , D.reflow $
1027+ "These examples show how to expose types, variants, operators, and functions. Everything\
1028+ \ should be some permutation of these examples, just with different names."
1029+ ]
1030+ )
1031+
1032+ ExposingOperator row col ->
1033+ let
1034+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1035+ region = toRegion row col
1036+ in
1037+ Report.Report "PROBLEM IN EXPOSING" region [] $
1038+ Code.toSnippet source surroundings (Just region)
1039+ (
1040+ D.reflow $
1041+ "I just saw an open parenthesis, so I was expecting an operator next:"
1042+ ,
1043+ D.fillSep $
1044+ ["It","is","possible","to","expose","operators,","so","I","was","expecting"
1045+ ,"to","see","something","like",D.dullyellow "(+)","or",D.dullyellow "(|=)"
1046+ ,"or",D.dullyellow "(||)","after","I","saw","that","open","parenthesis."
1047+ ]
1048+ )
1049+
1050+ ExposingOperatorReserved op row col ->
1051+ let
1052+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1053+ region = toRegion row col
1054+ in
1055+ Report.Report "RESERVED SYMBOL" region [] $
1056+ Code.toSnippet source surroundings (Just region)
1057+ (
1058+ D.reflow $
1059+ "I cannot expose this as an operator:"
1060+ ,
1061+ case op of
1062+ BadDot -> D.reflow "Try getting rid of this entry? Maybe I can give you a better hint after that?"
1063+ BadPipe -> D.fillSep ["Maybe","you","want",D.dullyellow "(||)","instead?"]
1064+ BadArrow -> D.reflow "Try getting rid of this entry? Maybe I can give you a better hint after that?"
1065+ BadEquals -> D.fillSep ["Maybe","you","want",D.dullyellow "(==)","instead?"]
1066+ BadHasType -> D.fillSep ["Maybe","you","want",D.dullyellow "(::)","instead?"]
1067+ )
1068+
1069+ ExposingOperatorRightParen row col ->
1070+ let
1071+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1072+ region = toRegion row col
1073+ in
1074+ Report.Report "PROBLEM IN EXPOSING" region [] $
1075+ Code.toSnippet source surroundings (Just region)
1076+ (
1077+ D.reflow $
1078+ "It looks like you are exposing an operator, but I got stuck here:"
1079+ ,
1080+ D.fillSep $
1081+ ["I","was","expecting","to","see","the","closing","parenthesis","immediately"
1082+ ,"after","the","operator.","Try","adding","a",D.green ")","right","here?"
1083+ ]
1084+ )
1085+
1086+ ExposingEnd row col ->
1087+ let
1088+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1089+ region = toRegion row col
1090+ in
1091+ Report.Report "UNFINISHED EXPOSING" region [] $
1092+ Code.toSnippet source surroundings (Just region)
1093+ (
1094+ D.reflow $
1095+ "I was partway through parsing exposed values, but I got stuck here:"
1096+ ,
1097+ D.reflow $
1098+ "Maybe there is a comma missing before this?"
1099+ )
1100+
1101+ ExposingTypePrivacy row col ->
1102+ let
1103+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1104+ region = toRegion row col
1105+ in
1106+ Report.Report "PROBLEM EXPOSING CUSTOM TYPE VARIANTS" region [] $
1107+ Code.toSnippet source surroundings (Just region)
1108+ (
1109+ D.reflow $
1110+ "It looks like you are trying to expose the variants of a custom type:"
1111+ ,
1112+ D.stack
1113+ [ D.fillSep $
1114+ ["You","need","to","write","something","like"
1115+ ,D.dullyellow "Status(..)","or",D.dullyellow "Entity(..)"
1116+ ,"though.","It","is","all","or","nothing,","otherwise","`case`"
1117+ ,"expressions","could","miss","a","variant","and","crash!"
1118+ ]
1119+ , D.toSimpleNote $
1120+ "It is often best to keep the variants hidden! If someone pattern matches on\
1121+ \ the variants, it is a MAJOR change if any new variants are added. Suddenly\
1122+ \ their `case` expressions do not cover all variants! So if you do not need\
1123+ \ people to pattern match, keep the variants hidden and expose functions to\
1124+ \ construct values of this type. This way you can add new variants as a MINOR change!"
1125+ ]
1126+ )
1127+
1128+ ExposingIndentEnd row col ->
1129+ let
1130+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1131+ region = toRegion row col
1132+ in
1133+ Report.Report "UNFINISHED EXPOSING" region [] $
1134+ Code.toSnippet source surroundings (Just region)
1135+ (
1136+ D.reflow $
1137+ "I was partway through parsing exposed values, but I got stuck here:"
1138+ ,
1139+ D.stack
1140+ [ D.fillSep $
1141+ ["I","was","expecting","a","closing","parenthesis."
1142+ ,"Try","adding","a",D.green ")","right","here?"
1143+ ]
1144+ , D.toSimpleNote $
1145+ "I can get confused when there is not enough indentation, so if you already\
1146+ \ have a closing parenthesis, it probably just needs some spaces in front of it."
1147+ ]
1148+ )
1149+
1150+ ExposingIndentValue row col ->
1151+ let
1152+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1153+ region = toRegion row col
1154+ in
1155+ Report.Report "UNFINISHED EXPOSING" region [] $
1156+ Code.toSnippet source surroundings (Just region)
1157+ (
1158+ D.reflow $
1159+ "I was partway through parsing exposed values, but I got stuck here:"
1160+ ,
1161+ D.reflow $
1162+ "I was expecting another value to expose."
1163+ )
1164+
1165+
1166+
9431167-- SPACES
9441168
9451169