1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Syntax
48import Prelude hiding (Char, String)
49import qualified Data.Char as Char
50import qualified Data.Name as Name
51import Data.Word (Word16)
52import Numeric (showHex)
54import qualified Elm.ModuleName as ModuleName
55import Parse.Primitives (Row, Col)
56import Parse.Symbol (BadOperator(..))
57import qualified Reporting.Annotation as A
58import qualified Reporting.Doc as D
59import qualified Reporting.Report as Report
60import qualified Reporting.Render.Code as Code
68 = ModuleNameUnspecified ModuleName.Raw
69 | ModuleNameMismatch ModuleName.Raw (A.Located ModuleName.Raw)
70 | UnexpectedPort A.Region
80 = ModuleSpace Space Row Col
81 | ModuleBadEnd Row Col
83 | ModuleProblem Row Col
85 | ModuleExposing Exposing Row Col
87 | PortModuleProblem Row Col
88 | PortModuleName Row Col
89 | PortModuleExposing Exposing Row Col
99 | ImportExposing Row Col
100 | ImportExposingList Exposing Row Col
101 | ImportEnd Row Col -- different based on col=1 or if greater
103 | ImportIndentName Row Col
104 | ImportIndentAlias Row Col
105 | ImportIndentExposingList Row Col
109 | Declarations Decl Row Col
113 = ExposingSpace Space Row Col
114 | ExposingStart Row Col
115 | ExposingValue Row Col
116 | ExposingOperator Row Col
117 | ExposingOperatorReserved BadOperator Row Col
118 | ExposingOperatorRightParen Row Col
119 | ExposingTypePrivacy Row Col
120 | ExposingEnd Row Col
122 | ExposingIndentEnd Row Col
123 | ExposingIndentValue Row Col
132 | DeclSpace Space Row Col
135 | DeclType DeclType Row Col
136 | DeclDef Name.Name DeclDef Row Col
138 | DeclFreshLineAfterDocComment Row Col
142 = DeclDefSpace Space Row Col
143 | DeclDefEquals Row Col
144 | DeclDefType Type Row Col
145 | DeclDefArg Pattern Row Col
146 | DeclDefBody Expr Row Col
147 | DeclDefNameRepeat Row Col
148 | DeclDefNameMatch Name.Name Row Col
150 | DeclDefIndentType Row Col
151 | DeclDefIndentEquals Row Col
152 | DeclDefIndentBody Row Col
156 = PortSpace Space Row Col
159 | PortType Type Row Col
160 | PortIndentName Row Col
161 | PortIndentColon Row Col
162 | PortIndentType Row Col
170 = DT_Space Space Row Col
172 | DT_Alias TypeAlias Row Col
173 | DT_Union CustomType Row Col
175 | DT_IndentName Row Col
179 = AliasSpace Space Row Col
181 | AliasEquals Row Col
182 | AliasBody Type Row Col
184 | AliasIndentEquals Row Col
185 | AliasIndentBody Row Col
189 = CT_Space Space Row Col
194 | CT_VariantArg Type Row Col
196 | CT_IndentEquals Row Col
197 | CT_IndentBar Row Col
198 | CT_IndentAfterBar Row Col
199 | CT_IndentAfterEquals Row Col
211 | Record Record Row Col
212 | Tuple Tuple Row Col
217 | OperatorRight Name.Name Row Col
218 | OperatorReserved BadOperator Row Col
222 | String String Row Col
223 | Number Number Row Col
224 | Space Space Row Col
225 | EndlessShader Row Col
226 | ShaderProblem [Char.Char] Row Col
227 | IndentOperatorRight Name.Name Row Col
233 | RecordField Row Col
234 | RecordEquals Row Col
235 | RecordExpr Expr Row Col
236 | RecordSpace Space Row Col
238 | RecordIndentOpen Row Col
239 | RecordIndentEnd Row Col
240 | RecordIndentField Row Col
241 | RecordIndentEquals Row Col
242 | RecordIndentExpr Row Col
246 = TupleExpr Expr Row Col
247 | TupleSpace Space Row Col
249 | TupleOperatorClose Row Col
250 | TupleOperatorReserved BadOperator Row Col
252 | TupleIndentExpr1 Row Col
253 | TupleIndentExprN Row Col
254 | TupleIndentEnd Row Col
258 = ListSpace Space Row Col
260 | ListExpr Expr Row Col
263 | ListIndentOpen Row Col
264 | ListIndentEnd Row Col
265 | ListIndentExpr Row Col
269 = FuncSpace Space Row Col
270 | FuncArg Pattern Row Col
271 | FuncBody Expr Row Col
274 | FuncIndentArg Row Col
275 | FuncIndentArrow Row Col
276 | FuncIndentBody Row Col
280 = CaseSpace Space Row Col
282 | CasePattern Pattern Row Col
284 | CaseExpr Expr Row Col
285 | CaseBranch Expr Row Col
287 | CaseIndentOf Row Col
288 | CaseIndentExpr Row Col
289 | CaseIndentPattern Row Col
290 | CaseIndentArrow Row Col
291 | CaseIndentBranch Row Col
292 | CasePatternAlignment Word16 Row Col
296 = IfSpace Space Row Col
299 | IfElseBranchStart Row Col
301 | IfCondition Expr Row Col
302 | IfThenBranch Expr Row Col
303 | IfElseBranch Expr Row Col
305 | IfIndentCondition Row Col
306 | IfIndentThen Row Col
307 | IfIndentThenBranch Row Col
308 | IfIndentElseBranch Row Col
309 | IfIndentElse Row Col
313 = LetSpace Space Row Col
315 | LetDefAlignment Word16 Row Col
317 | LetDef Name.Name Def Row Col
318 | LetDestruct Destruct Row Col
319 | LetBody Expr Row Col
320 | LetIndentDef Row Col
321 | LetIndentIn Row Col
322 | LetIndentBody Row Col
326 = DefSpace Space Row Col
327 | DefType Type Row Col
328 | DefNameRepeat Row Col
329 | DefNameMatch Name.Name Row Col
330 | DefArg Pattern Row Col
332 | DefBody Expr Row Col
333 | DefIndentEquals Row Col
334 | DefIndentType Row Col
335 | DefIndentBody Row Col
336 | DefAlignment Word16 Row Col
340 = DestructSpace Space Row Col
341 | DestructPattern Pattern Row Col
342 | DestructEquals Row Col
343 | DestructBody Expr Row Col
344 | DestructIndentEquals Row Col
345 | DestructIndentBody Row Col
353 = PRecord PRecord Row Col
354 | PTuple PTuple Row Col
355 | PList PList Row Col
359 | PString String Row Col
360 | PNumber Number Row Col
361 | PFloat Word16 Row Col
363 | PWildcardNotVar Name.Name Int Row Col
364 | PSpace Space Row Col
366 | PIndentStart Row Col
367 | PIndentAlias Row Col
371 = PRecordOpen Row Col
373 | PRecordField Row Col
374 | PRecordSpace Space Row Col
376 | PRecordIndentOpen Row Col
377 | PRecordIndentEnd Row Col
378 | PRecordIndentField Row Col
384 | PTupleExpr Pattern Row Col
385 | PTupleSpace Space Row Col
387 | PTupleIndentEnd Row Col
388 | PTupleIndentExpr1 Row Col
389 | PTupleIndentExprN Row Col
395 | PListExpr Pattern Row Col
396 | PListSpace Space Row Col
398 | PListIndentOpen Row Col
399 | PListIndentEnd Row Col
400 | PListIndentExpr Row Col
408 = TRecord TRecord Row Col
409 | TTuple TTuple Row Col
412 | TSpace Space Row Col
414 | TIndentStart Row Col
418 = TRecordOpen Row Col
421 | TRecordField Row Col
422 | TRecordColon Row Col
423 | TRecordType Type Row Col
425 | TRecordSpace Space Row Col
427 | TRecordIndentOpen Row Col
428 | TRecordIndentField Row Col
429 | TRecordIndentColon Row Col
430 | TRecordIndentType Row Col
431 | TRecordIndentEnd Row Col
437 | TTupleType Type Row Col
438 | TTupleSpace Space Row Col
440 | TTupleIndentType1 Row Col
441 | TTupleIndentTypeN Row Col
442 | TTupleIndentEnd Row Col
452 | CharNotString Word16
456 = StringEndless_Single
457 | StringEndless_Multi
458 | StringEscape Escape
463 | BadUnicodeFormat Word16
464 | BadUnicodeCode Word16
465 | BadUnicodeLength Word16 Int Int
472 | NumberNoLeadingZero
481 | EndlessMultiComment
488toReport :: Code.Source -> Error -> Report.Report
491 ModuleNameUnspecified name ->
493 region = toRegion 1 1
495 Report.Report "MODULE NAME MISSING" region [] $
498 "I need the module name to be declared at the top of this file, like this:"
499 , D.indent 4 $ D.fillSep $
500 [ D.cyan "module", D.fromName name, D.cyan "exposing", "(..)" ]
502 "Try adding that as the first line of your file!"
504 "It is best to replace (..) with an explicit list of types and\
505 \ functions you want to expose. When you know a value is only used\
506 \ within this module, you can refactor without worrying about uses\
507 \ elsewhere. Limiting exposed values can also speed up compilation\
508 \ because I can skip a bunch of work if I see that the exposed API\
512 ModuleNameMismatch expectedName (A.At region actualName) ->
513 Report.Report "MODULE NAME MISMATCH" region [ModuleName.toChars expectedName] $
514 Code.toSnippet source region Nothing
516 "It looks like this module name is out of sync:"
520 "I need it to match the file path, so I was expecting it to see `"
521 ++ ModuleName.toChars expectedName
522 ++ "` here. Make the following change, and you should be all set!"
524 D.dullyellow (D.fromName actualName) <> " -> " <> D.green (D.fromName expectedName)
526 "I require that module names correspond to file paths. This makes it much\
527 \ easier to explore unfamiliar codebases! So if you want to keep the current\
528 \ module name, try renaming the file instead."
532 UnexpectedPort region ->
533 Report.Report "UNEXPECTED PORTS" region [] $
534 Code.toSnippet source region Nothing
537 "You are declaring ports in a normal module."
541 ["Switch","this","to","say",D.cyan "port module","instead,"
542 ,"marking","that","this","module","contains","port","declarations."
545 "Ports are not a traditional FFI for calling JS functions directly. They need a different mindset! Read"
547 "to learn the syntax and how to use it effectively."
552 Report.Report "NO PORTS" region [] $
553 Code.toSnippet source region Nothing
556 "This module does not declare any ports, but it says it will:"
559 ["Switch","this","to",D.cyan "module"
560 ,"and","you","should","be","all","set!"
565 toParseErrorReport source modul
568toParseErrorReport :: Code.Source -> Module -> Report.Report
569toParseErrorReport source modul =
571 ModuleSpace space row col ->
572 toSpaceReport source space row col
574 ModuleBadEnd row col ->
575 case Code.whatIsNext source row col of
576 Code.Keyword keyword ->
578 region = toKeywordRegion row col keyword
580 Report.Report "RESERVED WORD" region [] $
581 Code.toSnippet source region Nothing
584 "I got stuck on this reserved word:"
587 "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
592 region = toKeywordRegion row col op
594 Report.Report "UNEXPECTED SYMBOL" region [] $
595 Code.toSnippet source region Nothing
598 "I ran into an unexpected symbol:"
601 "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
602 \ I can give a better hint from there?"
605 Code.Close term bracket ->
607 region = toRegion row col
609 Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
610 Code.toSnippet source region Nothing
613 "I ran into an unexpected " ++ term ++ ":"
616 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
621 region = toRegion row col
623 Report.Report "SYNTAX PROBLEM" region [] $
624 Code.toSnippet source region Nothing
630 "Whatever I am running into is confusing me a lot! Normally I can give fairly\
631 \ specific hints, but something is really tripping me up this time."
634 ModuleProblem row col ->
636 region = toRegion row col
638 Report.Report "UNFINISHED MODULE DECLARATION" region [] $
639 Code.toSnippet source region Nothing
642 "I am parsing an `module` declaration, but I got stuck here:"
646 "Here are some examples of valid `module` declarations:"
647 , D.indent 4 $ D.vcat $
648 [ D.fillSep [D.cyan "module","Main",D.cyan "exposing","(..)"]
649 , D.fillSep [D.cyan "module","Dict",D.cyan "exposing","(Dict, empty, get)"]
652 "I generally recommend using an explicit exposing list. I can skip compiling a bunch\
653 \ of files when the public interface of a module stays the same, so exposing fewer\
654 \ values can help improve compile times!"
658 ModuleName row col ->
660 region = toRegion row col
662 Report.Report "EXPECTING MODULE NAME" region [] $
663 Code.toSnippet source region Nothing
666 "I was parsing an `module` declaration until I got stuck here:"
670 "I was expecting to see the module name next, like in these examples:"
671 , D.indent 4 $ D.vcat $
672 [ D.fillSep [D.cyan "module","Dict",D.cyan "exposing","(..)"]
673 , D.fillSep [D.cyan "module","Maybe",D.cyan "exposing","(..)"]
674 , D.fillSep [D.cyan "module","Html.Attributes",D.cyan "exposing","(..)"]
675 , D.fillSep [D.cyan "module","Json.Decode",D.cyan "exposing","(..)"]
678 "Notice that the module names all start with capital letters. That is required!"
682 ModuleExposing exposing row col ->
683 toExposingReport source exposing row col
685 PortModuleProblem row col ->
687 region = toRegion row col
689 Report.Report "UNFINISHED PORT MODULE DECLARATION" region [] $
690 Code.toSnippet source region Nothing
693 "I am parsing an `port module` declaration, but I got stuck here:"
697 "Here are some examples of valid `port module` declarations:"
698 , D.indent 4 $ D.vcat $
699 [ D.fillSep [D.cyan "port",D.cyan "module","WebSockets",D.cyan "exposing","(send, listen, keepAlive)"]
700 , D.fillSep [D.cyan "port",D.cyan "module","Maps",D.cyan "exposing","(Location, goto)"]
702 , D.link "Note" "Read" "ports" "for more help."
706 PortModuleName row col ->
708 region = toRegion row col
710 Report.Report "EXPECTING MODULE NAME" region [] $
711 Code.toSnippet source region Nothing
714 "I was parsing an `module` declaration until I got stuck here:"
718 "I was expecting to see the module name next, like in these examples:"
719 , D.indent 4 $ D.vcat $
720 [ D.fillSep [D.cyan "port",D.cyan "module","WebSockets",D.cyan "exposing","(send, listen, keepAlive)"]
721 , D.fillSep [D.cyan "port",D.cyan "module","Maps",D.cyan "exposing","(Location, goto)"]
724 "Notice that the module names start with capital letters. That is required!"
728 PortModuleExposing exposing row col ->
729 toExposingReport source exposing row col
733 region = toRegion row col
735 Report.Report "BAD MODULE DECLARATION" region [] $
736 Code.toSnippet source region Nothing
739 "I cannot parse this module declaration:"
742 "This type of module is reserved for the @elm organization. It is used to\
743 \ define certain effects, avoiding building them into the compiler."
748 region = toRegion row col
750 toBadFirstLineReport keyword =
751 Report.Report "TOO MUCH INDENTATION" region [] $
752 Code.toSnippet source region Nothing
755 "This `" ++ keyword ++ "` should not have any spaces before it:"
758 "Delete the spaces before `" ++ keyword ++ "` until there are none left!"
762 case Code.whatIsNext source row col of
763 Code.Keyword "module" -> toBadFirstLineReport "module"
764 Code.Keyword "import" -> toBadFirstLineReport "import"
765 Code.Keyword "type" -> toBadFirstLineReport "type"
766 Code.Keyword "port" -> toBadFirstLineReport "port"
768 Report.Report "SYNTAX PROBLEM" region [] $
769 Code.toSnippet source region Nothing
776 "I am not sure what is going on, but I recommend starting an Elm\
777 \ file with the following lines:"
779 [ D.fillSep [D.cyan "import","Html"]
781 , D.fillSep [D.green "main","="]
782 , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
785 "You should be able to copy those lines directly into your file. Check out\
786 \ some of the examples on https://elm-lang.org for more help getting started!"
788 "This can also happen when something is indented too much!"
792 ImportStart row col ->
793 toImportReport source row col
795 ImportName row col ->
797 region = toRegion row col
799 Report.Report "EXPECTING IMPORT NAME" region [] $
800 Code.toSnippet source region Nothing
803 "I was parsing an `import` until I got stuck here:"
807 "I was expecting to see a module name next, like in these examples:"
808 , D.indent 4 $ D.vcat $
809 [ D.fillSep [D.cyan "import","Dict"]
810 , D.fillSep [D.cyan "import","Maybe"]
811 , D.fillSep [D.cyan "import","Html.Attributes"]
812 , D.fillSep [D.cyan "import","Json.Decode"]
815 "Notice that the module names all start with capital letters. That is required!"
820 toImportReport source row col
822 ImportAlias row col ->
824 region = toRegion row col
826 Report.Report "EXECTING IMPORT ALIAS" region [] $
827 Code.toSnippet source region Nothing
830 "I was parsing an `import` until I got stuck here:"
834 "I was expecting to see an alias next, like in these examples:"
835 , D.indent 4 $ D.vcat $
836 [ D.fillSep [D.cyan "import","Html.Attributes",D.cyan "as","Attr"]
837 , D.fillSep [D.cyan "import","WebGL.Texture",D.cyan "as","Texture"]
838 , D.fillSep [D.cyan "import","Json.Decode",D.cyan "as","D"]
841 "Notice that the alias always starts with a capital letter. That is required!"
845 ImportExposing row col ->
846 toImportReport source row col
848 ImportExposingList exposing row col ->
849 toExposingReport source exposing row col
852 toImportReport source row col
854 ImportIndentName row col ->
855 toImportReport source row col
857 ImportIndentAlias row col ->
858 toImportReport source row col
860 ImportIndentExposingList row col ->
862 region = toRegion row col
864 Report.Report "UNFINISHED IMPORT" region [] $
865 Code.toSnippet source region Nothing
868 "I was parsing an `import` until I got stuck here:"
872 "I was expecting to see the list of exposed values next. For example, here\
873 \ are two ways to expose values from the `Html` module:"
874 , D.indent 4 $ D.vcat $
875 [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
876 , D.fillSep [D.cyan "import","Html",D.cyan "exposing","(Html, div, text)"]
879 "I generally recommend the second style. It is more explicit, making it\
880 \ much easier to figure out where values are coming from in large projects!"
886 region = toRegion row col
888 Report.Report "BAD INFIX" region [] $
889 Code.toSnippet source region Nothing
892 "Something went wrong in this infix operator declaration:"
895 "This feature is used by the @elm organization to define the\
896 \ languages built-in operators."
899 Declarations decl _ _ ->
900 toDeclarationsReport source decl
907toImportReport :: Code.Source -> Row -> Col -> Report.Report
908toImportReport source row col =
910 region = toRegion row col
912 Report.Report "UNFINISHED IMPORT" region [] $
913 Code.toSnippet source region Nothing
916 "I am partway through parsing an import, but I got stuck here:"
920 "Here are some examples of valid `import` declarations:"
921 , D.indent 4 $ D.vcat $
922 [ D.fillSep [D.cyan "import","Html"]
923 , D.fillSep [D.cyan "import","Html",D.cyan "as","H"]
924 , D.fillSep [D.cyan "import","Html",D.cyan "as","H",D.cyan "exposing","(..)"]
925 , D.fillSep [D.cyan "import","Html",D.cyan "exposing","(Html, div, text)"]
928 "You are probably trying to import a different module, but try to make it look like one of these examples!"
937toExposingReport :: Code.Source -> Exposing -> Row -> Col -> Report.Report
938toExposingReport source exposing startRow startCol =
940 ExposingSpace space row col ->
941 toSpaceReport source space row col
943 ExposingStart row col ->
945 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
946 region = toRegion row col
948 Report.Report "PROBLEM IN EXPOSING" region [] $
949 Code.toSnippet source surroundings (Just region)
952 "I want to parse exposed values, but I am getting stuck here:"
956 ["Exposed","values","are","always","surrounded","by","parentheses."
957 ,"So","try","adding","a",D.green "(","here?"
959 , D.toSimpleNote "Here are some valid examples of `exposing` for reference:"
960 , D.indent 4 $ D.vcat $
961 [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
962 , D.fillSep [D.cyan "import","Html",D.cyan "exposing","(Html, div, text)"]
965 "If you are getting tripped up, you can just expose everything for now. It should\
966 \ get easier to make an explicit exposing list as you see more examples in the wild."
970 ExposingValue row col ->
971 case Code.whatIsNext source row col of
972 Code.Keyword keyword ->
974 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
975 region = toKeywordRegion row col keyword
977 Report.Report "RESERVED WORD" region [] $
978 Code.toSnippet source surroundings (Just region)
981 "I got stuck on this reserved word:"
984 "It looks like you are trying to expose `" ++ keyword ++ "` but that is a reserved word. Is there a typo?"
989 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
990 region = toKeywordRegion row col op
992 Report.Report "UNEXPECTED SYMBOL" region [] $
993 Code.toSnippet source surroundings (Just region)
996 "I got stuck on this symbol:"
1000 "If you are trying to expose an operator, add parentheses around it like this:"
1001 , D.indent 4 $ D.dullyellow (D.fromChars op) <> " -> " <> D.green ("(" <> D.fromChars op <> ")")
1007 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1008 region = toRegion row col
1010 Report.Report "PROBLEM IN EXPOSING" region [] $
1011 Code.toSnippet source surroundings (Just region)
1014 "I got stuck while parsing these exposed values:"
1018 "I do not have an exact recommendation, so here are some valid examples\
1019 \ of `exposing` for reference:"
1020 , D.indent 4 $ D.vcat $
1021 [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
1022 , D.fillSep [D.cyan "import","Basics",D.cyan "exposing","(Int, Float, Bool(..), (+), not, sqrt)"]
1025 "These examples show how to expose types, variants, operators, and functions. Everything\
1026 \ should be some permutation of these examples, just with different names."
1030 ExposingOperator row col ->
1032 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1033 region = toRegion row col
1035 Report.Report "PROBLEM IN EXPOSING" region [] $
1036 Code.toSnippet source surroundings (Just region)
1039 "I just saw an open parenthesis, so I was expecting an operator next:"
1042 ["It","is","possible","to","expose","operators,","so","I","was","expecting"
1043 ,"to","see","something","like",D.dullyellow "(+)","or",D.dullyellow "(|=)"
1044 ,"or",D.dullyellow "(||)","after","I","saw","that","open","parenthesis."
1048 ExposingOperatorReserved op row col ->
1050 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1051 region = toRegion row col
1053 Report.Report "RESERVED SYMBOL" region [] $
1054 Code.toSnippet source surroundings (Just region)
1057 "I cannot expose this as an operator:"
1060 BadDot -> D.reflow "Try getting rid of this entry? Maybe I can give you a better hint after that?"
1061 BadPipe -> D.fillSep ["Maybe","you","want",D.dullyellow "(||)","instead?"]
1062 BadArrow -> D.reflow "Try getting rid of this entry? Maybe I can give you a better hint after that?"
1063 BadEquals -> D.fillSep ["Maybe","you","want",D.dullyellow "(==)","instead?"]
1064 BadHasType -> D.fillSep ["Maybe","you","want",D.dullyellow "(::)","instead?"]
1067 ExposingOperatorRightParen row col ->
1069 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1070 region = toRegion row col
1072 Report.Report "PROBLEM IN EXPOSING" region [] $
1073 Code.toSnippet source surroundings (Just region)
1076 "It looks like you are exposing an operator, but I got stuck here:"
1079 ["I","was","expecting","to","see","the","closing","parenthesis","immediately"
1080 ,"after","the","operator.","Try","adding","a",D.green ")","right","here?"
1084 ExposingEnd row col ->
1086 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1087 region = toRegion row col
1089 Report.Report "UNFINISHED EXPOSING" region [] $
1090 Code.toSnippet source surroundings (Just region)
1093 "I was partway through parsing exposed values, but I got stuck here:"
1096 "Maybe there is a comma missing before this?"
1099 ExposingTypePrivacy row col ->
1101 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1102 region = toRegion row col
1104 Report.Report "PROBLEM EXPOSING CUSTOM TYPE VARIANTS" region [] $
1105 Code.toSnippet source surroundings (Just region)
1108 "It looks like you are trying to expose the variants of a custom type:"
1112 ["You","need","to","write","something","like"
1113 ,D.dullyellow "Status(..)","or",D.dullyellow "Entity(..)"
1114 ,"though.","It","is","all","or","nothing,","otherwise","`case`"
1115 ,"expressions","could","miss","a","variant","and","crash!"
1118 "It is often best to keep the variants hidden! If someone pattern matches on\
1119 \ the variants, it is a MAJOR change if any new variants are added. Suddenly\
1120 \ their `case` expressions do not cover all variants! So if you do not need\
1121 \ people to pattern match, keep the variants hidden and expose functions to\
1122 \ construct values of this type. This way you can add new variants as a MINOR change!"
1126 ExposingIndentEnd row col ->
1128 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1129 region = toRegion row col
1131 Report.Report "UNFINISHED EXPOSING" region [] $
1132 Code.toSnippet source surroundings (Just region)
1135 "I was partway through parsing exposed values, but I got stuck here:"
1139 ["I","was","expecting","a","closing","parenthesis."
1140 ,"Try","adding","a",D.green ")","right","here?"
1143 "I can get confused when there is not enough indentation, so if you already\
1144 \ have a closing parenthesis, it probably just needs some spaces in front of it."
1148 ExposingIndentValue row col ->
1150 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1151 region = toRegion row col
1153 Report.Report "UNFINISHED EXPOSING" region [] $
1154 Code.toSnippet source surroundings (Just region)
1157 "I was partway through parsing exposed values, but I got stuck here:"
1160 "I was expecting another value to expose."
1168toSpaceReport :: Code.Source -> Space -> Row -> Col -> Report.Report
1169toSpaceReport source space row col =
1173 region = toRegion row col
1175 Report.Report "NO TABS" region [] $
1176 Code.toSnippet source region Nothing
1179 "I ran into a tab, but tabs are not allowed in Elm files."
1182 "Replace the tab with spaces."
1185 EndlessMultiComment ->
1187 region = toWiderRegion row col 2
1189 Report.Report "ENDLESS COMMENT" region [] $
1190 Code.toSnippet source region Nothing
1193 "I cannot find the end of this multi-line comment:"
1196 [ D.reflow "Add a -} somewhere after this to end the comment."
1198 "Multi-line comments can be nested in Elm, so {- {- -} -} is a comment\
1199 \ that happens to contain another comment. Like parentheses and curly braces,\
1200 \ the start and end markers must always be balanced. Maybe that is the problem?"
1209toRegion :: Row -> Col -> A.Region
1212 pos = A.Position row col
1217toWiderRegion :: Row -> Col -> Word16 -> A.Region
1218toWiderRegion row col extra =
1220 (A.Position row col)
1221 (A.Position row (col + extra))
1224toKeywordRegion :: Row -> Col -> [Char.Char] -> A.Region
1225toKeywordRegion row col keyword =
1227 (A.Position row col)
1228 (A.Position row (col + fromIntegral (length keyword)))
1231toDeclarationsReport :: Code.Source -> Decl -> Report.Report
1232toDeclarationsReport source decl =
1234 DeclStart row col ->
1235 case Code.whatIsNext source row col of
1236 Code.Close term bracket ->
1238 region = toRegion row col
1240 Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1241 Code.toSnippet source region Nothing
1244 "I was not expecting to see a " ++ term ++ " here:"
1246 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1249 Code.Keyword keyword ->
1251 region = toKeywordRegion row col keyword
1253 Report.Report "RESERVED WORD" region [] $
1254 Code.toSnippet source region Nothing
1257 "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1262 "It is reserved for declaring imports at the top of your module. If you want\
1263 \ another import, try moving it up top with the other imports. If you want to\
1264 \ define a value or function, try changing the name to something else!"
1269 "It is reserved for writing `case` expressions. Try using a different name?"
1271 "If you are trying to write a `case` expression, it needs to be part of a\
1272 \ definition. So you could write something like this instead:"
1274 [ D.indent 0 $ D.fillSep [D.green "getWidth","maybeWidth","="]
1275 , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1276 , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1277 , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1279 , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1280 , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1283 "This defines a `getWidth` function that we can use elsewhere in our program."
1289 "It is reserved for writing `if` expressions. Try using a different name?"
1291 "If you are trying to write an `if` expression, it needs to be part of a\
1292 \ definition. So you could write something like this instead:"
1294 [ D.indent 0 $ D.fillSep [D.green "reviewPowerLevel","powerLevel","="]
1295 , D.indent 2 $ D.fillSep $
1296 [D.cyan "if","powerLevel",">",D.dullyellow "9000"
1297 ,D.cyan "then",D.dullyellow "\"OVER 9000!!!\""
1298 ,D.cyan "else",D.dullyellow "\"not bad\""
1302 "This defines a `reviewPowerLevel` function that we can use elsewhere in our program."
1307 "It is a reserved word. Try changing the name to something else?"
1312 region = toRegion row col
1314 Report.Report "SYNTAX PROBLEM" region [] $
1315 Code.toSnippet source region Nothing
1318 "I was expecting to see a new declaration here:"
1322 "I am not sure what is going wrong exactly, but here are a couple valid\
1323 \ declarations for reference:"
1325 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1326 , D.fillSep [D.green "add","x","y","="]
1327 , D.fillSep [" ","x","+","y"]
1329 , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1331 "Note that all declarations start with lower-case letters in Elm. Capitalization\
1332 \ makes a difference, so be consious of that if you are working from examples!"
1336 DeclSpace space row col ->
1337 toSpaceReport source space row col
1339 Port port_ row col ->
1340 toPortReport source port_ row col
1342 DeclType declType row col ->
1343 toDeclTypeReport source declType row col
1345 DeclDef name declDef row col ->
1346 toDeclDefReport source name declDef row col
1348 DeclFreshLineAfterDocComment row col ->
1350 region = toRegion row col
1352 Report.Report "EXPECTING DECLARATION" region [] $
1353 Code.toSnippet source region Nothing
1356 "I just saw a doc comment, but then I got stuck here:"
1359 "I was expecting to see the corresponding declaration next, starting on a fresh\
1360 \ line with no indentation."
1368toPortReport :: Code.Source -> Port -> Row -> Col -> Report.Report
1369toPortReport source port_ startRow startCol =
1371 PortSpace space row col ->
1372 toSpaceReport source space row col
1375 case Code.whatIsNext source row col of
1376 Code.Keyword keyword ->
1378 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1379 region = toKeywordRegion row col keyword
1381 Report.Report "RESERVED WORD" region [] $
1382 Code.toSnippet source surroundings (Just region)
1385 "I cannot handle ports with names like this:"
1388 "You are trying to make a port named `" ++ keyword
1389 ++ "` but that is a reserved word. Try using some other name?"
1394 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1395 region = toRegion row col
1397 Report.Report "PORT PROBLEM" region [] $
1398 Code.toSnippet source surroundings (Just region)
1401 "I just saw the start of a `port` declaration, but then I got stuck here:"
1405 ["I","was","expecting","to","see","a","name","like"
1406 ,D.dullyellow "send","or",D.dullyellow "receive","next."
1407 ,"Something","that","starts","with","a","lower-case","letter."
1413 PortColon row col ->
1415 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1416 region = toRegion row col
1418 Report.Report "PORT PROBLEM" region [] $
1419 Code.toSnippet source surroundings (Just region)
1422 "I just saw the start of a `port` declaration, but then I got stuck here:"
1426 "I was expecting to see a colon next. And then a type that tells me\
1427 \ what type of values are going to flow through."
1432 PortType tipe row col ->
1433 toTypeReport source TC_Port tipe row col
1435 PortIndentName row col ->
1437 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1438 region = toRegion row col
1440 Report.Report "UNFINISHED PORT" region [] $
1441 Code.toSnippet source surroundings (Just region)
1444 "I just saw the start of a `port` declaration, but then I got stuck here:"
1448 ["I","was","expecting","to","see","a","name","like"
1449 ,D.dullyellow "send","or",D.dullyellow "receive","next."
1450 ,"Something","that","starts","with","a","lower-case","letter."
1456 PortIndentColon row col ->
1458 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1459 region = toRegion row col
1461 Report.Report "UNFINISHED PORT" region [] $
1462 Code.toSnippet source surroundings (Just region)
1465 "I just saw the start of a `port` declaration, but then I got stuck here:"
1469 "I was expecting to see a colon next. And then a type that tells me\
1470 \ what type of values are going to flow through."
1475 PortIndentType row col ->
1477 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1478 region = toRegion row col
1480 Report.Report "UNFINISHED PORT" region [] $
1481 Code.toSnippet source surroundings (Just region)
1484 "I just saw the start of a `port` declaration, but then I got stuck here:"
1488 "I was expecting to see a type next. Here are examples of outgoing and\
1489 \ incoming ports for reference:"
1491 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1492 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1495 "The first line defines a `send` port so you can send strings out to JavaScript.\
1496 \ Maybe you send them on a WebSocket or put them into IndexedDB. The second line\
1497 \ defines a `receive` port so you can receive strings from JavaScript. Maybe you\
1498 \ get receive messages when new WebSocket messages come in or when an entry in\
1499 \ IndexedDB changes for some external reason."
1508 "Here are some example `port` declarations for reference:"
1510 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1511 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1514 "The first line defines a `send` port so you can send strings out to JavaScript.\
1515 \ Maybe you send them on a WebSocket or put them into IndexedDB. The second line\
1516 \ defines a `receive` port so you can receive strings from JavaScript. Maybe you\
1517 \ get receive messages when new WebSocket messages come in or when the IndexedDB\
1518 \ is changed for some external reason."
1526toDeclTypeReport :: Code.Source -> DeclType -> Row -> Col -> Report.Report
1527toDeclTypeReport source declType startRow startCol =
1529 DT_Space space row col ->
1530 toSpaceReport source space row col
1534 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1535 region = toRegion row col
1537 Report.Report "EXPECTING TYPE NAME" region [] $
1538 Code.toSnippet source surroundings (Just region)
1541 "I think I am parsing a type declaration, but I got stuck here:"
1545 ["I","was","expecting","a","name","like",D.dullyellow "Status","or",D.dullyellow "Style"
1546 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1552 DT_Alias typeAlias row col ->
1553 toTypeAliasReport source typeAlias row col
1555 DT_Union customType row col ->
1556 toCustomTypeReport source customType row col
1558 DT_IndentName row col ->
1560 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1561 region = toRegion row col
1563 Report.Report "EXPECTING TYPE NAME" region [] $
1564 Code.toSnippet source surroundings (Just region)
1567 "I think I am parsing a type declaration, but I got stuck here:"
1571 ["I","was","expecting","a","name","like",D.dullyellow "Status","or",D.dullyellow "Style"
1572 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1579toTypeAliasReport :: Code.Source -> TypeAlias -> Row -> Col -> Report.Report
1580toTypeAliasReport source typeAlias startRow startCol =
1582 AliasSpace space row col ->
1583 toSpaceReport source space row col
1585 AliasName row col ->
1587 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1588 region = toRegion row col
1590 Report.Report "EXPECTING TYPE ALIAS NAME" region [] $
1591 Code.toSnippet source surroundings (Just region)
1594 "I am partway through parsing a type alias, but I got stuck here:"
1598 ["I","was","expecting","a","name","like",D.dullyellow "Person","or",D.dullyellow "Point"
1599 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1605 AliasEquals row col ->
1606 case Code.whatIsNext source row col of
1607 Code.Keyword keyword ->
1609 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1610 region = toKeywordRegion row col keyword
1612 Report.Report "RESERVED WORD" region [] $
1613 Code.toSnippet source surroundings (Just region)
1616 "I ran into a reserved word unexpectedly while parsing this type alias:"
1620 "It looks like you are trying use `" ++ keyword
1621 ++ "` as a type variable, but it is a reserved word. Try using a different name?"
1628 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1629 region = toRegion row col
1631 Report.Report "PROBLEM IN TYPE ALIAS" region [] $
1632 Code.toSnippet source surroundings (Just region)
1635 "I am partway through parsing a type alias, but I got stuck here:"
1639 "I was expecting to see a type variable or an an equals sign next."
1644 AliasBody tipe row col ->
1645 toTypeReport source TC_TypeAlias tipe row col
1647 AliasIndentEquals row col ->
1649 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1650 region = toRegion row col
1652 Report.Report "UNFINISHED TYPE ALIAS" region [] $
1653 Code.toSnippet source surroundings (Just region)
1656 "I am partway through parsing a type alias, but I got stuck here:"
1660 "I was expecting to see a type variable or an an equals sign next."
1665 AliasIndentBody row col ->
1667 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1668 region = toRegion row col
1670 Report.Report "UNFINISHED TYPE ALIAS" region [] $
1671 Code.toSnippet source surroundings (Just region)
1674 "I am partway through parsing a type alias, but I got stuck here:"
1678 ["I","was","expecting","to","see","a","type","next.","Something","as","simple"
1679 ,"as",D.dullyellow "Int","or",D.dullyellow "Float","would","work!"
1686typeAliasNote :: D.Doc
1690 "Here is an example of a valid `type alias` for reference:"
1692 [ D.indent 0 $ D.fillSep [D.cyan "type",D.cyan "alias",D.green "Person","="]
1693 , D.indent 2 $ D.vcat $
1701 "This would let us use `Person` as a shorthand for that record type. Using this\
1702 \ shorthand makes type annotations much easier to read, and makes changing code\
1703 \ easier if you decide later that there is more to a person than age and height!"
1707toCustomTypeReport :: Code.Source -> CustomType -> Row -> Col -> Report.Report
1708toCustomTypeReport source customType startRow startCol =
1710 CT_Space space row col ->
1711 toSpaceReport source space row col
1715 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1716 region = toRegion row col
1718 Report.Report "EXPECTING TYPE NAME" region [] $
1719 Code.toSnippet source surroundings (Just region)
1722 "I think I am parsing a type declaration, but I got stuck here:"
1726 ["I","was","expecting","a","name","like",D.dullyellow "Status","or",D.dullyellow "Style"
1727 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1733 CT_Equals row col ->
1734 case Code.whatIsNext source row col of
1735 Code.Keyword keyword ->
1737 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1738 region = toKeywordRegion row col keyword
1740 Report.Report "RESERVED WORD" region [] $
1741 Code.toSnippet source surroundings (Just region)
1744 "I ran into a reserved word unexpectedly while parsing this custom type:"
1748 "It looks like you are trying use `" ++ keyword
1749 ++ "` as a type variable, but it is a reserved word. Try using a different name?"
1756 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1757 region = toRegion row col
1759 Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1760 Code.toSnippet source surroundings (Just region)
1763 "I am partway through parsing a custom type, but I got stuck here:"
1767 "I was expecting to see a type variable or an an equals sign next."
1774 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1775 region = toRegion row col
1777 Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1778 Code.toSnippet source surroundings (Just region)
1781 "I am partway through parsing a custom type, but I got stuck here:"
1785 "I was expecting to see a vertical bar like | next."
1790 CT_Variant row col ->
1792 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1793 region = toRegion row col
1795 Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1796 Code.toSnippet source surroundings (Just region)
1799 "I am partway through parsing a custom type, but I got stuck here:"
1803 ["I","was","expecting","to","see","a","variant","name","next."
1804 ,"Something","like",D.dullyellow "Success","or",D.dullyellow "Sandwich" <> "."
1805 ,"Any","name","that","starts","with","a","capital","letter","really!"
1811 CT_VariantArg tipe row col ->
1812 toTypeReport source TC_CustomType tipe row col
1814 CT_IndentEquals row col ->
1816 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1817 region = toRegion row col
1819 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1820 Code.toSnippet source surroundings (Just region)
1823 "I am partway through parsing a custom type, but I got stuck here:"
1827 "I was expecting to see a type variable or an an equals sign next."
1832 CT_IndentBar row col ->
1834 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1835 region = toRegion row col
1837 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1838 Code.toSnippet source surroundings (Just region)
1841 "I am partway through parsing a custom type, but I got stuck here:"
1845 "I was expecting to see a vertical bar like | next."
1850 CT_IndentAfterBar row col ->
1852 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1853 region = toRegion row col
1855 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1856 Code.toSnippet source surroundings (Just region)
1859 "I am partway through parsing a custom type, but I got stuck here:"
1863 "I just saw a vertical bar, so I was expecting to see another variant defined next."
1868 CT_IndentAfterEquals row col ->
1870 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1871 region = toRegion row col
1873 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1874 Code.toSnippet source surroundings (Just region)
1877 "I am partway through parsing a custom type, but I got stuck here:"
1881 "I just saw an equals sign, so I was expecting to see the first variant defined next."
1887customTypeNote :: D.Doc
1891 "Here is an example of a valid `type` declaration for reference:"
1893 [ D.indent 0 $ D.fillSep [D.cyan "type",D.green "Status"]
1894 , D.indent 2 $ D.fillSep ["=","Failure"]
1895 , D.indent 2 $ D.fillSep ["|","Waiting"]
1896 , D.indent 2 $ D.fillSep ["|","Success","String"]
1899 "This defines a new `Status` type with three variants. This could be useful if\
1900 \ we are waiting for an HTTP request. Maybe we start with `Waiting` and then\
1901 \ switch to `Failure` or `Success \"message from server\"` depending on how\
1902 \ things go. Notice that the Success variant has some associated data, allowing\
1903 \ us to store a String if the request goes well!"
1911toDeclDefReport :: Code.Source -> Name.Name -> DeclDef -> Row -> Col -> Report.Report
1912toDeclDefReport source name declDef startRow startCol =
1914 DeclDefSpace space row col ->
1915 toSpaceReport source space row col
1917 DeclDefEquals row col ->
1918 case Code.whatIsNext source row col of
1919 Code.Keyword keyword ->
1921 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1922 region = toKeywordRegion row col keyword
1924 Report.Report "RESERVED WORD" region [] $
1925 Code.toSnippet source surroundings (Just region)
1928 "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
1931 "This is a reserved word! Try using some other name?"
1936 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1937 region = toKeywordRegion row col op
1939 Report.Report "UNEXPECTED SYMBOL" region [] $
1940 Code.toSnippet source surroundings (Just region)
1943 "I was not expecting to see this symbol here:"
1947 "I am not sure what is going wrong exactly, so here is a valid\
1948 \ definition (with an optional type annotation) for reference:"
1950 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1951 , D.fillSep [D.green "add","x","y","="]
1952 , D.fillSep [" ","x","+","y"]
1955 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
1961 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1962 region = toRegion row col
1964 Report.Report "PROBLEM IN DEFINITION" region [] $
1965 Code.toSnippet source surroundings (Just region)
1968 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
1972 "I am not sure what is going wrong exactly, so here is a valid\
1973 \ definition (with an optional type annotation) for reference:"
1975 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1976 , D.fillSep [D.green "add","x","y","="]
1977 , D.fillSep [" ","x","+","y"]
1980 "Try to use that format!"
1984 DeclDefType tipe row col ->
1985 toTypeReport source (TC_Annotation name) tipe row col
1987 DeclDefArg pattern row col ->
1988 toPatternReport source PArg pattern row col
1990 DeclDefBody expr row col ->
1991 toExprReport source (InDef name startRow startCol) expr row col
1993 DeclDefNameRepeat row col ->
1995 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1996 region = toRegion row col
1998 Report.Report "EXPECTING DEFINITION" region [] $
1999 Code.toSnippet source surroundings (Just region)
2002 "I just saw the type annotation for `" ++ Name.toChars name
2003 ++ "` so I was expecting to see its definition here:"
2007 "Type annotations always appear directly above the relevant\
2008 \ definition, without anything else in between. (Not even doc comments!)"
2013 DeclDefNameMatch defName row col ->
2015 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2016 region = toRegion row col
2018 Report.Report "NAME MISMATCH" region [] $
2019 Code.toSnippet source surroundings (Just region)
2022 "I just saw a type annotation for `" ++ Name.toChars name ++ "`, but it is followed by a definition for `" ++ Name.toChars defName ++ "`:"
2026 "These names do not match! Is there a typo?"
2027 , D.indent 4 $ D.fillSep $
2028 [D.dullyellow (D.fromName defName),"->",D.green (D.fromName name)]
2032 DeclDefIndentType row col ->
2034 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2035 region = toRegion row col
2037 Report.Report "UNFINISHED DEFINITION" region [] $
2038 Code.toSnippet source surroundings (Just region)
2041 "I got stuck while parsing the `" ++ Name.toChars name ++ "` type annotation:"
2045 "I just saw a colon, so I am expecting to see a type next."
2050 DeclDefIndentEquals row col ->
2052 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2053 region = toRegion row col
2055 Report.Report "UNFINISHED DEFINITION" region [] $
2056 Code.toSnippet source surroundings (Just region)
2059 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
2063 "I was expecting to see an argument or an equals sign next."
2068 DeclDefIndentBody row col ->
2070 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2071 region = toRegion row col
2073 Report.Report "UNFINISHED DEFINITION" region [] $
2074 Code.toSnippet source surroundings (Just region)
2077 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
2081 "I was expecting to see an expression next. What is it equal to?"
2091 "Here is a valid definition (with a type annotation) for reference:"
2093 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2094 , D.fillSep [D.green "add","x","y","="]
2095 , D.fillSep [" ","x","+","y"]
2098 "The top line (called a \"type annotation\") is optional. You can leave it off\
2099 \ if you want. As you get more comfortable with Elm and as your project grows,\
2100 \ it becomes more and more valuable to add them though! They work great as\
2101 \ compiler-verified documentation, and they often improve error messages!"
2110 = InNode Node Row Col Context
2111 | InDef Name.Name Row Col
2112 | InDestruct Row Col
2128getDefName :: Context -> Maybe Name.Name
2131 InDestruct _ _ -> Nothing
2132 InDef name _ _ -> Just name
2133 InNode _ _ _ c -> getDefName c
2136isWithin :: Node -> Context -> Bool
2137isWithin desiredNode context =
2139 InDestruct _ _ -> False
2140 InDef _ _ _ -> False
2141 InNode actualNode _ _ _ -> desiredNode == actualNode
2148toExprReport :: Code.Source -> Context -> Expr -> Row -> Col -> Report.Report
2149toExprReport source context expr startRow startCol =
2152 toLetReport source context let_ row col
2154 Case case_ row col ->
2155 toCaseReport source context case_ row col
2158 toIfReport source context if_ row col
2160 List list row col ->
2161 toListReport source context list row col
2163 Record record row col ->
2164 toRecordReport source context record row col
2166 Tuple tuple row col ->
2167 toTupleReport source context tuple row col
2169 Func func row col ->
2170 toFuncReport source context func row col
2173 let region = toRegion row col in
2174 Report.Report "EXPECTING RECORD ACCESSOR" region [] $
2175 Code.toSnippet source region Nothing
2178 "I was expecting to see a record accessor here:"
2181 ["Something","like",D.dullyellow".name","or",D.dullyellow".price"
2182 ,"that","accesses","a","value","from","a","record."
2187 let region = toRegion row col in
2188 Report.Report "EXPECTING RECORD ACCESSOR" region [] $
2189 Code.toSnippet source region Nothing
2192 "I am trying to parse a record accessor here:"
2197 ["Something","like",D.dullyellow".name","or",D.dullyellow".price"
2198 ,"that","accesses","a","value","from","a","record."
2202 "Record field names must start with a lower case letter!"
2206 OperatorRight op row col ->
2207 let region = toRegion row col in
2208 Report.Report "MISSING EXPRESSION" region [] $
2209 Code.toSnippet source region Nothing
2212 "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
2216 ["You","can","just","put","anything","for","now,","like"
2217 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2218 ,"Once","there","is","something","there,","I","can","probably"
2219 ,"give","a","more","specific","hint!"
2222 "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2223 \ Or if I run into operators in unexpected spots. Point is, there are a\
2224 \ couple ways I can get confused and give sort of weird advice!"
2228 OperatorReserved operator row col ->
2229 toOperatorReport source context operator row col
2233 (contextRow, contextCol, aThing) =
2235 InDestruct r c -> (r, c, "a definition")
2236 InDef name r c -> (r, c, "the `" ++ Name.toChars name ++ "` definition")
2237 InNode NRecord r c _ -> (r, c, "a record")
2238 InNode NParens r c _ -> (r, c, "some parentheses")
2239 InNode NList r c _ -> (r, c, "a list")
2240 InNode NFunc r c _ -> (r, c, "an anonymous function")
2241 InNode NCond r c _ -> (r, c, "an `if` expression")
2242 InNode NThen r c _ -> (r, c, "an `if` expression")
2243 InNode NElse r c _ -> (r, c, "an `if` expression")
2244 InNode NCase r c _ -> (r, c, "a `case` expression")
2245 InNode NBranch r c _ -> (r, c, "a `case` expression")
2246 -- TODO check if this is actually the best way to get error messages here
2248 surroundings = A.Region (A.Position contextRow contextCol) (A.Position row col)
2249 region = toRegion row col
2251 Report.Report "MISSING EXPRESSION" region [] $
2252 Code.toSnippet source surroundings (Just region)
2255 "I am partway through parsing " ++ aThing ++ ", but I got stuck here:"
2259 ["I","was","expecting","to","see","an","expression","like"
2260 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2261 ,"Once","there","is","something","there,","I","can","probably"
2262 ,"give","a","more","specific","hint!"
2265 "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2266 \ Or if I run into operators in unexpected spots. Point is, there are a\
2267 \ couple ways I can get confused and give sort of weird advice!"
2271 Char char row col ->
2272 toCharReport source char row col
2274 String string row col ->
2275 toStringReport source string row col
2277 Number number row col ->
2278 toNumberReport source number row col
2280 Space space row col ->
2281 toSpaceReport source space row col
2283 EndlessShader row col ->
2285 region = toWiderRegion row col 6
2287 Report.Report "ENDLESS SHADER" region [] $
2288 Code.toSnippet source region Nothing
2290 D.reflow "I cannot find the end of this shader:"
2292 D.reflow "Add a |] somewhere after this to end the shader."
2295 ShaderProblem problem row col ->
2297 region = toRegion row col
2299 Report.Report "SHADER PROBLEM" region [] $
2300 Code.toSnippet source region Nothing
2303 "I ran into a problem while parsing this GLSL block."
2307 "I use a 3rd party GLSL parser for now, and I did my best to extract their error message:"
2308 , D.indent 4 $ D.vcat $
2309 map D.fromChars (filter (/="") (lines problem))
2313 IndentOperatorRight op row col ->
2315 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2316 region = toRegion row col
2318 Report.Report "MISSING EXPRESSION" region [] $
2319 Code.toSnippet source surroundings (Just region)
2322 "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
2327 ["You","can","just","put","anything","for","now,","like"
2328 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2329 ,"Once","there","is","something","there,","I","can","probably"
2330 ,"give","a","more","specific","hint!"
2334 "I may be getting confused by your indentation? The easiest way to make sure\
2335 \ this is not an indentation problem is to put the expression on the right of\
2336 \ the " ++ Name.toChars op ++ " operator on the same line."
2345toCharReport :: Code.Source -> Char -> Row -> Col -> Report.Report
2346toCharReport source char row col =
2350 region = toRegion row col
2352 Report.Report "MISSING SINGLE QUOTE" region [] $
2353 Code.toSnippet source region Nothing
2356 "I thought I was parsing a character, but I got to the end of\
2357 \ the line without seeing the closing single quote:"
2360 "Add a closing single quote here!"
2363 CharEscape escape ->
2364 toEscapeReport source escape row col
2366 CharNotString width ->
2368 region = toWiderRegion row col width
2370 Report.Report "NEEDS DOUBLE QUOTES" region [] $
2371 Code.toSnippet source region Nothing
2373 "The following string uses single quotes:"
2376 [ "Please switch to double quotes instead:"
2378 D.dullyellow "'this'" <> " => " <> D.green "\"this\""
2380 "Elm uses double quotes for strings like \"hello\", whereas it uses single\
2381 \ quotes for individual characters like 'a' and 'ø'. This distinction helps with\
2382 \ code like (String.any (\\c -> c == 'X') \"90210\") where you are inspecting\
2383 \ individual characters."
2392toStringReport :: Code.Source -> String -> Row -> Col -> Report.Report
2393toStringReport source string row col =
2395 StringEndless_Single ->
2397 region = toRegion row col
2399 Report.Report "ENDLESS STRING" region [] $
2400 Code.toSnippet source region Nothing
2403 "I got to the end of the line without seeing the closing double quote:"
2407 ["Strings","look","like",D.green "\"this\"","with","double"
2408 ,"quotes","on","each","end.","Is","the","closing","double"
2409 ,"quote","missing","in","your","code?"
2411 , D.link "Note" "Read" "TODO" "if you want a string that spans multiple lines."
2415 StringEndless_Multi ->
2417 region = toWiderRegion row col 3
2419 Report.Report "ENDLESS STRING" region [] $
2420 Code.toSnippet source region Nothing
2423 "I cannot find the end of this multi-line string:"
2426 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
2427 , D.link "Hint" "Read" "TODO" "for more information on strings and multi-line strings."
2431 StringEscape escape ->
2432 toEscapeReport source escape row col
2439toEscapeReport :: Code.Source -> Escape -> Row -> Col -> Report.Report
2440toEscapeReport source escape row col =
2444 region = toWiderRegion row col 2
2446 Report.Report "UNKNOWN ESCAPE" region [] $
2447 Code.toSnippet source region Nothing
2450 "Backslashes always start escaped characters, but I do not recognize this one:"
2454 "Valid escape characters include:"
2455 , D.dullyellow $ D.indent 4 $ D.vcat $
2465 "Do you want one of those instead? Maybe you need \\\\ to escape a backslash?"
2467 "The last style lets encode ANY character by its Unicode code\
2468 \ point. That means \\u{0009} and \\t are the same. You can use\
2469 \ that style for anything not covered by the other six escapes!"
2473 BadUnicodeFormat width ->
2475 region = toWiderRegion row col width
2477 Report.Report "BAD UNICODE ESCAPE" region [] $
2478 Code.toSnippet source region Nothing
2481 "I ran into an invalid Unicode escape:"
2485 "Here are some examples of valid Unicode escapes:"
2486 , D.dullyellow $ D.indent 4 $ D.vcat $
2493 "Notice that the code point is always surrounded by curly braces.\
2494 \ Maybe you are missing the opening or closing curly brace?"
2497 BadUnicodeCode width ->
2499 region = toWiderRegion row col width
2501 Report.Report "BAD UNICODE ESCAPE" region [] $
2502 Code.toSnippet source region Nothing
2505 "This is not a valid code point:"
2508 "The valid code points are between 0 and 10FFFF inclusive."
2511 BadUnicodeLength width numDigits badCode ->
2513 region = toWiderRegion row col width
2515 Report.Report "BAD UNICODE ESCAPE" region [] $
2516 Code.toSnippet source region Nothing $
2517 if numDigits < 4 then
2520 "Every code point needs at least four digits:"
2523 goodCode = replicate (4 - numDigits) '0' ++ map Char.toUpper (showHex badCode "")
2524 suggestion = "\\u{" <> D.fromChars goodCode <> "}"
2526 D.fillSep ["Try",D.green suggestion,"instead?"]
2532 "This code point has too many digits:"
2535 ["Valid","code","points","are","between"
2536 ,D.green "\\u{0000}","and",D.green "\\u{10FFFF}" <> ","
2537 ,"so","try","trimming","any","leading","zeros","until"
2538 ,"you","have","between","four","and","six","digits."
2547toNumberReport :: Code.Source -> Number -> Row -> Col -> Report.Report
2548toNumberReport source number row col =
2550 region = toRegion row col
2554 Report.Report "WEIRD NUMBER" region [] $
2555 Code.toSnippet source region Nothing
2558 "I thought I was reading a number, but I ran into some weird stuff here:"
2562 "I recognize numbers in the following formats:"
2563 , D.indent 4 $ D.vcat [ "42", "3.14", "6.022e23", "0x002B" ]
2565 "So is there a way to write it like one of those?"
2570 Report.Report "WEIRD NUMBER" region [] $
2571 Code.toSnippet source region Nothing
2574 "Numbers cannot end with a dot like this:"
2577 ["Switching","to",D.green (D.fromChars (show int))
2578 ,"or",D.green (D.fromChars (show int ++ ".0"))
2579 ,"will","work","though!"
2584 Report.Report "WEIRD HEXIDECIMAL" region [] $
2585 Code.toSnippet source region Nothing
2588 "I thought I was reading a hexidecimal number until I got here:"
2592 "Valid hexidecimal digits include 0123456789abcdefABCDEF, so I can\
2593 \ only recognize things like this:"
2594 , D.indent 4 $ D.vcat [ "0x2B", "0x002B", "0x00ffb3" ]
2598 NumberNoLeadingZero ->
2599 Report.Report "LEADING ZEROS" region [] $
2600 Code.toSnippet source region Nothing
2603 "I do not accept numbers with leading zeros:"
2607 "Just delete the leading zeros and it should work!"
2609 "Some languages let you to specify octal numbers by adding a leading zero.\
2610 \ So in C, writing 0111 is the same as writing 73. Some people are used to\
2611 \ that, but others probably want it to equal 111. Either path is going to\
2612 \ surprise people from certain backgrounds, so Elm tries to avoid this whole\
2622toOperatorReport :: Code.Source -> Context -> BadOperator -> Row -> Col -> Report.Report
2623toOperatorReport source context operator row col =
2627 region = toRegion row col
2629 Report.Report "UNEXPECTED SYMBOL" region [] $
2630 Code.toSnippet source region Nothing
2632 "I was not expecting this dot:"
2635 "Dots are for record access and decimal points, so\
2636 \ they cannot float around on their own. Maybe\
2637 \ there is some extra whitespace?"
2642 region = toRegion row col
2644 Report.Report "UNEXPECTED SYMBOL" region [] $
2645 Code.toSnippet source region Nothing
2648 "I was not expecting this vertical bar:"
2651 "Vertical bars should only appear in custom type declarations. Maybe you want || instead?"
2656 region = toWiderRegion row col 2
2658 Report.Report "UNEXPECTED ARROW" region [] $
2659 Code.toSnippet source region Nothing $
2660 if isWithin NBranch context then
2663 "I was not expecting to see an arrow here:"
2668 "I think I am parsing a `case` expression right now, so it makes sense to\
2669 \ see arrows around here. This one is confusing me though!"
2672 "I may be getting confused by the indentation. Every pattern in a `case` must be\
2673 \ exactly aligned (with exactly the same amount of indentation) so maybe this arrow\
2674 \ appears after the next `case` pattern (correctly!) but the pattern itself is\
2675 \ indented too far?"
2682 "I was not expecting an arrow here:"
2685 "Arrows should only appear in `case` expressions and anonymous functions. Maybe\
2686 \ you want > or >= instead?"
2691 region = toRegion row col
2693 Report.Report "UNEXPECTED EQUALS" region [] $
2694 Code.toSnippet source region Nothing
2697 "I was not expecting to see this equals sign:"
2701 D.reflow "Maybe you want == instead? To check if two values are equal?"
2704 if isWithin NRecord context then
2705 "Records look like { x = 3, y = 4 } with the equals sign right\
2706 \ after the field name. So maybe you forgot a comma?"
2708 case getDefName context of
2710 "I may be getting confused by your indentation. I need all definitions to be indented\
2711 \ exactly the same amount, so if this is meant to be a new definition, it may have too\
2712 \ many spaces in front of it."
2715 "I may be getting confused by your indentation. I think I am still parsing the `"
2716 ++ Name.toChars name ++ "` definition. Is this supposed to be part of a definition\
2717 \ after that? If so, the problem may be a bit before the equals sign. I need all\
2718 \ definitions to be indented exactly the same amount, so the problem may be that\
2719 \ this new definition has too many spaces in front of it."
2725 region = toRegion row col
2727 Report.Report "UNEXPECTED SYMBOL" region [] $
2728 Code.toSnippet source region Nothing $
2731 "I was not expecting to run into the \"has type\" symbol here:"
2733 case getDefName context of
2736 ["Maybe","you","want",D.green "::","instead?"
2737 ,"To","put","something","on","the","front","of","a","list?"
2744 ["Maybe","you","want",D.green "::","instead?"
2745 ,"To","put","something","on","the","front","of","a","list?"
2748 "The single colon is reserved for type annotations and record types, but I think\
2749 \ I am parsing the definition of `" ++ Name.toChars name ++ "` right now."
2752 "I may be getting confused by your indentation. Is this supposed to be part of\
2753 \ a type annotation AFTER the `" ++ Name.toChars name ++ "` definition? If so,\
2754 \ the problem may be a bit before the \"has type\" symbol. I need all definitions to\
2755 \ be exactly aligned (with exactly the same indentation) so the problem may be that\
2756 \ this new definition is indented a bit too much."
2765toLetReport :: Code.Source -> Context -> Let -> Row -> Col -> Report.Report
2766toLetReport source context let_ startRow startCol =
2768 LetSpace space row col ->
2769 toSpaceReport source space row col
2773 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2774 region = toRegion row col
2776 Report.Report "LET PROBLEM" region [] $
2777 Code.toSnippet source surroundings (Just region)
2780 "I was partway through parsing a `let` expression, but I got stuck here:"
2784 ["Based","on","the","indentation,","I","was","expecting","to","see","the",D.cyan "in"
2785 ,"keyword","next.","Is","there","a","typo?"
2788 "This can also happen if you are trying to define another value within the `let` but\
2789 \ it is not indented enough. Make sure each definition has exactly the same amount of\
2790 \ spaces before it. They should line up exactly!"
2794 LetDefAlignment _ row col ->
2796 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2797 region = toRegion row col
2799 Report.Report "LET PROBLEM" region [] $
2800 Code.toSnippet source surroundings (Just region)
2803 "I was partway through parsing a `let` expression, but I got stuck here:"
2807 ["Based","on","the","indentation,","I","was","expecting","to","see","the",D.cyan "in"
2808 ,"keyword","next.","Is","there","a","typo?"
2811 "This can also happen if you are trying to define another value within the `let` but\
2812 \ it is not indented enough. Make sure each definition has exactly the same amount of\
2813 \ spaces before it. The should line up exactly!"
2817 LetDefName row col ->
2818 case Code.whatIsNext source row col of
2819 Code.Keyword keyword ->
2821 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2822 region = toKeywordRegion row col keyword
2824 Report.Report "RESERVED WORD" region [] $
2825 Code.toSnippet source surroundings (Just region)
2828 "I was partway through parsing a `let` expression, but I got stuck here:"
2831 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name, but\
2832 \ it is a reserved word! Try using a different name instead."
2836 toUnfinishLetReport source row col startRow startCol $
2838 "I was expecting the name of a definition next."
2840 LetDef name def row col ->
2841 toLetDefReport source name def row col
2843 LetDestruct destruct row col ->
2844 toLetDestructReport source destruct row col
2846 LetBody expr row col ->
2847 toExprReport source context expr row col
2849 LetIndentDef row col ->
2850 toUnfinishLetReport source row col startRow startCol $
2852 "I was expecting a value to be defined here."
2854 LetIndentIn row col ->
2855 toUnfinishLetReport source row col startRow startCol $
2857 ["I","was","expecting","to","see","the",D.cyan "in","keyword","next."
2858 ,"Or","maybe","more","of","that","expression?"
2861 LetIndentBody row col ->
2862 toUnfinishLetReport source row col startRow startCol $
2864 "I was expecting an expression next. Tell me what should happen with the value you just defined!"
2867toUnfinishLetReport :: Code.Source -> Row -> Col -> Row -> Col -> D.Doc -> Report.Report
2868toUnfinishLetReport source row col startRow startCol message =
2870 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2871 region = toRegion row col
2873 Report.Report "UNFINISHED LET" region [] $
2874 Code.toSnippet source surroundings (Just region)
2877 "I was partway through parsing a `let` expression, but I got stuck here:"
2882 "Here is an example with a valid `let` expression for reference:"
2884 [ D.indent 0 $ D.fillSep [D.green "viewPerson","person","="]
2885 , D.indent 2 $ D.fillSep [D.cyan "let"]
2886 , D.indent 4 $ D.fillSep ["fullName","="]
2887 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
2888 , D.indent 2 $ D.fillSep [D.cyan "in"]
2889 , D.indent 2 $ D.fillSep ["div","[]","[","text","fullName","]"]
2892 "Here we defined a `viewPerson` function that turns a person into some HTML. We use\
2893 \ a `let` expression to define the `fullName` we want to show. Notice the indentation! The\
2894 \ `fullName` is indented more than the `let` keyword, and the actual value of `fullName` is\
2895 \ indented a bit more than that. That is important!"
2900toLetDefReport :: Code.Source -> Name.Name -> Def -> Row -> Col -> Report.Report
2901toLetDefReport source name def startRow startCol =
2903 DefSpace space row col ->
2904 toSpaceReport source space row col
2906 DefType tipe row col ->
2907 toTypeReport source (TC_Annotation name) tipe row col
2909 DefNameRepeat row col ->
2911 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2912 region = toRegion row col
2914 Report.Report "EXPECTING DEFINITION" region [] $
2915 Code.toSnippet source surroundings (Just region)
2918 "I just saw the type annotation for `" ++ Name.toChars name
2919 ++ "` so I was expecting to see its definition here:"
2923 "Type annotations always appear directly above the relevant\
2924 \ definition, without anything else in between."
2929 DefNameMatch defName row col ->
2931 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2932 region = toRegion row col
2934 Report.Report "NAME MISMATCH" region [] $
2935 Code.toSnippet source surroundings (Just region)
2938 "I just saw a type annotation for `" ++ Name.toChars name ++ "`, but it is followed by a definition for `" ++ Name.toChars defName ++ "`:"
2942 "These names do not match! Is there a typo?"
2943 , D.indent 4 $ D.fillSep $
2944 [D.dullyellow (D.fromName defName),"->",D.green (D.fromName name)]
2948 DefArg pattern row col ->
2949 toPatternReport source PArg pattern row col
2951 DefEquals row col ->
2952 case Code.whatIsNext source row col of
2953 Code.Keyword keyword ->
2955 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2956 region = toKeywordRegion row col keyword
2958 Report.Report "RESERVED WORD" region [] $
2959 Code.toSnippet source surroundings (Just region)
2962 "It looks like you are trying to use `" ++ keyword ++ "` as an argument:"
2965 "This is a reserved word! Try using some other name?"
2970 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2971 region = toKeywordRegion row col op
2973 Report.Report "UNEXPECTED SYMBOL" region [] $
2974 Code.toSnippet source surroundings (Just region)
2977 "I was not expecting to see this symbol here:"
2981 "I am not sure what is going wrong exactly, so here is a valid\
2982 \ definition (with an optional type annotation) for reference:"
2984 [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2985 , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
2986 , D.indent 6 $ D.fillSep ["x","+","y"]
2989 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2995 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2996 region = toRegion row col
2998 Report.Report "PROBLEM IN DEFINITION" region [] $
2999 Code.toSnippet source surroundings (Just region)
3002 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3006 "I am not sure what is going wrong exactly, so here is a valid\
3007 \ definition (with an optional type annotation) for reference:"
3009 [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3010 , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3011 , D.indent 4 $ D.fillSep ["x","+","y"]
3014 "Try to use that format!"
3018 DefBody expr row col ->
3019 toExprReport source (InDef name startRow startCol) expr row col
3021 DefIndentEquals row col ->
3023 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3024 region = toRegion row col
3026 Report.Report "UNFINISHED DEFINITION" region [] $
3027 Code.toSnippet source surroundings (Just region)
3030 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3034 "I was expecting to see an argument or an equals sign next."
3039 DefIndentType row col ->
3041 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3042 region = toRegion row col
3044 Report.Report "UNFINISHED DEFINITION" region [] $
3045 Code.toSnippet source surroundings (Just region)
3048 "I got stuck while parsing the `" ++ Name.toChars name ++ "` type annotation:"
3052 "I just saw a colon, so I am expecting to see a type next."
3057 DefIndentBody row col ->
3059 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3060 region = toRegion row col
3062 Report.Report "UNFINISHED DEFINITION" region [] $
3063 Code.toSnippet source surroundings (Just region)
3066 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3070 "I was expecting to see an expression next. What is it equal to?"
3075 DefAlignment indent row col ->
3077 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3078 region = toRegion row col
3079 offset = indent - col
3081 Report.Report "PROBLEM IN DEFINITION" region [] $
3082 Code.toSnippet source surroundings (Just region)
3085 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3088 "I just saw a type annotation indented " ++ show indent ++ " spaces, so I was\
3089 \ expecting to see the corresponding definition next with the exact same amount\
3090 \ of indentation. It looks like this line needs "
3091 ++ show offset ++ " more " ++ (if offset == 1 then "space" else "spaces") ++ "?"
3100 "Here is a valid definition (with a type annotation) for reference:"
3102 [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3103 , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3104 , D.indent 6 $ D.fillSep ["x","+","y"]
3107 "The top line (called a \"type annotation\") is optional. You can leave it off\
3108 \ if you want. As you get more comfortable with Elm and as your project grows,\
3109 \ it becomes more and more valuable to add them though! They work great as\
3110 \ compiler-verified documentation, and they often improve error messages!"
3114toLetDestructReport :: Code.Source -> Destruct -> Row -> Col -> Report.Report
3115toLetDestructReport source destruct startRow startCol =
3117 DestructSpace space row col ->
3118 toSpaceReport source space row col
3120 DestructPattern pattern row col ->
3121 toPatternReport source PLet pattern row col
3123 DestructEquals row col ->
3125 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3126 region = toRegion row col
3128 Report.Report "PROBLEM IN DEFINITION" region [] $
3129 Code.toSnippet source surroundings (Just region)
3132 "I got stuck trying to parse this definition:"
3134 case Code.whatIsNext source row col of
3135 Code.Operator ":" ->
3138 "I was expecting to see an equals sign next, followed by an expression\
3139 \ telling me what to compute."
3141 "It looks like you may be trying to write a type annotation? It is not\
3142 \ possible to add type annotations on destructuring definitions like this.\
3143 \ You can assign a name to the overall structure, put a type annotation on\
3144 \ that, and then destructure separately though."
3149 "I was expecting to see an equals sign next, followed by an expression\
3150 \ telling me what to compute."
3153 DestructBody expr row col ->
3154 toExprReport source (InDestruct startRow startCol) expr row col
3156 DestructIndentEquals row col ->
3158 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3159 region = toRegion row col
3161 Report.Report "UNFINISHED DEFINITION" region [] $
3162 Code.toSnippet source surroundings (Just region)
3165 "I got stuck trying to parse this definition:"
3168 "I was expecting to see an equals sign next, followed by an expression\
3169 \ telling me what to compute."
3172 DestructIndentBody row col ->
3174 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3175 region = toRegion row col
3177 Report.Report "UNFINISHED DEFINITION" region [] $
3178 Code.toSnippet source surroundings (Just region)
3181 "I got stuck while parsing this definition:"
3184 "I was expecting to see an expression next. What is it equal to?"
3192toCaseReport :: Code.Source -> Context -> Case -> Row -> Col -> Report.Report
3193toCaseReport source context case_ startRow startCol =
3195 CaseSpace space row col ->
3196 toSpaceReport source space row col
3199 toUnfinishCaseReport source row col startRow startCol $
3200 D.fillSep ["I","was","expecting","to","see","the",D.dullyellow "of","keyword","next."]
3202 CasePattern pattern row col ->
3203 toPatternReport source PCase pattern row col
3205 CaseArrow row col ->
3206 case Code.whatIsNext source row col of
3207 Code.Keyword keyword ->
3209 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3210 region = toKeywordRegion row col keyword
3212 Report.Report "RESERVED WORD" region [] $
3213 Code.toSnippet source surroundings (Just region)
3216 "I am partway through parsing a `case` expression, but I got stuck here:"
3219 "It looks like you are trying to use `" ++ keyword ++ "` in one of your\
3220 \ patterns, but it is a reserved word. Try using a different name?"
3223 Code.Operator ":" ->
3225 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3226 region = toRegion row col
3228 Report.Report "UNEXPECTED OPERATOR" region [] $
3229 Code.toSnippet source surroundings (Just region)
3232 "I am partway through parsing a `case` expression, but I got stuck here:"
3235 ["I","am","seeing",D.dullyellow ":","but","maybe","you","want",D.green "::","instead?"
3236 ,"For","pattern","matching","on","lists?"
3240 Code.Operator "=" ->
3242 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3243 region = toRegion row col
3245 Report.Report "UNEXPECTED OPERATOR" region [] $
3246 Code.toSnippet source surroundings (Just region)
3249 "I am partway through parsing a `case` expression, but I got stuck here:"
3252 ["I","am","seeing",D.dullyellow "=","but","maybe","you","want",D.green "->","instead?"
3258 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3259 region = toRegion row col
3261 Report.Report "MISSING ARROW" region [] $
3262 Code.toSnippet source surroundings (Just region)
3265 "I am partway through parsing a `case` expression, but I got stuck here:"
3267 addNoteForCaseIndentError $
3269 "I was expecting to see an arrow next."
3272 CaseExpr expr row col ->
3273 toExprReport source (InNode NCase startRow startCol context) expr row col
3275 CaseBranch expr row col ->
3276 toExprReport source (InNode NBranch startRow startCol context) expr row col
3278 CaseIndentOf row col ->
3279 toUnfinishCaseReport source row col startRow startCol $
3280 D.fillSep ["I","was","expecting","to","see","the",D.dullyellow "of","keyword","next."]
3282 CaseIndentExpr row col ->
3283 toUnfinishCaseReport source row col startRow startCol $
3284 D.reflow "I was expecting to see a expression next."
3286 CaseIndentPattern row col ->
3287 toUnfinishCaseReport source row col startRow startCol $
3288 D.reflow "I was expecting to see a pattern next."
3290 CaseIndentArrow row col ->
3291 toUnfinishCaseReport source row col startRow startCol $
3293 ["I","just","saw","a","pattern,","so","I","was","expecting"
3294 ,"to","see","a",D.dullyellow "->","next."
3297 CaseIndentBranch row col ->
3298 toUnfinishCaseReport source row col startRow startCol $
3300 "I was expecting to see an expression next. What should I do when\
3301 \ I run into this particular pattern?"
3303 CasePatternAlignment indent row col ->
3304 toUnfinishCaseReport source row col startRow startCol $
3306 "I suspect this is a pattern that is not indented far enough? (" ++ show indent ++ " spaces)"
3309toUnfinishCaseReport :: Code.Source -> Row -> Col -> Row -> Col -> D.Doc -> Report.Report
3310toUnfinishCaseReport source row col startRow startCol message =
3312 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3313 region = toRegion row col
3315 Report.Report "UNFINISHED CASE" region [] $
3316 Code.toSnippet source surroundings (Just region)
3319 "I was partway through parsing a `case` expression, but I got stuck here:"
3324 "Here is an example of a valid `case` expression for reference."
3326 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3327 , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
3328 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3330 , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
3331 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3334 "Notice the indentation. Each pattern is aligned, and each branch is indented\
3335 \ a bit more than the corresponding pattern. That is important!"
3340addNoteForCaseIndentError :: D.Doc -> D.Doc
3341addNoteForCaseIndentError message =
3346 "Sometimes I get confused by indentation, so try to make your `case` look\
3347 \ something like this:"
3349 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3350 , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
3351 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3353 , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
3354 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3357 "Notice the indentation! Each pattern is aligned, and each branch is indented\
3358 \ a bit more than the corresponding pattern. That is important!"
3366toIfReport :: Code.Source -> Context -> If -> Row -> Col -> Report.Report
3367toIfReport source context if_ startRow startCol =
3369 IfSpace space row col ->
3370 toSpaceReport source space row col
3374 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3375 region = toRegion row col
3377 Report.Report "UNFINISHED IF" region [] $
3378 Code.toSnippet source surroundings (Just region)
3381 "I was expecting to see more of this `if` expression, but I got stuck here:"
3384 ["I","was","expecting","to","see","the",D.cyan "then","keyword","next."
3390 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3391 region = toRegion row col
3393 Report.Report "UNFINISHED IF" region [] $
3394 Code.toSnippet source surroundings (Just region)
3397 "I was expecting to see more of this `if` expression, but I got stuck here:"
3400 ["I","was","expecting","to","see","the",D.cyan "else","keyword","next."
3404 IfElseBranchStart row col ->
3406 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3407 region = toRegion row col
3409 Report.Report "UNFINISHED IF" region [] $
3410 Code.toSnippet source surroundings (Just region)
3413 "I just saw the start of an `else` branch, but then I got stuck here:"
3416 "I was expecting to see an expression next. Maybe it is not filled in yet?"
3419 IfCondition expr row col ->
3420 toExprReport source (InNode NCond startRow startCol context) expr row col
3422 IfThenBranch expr row col ->
3423 toExprReport source (InNode NThen startRow startCol context) expr row col
3425 IfElseBranch expr row col ->
3426 toExprReport source (InNode NElse startRow startCol context) expr row col
3428 IfIndentCondition row col ->
3430 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3431 region = toRegion row col
3433 Report.Report "UNFINISHED IF" region [] $
3434 Code.toSnippet source surroundings (Just region)
3437 "I was expecting to see more of this `if` expression, but I got stuck here:"
3441 ["I","was","expecting","to","see","an","expression","like",D.dullyellow "x < 0"
3442 ,"that","evaluates","to","True","or","False."
3445 "I can be confused by indentation. Maybe something is not indented enough?"
3449 IfIndentThen row col ->
3451 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3452 region = toRegion row col
3454 Report.Report "UNFINISHED IF" region [] $
3455 Code.toSnippet source surroundings (Just region)
3458 "I was expecting to see more of this `if` expression, but I got stuck here:"
3462 ["I","was","expecting","to","see","the",D.cyan "then","keyword","next."
3465 "I can be confused by indentation. Maybe something is not indented enough?"
3469 IfIndentThenBranch row col ->
3471 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3472 region = toRegion row col
3474 Report.Report "UNFINISHED IF" region [] $
3475 Code.toSnippet source surroundings (Just region)
3478 "I got stuck after the start of this `then` branch:"
3482 "I was expecting to see an expression next. Maybe it is not filled in yet?"
3484 "I can be confused by indentation, so if the `then` branch is already\
3485 \ present, it may not be indented enough for me to recognize it."
3489 IfIndentElseBranch row col ->
3491 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3492 region = toRegion row col
3494 Report.Report "UNFINISHED IF" region [] $
3495 Code.toSnippet source surroundings (Just region)
3498 "I got stuck after the start of this `else` branch:"
3502 "I was expecting to see an expression next. Maybe it is not filled in yet?"
3504 "I can be confused by indentation, so if the `else` branch is already\
3505 \ present, it may not be indented enough for me to recognize it."
3509 IfIndentElse row col ->
3511 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3512 region = toRegion row col
3514 Report.Report "UNFINISHED IF" region [] $
3515 Code.toSnippet source surroundings (Just region)
3518 "I was expecting to see an `else` branch after this:"
3522 "I know what to do when the condition is `True`, but not when it is `False`."
3524 ["Add","an",D.cyan "else","branch","to","handle","that","scenario!"]
3533toRecordReport :: Code.Source -> Context -> Record -> Row -> Col -> Report.Report
3534toRecordReport source context record startRow startCol =
3536 RecordOpen row col ->
3537 case Code.whatIsNext source row col of
3538 Code.Keyword keyword ->
3540 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3541 region = toKeywordRegion row col keyword
3543 Report.Report "RESERVED WORD" region [] $
3544 Code.toSnippet source surroundings (Just region)
3547 "I just started parsing a record, but I got stuck on this field name:"
3550 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3551 \ that is a reserved word. Try using a different name!"
3556 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3557 region = toRegion row col
3559 Report.Report "UNFINISHED RECORD" region [] $
3560 Code.toSnippet source surroundings (Just region)
3563 "I just started parsing a record, but I got stuck here:"
3566 ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
3567 ,"so","I","was","expecting","to","see","a","field","name","next."
3571 RecordEnd row col ->
3573 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3574 region = toRegion row col
3576 Report.Report "UNFINISHED RECORD" region [] $
3577 Code.toSnippet source surroundings (Just region)
3580 "I am partway through parsing a record, but I got stuck here:"
3584 ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
3585 ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
3588 "When I get stuck like this, it usually means that there is a missing parenthesis\
3589 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
3593 RecordField row col ->
3594 case Code.whatIsNext source row col of
3595 Code.Keyword keyword ->
3597 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3598 region = toKeywordRegion row col keyword
3600 Report.Report "RESERVED WORD" region [] $
3601 Code.toSnippet source surroundings (Just region)
3604 "I am partway through parsing a record, but I got stuck on this field name:"
3607 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3608 \ that is a reserved word. Try using a different name!"
3613 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3614 region = toRegion row col
3616 Report.Report "UNFINISHED RECORD" region [] $
3617 Code.toSnippet source surroundings (Just region)
3620 "I am partway through parsing a record, but I got stuck after that last comma:"
3622 addNoteForRecordError $
3624 "Trailing commas are not allowed in records, so I was expecting to see another\
3625 \ record field defined next. If you are done defining the record, the fix may\
3626 \ be to delete that last comma?"
3629 RecordEquals row col ->
3631 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3632 region = toRegion row col
3634 Report.Report "UNFINISHED RECORD" region [] $
3635 Code.toSnippet source surroundings (Just region)
3638 "I am partway through parsing a record, but I got stuck here:"
3640 addNoteForRecordError $
3642 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
3643 ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
3647 RecordExpr expr row col ->
3648 toExprReport source (InNode NRecord startRow startCol context) expr row col
3650 RecordSpace space row col ->
3651 toSpaceReport source space row col
3653 RecordIndentOpen row col ->
3655 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3656 region = toRegion row col
3658 Report.Report "UNFINISHED RECORD" region [] $
3659 Code.toSnippet source surroundings (Just region)
3662 "I just saw the opening curly brace of a record, but then I got stuck here:"
3664 addNoteForRecordIndentError $
3666 ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
3667 ,"Try","defining","some","fields","of","your","own?"
3671 RecordIndentEnd row col ->
3673 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3674 region = toRegion row col
3676 Report.Report "UNFINISHED RECORD" region [] $
3677 Code.toSnippet source surroundings (Just region)
3680 "I was expecting to see a closing curly brace next:"
3682 addNoteForRecordIndentError $
3684 ["Try","putting","an",D.green "}","and","see","if","that","helps?"
3688 RecordIndentField row col ->
3690 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3691 region = toRegion row col
3693 Report.Report "UNFINISHED RECORD" region [] $
3694 Code.toSnippet source surroundings (Just region)
3697 "I am partway through parsing a record, but I got stuck after that last comma:"
3699 addNoteForRecordError $
3701 "Trailing commas are not allowed in records, so the fix may be to\
3702 \ delete that last comma? Or maybe you were in the middle of defining\
3703 \ an additional field?"
3706 RecordIndentEquals row col ->
3708 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3709 region = toRegion row col
3711 Report.Report "UNFINISHED RECORD" region [] $
3712 Code.toSnippet source surroundings (Just region)
3715 "I am partway through parsing a record. I just saw a record\
3716 \ field, so I was expecting to see an equals sign next:"
3718 addNoteForRecordIndentError $
3720 ["Try","putting","an",D.green "=","followed","by","an","expression?"
3724 RecordIndentExpr row col ->
3726 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3727 region = toRegion row col
3729 Report.Report "UNFINISHED RECORD" region [] $
3730 Code.toSnippet source surroundings (Just region)
3733 "I am partway through parsing a record, and I was expecting to run into an expression next:"
3735 addNoteForRecordIndentError $
3737 ["Try","putting","something","like"
3738 ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
3743addNoteForRecordError :: D.Doc -> D.Doc
3744addNoteForRecordError normalRecommendation =
3746 normalRecommendation
3749 "If you are trying to define a record across multiple lines, I recommend using this format:"
3750 , D.indent 4 $ D.vcat $
3751 [ "{ name = \"Alice\""
3757 "Notice that each line starts with some indentation. Usually two or four spaces. I\
3758 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3759 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
3763addNoteForRecordIndentError :: D.Doc -> D.Doc
3764addNoteForRecordIndentError normalRecommendation =
3766 normalRecommendation
3769 "I may be confused by indentation. For example, if you are trying to define\
3770 \ a record across multiple lines, I recommend using this format:"
3771 , D.indent 4 $ D.vcat $
3772 [ "{ name = \"Alice\""
3778 "Notice that each line starts with some indentation. Usually two or four spaces. I\
3779 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3780 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
3788toTupleReport :: Code.Source -> Context -> Tuple -> Row -> Col -> Report.Report
3789toTupleReport source context tuple startRow startCol =
3791 TupleExpr expr row col ->
3792 toExprReport source (InNode NParens startRow startCol context) expr row col
3794 TupleSpace space row col ->
3795 toSpaceReport source space row col
3799 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3800 region = toRegion row col
3802 Report.Report "UNFINISHED PARENTHESES" region [] $
3803 Code.toSnippet source surroundings (Just region)
3806 "I was expecting to see a closing parentheses next, but I got stuck here:"
3809 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
3811 "I can get stuck when I run into keywords, operators, parentheses, or brackets\
3812 \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
3813 \ or missing brackets) that is confusing me."
3817 TupleOperatorClose row col ->
3819 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3820 region = toRegion row col
3822 Report.Report "UNFINISHED OPERATOR FUNCTION" region [] $
3823 Code.toSnippet source surroundings (Just region)
3825 D.reflow "I was expecting a closing parenthesis here:"
3828 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
3830 "I think I am parsing an operator function right now, so I am expecting to see\
3831 \ something like (+) or (&&) where an operator is surrounded by parentheses with\
3836 TupleOperatorReserved operator row col ->
3838 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3839 region = toRegion row col
3841 Report.Report "UNEXPECTED SYMBOL" region [] $
3842 Code.toSnippet source surroundings (Just region)
3845 "I ran into an unexpected symbol here:"
3849 BadDot -> ["Maybe","you","wanted","a","record","accessor","like",D.dullyellow ".x","or",D.dullyellow ".name","instead?"]
3850 BadPipe -> ["Try",D.dullyellow "(||)","instead?","To","turn","boolean","OR","into","a","function?"]
3851 BadArrow -> ["Maybe","you","wanted",D.dullyellow "(>)","or",D.dullyellow "(>=)","instead?"]
3852 BadEquals -> ["Try",D.dullyellow "(==)","instead?","To","make","a","function","that","checks","equality?"]
3853 BadHasType -> ["Try",D.dullyellow "(::)","instead?","To","add","values","to","the","front","of","lists?"]
3856 TupleIndentExpr1 row col ->
3858 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3859 region = toRegion row col
3861 Report.Report "UNFINISHED PARENTHESES" region [] $
3862 Code.toSnippet source surroundings (Just region)
3865 "I just saw an open parenthesis, so I was expecting to see an expression next."
3869 ["Something","like",D.dullyellow "(4 + 5)","or"
3870 ,D.dullyellow "(String.reverse \"desserts\")" <> "."
3871 ,"Anything","where","you","are","putting","parentheses","around","normal","expressions."
3874 "I can get confused by indentation in cases like this, so\
3875 \ maybe you have an expression but it is not indented enough?"
3879 TupleIndentExprN row col ->
3881 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3882 region = toRegion row col
3884 Report.Report "UNFINISHED TUPLE" region [] $
3885 Code.toSnippet source surroundings (Just region)
3888 "I think I am in the middle of parsing a tuple. I just saw a comma, so I was expecting to see an expression next."
3892 ["A","tuple","looks","like",D.dullyellow "(3,4)","or"
3893 ,D.dullyellow "(\"Tom\",42)" <> ","
3894 ,"so","I","think","there","is","an","expression","missing","here?"
3897 "I can get confused by indentation in cases like this, so\
3898 \ maybe you have an expression but it is not indented enough?"
3902 TupleIndentEnd row col ->
3904 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3905 region = toRegion row col
3907 Report.Report "UNFINISHED PARENTHESES" region [] $
3908 Code.toSnippet source surroundings (Just region)
3911 "I was expecting to see a closing parenthesis next:"
3914 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
3916 "I can get confused by indentation in cases like this, so\
3917 \ maybe you have a closing parenthesis but it is not indented enough?"
3922toListReport :: Code.Source -> Context -> List -> Row -> Col -> Report.Report
3923toListReport source context list startRow startCol =
3925 ListSpace space row col ->
3926 toSpaceReport source space row col
3930 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3931 region = toRegion row col
3933 Report.Report "UNFINISHED LIST" region [] $
3934 Code.toSnippet source surroundings (Just region)
3937 "I am partway through parsing a list, but I got stuck here:"
3941 ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
3942 ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
3945 "When I get stuck like this, it usually means that there is a missing parenthesis\
3946 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
3950 ListExpr expr row col ->
3954 surroundings = A.Region (A.Position startRow startCol) (A.Position r c)
3955 region = toRegion r c
3957 Report.Report "UNFINISHED LIST" region [] $
3958 Code.toSnippet source surroundings (Just region)
3961 "I was expecting to see another list entry after that last comma:"
3965 "Trailing commas are not allowed in lists, so the fix may be to delete the comma?"
3967 "I recommend using the following format for lists that span multiple lines:"
3968 , D.indent 4 $ D.vcat $
3975 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
3976 \ This style can be jarring for people coming from C-like syntax, but folks generally\
3977 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
3982 toExprReport source (InNode NList startRow startCol context) expr row col
3986 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3987 region = toRegion row col
3989 Report.Report "UNFINISHED LIST" region [] $
3990 Code.toSnippet source surroundings (Just region)
3993 "I am partway through parsing a list, but I got stuck here:"
3997 ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
3998 ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
4001 "When I get stuck like this, it usually means that there is a missing parenthesis\
4002 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
4006 ListIndentOpen row col ->
4008 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4009 region = toRegion row col
4011 Report.Report "UNFINISHED LIST" region [] $
4012 Code.toSnippet source surroundings (Just region)
4015 "I cannot find the end of this list:"
4019 ["You","could","change","it","to","something","like"
4020 ,D.dullyellow "[3,4,5]"
4022 ,D.dullyellow "[]" <> "."
4023 ,"Anything","where","there","is","an","open","and","close","square","brace,"
4024 ,"and","where","the","elements","of","the","list","are","separated","by","commas."
4027 "I may be confused by indentation. For example, if you are trying to define\
4028 \ a list across multiple lines, I recommend using this format:"
4029 , D.indent 4 $ D.vcat $
4036 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4037 \ This style can be jarring for people coming from C-like syntax, but folks generally\
4038 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4042 ListIndentEnd row col ->
4044 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4045 region = toRegion row col
4047 Report.Report "UNFINISHED LIST" region [] $
4048 Code.toSnippet source surroundings (Just region)
4051 "I cannot find the end of this list:"
4055 ["You","can","just","add","a","closing",D.dullyellow "]"
4056 ,"right","here,","and","I","will","be","all","set!"
4059 "I may be confused by indentation. For example, if you are trying to define\
4060 \ a list across multiple lines, I recommend using this format:"
4061 , D.indent 4 $ D.vcat $
4068 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4069 \ This style can be jarring for people coming from C-like syntax, but folks generally\
4070 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4074 ListIndentExpr row col ->
4076 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4077 region = toRegion row col
4079 Report.Report "UNFINISHED LIST" region [] $
4080 Code.toSnippet source surroundings (Just region)
4083 "I was expecting to see another list entry after this comma:"
4087 "Trailing commas are not allowed in lists, so the fix may be to delete the comma?"
4089 "I recommend using the following format for lists that span multiple lines:"
4090 , D.indent 4 $ D.vcat $
4097 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4098 \ This style can be jarring for people coming from C-like syntax, but folks generally\
4099 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4104toFuncReport :: Code.Source -> Context -> Func -> Row -> Col -> Report.Report
4105toFuncReport source context func startRow startCol =
4107 FuncSpace space row col ->
4108 toSpaceReport source space row col
4110 FuncArg pattern row col ->
4111 toPatternReport source PArg pattern row col
4113 FuncBody expr row col ->
4114 toExprReport source (InNode NFunc startRow startCol context) expr row col
4116 FuncArrow row col ->
4117 case Code.whatIsNext source row col of
4118 Code.Keyword keyword ->
4120 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4121 region = toKeywordRegion row col keyword
4123 Report.Report "RESERVED WORD" region [] $
4124 Code.toSnippet source surroundings (Just region)
4127 "I was parsing an anonymous function, but I got stuck here:"
4130 "It looks like you are trying to use `" ++ keyword ++ "` as an argument, but\
4131 \ it is a reserved word in this language. Try using a different argument name!"
4136 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4137 region = toRegion row col
4139 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4140 Code.toSnippet source surroundings (Just region)
4143 "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
4146 ["The","syntax","for","anonymous","functions","is"
4147 ,D.dullyellow "(\\x -> x + 1)"
4148 ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
4152 FuncIndentArg row col ->
4154 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4155 region = toRegion row col
4157 Report.Report "MISSING ARGUMENT" region [] $
4158 Code.toSnippet source surroundings (Just region)
4161 "I just saw the beginning of an anonymous function, so I was expecting to see an argument next:"
4165 ["Something","like",D.dullyellow"x","or",D.dullyellow "name" <> "."
4166 ,"Anything","that","starts","with","a","lower","case","letter!"
4169 "The syntax for anonymous functions is (\\x -> x + 1) where the backslash\
4170 \ is meant to look a bit like a lambda if you squint. This visual pun seemed\
4171 \ like a better idea at the time!"
4175 FuncIndentArrow row col ->
4177 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4178 region = toRegion row col
4180 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4181 Code.toSnippet source surroundings (Just region)
4184 "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
4188 ["The","syntax","for","anonymous","functions","is"
4189 ,D.dullyellow "(\\x -> x + 1)"
4190 ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
4193 "It is possible that I am confused about indetation! I generally recommend\
4194 \ switching to named functions if the definition cannot fit inline nicely, so\
4195 \ either (1) try to fit the whole anonymous function on one line or (2) break\
4196 \ the whole thing out into a named function. Things tend to be clearer that way!"
4200 FuncIndentBody row col ->
4202 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4203 region = toRegion row col
4205 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4206 Code.toSnippet source surroundings (Just region)
4209 "I was expecting to see the body of your anonymous function next:"
4213 ["The","syntax","for","anonymous","functions","is"
4214 ,D.dullyellow "(\\x -> x + 1)"
4215 ,"so","I","am","missing","all","the","stuff","after","the","arrow!"
4218 "It is possible that I am confused about indetation! I generally recommend\
4219 \ switching to named functions if the definition cannot fit inline nicely, so\
4220 \ either (1) try to fit the whole anonymous function on one line or (2) break\
4221 \ the whole thing out into a named function. Things tend to be clearer that way!"
4236toPatternReport :: Code.Source -> PContext -> Pattern -> Row -> Col -> Report.Report
4237toPatternReport source context pattern startRow startCol =
4239 PRecord record row col ->
4240 toPRecordReport source record row col
4242 PTuple tuple row col ->
4243 toPTupleReport source context tuple row col
4245 PList list row col ->
4246 toPListReport source context list row col
4249 case Code.whatIsNext source row col of
4250 Code.Keyword keyword ->
4252 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4253 region = toKeywordRegion row col keyword
4256 PArg -> "as an argument"
4257 PCase -> "in this pattern"
4258 PLet -> "in this pattern"
4260 Report.Report "RESERVED WORD" region [] $
4261 Code.toSnippet source surroundings (Just region)
4264 "It looks like you are trying to use `" ++ keyword ++ "` " ++ inThisThing ++ ":"
4267 "This is a reserved word! Try using some other name?"
4270 Code.Operator "-" ->
4272 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4273 region = toRegion row col
4275 Report.Report "UNEXPECTED SYMBOL" region [] $
4276 Code.toSnippet source surroundings (Just region)
4279 "I ran into a minus sign unexpectedly in this pattern:"
4282 "It is not possible to pattern match on negative numbers at this\
4283 \ time. Try using an `if` expression for that sort of thing for now."
4288 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4289 region = toRegion row col
4291 Report.Report "PROBLEM IN PATTERN" region [] $
4292 Code.toSnippet source surroundings (Just region)
4295 "I wanted to parse a pattern next, but I got stuck here:"
4298 ["I","am","not","sure","why","I","am","getting","stuck","exactly."
4299 ,"I","just","know","that","I","want","a","pattern","next."
4300 ,"Something","as","simple","as"
4301 ,D.dullyellow "maybeHeight","or",D.dullyellow "result"
4306 PChar char row col ->
4307 toCharReport source char row col
4309 PString string row col ->
4310 toStringReport source string row col
4312 PNumber number row col ->
4313 toNumberReport source number row col
4315 PFloat width row col ->
4317 region = toWiderRegion row col width
4319 Report.Report "UNEXPECTED PATTERN" region [] $
4320 Code.toSnippet source region Nothing
4323 "I cannot pattern match with floating point numbers:"
4326 ["Equality","on","floats","can","be","unreliable,","so","you","usually","want"
4327 ,"to","check","that","they","are","nearby","with","some","sort","of"
4328 ,D.dullyellow "(abs (actual - expected) < 0.001)","check."
4334 region = toRegion row col
4336 Report.Report "UNFINISHED PATTERN" region [] $
4337 Code.toSnippet source region Nothing $
4340 "I was expecting to see a variable name after the `as` keyword:"
4344 ["The","`as`","keyword","lets","you","write","patterns","like"
4345 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4346 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4347 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4348 ,"thing","with",D.dullyellow "point."
4351 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
4352 \ people just want to use `as` as a variable name though. Try using a different name\
4357 PWildcardNotVar name width row col ->
4359 region = toWiderRegion row col (fromIntegral width)
4361 case dropWhile (=='_') (Name.toChars name) of
4362 [] -> [D.dullyellow "x","or",D.dullyellow "age"]
4363 c:cs -> [D.dullyellow (D.fromChars (Char.toLower c : cs))]
4365 Report.Report "UNEXPECTED NAME" region [] $
4366 Code.toSnippet source region Nothing $
4369 "Variable names cannot start with underscores like this:"
4372 ["You","can","either","have","an","underscore","like",D.dullyellow "_","to"
4373 ,"ignore","the","value,","or","you","can","have","a","name","like"
4374 ] ++ examples ++ ["to","use","the","matched","value." ]
4377 PSpace space row col ->
4378 toSpaceReport source space row col
4380 PIndentStart row col ->
4382 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4383 region = toRegion row col
4385 Report.Report "UNFINISHED PATTERN" region [] $
4386 Code.toSnippet source surroundings (Just region)
4389 "I wanted to parse a pattern next, but I got stuck here:"
4393 ["I","am","not","sure","why","I","am","getting","stuck","exactly."
4394 ,"I","just","know","that","I","want","a","pattern","next."
4395 ,"Something","as","simple","as"
4396 ,D.dullyellow "maybeHeight","or",D.dullyellow "result"
4400 "I can get confused by indentation. If you think there is a pattern next, maybe\
4401 \ it needs to be indented a bit more?"
4405 PIndentAlias row col ->
4407 region = toRegion row col
4409 Report.Report "UNFINISHED PATTERN" region [] $
4410 Code.toSnippet source region Nothing $
4413 "I was expecting to see a variable name after the `as` keyword:"
4417 ["The","`as`","keyword","lets","you","write","patterns","like"
4418 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4419 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4420 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4421 ,"thing","with",D.dullyellow "point."
4424 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
4425 \ people just want to use `as` as a variable name though. Try using a different name\
4431toPRecordReport :: Code.Source -> PRecord -> Row -> Col -> Report.Report
4432toPRecordReport source record startRow startCol =
4434 PRecordOpen row col ->
4435 toUnfinishRecordPatternReport source row col startRow startCol $
4436 D.reflow "I was expecting to see a field name next."
4438 PRecordEnd row col ->
4439 toUnfinishRecordPatternReport source row col startRow startCol $
4441 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4442 ,"Try","adding","a",D.dullyellow "}","here?"
4445 PRecordField row col ->
4446 case Code.whatIsNext source row col of
4447 Code.Keyword keyword ->
4449 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4450 region = toKeywordRegion row col keyword
4452 Report.Report "RESERVED WORD" region [] $
4453 Code.toSnippet source surroundings (Just region)
4456 "I was not expecting to see `" ++ keyword ++ "` as a record field name:"
4459 "This is a reserved word, not available for variable names. Try another name!"
4463 toUnfinishRecordPatternReport source row col startRow startCol $
4464 D.reflow "I was expecting to see a field name next."
4466 PRecordSpace space row col ->
4467 toSpaceReport source space row col
4469 PRecordIndentOpen row col ->
4470 toUnfinishRecordPatternReport source row col startRow startCol $
4471 D.reflow "I was expecting to see a field name next."
4473 PRecordIndentEnd row col ->
4474 toUnfinishRecordPatternReport source row col startRow startCol $
4476 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4477 ,"Try","adding","a",D.dullyellow "}","here?"
4480 PRecordIndentField row col ->
4481 toUnfinishRecordPatternReport source row col startRow startCol $
4482 D.reflow "I was expecting to see a field name next."
4485toUnfinishRecordPatternReport :: Code.Source -> Row -> Col -> Row -> Col -> D.Doc -> Report.Report
4486toUnfinishRecordPatternReport source row col startRow startCol message =
4488 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4489 region = toRegion row col
4491 Report.Report "UNFINISHED RECORD PATTERN" region [] $
4492 Code.toSnippet source surroundings (Just region)
4495 "I was partway through parsing a record pattern, but I got stuck here:"
4500 ["A","record","pattern","looks","like",D.dullyellow "{x,y}","or",D.dullyellow "{name,age}"
4501 ,"where","you","list","the","field","names","you","want","to","access."
4508toPTupleReport :: Code.Source -> PContext -> PTuple -> Row -> Col -> Report.Report
4509toPTupleReport source context tuple startRow startCol =
4511 PTupleOpen row col ->
4512 case Code.whatIsNext source row col of
4513 Code.Keyword keyword ->
4515 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4516 region = toKeywordRegion row col keyword
4518 Report.Report "RESERVED WORD" region [] $
4519 Code.toSnippet source surroundings (Just region)
4522 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name:"
4525 "This is a reserved word! Try using some other name?"
4530 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4531 region = toRegion row col
4533 Report.Report "UNFINISHED PARENTHESES" region [] $
4534 Code.toSnippet source surroundings (Just region)
4537 "I just saw an open parenthesis, but I got stuck here:"
4540 ["I","was","expecting","so","see","a","pattern","next."
4541 ,"Maybe","it","will","end","up","being","something"
4542 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
4546 PTupleEnd row col ->
4547 case Code.whatIsNext source row col of
4548 Code.Keyword keyword ->
4550 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4551 region = toKeywordRegion row col keyword
4553 Report.Report "RESERVED WORD" region [] $
4554 Code.toSnippet source surroundings (Just region) $
4557 "I ran into a reserved word in this pattern:"
4560 "The `" ++ keyword ++ "` keyword is reserved. Try using a different name instead!"
4565 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4566 region = toKeywordRegion row col op
4568 Report.Report "UNEXPECTED SYMBOL" region [] $
4569 Code.toSnippet source surroundings (Just region) $
4572 "I ran into the " ++ op ++ " symbol unexpectedly in this pattern:"
4575 "Only the :: symbol that works in patterns. It is useful if you\
4576 \ are pattern matching on lists, trying to get the first element\
4577 \ off the front. Did you want that instead?"
4580 Code.Close term bracket ->
4582 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4583 region = toRegion row col
4585 Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
4586 Code.toSnippet source surroundings (Just region) $
4589 "I ran into a an unexpected " ++ term ++ " in this pattern:"
4592 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
4597 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4598 region = toRegion row col
4600 Report.Report "UNFINISHED PARENTHESES" region [] $
4601 Code.toSnippet source surroundings (Just region) $
4604 "I was partway through parsing a pattern, but I got stuck here:"
4607 ["I","was","expecting","a","closing","parenthesis","next,","so"
4608 ,"try","adding","a",D.dullyellow ")","to","see","if","that","helps?"
4612 PTupleExpr pattern row col ->
4613 toPatternReport source context pattern row col
4615 PTupleSpace space row col ->
4616 toSpaceReport source space row col
4618 PTupleIndentEnd row col ->
4620 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4621 region = toRegion row col
4623 Report.Report "UNFINISHED PARENTHESES" region [] $
4624 Code.toSnippet source surroundings (Just region) $
4627 "I was expecting a closing parenthesis next:"
4630 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
4632 "I can get confused by indentation in cases like this, so\
4633 \ maybe you have a closing parenthesis but it is not indented enough?"
4637 PTupleIndentExpr1 row col ->
4639 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4640 region = toRegion row col
4642 Report.Report "UNFINISHED PARENTHESES" region [] $
4643 Code.toSnippet source surroundings (Just region) $
4646 "I just saw an open parenthesis, but then I got stuck here:"
4649 ["I","was","expecting","so","see","a","pattern","next."
4650 ,"Maybe","it","will","end","up","being","something"
4651 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
4655 PTupleIndentExprN row col ->
4657 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4658 region = toRegion row col
4660 Report.Report "UNFINISHED TUPLE PATTERN" region [] $
4661 Code.toSnippet source surroundings (Just region) $
4664 "I am partway through parsing a tuple pattern, but I got stuck here:"
4668 ["I","was","expecting","so","see","a","pattern","next."
4669 ,"I","am","expecting","the","final","result","to","be","something"
4670 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "."
4673 "I can get confused by indentation in cases like this, so the problem\
4674 \ may be that the next part is not indented enough?"
4679toPListReport :: Code.Source -> PContext -> PList -> Row -> Col -> Report.Report
4680toPListReport source context list startRow startCol =
4682 PListOpen row col ->
4683 case Code.whatIsNext source row col of
4684 Code.Keyword keyword ->
4686 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4687 region = toKeywordRegion row col keyword
4689 Report.Report "RESERVED WORD" region [] $
4690 Code.toSnippet source surroundings (Just region)
4693 "It looks like you are trying to use `" ++ keyword ++ "` to name an element of a list:"
4696 "This is a reserved word though! Try using some other name?"
4701 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4702 region = toRegion row col
4704 Report.Report "UNFINISHED LIST PATTERN" region [] $
4705 Code.toSnippet source surroundings (Just region) $
4708 "I just saw an open square bracket, but then I got stuck here:"
4710 D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
4715 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4716 region = toRegion row col
4718 Report.Report "UNFINISHED LIST PATTERN" region [] $
4719 Code.toSnippet source surroundings (Just region) $
4722 "I was expecting a closing square bracket to end this list pattern:"
4724 D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
4727 PListExpr pattern row col ->
4728 toPatternReport source context pattern row col
4730 PListSpace space row col ->
4731 toSpaceReport source space row col
4733 PListIndentOpen row col ->
4735 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4736 region = toRegion row col
4738 Report.Report "UNFINISHED LIST PATTERN" region [] $
4739 Code.toSnippet source surroundings (Just region) $
4742 "I just saw an open square bracket, but then I got stuck here:"
4745 [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
4747 "I can get confused by indentation in cases like this, so\
4748 \ maybe there is something next, but it is not indented enough?"
4752 PListIndentEnd row col ->
4754 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4755 region = toRegion row col
4757 Report.Report "UNFINISHED LIST PATTERN" region [] $
4758 Code.toSnippet source surroundings (Just region) $
4761 "I was expecting a closing square bracket to end this list pattern:"
4764 [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
4766 "I can get confused by indentation in cases like this, so\
4767 \ maybe you have a closing square bracket but it is not indented enough?"
4771 PListIndentExpr row col ->
4773 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4774 region = toRegion row col
4776 Report.Report "UNFINISHED LIST PATTERN" region [] $
4777 Code.toSnippet source surroundings (Just region) $
4780 "I am partway through parsing a list pattern, but I got stuck here:"
4784 "I was expecting to see another pattern next. Maybe a variable name."
4786 "I can get confused by indentation in cases like this, so\
4787 \ maybe there is more to this pattern but it is not indented enough?"
4797 = TC_Annotation Name.Name
4803toTypeReport :: Code.Source -> TContext -> Type -> Row -> Col -> Report.Report
4804toTypeReport source context tipe startRow startCol =
4806 TRecord record row col ->
4807 toTRecordReport source context record row col
4809 TTuple tuple row col ->
4810 toTTupleReport source context tuple row col
4813 case Code.whatIsNext source row col of
4814 Code.Keyword keyword ->
4816 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4817 region = toKeywordRegion row col keyword
4819 Report.Report "RESERVED WORD" region [] $
4820 Code.toSnippet source surroundings (Just region)
4823 "I was expecting to see a type next, but I got stuck on this reserved word:"
4826 "It looks like you are trying to use `" ++ keyword ++ "` as a type variable, but \
4827 \ it is a reserved word. Try using a different name!"
4832 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4833 region = toRegion row col
4837 TC_Annotation _ -> "type annotation"
4838 TC_CustomType -> "custom type"
4839 TC_TypeAlias -> "type alias"
4844 TC_Annotation name -> "the `" ++ Name.toChars name ++ "` type annotation"
4845 TC_CustomType -> "a custom type"
4846 TC_TypeAlias -> "a type alias"
4849 Report.Report ("PROBLEM IN " ++ map Char.toUpper thing) region [] $
4850 Code.toSnippet source surroundings (Just region)
4853 "I was partway through parsing " ++ something ++ ", but I got stuck here:"
4856 ["I","was","expecting","to","see","a","type","next."
4857 ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
4861 TSpace space row col ->
4862 toSpaceReport source space row col
4864 TIndentStart row col ->
4866 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4867 region = toRegion row col
4871 TC_Annotation _ -> "type annotation"
4872 TC_CustomType -> "custom type"
4873 TC_TypeAlias -> "type alias"
4876 Report.Report ("UNFINISHED " ++ map Char.toUpper thing) region [] $
4877 Code.toSnippet source surroundings (Just region)
4880 "I was partway through parsing a " ++ thing ++ ", but I got stuck here:"
4884 ["I","was","expecting","to","see","a","type","next."
4885 ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
4888 "I can get confused by indentation. If you think there is already a type\
4889 \ next, maybe it is not indented enough?"
4894toTRecordReport :: Code.Source -> TContext -> TRecord -> Row -> Col -> Report.Report
4895toTRecordReport source context record startRow startCol =
4897 TRecordOpen row col ->
4898 case Code.whatIsNext source row col of
4899 Code.Keyword keyword ->
4901 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4902 region = toKeywordRegion row col keyword
4904 Report.Report "RESERVED WORD" region [] $
4905 Code.toSnippet source surroundings (Just region)
4908 "I just started parsing a record type, but I got stuck on this field name:"
4911 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
4912 \ that is a reserved word. Try using a different name!"
4917 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4918 region = toRegion row col
4920 Report.Report "UNFINISHED RECORD TYPE" region [] $
4921 Code.toSnippet source surroundings (Just region)
4924 "I just started parsing a record type, but I got stuck here:"
4927 ["Record","types","look","like",D.dullyellow "{ name : String, age : Int },"
4928 ,"so","I","was","expecting","to","see","a","field","name","next."
4932 TRecordEnd row col ->
4934 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4935 region = toRegion row col
4937 Report.Report "UNFINISHED RECORD TYPE" region [] $
4938 Code.toSnippet source surroundings (Just region)
4941 "I am partway through parsing a record type, but I got stuck here:"
4945 ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
4946 ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
4949 "When I get stuck like this, it usually means that there is a missing parenthesis\
4950 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
4954 TRecordField row col ->
4955 case Code.whatIsNext source row col of
4956 Code.Keyword keyword ->
4958 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4959 region = toKeywordRegion row col keyword
4961 Report.Report "RESERVED WORD" region [] $
4962 Code.toSnippet source surroundings (Just region)
4965 "I am partway through parsing a record type, but I got stuck on this field name:"
4968 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
4969 \ that is a reserved word. Try using a different name!"
4974 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4975 region = toRegion row col
4977 Report.Report "UNFINISHED RECORD TYPE" region [] $
4978 Code.toSnippet source surroundings (Just region)
4981 "I am partway through parsing a record type, but I got stuck after that last comma:"
4983 addNoteForRecordTypeError $
4985 "Trailing commas are not allowed in records, so I was expecting to see another\
4986 \ record field defined next. If you are done defining the record, the fix may\
4987 \ be to delete that last comma?"
4990 TRecordColon row col ->
4992 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4993 region = toRegion row col
4995 Report.Report "UNFINISHED RECORD TYPE" region [] $
4996 Code.toSnippet source surroundings (Just region)
4999 "I am partway through parsing a record type, but I got stuck here:"
5001 addNoteForRecordTypeError $
5003 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5004 ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5008 TRecordType tipe row col ->
5009 toTypeReport source context tipe row col
5011 TRecordSpace space row col ->
5012 toSpaceReport source space row col
5014 TRecordIndentOpen row col ->
5016 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5017 region = toRegion row col
5019 Report.Report "UNFINISHED RECORD TYPE" region [] $
5020 Code.toSnippet source surroundings (Just region)
5023 "I just saw the opening curly brace of a record type, but then I got stuck here:"
5025 addNoteForRecordTypeIndentError $
5027 ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5028 ,"Try","defining","some","fields","of","your","own?"
5032 TRecordIndentEnd row col ->
5034 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5035 region = toRegion row col
5037 Report.Report "UNFINISHED RECORD TYPE" region [] $
5038 Code.toSnippet source surroundings (Just region)
5041 "I was expecting to see a closing curly brace next:"
5043 addNoteForRecordTypeIndentError $
5045 ["Try","putting","an",D.green "}","and","see","if","that","helps?"
5049 TRecordIndentField row col ->
5051 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5052 region = toRegion row col
5054 Report.Report "UNFINISHED RECORD TYPE" region [] $
5055 Code.toSnippet source surroundings (Just region)
5058 "I am partway through parsing a record type, but I got stuck after that last comma:"
5060 addNoteForRecordTypeIndentError $
5062 "Trailing commas are not allowed in record types, so the fix may be to\
5063 \ delete that last comma? Or maybe you were in the middle of defining\
5064 \ an additional field?"
5067 TRecordIndentColon row col ->
5069 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5070 region = toRegion row col
5072 Report.Report "UNFINISHED RECORD TYPE" region [] $
5073 Code.toSnippet source surroundings (Just region)
5076 "I am partway through parsing a record type. I just saw a record\
5077 \ field, so I was expecting to see a colon next:"
5079 addNoteForRecordTypeIndentError $
5081 ["Try","putting","an",D.green ":","followed","by","a","type?"
5085 TRecordIndentType row col ->
5087 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5088 region = toRegion row col
5090 Report.Report "UNFINISHED RECORD TYPE" region [] $
5091 Code.toSnippet source surroundings (Just region)
5094 "I am partway through parsing a record type, and I was expecting to run into a type next:"
5096 addNoteForRecordTypeIndentError $
5098 ["Try","putting","something","like"
5099 ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5104addNoteForRecordTypeError :: D.Doc -> D.Doc
5105addNoteForRecordTypeError normalRecommendation =
5107 normalRecommendation
5110 "If you are trying to define a record type across multiple lines, I recommend using this format:"
5111 , D.indent 4 $ D.vcat $
5114 , ", height : Float"
5118 "Notice that each line starts with some indentation. Usually two or four spaces. I\
5119 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5120 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
5124addNoteForRecordTypeIndentError :: D.Doc -> D.Doc
5125addNoteForRecordTypeIndentError normalRecommendation =
5127 normalRecommendation
5130 "I may be confused by indentation. For example, if you are trying to define\
5131 \ a record type across multiple lines, I recommend using this format:"
5132 , D.indent 4 $ D.vcat $
5135 , ", height : Float"
5139 "Notice that each line starts with some indentation. Usually two or four spaces. I\
5140 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5141 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
5145toTTupleReport :: Code.Source -> TContext -> TTuple -> Row -> Col -> Report.Report
5146toTTupleReport source context tuple startRow startCol =
5148 TTupleOpen row col ->
5149 case Code.whatIsNext source row col of
5150 Code.Keyword keyword ->
5152 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5153 region = toKeywordRegion row col keyword
5155 Report.Report "RESERVED WORD" region [] $
5156 Code.toSnippet source surroundings (Just region)
5159 "I ran into a reserved word unexpectedly:"
5162 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name, but \
5163 \ it is a reserved word. Try using a different name!"
5168 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5169 region = toRegion row col
5171 Report.Report "UNFINISHED PARENTHESES" region [] $
5172 Code.toSnippet source surroundings (Just region)
5175 "I just saw an open parenthesis, so I was expecting to see a type next."
5178 ["Something","like",D.dullyellow "(Maybe Int)","or"
5179 ,D.dullyellow "(List Person)" <> "."
5180 ,"Anything","where","you","are","putting","parentheses","around","normal","types."
5184 TTupleEnd row col ->
5186 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5187 region = toRegion row col
5189 Report.Report "UNFINISHED PARENTHESES" region [] $
5190 Code.toSnippet source surroundings (Just region)
5193 "I was expecting to see a closing parentheses next, but I got stuck here:"
5196 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
5198 "I can get stuck when I run into keywords, operators, parentheses, or brackets\
5199 \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
5200 \ or missing brackets) that is confusing me."
5204 TTupleType tipe row col ->
5205 toTypeReport source context tipe row col
5207 TTupleSpace space row col ->
5208 toSpaceReport source space row col
5210 TTupleIndentType1 row col ->
5212 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5213 region = toRegion row col
5215 Report.Report "UNFINISHED PARENTHESES" region [] $
5216 Code.toSnippet source surroundings (Just region)
5219 "I just saw an open parenthesis, so I was expecting to see a type next."
5223 ["Something","like",D.dullyellow "(Maybe Int)","or"
5224 ,D.dullyellow "(List Person)" <> "."
5225 ,"Anything","where","you","are","putting","parentheses","around","normal","types."
5228 "I can get confused by indentation in cases like this, so\
5229 \ maybe you have a type but it is not indented enough?"
5233 TTupleIndentTypeN row col ->
5235 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5236 region = toRegion row col
5238 Report.Report "UNFINISHED TUPLE TYPE" region [] $
5239 Code.toSnippet source surroundings (Just region)
5242 "I think I am in the middle of parsing a tuple type. I just saw a comma, so I was expecting to see a type next."
5246 ["A","tuple","type","looks","like",D.dullyellow "(Float,Float)","or"
5247 ,D.dullyellow "(String,Int)" <> ","
5248 ,"so","I","think","there","is","a","type","missing","here?"
5251 "I can get confused by indentation in cases like this, so\
5252 \ maybe you have an expression but it is not indented enough?"
5256 TTupleIndentEnd row col ->
5258 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5259 region = toRegion row col
5261 Report.Report "UNFINISHED PARENTHESES" region [] $
5262 Code.toSnippet source surroundings (Just region)
5265 "I was expecting to see a closing parenthesis next:"
5268 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
5270 "I can get confused by indentation in cases like this, so\
5271 \ maybe you have a closing parenthesis but it is not indented enough?"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list