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
72 | NoPortsInPackage (A.Located Name.Name)
73 | NoPortModulesInPackage A.Region
74 | NoEffectsOutsideKernel A.Region
83 = ModuleSpace Space Row Col
84 | ModuleBadEnd Row Col
86 | ModuleProblem Row Col
88 | ModuleExposing Exposing Row Col
90 | PortModuleProblem Row Col
91 | PortModuleName Row Col
92 | PortModuleExposing Exposing Row Col
101 | ImportAlias Row Col
102 | ImportExposing Row Col
103 | ImportExposingList Exposing Row Col
104 | ImportEnd Row Col -- different based on col=1 or if greater
106 | ImportIndentName Row Col
107 | ImportIndentAlias Row Col
108 | ImportIndentExposingList Row Col
112 | Declarations Decl Row Col
116 = ExposingSpace Space Row Col
117 | ExposingStart Row Col
118 | ExposingValue Row Col
119 | ExposingOperator Row Col
120 | ExposingOperatorReserved BadOperator Row Col
121 | ExposingOperatorRightParen Row Col
122 | ExposingTypePrivacy Row Col
123 | ExposingEnd Row Col
125 | ExposingIndentEnd Row Col
126 | ExposingIndentValue Row Col
135 | DeclSpace Space Row Col
138 | DeclType DeclType Row Col
139 | DeclDef Name.Name DeclDef Row Col
141 | DeclFreshLineAfterDocComment Row Col
145 = DeclDefSpace Space Row Col
146 | DeclDefEquals Row Col
147 | DeclDefType Type Row Col
148 | DeclDefArg Pattern Row Col
149 | DeclDefBody Expr Row Col
150 | DeclDefNameRepeat Row Col
151 | DeclDefNameMatch Name.Name Row Col
153 | DeclDefIndentType Row Col
154 | DeclDefIndentEquals Row Col
155 | DeclDefIndentBody Row Col
159 = PortSpace Space Row Col
162 | PortType Type Row Col
163 | PortIndentName Row Col
164 | PortIndentColon Row Col
165 | PortIndentType Row Col
173 = DT_Space Space Row Col
175 | DT_Alias TypeAlias Row Col
176 | DT_Union CustomType Row Col
178 | DT_IndentName Row Col
182 = AliasSpace Space Row Col
184 | AliasEquals Row Col
185 | AliasBody Type Row Col
187 | AliasIndentEquals Row Col
188 | AliasIndentBody Row Col
192 = CT_Space Space Row Col
197 | CT_VariantArg Type Row Col
199 | CT_IndentEquals Row Col
200 | CT_IndentBar Row Col
201 | CT_IndentAfterBar Row Col
202 | CT_IndentAfterEquals Row Col
214 | Record Record Row Col
215 | Tuple Tuple Row Col
220 | OperatorRight Name.Name Row Col
221 | OperatorReserved BadOperator Row Col
225 | String String Row Col
226 | Number Number Row Col
227 | Space Space Row Col
228 | EndlessShader Row Col
229 | ShaderProblem [Char.Char] Row Col
230 | IndentOperatorRight Name.Name Row Col
236 | RecordField Row Col
237 | RecordEquals Row Col
238 | RecordExpr Expr Row Col
239 | RecordSpace Space Row Col
241 | RecordIndentOpen Row Col
242 | RecordIndentEnd Row Col
243 | RecordIndentField Row Col
244 | RecordIndentEquals Row Col
245 | RecordIndentExpr Row Col
249 = TupleExpr Expr Row Col
250 | TupleSpace Space Row Col
252 | TupleOperatorClose Row Col
253 | TupleOperatorReserved BadOperator Row Col
255 | TupleIndentExpr1 Row Col
256 | TupleIndentExprN Row Col
257 | TupleIndentEnd Row Col
261 = ListSpace Space Row Col
263 | ListExpr Expr Row Col
266 | ListIndentOpen Row Col
267 | ListIndentEnd Row Col
268 | ListIndentExpr Row Col
272 = FuncSpace Space Row Col
273 | FuncArg Pattern Row Col
274 | FuncBody Expr Row Col
277 | FuncIndentArg Row Col
278 | FuncIndentArrow Row Col
279 | FuncIndentBody Row Col
283 = CaseSpace Space Row Col
285 | CasePattern Pattern Row Col
287 | CaseExpr Expr Row Col
288 | CaseBranch Expr Row Col
290 | CaseIndentOf Row Col
291 | CaseIndentExpr Row Col
292 | CaseIndentPattern Row Col
293 | CaseIndentArrow Row Col
294 | CaseIndentBranch Row Col
295 | CasePatternAlignment Word16 Row Col
299 = IfSpace Space Row Col
302 | IfElseBranchStart Row Col
304 | IfCondition Expr Row Col
305 | IfThenBranch Expr Row Col
306 | IfElseBranch Expr Row Col
308 | IfIndentCondition Row Col
309 | IfIndentThen Row Col
310 | IfIndentThenBranch Row Col
311 | IfIndentElseBranch Row Col
312 | IfIndentElse Row Col
316 = LetSpace Space Row Col
318 | LetDefAlignment Word16 Row Col
320 | LetDef Name.Name Def Row Col
321 | LetDestruct Destruct Row Col
322 | LetBody Expr Row Col
323 | LetIndentDef Row Col
324 | LetIndentIn Row Col
325 | LetIndentBody Row Col
329 = DefSpace Space Row Col
330 | DefType Type Row Col
331 | DefNameRepeat Row Col
332 | DefNameMatch Name.Name Row Col
333 | DefArg Pattern Row Col
335 | DefBody Expr Row Col
336 | DefIndentEquals Row Col
337 | DefIndentType Row Col
338 | DefIndentBody Row Col
339 | DefAlignment Word16 Row Col
343 = DestructSpace Space Row Col
344 | DestructPattern Pattern Row Col
345 | DestructEquals Row Col
346 | DestructBody Expr Row Col
347 | DestructIndentEquals Row Col
348 | DestructIndentBody Row Col
356 = PRecord PRecord Row Col
357 | PTuple PTuple Row Col
358 | PList PList Row Col
362 | PString String Row Col
363 | PNumber Number Row Col
364 | PFloat Word16 Row Col
366 | PWildcardNotVar Name.Name Int Row Col
367 | PSpace Space Row Col
369 | PIndentStart Row Col
370 | PIndentAlias Row Col
374 = PRecordOpen Row Col
376 | PRecordField Row Col
377 | PRecordSpace Space Row Col
379 | PRecordIndentOpen Row Col
380 | PRecordIndentEnd Row Col
381 | PRecordIndentField Row Col
387 | PTupleExpr Pattern Row Col
388 | PTupleSpace Space Row Col
390 | PTupleIndentEnd Row Col
391 | PTupleIndentExpr1 Row Col
392 | PTupleIndentExprN Row Col
398 | PListExpr Pattern Row Col
399 | PListSpace Space Row Col
401 | PListIndentOpen Row Col
402 | PListIndentEnd Row Col
403 | PListIndentExpr Row Col
411 = TRecord TRecord Row Col
412 | TTuple TTuple Row Col
415 | TSpace Space Row Col
417 | TIndentStart Row Col
421 = TRecordOpen Row Col
424 | TRecordField Row Col
425 | TRecordColon Row Col
426 | TRecordType Type Row Col
428 | TRecordSpace Space Row Col
430 | TRecordIndentOpen Row Col
431 | TRecordIndentField Row Col
432 | TRecordIndentColon Row Col
433 | TRecordIndentType Row Col
434 | TRecordIndentEnd Row Col
440 | TTupleType Type Row Col
441 | TTupleSpace Space Row Col
443 | TTupleIndentType1 Row Col
444 | TTupleIndentTypeN Row Col
445 | TTupleIndentEnd Row Col
455 | CharNotString Word16
459 = StringEndless_Single
460 | StringEndless_Multi
461 | StringEscape Escape
466 | BadUnicodeFormat Word16
467 | BadUnicodeCode Word16
468 | BadUnicodeLength Word16 Int Int
475 | NumberNoLeadingZero
484 | EndlessMultiComment
491toReport :: Code.Source -> Error -> Report.Report
494 ModuleNameUnspecified name ->
496 region = toRegion 1 1
498 Report.Report "MODULE NAME MISSING" region [] $
501 "I need the module name to be declared at the top of this file, like this:"
502 , D.indent 4 $ D.fillSep $
503 [ D.cyan "module", D.fromName name, D.cyan "exposing", "(..)" ]
505 "Try adding that as the first line of your file!"
507 "It is best to replace (..) with an explicit list of types and\
508 \ functions you want to expose. When you know a value is only used\
509 \ within this module, you can refactor without worrying about uses\
510 \ elsewhere. Limiting exposed values can also speed up compilation\
511 \ because I can skip a bunch of work if I see that the exposed API\
515 ModuleNameMismatch expectedName (A.At region actualName) ->
516 Report.Report "MODULE NAME MISMATCH" region [ModuleName.toChars expectedName] $
517 Code.toSnippet source region Nothing
519 "It looks like this module name is out of sync:"
523 "I need it to match the file path, so I was expecting to see `"
524 ++ ModuleName.toChars expectedName
525 ++ "` here. Make the following change, and you should be all set!"
527 D.dullyellow (D.fromName actualName) <> " -> " <> D.green (D.fromName expectedName)
529 "I require that module names correspond to file paths. This makes it much\
530 \ easier to explore unfamiliar codebases! So if you want to keep the current\
531 \ module name, try renaming the file instead."
535 UnexpectedPort region ->
536 Report.Report "UNEXPECTED PORTS" region [] $
537 Code.toSnippet source region Nothing
540 "You are declaring ports in a normal module."
544 ["Switch","this","to","say",D.cyan "port module","instead,"
545 ,"marking","that","this","module","contains","port","declarations."
548 "Ports are not a traditional FFI for calling JS functions directly. They need a different mindset! Read"
550 "to learn the syntax and how to use it effectively."
555 Report.Report "NO PORTS" region [] $
556 Code.toSnippet source region Nothing
559 "This module does not declare any ports, but it says it will:"
562 ["Switch","this","to",D.cyan "module"
563 ,"and","you","should","be","all","set!"
567 NoPortsInPackage (A.At region _) ->
568 Report.Report "PACKAGES CANNOT HAVE PORTS" region [] $
569 Code.toSnippet source region Nothing
572 "Packages cannot declare any ports, so I am getting stuck here:"
576 "Remove this port declaration."
577 , noteForPortsInPackage
581 NoPortModulesInPackage region ->
582 Report.Report "PACKAGES CANNOT HAVE PORTS" region [] $
583 Code.toSnippet source region Nothing
586 "Packages cannot declare any ports, so I am getting stuck here:"
590 ["Remove","the",D.cyan "port","keyword","and","I"
591 ,"should","be","able","to","continue."
593 , noteForPortsInPackage
597 NoEffectsOutsideKernel region ->
598 Report.Report "INVALID EFFECT MODULE" region [] $
599 Code.toSnippet source region Nothing
602 "It is not possible to declare an `effect module` outside the @elm organization,\
603 \ so I am getting stuck here:"
607 "Switch to a normal module declaration."
609 "Effect modules are designed to allow certain core functionality to be\
610 \ defined separately from the compiler. So the @elm organization has access to\
611 \ this so that certain changes, extensions, and fixes can be introduced without\
612 \ needing to release new Elm binaries. For example, we want to make it possible\
613 \ to test effects, but this may require changes to the design of effect modules.\
614 \ By only having them defined in the @elm organization, that kind of design work\
615 \ can proceed much more smoothly."
620 toParseErrorReport source modul
623noteForPortsInPackage :: D.Doc
624noteForPortsInPackage =
627 "One of the major goals of the package ecosystem is to be completely written\
628 \ in Elm. This means when you install an Elm package, you can be sure you are safe\
629 \ from security issues on install and that you are not going to get any runtime\
630 \ exceptions coming from your new dependency. This design also sets the ecosystem\
631 \ up to target other platforms more easily (like mobile phones, WebAssembly, etc.)\
632 \ since no community code explicitly depends on JavaScript even existing."
634 "Given that overall goal, allowing ports in packages would lead to some pretty\
635 \ surprising behavior. If ports were allowed in packages, you could install a\
636 \ package but not realize that it brings in an indirect dependency that defines a\
637 \ port. Now you have a program that does not work and the fix is to realize that\
638 \ some JavaScript needs to be added for a dependency you did not even know about.\
639 \ That would be extremely frustrating! \"So why not allow the package author to\
640 \ include the necessary JS code as well?\" Now we are back in conflict with our\
641 \ overall goal to keep all community packages free from runtime exceptions."
645toParseErrorReport :: Code.Source -> Module -> Report.Report
646toParseErrorReport source modul =
648 ModuleSpace space row col ->
649 toSpaceReport source space row col
651 ModuleBadEnd row col ->
652 case Code.whatIsNext source row col of
653 Code.Keyword keyword ->
655 region = toKeywordRegion row col keyword
657 Report.Report "RESERVED WORD" region [] $
658 Code.toSnippet source region Nothing
661 "I got stuck on this reserved word:"
664 "The name `" ++ keyword ++ "` is reserved, so try using a different name?"
669 region = toKeywordRegion row col op
671 Report.Report "UNEXPECTED SYMBOL" region [] $
672 Code.toSnippet source region Nothing
675 "I ran into an unexpected symbol:"
678 "I was not expecting to see a " ++ op ++ " here. Try deleting it? Maybe\
679 \ I can give a better hint from there?"
682 Code.Close term bracket ->
684 region = toRegion row col
686 Report.Report ("UNEXPECTED " ++ map Char.toUpper term) region [] $
687 Code.toSnippet source region Nothing
690 "I ran into an unexpected " ++ term ++ ":"
693 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
696 Code.Other maybeChar ->
698 region = toRegion row col
702 Report.Report "UNEXPECTED SEMICOLON" region [] $
703 Code.toSnippet source region Nothing
706 "I got stuck on this semicolon:"
709 [ D.reflow $ "Try removing it?"
711 "Some languages require semicolons at the end of each statement. These are\
712 \ often called C-like languages, and they usually share a lot of language design\
713 \ choices. (E.g. side-effects, for loops, etc.) Elm manages effects with commands\
714 \ and subscriptions instead, so there is no special syntax for \"statements\" and\
715 \ therefore no need to use semicolons to separate them. I think this will make\
716 \ more sense as you work through <https://guide.elm-lang.org> though!"
721 Report.Report "UNEXPECTED COMMA" region [] $
722 Code.toSnippet source region Nothing
725 "I got stuck on this comma:"
729 "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
731 "If this is supposed to be part of a list, the problem may be a bit earlier.\
732 \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\
733 \ closing ] that is making me think the list ended earlier? The same kinds of\
734 \ things could be going wrong if this is supposed to be a tuple."
739 Report.Report "UNEXPECTED CHARACTER" region [] $
740 Code.toSnippet source region Nothing
743 "I got stuck on this character:"
747 "It is not used for anything in Elm syntax. It is used for multi-line strings in\
748 \ some languages though, so if you want a string that spans multiple lines, you\
749 \ can use Elm's multi-line string syntax like this:"
751 [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
753 , D.dullyellow "# Multi-line Strings"
755 , D.dullyellow "- start with triple double quotes"
756 , D.dullyellow "- write whatever you want"
757 , D.dullyellow "- no need to escape newlines or double quotes"
758 , D.dullyellow "- end with triple double quotes"
760 , D.dullyellow "\"\"\""
763 "Otherwise I do not know what is going on! Try removing the character?"
768 Report.Report "UNEXPECTED SYMBOL" region [] $
769 Code.toSnippet source region Nothing
772 "I got stuck on this dollar sign:"
775 "It is not used for anything in Elm syntax. Are you coming from a language where\
776 \ dollar signs can be used in variable names? If so, try a name that (1) starts\
777 \ with a letter and (2) only contains letters, numbers, and underscores."
780 Just c | elem c ['#','@','!','%','~'] ->
781 Report.Report "UNEXPECTED SYMBOL" region [] $
782 Code.toSnippet source region Nothing
785 "I got stuck on this symbol:"
788 "It is not used for anything in Elm syntax. Try removing it?"
792 Report.Report "SYNTAX PROBLEM" region [] $
793 Code.toSnippet source region Nothing
799 "Whatever I am running into is confusing me a lot! Normally I can give fairly\
800 \ specific hints, but something is really tripping me up this time."
803 ModuleProblem row col ->
805 region = toRegion row col
807 Report.Report "UNFINISHED MODULE DECLARATION" region [] $
808 Code.toSnippet source region Nothing
811 "I am parsing an `module` declaration, but I got stuck here:"
815 "Here are some examples of valid `module` declarations:"
816 , D.indent 4 $ D.vcat $
817 [ D.fillSep [D.cyan "module","Main",D.cyan "exposing","(..)"]
818 , D.fillSep [D.cyan "module","Dict",D.cyan "exposing","(Dict, empty, get)"]
821 "I generally recommend using an explicit exposing list. I can skip compiling a bunch\
822 \ of files when the public interface of a module stays the same, so exposing fewer\
823 \ values can help improve compile times!"
827 ModuleName row col ->
829 region = toRegion row col
831 Report.Report "EXPECTING MODULE NAME" region [] $
832 Code.toSnippet source region Nothing
835 "I was parsing an `module` declaration until I got stuck here:"
839 "I was expecting to see the module name next, like in these examples:"
840 , D.indent 4 $ D.vcat $
841 [ D.fillSep [D.cyan "module","Dict",D.cyan "exposing","(..)"]
842 , D.fillSep [D.cyan "module","Maybe",D.cyan "exposing","(..)"]
843 , D.fillSep [D.cyan "module","Html.Attributes",D.cyan "exposing","(..)"]
844 , D.fillSep [D.cyan "module","Json.Decode",D.cyan "exposing","(..)"]
847 "Notice that the module names all start with capital letters. That is required!"
851 ModuleExposing exposing row col ->
852 toExposingReport source exposing row col
854 PortModuleProblem row col ->
856 region = toRegion row col
858 Report.Report "UNFINISHED PORT MODULE DECLARATION" region [] $
859 Code.toSnippet source region Nothing
862 "I am parsing an `port module` declaration, but I got stuck here:"
866 "Here are some examples of valid `port module` declarations:"
867 , D.indent 4 $ D.vcat $
868 [ D.fillSep [D.cyan "port",D.cyan "module","WebSockets",D.cyan "exposing","(send, listen, keepAlive)"]
869 , D.fillSep [D.cyan "port",D.cyan "module","Maps",D.cyan "exposing","(Location, goto)"]
871 , D.link "Note" "Read" "ports" "for more help."
875 PortModuleName row col ->
877 region = toRegion row col
879 Report.Report "EXPECTING MODULE NAME" region [] $
880 Code.toSnippet source region Nothing
883 "I was parsing an `module` declaration until I got stuck here:"
887 "I was expecting to see the module name next, like in these examples:"
888 , D.indent 4 $ D.vcat $
889 [ D.fillSep [D.cyan "port",D.cyan "module","WebSockets",D.cyan "exposing","(send, listen, keepAlive)"]
890 , D.fillSep [D.cyan "port",D.cyan "module","Maps",D.cyan "exposing","(Location, goto)"]
893 "Notice that the module names start with capital letters. That is required!"
897 PortModuleExposing exposing row col ->
898 toExposingReport source exposing row col
902 region = toRegion row col
904 Report.Report "BAD MODULE DECLARATION" region [] $
905 Code.toSnippet source region Nothing
908 "I cannot parse this module declaration:"
911 "This type of module is reserved for the @elm organization. It is used to\
912 \ define certain effects, avoiding building them into the compiler."
917 region = toRegion row col
919 toBadFirstLineReport keyword =
920 Report.Report "TOO MUCH INDENTATION" region [] $
921 Code.toSnippet source region Nothing
924 "This `" ++ keyword ++ "` should not have any spaces before it:"
927 "Delete the spaces before `" ++ keyword ++ "` until there are none left!"
931 case Code.whatIsNext source row col of
932 Code.Keyword "module" -> toBadFirstLineReport "module"
933 Code.Keyword "import" -> toBadFirstLineReport "import"
934 Code.Keyword "type" -> toBadFirstLineReport "type"
935 Code.Keyword "port" -> toBadFirstLineReport "port"
937 Report.Report "SYNTAX PROBLEM" region [] $
938 Code.toSnippet source region Nothing
945 "I am not sure what is going on, but I recommend starting an Elm\
946 \ file with the following lines:"
948 [ D.fillSep [D.cyan "import","Html"]
950 , D.fillSep [D.green "main","="]
951 , D.indent 2 $ D.fillSep [D.cyan "Html" <> ".text",D.dullyellow "\"Hello!\""]
954 "You should be able to copy those lines directly into your file. Check out the\
955 \ examples at <https://elm-lang.org/examples> for more help getting started!"
957 "This can also happen when something is indented too much!"
961 ImportStart row col ->
962 toImportReport source row col
964 ImportName row col ->
966 region = toRegion row col
968 Report.Report "EXPECTING IMPORT NAME" region [] $
969 Code.toSnippet source region Nothing
972 "I was parsing an `import` until I got stuck here:"
976 "I was expecting to see a module name next, like in these examples:"
977 , D.indent 4 $ D.vcat $
978 [ D.fillSep [D.cyan "import","Dict"]
979 , D.fillSep [D.cyan "import","Maybe"]
980 , D.fillSep [D.cyan "import","Html.Attributes"]
981 , D.fillSep [D.cyan "import","Json.Decode"]
984 "Notice that the module names all start with capital letters. That is required!"
989 toImportReport source row col
991 ImportAlias row col ->
993 region = toRegion row col
995 Report.Report "EXPECTING IMPORT ALIAS" region [] $
996 Code.toSnippet source region Nothing
999 "I was parsing an `import` until I got stuck here:"
1003 "I was expecting to see an alias next, like in these examples:"
1004 , D.indent 4 $ D.vcat $
1005 [ D.fillSep [D.cyan "import","Html.Attributes",D.cyan "as","Attr"]
1006 , D.fillSep [D.cyan "import","WebGL.Texture",D.cyan "as","Texture"]
1007 , D.fillSep [D.cyan "import","Json.Decode",D.cyan "as","D"]
1010 "Notice that the alias always starts with a capital letter. That is required!"
1014 ImportExposing row col ->
1015 toImportReport source row col
1017 ImportExposingList exposing row col ->
1018 toExposingReport source exposing row col
1020 ImportEnd row col ->
1021 toImportReport source row col
1023 ImportIndentName row col ->
1024 toImportReport source row col
1026 ImportIndentAlias row col ->
1027 toImportReport source row col
1029 ImportIndentExposingList row col ->
1031 region = toRegion row col
1033 Report.Report "UNFINISHED IMPORT" region [] $
1034 Code.toSnippet source region Nothing
1037 "I was parsing an `import` until I got stuck here:"
1041 "I was expecting to see the list of exposed values next. For example, here\
1042 \ are two ways to expose values from the `Html` module:"
1043 , D.indent 4 $ D.vcat $
1044 [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
1045 , D.fillSep [D.cyan "import","Html",D.cyan "exposing","(Html, div, text)"]
1048 "I generally recommend the second style. It is more explicit, making it\
1049 \ much easier to figure out where values are coming from in large projects!"
1055 region = toRegion row col
1057 Report.Report "BAD INFIX" region [] $
1058 Code.toSnippet source region Nothing
1061 "Something went wrong in this infix operator declaration:"
1064 "This feature is used by the @elm organization to define the\
1065 \ languages built-in operators."
1068 Declarations decl _ _ ->
1069 toDeclarationsReport source decl
1076toImportReport :: Code.Source -> Row -> Col -> Report.Report
1077toImportReport source row col =
1079 region = toRegion row col
1081 Report.Report "UNFINISHED IMPORT" region [] $
1082 Code.toSnippet source region Nothing
1085 "I am partway through parsing an import, but I got stuck here:"
1089 "Here are some examples of valid `import` declarations:"
1090 , D.indent 4 $ D.vcat $
1091 [ D.fillSep [D.cyan "import","Html"]
1092 , D.fillSep [D.cyan "import","Html",D.cyan "as","H"]
1093 , D.fillSep [D.cyan "import","Html",D.cyan "as","H",D.cyan "exposing","(..)"]
1094 , D.fillSep [D.cyan "import","Html",D.cyan "exposing","(Html, div, text)"]
1097 "You are probably trying to import a different module, but try to make it look like one of these examples!"
1106toExposingReport :: Code.Source -> Exposing -> Row -> Col -> Report.Report
1107toExposingReport source exposing startRow startCol =
1109 ExposingSpace space row col ->
1110 toSpaceReport source space row col
1112 ExposingStart row col ->
1114 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1115 region = toRegion row col
1117 Report.Report "PROBLEM IN EXPOSING" region [] $
1118 Code.toSnippet source surroundings (Just region)
1121 "I want to parse exposed values, but I am getting stuck here:"
1125 ["Exposed","values","are","always","surrounded","by","parentheses."
1126 ,"So","try","adding","a",D.green "(","here?"
1128 , D.toSimpleNote "Here are some valid examples of `exposing` for reference:"
1129 , D.indent 4 $ D.vcat $
1130 [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
1131 , D.fillSep [D.cyan "import","Html",D.cyan "exposing","(Html, div, text)"]
1134 "If you are getting tripped up, you can just expose everything for now. It should\
1135 \ get easier to make an explicit exposing list as you see more examples in the wild."
1139 ExposingValue row col ->
1140 case Code.whatIsNext source row col of
1141 Code.Keyword keyword ->
1143 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1144 region = toKeywordRegion row col keyword
1146 Report.Report "RESERVED WORD" region [] $
1147 Code.toSnippet source surroundings (Just region)
1150 "I got stuck on this reserved word:"
1153 "It looks like you are trying to expose `" ++ keyword ++ "` but that is a reserved word. Is there a typo?"
1158 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1159 region = toKeywordRegion row col op
1161 Report.Report "UNEXPECTED SYMBOL" region [] $
1162 Code.toSnippet source surroundings (Just region)
1165 "I got stuck on this symbol:"
1169 "If you are trying to expose an operator, add parentheses around it like this:"
1170 , D.indent 4 $ D.dullyellow (D.fromChars op) <> " -> " <> D.green ("(" <> D.fromChars op <> ")")
1176 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1177 region = toRegion row col
1179 Report.Report "PROBLEM IN EXPOSING" region [] $
1180 Code.toSnippet source surroundings (Just region)
1183 "I got stuck while parsing these exposed values:"
1187 "I do not have an exact recommendation, so here are some valid examples\
1188 \ of `exposing` for reference:"
1189 , D.indent 4 $ D.vcat $
1190 [ D.fillSep [D.cyan "import","Html",D.cyan "exposing","(..)"]
1191 , D.fillSep [D.cyan "import","Basics",D.cyan "exposing","(Int, Float, Bool(..), (+), not, sqrt)"]
1194 "These examples show how to expose types, variants, operators, and functions. Everything\
1195 \ should be some permutation of these examples, just with different names."
1199 ExposingOperator row col ->
1201 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1202 region = toRegion row col
1204 Report.Report "PROBLEM IN EXPOSING" region [] $
1205 Code.toSnippet source surroundings (Just region)
1208 "I just saw an open parenthesis, so I was expecting an operator next:"
1211 ["It","is","possible","to","expose","operators,","so","I","was","expecting"
1212 ,"to","see","something","like",D.dullyellow "(+)","or",D.dullyellow "(|=)"
1213 ,"or",D.dullyellow "(||)","after","I","saw","that","open","parenthesis."
1217 ExposingOperatorReserved op row col ->
1219 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1220 region = toRegion row col
1222 Report.Report "RESERVED SYMBOL" region [] $
1223 Code.toSnippet source surroundings (Just region)
1226 "I cannot expose this as an operator:"
1229 BadDot -> D.reflow "Try getting rid of this entry? Maybe I can give you a better hint after that?"
1230 BadPipe -> D.fillSep ["Maybe","you","want",D.dullyellow "(||)","instead?"]
1231 BadArrow -> D.reflow "Try getting rid of this entry? Maybe I can give you a better hint after that?"
1232 BadEquals -> D.fillSep ["Maybe","you","want",D.dullyellow "(==)","instead?"]
1233 BadHasType -> D.fillSep ["Maybe","you","want",D.dullyellow "(::)","instead?"]
1236 ExposingOperatorRightParen row col ->
1238 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1239 region = toRegion row col
1241 Report.Report "PROBLEM IN EXPOSING" region [] $
1242 Code.toSnippet source surroundings (Just region)
1245 "It looks like you are exposing an operator, but I got stuck here:"
1248 ["I","was","expecting","to","see","the","closing","parenthesis","immediately"
1249 ,"after","the","operator.","Try","adding","a",D.green ")","right","here?"
1253 ExposingEnd row col ->
1255 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1256 region = toRegion row col
1258 Report.Report "UNFINISHED EXPOSING" region [] $
1259 Code.toSnippet source surroundings (Just region)
1262 "I was partway through parsing exposed values, but I got stuck here:"
1265 "Maybe there is a comma missing before this?"
1268 ExposingTypePrivacy row col ->
1270 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1271 region = toRegion row col
1273 Report.Report "PROBLEM EXPOSING CUSTOM TYPE VARIANTS" region [] $
1274 Code.toSnippet source surroundings (Just region)
1277 "It looks like you are trying to expose the variants of a custom type:"
1281 ["You","need","to","write","something","like"
1282 ,D.dullyellow "Status(..)","or",D.dullyellow "Entity(..)"
1283 ,"though.","It","is","all","or","nothing,","otherwise","`case`"
1284 ,"expressions","could","miss","a","variant","and","crash!"
1287 "It is often best to keep the variants hidden! If someone pattern matches on\
1288 \ the variants, it is a MAJOR change if any new variants are added. Suddenly\
1289 \ their `case` expressions do not cover all variants! So if you do not need\
1290 \ people to pattern match, keep the variants hidden and expose functions to\
1291 \ construct values of this type. This way you can add new variants as a MINOR change!"
1295 ExposingIndentEnd row col ->
1297 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1298 region = toRegion row col
1300 Report.Report "UNFINISHED EXPOSING" region [] $
1301 Code.toSnippet source surroundings (Just region)
1304 "I was partway through parsing exposed values, but I got stuck here:"
1308 ["I","was","expecting","a","closing","parenthesis."
1309 ,"Try","adding","a",D.green ")","right","here?"
1312 "I can get confused when there is not enough indentation, so if you already\
1313 \ have a closing parenthesis, it probably just needs some spaces in front of it."
1317 ExposingIndentValue row col ->
1319 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1320 region = toRegion row col
1322 Report.Report "UNFINISHED EXPOSING" region [] $
1323 Code.toSnippet source surroundings (Just region)
1326 "I was partway through parsing exposed values, but I got stuck here:"
1329 "I was expecting another value to expose."
1337toSpaceReport :: Code.Source -> Space -> Row -> Col -> Report.Report
1338toSpaceReport source space row col =
1342 region = toRegion row col
1344 Report.Report "NO TABS" region [] $
1345 Code.toSnippet source region Nothing
1348 "I ran into a tab, but tabs are not allowed in Elm files."
1351 "Replace the tab with spaces."
1354 EndlessMultiComment ->
1356 region = toWiderRegion row col 2
1358 Report.Report "ENDLESS COMMENT" region [] $
1359 Code.toSnippet source region Nothing
1362 "I cannot find the end of this multi-line comment:"
1365 [ D.reflow "Add a -} somewhere after this to end the comment."
1367 "Multi-line comments can be nested in Elm, so {- {- -} -} is a comment\
1368 \ that happens to contain another comment. Like parentheses and curly braces,\
1369 \ the start and end markers must always be balanced. Maybe that is the problem?"
1378toRegion :: Row -> Col -> A.Region
1381 pos = A.Position row col
1386toWiderRegion :: Row -> Col -> Word16 -> A.Region
1387toWiderRegion row col extra =
1389 (A.Position row col)
1390 (A.Position row (col + extra))
1393toKeywordRegion :: Row -> Col -> [Char.Char] -> A.Region
1394toKeywordRegion row col keyword =
1396 (A.Position row col)
1397 (A.Position row (col + fromIntegral (length keyword)))
1400toDeclarationsReport :: Code.Source -> Decl -> Report.Report
1401toDeclarationsReport source decl =
1403 DeclStart row col ->
1404 case Code.whatIsNext source row col of
1405 Code.Close term bracket ->
1407 region = toRegion row col
1409 Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
1410 Code.toSnippet source region Nothing
1413 "I was not expecting to see a " ++ term ++ " here:"
1415 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
1418 Code.Keyword keyword ->
1420 region = toKeywordRegion row col keyword
1422 Report.Report "RESERVED WORD" region [] $
1423 Code.toSnippet source region Nothing
1426 "I was not expecting to run into the `" ++ keyword ++ "` keyword here:"
1431 "It is reserved for declaring imports at the top of your module. If you want\
1432 \ another import, try moving it up top with the other imports. If you want to\
1433 \ define a value or function, try changing the name to something else!"
1438 "It is reserved for writing `case` expressions. Try using a different name?"
1440 "If you are trying to write a `case` expression, it needs to be part of a\
1441 \ definition. So you could write something like this instead:"
1443 [ D.indent 0 $ D.fillSep [D.green "getWidth","maybeWidth","="]
1444 , D.indent 2 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
1445 , D.indent 4 $ D.fillSep [D.blue "Just","width","->"]
1446 , D.indent 6 $ D.fillSep ["width","+",D.dullyellow "200"]
1448 , D.indent 4 $ D.fillSep [D.blue "Nothing","->"]
1449 , D.indent 6 $ D.fillSep [D.dullyellow "400"]
1452 "This defines a `getWidth` function that we can use elsewhere in our program."
1458 "It is reserved for writing `if` expressions. Try using a different name?"
1460 "If you are trying to write an `if` expression, it needs to be part of a\
1461 \ definition. So you could write something like this instead:"
1463 [ D.indent 0 $ D.fillSep [D.green "reviewPowerLevel","powerLevel","="]
1464 , D.indent 2 $ D.fillSep $
1465 [D.cyan "if","powerLevel",">",D.dullyellow "9000"
1466 ,D.cyan "then",D.dullyellow "\"OVER 9000!!!\""
1467 ,D.cyan "else",D.dullyellow "\"not bad\""
1471 "This defines a `reviewPowerLevel` function that we can use elsewhere in our program."
1476 "It is a reserved word. Try changing the name to something else?"
1481 region = toRegion row col
1483 Report.Report "SYNTAX PROBLEM" region [] $
1484 Code.toSnippet source region Nothing
1487 "I was expecting to see a declaration, but I am getting stuck here:"
1490 [ case Code.whatIsNext source row col of
1491 Code.Other (Just char) | Char.isUpper char ->
1493 "All declarations start with lower-case letters in Elm, so maybe this letter can\
1494 \ be changed to lower-case?"
1498 "Declarations normally start with a lower-case name or the `type` keyword."
1500 "Here are a couple valid declarations for reference:"
1502 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
1503 , D.fillSep [D.green "add","x","y","="]
1504 , D.fillSep [" ","x","+","y"]
1506 , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1508 "Notice that these declarations start with lower-case letters. Capitalization\
1509 \ makes a difference in Elm!"
1513 DeclSpace space row col ->
1514 toSpaceReport source space row col
1516 Port port_ row col ->
1517 toPortReport source port_ row col
1519 DeclType declType row col ->
1520 toDeclTypeReport source declType row col
1522 DeclDef name declDef row col ->
1523 toDeclDefReport source name declDef row col
1525 DeclFreshLineAfterDocComment row col ->
1527 region = toRegion row col
1529 Report.Report "EXPECTING DECLARATION" region [] $
1530 Code.toSnippet source region Nothing
1533 "I just saw a doc comment, but then I got stuck here:"
1536 "I was expecting to see the corresponding declaration next, starting on a fresh\
1537 \ line with no indentation."
1545toPortReport :: Code.Source -> Port -> Row -> Col -> Report.Report
1546toPortReport source port_ startRow startCol =
1548 PortSpace space row col ->
1549 toSpaceReport source space row col
1552 case Code.whatIsNext source row col of
1553 Code.Keyword keyword ->
1555 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1556 region = toKeywordRegion row col keyword
1558 Report.Report "RESERVED WORD" region [] $
1559 Code.toSnippet source surroundings (Just region)
1562 "I cannot handle ports with names like this:"
1565 "You are trying to make a port named `" ++ keyword
1566 ++ "` but that is a reserved word. Try using some other name?"
1571 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1572 region = toRegion row col
1574 Report.Report "PORT PROBLEM" region [] $
1575 Code.toSnippet source surroundings (Just region)
1578 "I just saw the start of a `port` declaration, but then I got stuck here:"
1582 ["I","was","expecting","to","see","a","name","like"
1583 ,D.dullyellow "send","or",D.dullyellow "receive","next."
1584 ,"Something","that","starts","with","a","lower-case","letter."
1590 PortColon row col ->
1592 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1593 region = toRegion row col
1595 Report.Report "PORT PROBLEM" region [] $
1596 Code.toSnippet source surroundings (Just region)
1599 "I just saw the start of a `port` declaration, but then I got stuck here:"
1603 "I was expecting to see a colon next. And then a type that tells me\
1604 \ what type of values are going to flow through."
1609 PortType tipe row col ->
1610 toTypeReport source TC_Port tipe row col
1612 PortIndentName row col ->
1614 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1615 region = toRegion row col
1617 Report.Report "UNFINISHED PORT" region [] $
1618 Code.toSnippet source surroundings (Just region)
1621 "I just saw the start of a `port` declaration, but then I got stuck here:"
1625 ["I","was","expecting","to","see","a","name","like"
1626 ,D.dullyellow "send","or",D.dullyellow "receive","next."
1627 ,"Something","that","starts","with","a","lower-case","letter."
1633 PortIndentColon row col ->
1635 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1636 region = toRegion row col
1638 Report.Report "UNFINISHED PORT" region [] $
1639 Code.toSnippet source surroundings (Just region)
1642 "I just saw the start of a `port` declaration, but then I got stuck here:"
1646 "I was expecting to see a colon next. And then a type that tells me\
1647 \ what type of values are going to flow through."
1652 PortIndentType row col ->
1654 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1655 region = toRegion row col
1657 Report.Report "UNFINISHED PORT" region [] $
1658 Code.toSnippet source surroundings (Just region)
1661 "I just saw the start of a `port` declaration, but then I got stuck here:"
1665 "I was expecting to see a type next. Here are examples of outgoing and\
1666 \ incoming ports for reference:"
1668 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1669 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1672 "The first line defines a `send` port so you can send strings out to JavaScript.\
1673 \ Maybe you send them on a WebSocket or put them into IndexedDB. The second line\
1674 \ defines a `receive` port so you can receive strings from JavaScript. Maybe you\
1675 \ get receive messages when new WebSocket messages come in or when an entry in\
1676 \ IndexedDB changes for some external reason."
1685 "Here are some example `port` declarations for reference:"
1687 [ D.fillSep [D.cyan "port","send",":","String -> Cmd msg"]
1688 , D.fillSep [D.cyan "port","receive",":","(String -> msg) -> Sub msg"]
1691 "The first line defines a `send` port so you can send strings out to JavaScript.\
1692 \ Maybe you send them on a WebSocket or put them into IndexedDB. The second line\
1693 \ defines a `receive` port so you can receive strings from JavaScript. Maybe you\
1694 \ get receive messages when new WebSocket messages come in or when the IndexedDB\
1695 \ is changed for some external reason."
1703toDeclTypeReport :: Code.Source -> DeclType -> Row -> Col -> Report.Report
1704toDeclTypeReport source declType startRow startCol =
1706 DT_Space space row col ->
1707 toSpaceReport source space row col
1711 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1712 region = toRegion row col
1714 Report.Report "EXPECTING TYPE NAME" region [] $
1715 Code.toSnippet source surroundings (Just region)
1718 "I think I am parsing a type declaration, but I got stuck here:"
1722 ["I","was","expecting","a","name","like",D.dullyellow "Status","or",D.dullyellow "Style"
1723 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1729 DT_Alias typeAlias row col ->
1730 toTypeAliasReport source typeAlias row col
1732 DT_Union customType row col ->
1733 toCustomTypeReport source customType row col
1735 DT_IndentName row col ->
1737 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1738 region = toRegion row col
1740 Report.Report "EXPECTING TYPE NAME" region [] $
1741 Code.toSnippet source surroundings (Just region)
1744 "I think I am parsing a type declaration, but I got stuck here:"
1748 ["I","was","expecting","a","name","like",D.dullyellow "Status","or",D.dullyellow "Style"
1749 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1756toTypeAliasReport :: Code.Source -> TypeAlias -> Row -> Col -> Report.Report
1757toTypeAliasReport source typeAlias startRow startCol =
1759 AliasSpace space row col ->
1760 toSpaceReport source space row col
1762 AliasName row col ->
1764 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1765 region = toRegion row col
1767 Report.Report "EXPECTING TYPE ALIAS NAME" region [] $
1768 Code.toSnippet source surroundings (Just region)
1771 "I am partway through parsing a type alias, but I got stuck here:"
1775 ["I","was","expecting","a","name","like",D.dullyellow "Person","or",D.dullyellow "Point"
1776 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1782 AliasEquals row col ->
1783 case Code.whatIsNext source row col of
1784 Code.Keyword keyword ->
1786 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1787 region = toKeywordRegion row col keyword
1789 Report.Report "RESERVED WORD" region [] $
1790 Code.toSnippet source surroundings (Just region)
1793 "I ran into a reserved word unexpectedly while parsing this type alias:"
1797 "It looks like you are trying use `" ++ keyword
1798 ++ "` as a type variable, but it is a reserved word. Try using a different name?"
1805 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1806 region = toRegion row col
1808 Report.Report "PROBLEM IN TYPE ALIAS" region [] $
1809 Code.toSnippet source surroundings (Just region)
1812 "I am partway through parsing a type alias, but I got stuck here:"
1816 "I was expecting to see a type variable or an equals sign next."
1821 AliasBody tipe row col ->
1822 toTypeReport source TC_TypeAlias tipe row col
1824 AliasIndentEquals row col ->
1826 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1827 region = toRegion row col
1829 Report.Report "UNFINISHED TYPE ALIAS" region [] $
1830 Code.toSnippet source surroundings (Just region)
1833 "I am partway through parsing a type alias, but I got stuck here:"
1837 "I was expecting to see a type variable or an equals sign next."
1842 AliasIndentBody row col ->
1844 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1845 region = toRegion row col
1847 Report.Report "UNFINISHED TYPE ALIAS" region [] $
1848 Code.toSnippet source surroundings (Just region)
1851 "I am partway through parsing a type alias, but I got stuck here:"
1855 ["I","was","expecting","to","see","a","type","next.","Something","as","simple"
1856 ,"as",D.dullyellow "Int","or",D.dullyellow "Float","would","work!"
1863typeAliasNote :: D.Doc
1867 "Here is an example of a valid `type alias` for reference:"
1869 [ D.indent 0 $ D.fillSep [D.cyan "type",D.cyan "alias",D.green "Person","="]
1870 , D.indent 2 $ D.vcat $
1878 "This would let us use `Person` as a shorthand for that record type. Using this\
1879 \ shorthand makes type annotations much easier to read, and makes changing code\
1880 \ easier if you decide later that there is more to a person than age and height!"
1884toCustomTypeReport :: Code.Source -> CustomType -> Row -> Col -> Report.Report
1885toCustomTypeReport source customType startRow startCol =
1887 CT_Space space row col ->
1888 toSpaceReport source space row col
1892 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1893 region = toRegion row col
1895 Report.Report "EXPECTING TYPE NAME" region [] $
1896 Code.toSnippet source surroundings (Just region)
1899 "I think I am parsing a type declaration, but I got stuck here:"
1903 ["I","was","expecting","a","name","like",D.dullyellow "Status","or",D.dullyellow "Style"
1904 ,"next.","Just","make","sure","it","is","a","name","that","starts","with","a","capital","letter!"
1910 CT_Equals row col ->
1911 case Code.whatIsNext source row col of
1912 Code.Keyword keyword ->
1914 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1915 region = toKeywordRegion row col keyword
1917 Report.Report "RESERVED WORD" region [] $
1918 Code.toSnippet source surroundings (Just region)
1921 "I ran into a reserved word unexpectedly while parsing this custom type:"
1925 "It looks like you are trying use `" ++ keyword
1926 ++ "` as a type variable, but it is a reserved word. Try using a different name?"
1933 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1934 region = toRegion row col
1936 Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1937 Code.toSnippet source surroundings (Just region)
1940 "I am partway through parsing a custom type, but I got stuck here:"
1944 "I was expecting to see a type variable or an equals sign next."
1951 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1952 region = toRegion row col
1954 Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1955 Code.toSnippet source surroundings (Just region)
1958 "I am partway through parsing a custom type, but I got stuck here:"
1962 "I was expecting to see a vertical bar like | next."
1967 CT_Variant row col ->
1969 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1970 region = toRegion row col
1972 Report.Report "PROBLEM IN CUSTOM TYPE" region [] $
1973 Code.toSnippet source surroundings (Just region)
1976 "I am partway through parsing a custom type, but I got stuck here:"
1980 ["I","was","expecting","to","see","a","variant","name","next."
1981 ,"Something","like",D.dullyellow "Success","or",D.dullyellow "Sandwich" <> "."
1982 ,"Any","name","that","starts","with","a","capital","letter","really!"
1988 CT_VariantArg tipe row col ->
1989 toTypeReport source TC_CustomType tipe row col
1991 CT_IndentEquals row col ->
1993 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1994 region = toRegion row col
1996 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
1997 Code.toSnippet source surroundings (Just region)
2000 "I am partway through parsing a custom type, but I got stuck here:"
2004 "I was expecting to see a type variable or an equals sign next."
2009 CT_IndentBar row col ->
2011 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2012 region = toRegion row col
2014 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
2015 Code.toSnippet source surroundings (Just region)
2018 "I am partway through parsing a custom type, but I got stuck here:"
2022 "I was expecting to see a vertical bar like | next."
2027 CT_IndentAfterBar row col ->
2029 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2030 region = toRegion row col
2032 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
2033 Code.toSnippet source surroundings (Just region)
2036 "I am partway through parsing a custom type, but I got stuck here:"
2040 "I just saw a vertical bar, so I was expecting to see another variant defined next."
2045 CT_IndentAfterEquals row col ->
2047 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2048 region = toRegion row col
2050 Report.Report "UNFINISHED CUSTOM TYPE" region [] $
2051 Code.toSnippet source surroundings (Just region)
2054 "I am partway through parsing a custom type, but I got stuck here:"
2058 "I just saw an equals sign, so I was expecting to see the first variant defined next."
2064customTypeNote :: D.Doc
2068 "Here is an example of a valid `type` declaration for reference:"
2070 [ D.indent 0 $ D.fillSep [D.cyan "type",D.green "Status"]
2071 , D.indent 2 $ D.fillSep ["=","Failure"]
2072 , D.indent 2 $ D.fillSep ["|","Waiting"]
2073 , D.indent 2 $ D.fillSep ["|","Success","String"]
2076 "This defines a new `Status` type with three variants. This could be useful if\
2077 \ we are waiting for an HTTP request. Maybe we start with `Waiting` and then\
2078 \ switch to `Failure` or `Success \"message from server\"` depending on how\
2079 \ things go. Notice that the Success variant has some associated data, allowing\
2080 \ us to store a String if the request goes well!"
2088toDeclDefReport :: Code.Source -> Name.Name -> DeclDef -> Row -> Col -> Report.Report
2089toDeclDefReport source name declDef startRow startCol =
2091 DeclDefSpace space row col ->
2092 toSpaceReport source space row col
2094 DeclDefEquals row col ->
2095 case Code.whatIsNext source row col of
2096 Code.Keyword keyword ->
2098 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2099 region = toKeywordRegion row col keyword
2101 Report.Report "RESERVED WORD" region [] $
2102 Code.toSnippet source surroundings (Just region)
2106 ,"`" <> D.cyan (D.fromChars keyword) <> "`"
2107 ,"is","reserved","in","Elm,","so","it","cannot"
2108 ,"be","used","as","an","argument","here:"
2113 "Try renaming it to something else."
2117 ["This","keyword","is","reserved","for","pattern","matches","like"
2118 ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
2119 ,"the","values","it","contains."
2124 "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
2128 Code.Operator "->" ->
2130 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2131 region = toWiderRegion row col 2
2133 Report.Report "MISSING COLON?" region [] $
2134 Code.toSnippet source surroundings (Just region)
2137 "I was not expecting to see an arrow here:"
2141 ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
2142 ,"a","type","annotation.","It","could","be","something","else","though,","so"
2143 ,"here","is","a","valid","definition","for","reference:"
2146 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2147 , D.fillSep [D.green "add","x","y","="]
2148 , D.fillSep [" ","x","+","y"]
2151 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2157 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2158 region = toKeywordRegion row col op
2160 Report.Report "UNEXPECTED SYMBOL" region [] $
2161 Code.toSnippet source surroundings (Just region)
2164 "I was not expecting to see this symbol here:"
2168 "I am not sure what is going wrong exactly, so here is a valid\
2169 \ definition (with an optional type annotation) for reference:"
2171 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2172 , D.fillSep [D.green "add","x","y","="]
2173 , D.fillSep [" ","x","+","y"]
2176 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
2182 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2183 region = toRegion row col
2185 Report.Report "PROBLEM IN DEFINITION" region [] $
2186 Code.toSnippet source surroundings (Just region)
2189 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
2193 "I am not sure what is going wrong exactly, so here is a valid\
2194 \ definition (with an optional type annotation) for reference:"
2196 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2197 , D.fillSep [D.green "add","x","y","="]
2198 , D.fillSep [" ","x","+","y"]
2201 "Try to use that format!"
2205 DeclDefType tipe row col ->
2206 toTypeReport source (TC_Annotation name) tipe row col
2208 DeclDefArg pattern row col ->
2209 toPatternReport source PArg pattern row col
2211 DeclDefBody expr row col ->
2212 toExprReport source (InDef name startRow startCol) expr row col
2214 DeclDefNameRepeat row col ->
2216 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2217 region = toRegion row col
2219 Report.Report "EXPECTING DEFINITION" region [] $
2220 Code.toSnippet source surroundings (Just region)
2223 "I just saw the type annotation for `" ++ Name.toChars name
2224 ++ "` so I was expecting to see its definition here:"
2228 "Type annotations always appear directly above the relevant\
2229 \ definition, without anything else in between. (Not even doc comments!)"
2234 DeclDefNameMatch defName row col ->
2236 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2237 region = toRegion row col
2239 Report.Report "NAME MISMATCH" region [] $
2240 Code.toSnippet source surroundings (Just region)
2243 "I just saw a type annotation for `" ++ Name.toChars name ++ "`, but it is followed by a definition for `" ++ Name.toChars defName ++ "`:"
2247 "These names do not match! Is there a typo?"
2248 , D.indent 4 $ D.fillSep $
2249 [D.dullyellow (D.fromName defName),"->",D.green (D.fromName name)]
2253 DeclDefIndentType row col ->
2255 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2256 region = toRegion row col
2258 Report.Report "UNFINISHED DEFINITION" region [] $
2259 Code.toSnippet source surroundings (Just region)
2262 "I got stuck while parsing the `" ++ Name.toChars name ++ "` type annotation:"
2266 "I just saw a colon, so I am expecting to see a type next."
2271 DeclDefIndentEquals row col ->
2273 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2274 region = toRegion row col
2276 Report.Report "UNFINISHED DEFINITION" region [] $
2277 Code.toSnippet source surroundings (Just region)
2280 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
2284 "I was expecting to see an argument or an equals sign next."
2289 DeclDefIndentBody row col ->
2291 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2292 region = toRegion row col
2294 Report.Report "UNFINISHED DEFINITION" region [] $
2295 Code.toSnippet source surroundings (Just region)
2298 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
2302 "I was expecting to see an expression next. What is it equal to?"
2312 "Here is a valid definition (with a type annotation) for reference:"
2314 [ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
2315 , D.fillSep [D.green "add","x","y","="]
2316 , D.fillSep [" ","x","+","y"]
2319 "The top line (called a \"type annotation\") is optional. You can leave it off\
2320 \ if you want. As you get more comfortable with Elm and as your project grows,\
2321 \ it becomes more and more valuable to add them though! They work great as\
2322 \ compiler-verified documentation, and they often improve error messages!"
2331 = InNode Node Row Col Context
2332 | InDef Name.Name Row Col
2333 | InDestruct Row Col
2349getDefName :: Context -> Maybe Name.Name
2352 InDestruct _ _ -> Nothing
2353 InDef name _ _ -> Just name
2354 InNode _ _ _ c -> getDefName c
2357isWithin :: Node -> Context -> Bool
2358isWithin desiredNode context =
2360 InDestruct _ _ -> False
2361 InDef _ _ _ -> False
2362 InNode actualNode _ _ _ -> desiredNode == actualNode
2369toExprReport :: Code.Source -> Context -> Expr -> Row -> Col -> Report.Report
2370toExprReport source context expr startRow startCol =
2373 toLetReport source context let_ row col
2375 Case case_ row col ->
2376 toCaseReport source context case_ row col
2379 toIfReport source context if_ row col
2381 List list row col ->
2382 toListReport source context list row col
2384 Record record row col ->
2385 toRecordReport source context record row col
2387 Tuple tuple row col ->
2388 toTupleReport source context tuple row col
2390 Func func row col ->
2391 toFuncReport source context func row col
2394 let region = toRegion row col in
2395 Report.Report "EXPECTING RECORD ACCESSOR" region [] $
2396 Code.toSnippet source region Nothing
2399 "I was expecting to see a record accessor here:"
2402 ["Something","like",D.dullyellow".name","or",D.dullyellow".price"
2403 ,"that","accesses","a","value","from","a","record."
2408 let region = toRegion row col in
2409 Report.Report "EXPECTING RECORD ACCESSOR" region [] $
2410 Code.toSnippet source region Nothing
2413 "I am trying to parse a record accessor here:"
2418 ["Something","like",D.dullyellow".name","or",D.dullyellow".price"
2419 ,"that","accesses","a","value","from","a","record."
2423 "Record field names must start with a lower case letter!"
2427 OperatorRight op row col ->
2429 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2430 region = toRegion row col
2431 isMath = elem op ["-","+","*","/","^"]
2433 Report.Report "MISSING EXPRESSION" region [] $
2434 Code.toSnippet source surroundings (Just region)
2437 "I just saw a " ++ Name.toChars op ++ " "
2438 ++ (if isMath then "sign" else "operator")
2439 ++ ", so I am getting stuck here:"
2443 ["I","was","expecting","to","see","an","expression","next."
2444 ,"Something","like",D.dullyellow "42","or",D.dullyellow "1000"
2445 ,"that","makes","sense","with","a",D.fromName op,"sign."
2447 else if op == "&&" || op == "||" then
2449 ["I","was","expecting","to","see","an","expression","next."
2450 ,"Something","like",D.dullyellow "True","or",D.dullyellow "False"
2451 ,"that","makes","sense","with","boolean","logic."
2453 else if op == "|>" then
2455 "I was expecting to see a function next."
2456 else if op == "<|" then
2458 "I was expecting to see an argument next."
2461 "I was expecting to see an expression next."
2464 OperatorReserved operator row col ->
2465 toOperatorReport source context operator row col
2469 (contextRow, contextCol, aThing) =
2471 InDestruct r c -> (r, c, "a definition")
2472 InDef name r c -> (r, c, "the `" ++ Name.toChars name ++ "` definition")
2473 InNode NRecord r c _ -> (r, c, "a record")
2474 InNode NParens r c _ -> (r, c, "some parentheses")
2475 InNode NList r c _ -> (r, c, "a list")
2476 InNode NFunc r c _ -> (r, c, "an anonymous function")
2477 InNode NCond r c _ -> (r, c, "an `if` expression")
2478 InNode NThen r c _ -> (r, c, "an `if` expression")
2479 InNode NElse r c _ -> (r, c, "an `if` expression")
2480 InNode NCase r c _ -> (r, c, "a `case` expression")
2481 InNode NBranch r c _ -> (r, c, "a `case` expression")
2483 surroundings = A.Region (A.Position contextRow contextCol) (A.Position row col)
2484 region = toRegion row col
2486 Report.Report "MISSING EXPRESSION" region [] $
2487 Code.toSnippet source surroundings (Just region)
2490 "I am partway through parsing " ++ aThing ++ ", but I got stuck here:"
2494 ["I","was","expecting","to","see","an","expression","like"
2495 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2496 ,"Once","there","is","something","there,","I","can","probably"
2497 ,"give","a","more","specific","hint!"
2500 "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
2501 \ Or if I run into operators in unexpected spots. Point is, there are a\
2502 \ couple ways I can get confused and give sort of weird advice!"
2506 Char char row col ->
2507 toCharReport source char row col
2509 String string row col ->
2510 toStringReport source string row col
2512 Number number row col ->
2513 toNumberReport source number row col
2515 Space space row col ->
2516 toSpaceReport source space row col
2518 EndlessShader row col ->
2520 region = toWiderRegion row col 6
2522 Report.Report "ENDLESS SHADER" region [] $
2523 Code.toSnippet source region Nothing
2525 D.reflow "I cannot find the end of this shader:"
2527 D.reflow "Add a |] somewhere after this to end the shader."
2530 ShaderProblem problem row col ->
2532 region = toRegion row col
2534 Report.Report "SHADER PROBLEM" region [] $
2535 Code.toSnippet source region Nothing
2538 "I ran into a problem while parsing this GLSL block."
2542 "I use a 3rd party GLSL parser for now, and I did my best to extract their error message:"
2543 , D.indent 4 $ D.vcat $
2544 map D.fromChars (filter (/="") (lines problem))
2548 IndentOperatorRight op row col ->
2550 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2551 region = toRegion row col
2553 Report.Report "MISSING EXPRESSION" region [] $
2554 Code.toSnippet source surroundings (Just region)
2557 "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
2562 ["You","can","just","put","anything","for","now,","like"
2563 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
2564 ,"Once","there","is","something","there,","I","can","probably"
2565 ,"give","a","more","specific","hint!"
2569 "I may be getting confused by your indentation? The easiest way to make sure\
2570 \ this is not an indentation problem is to put the expression on the right of\
2571 \ the " ++ Name.toChars op ++ " operator on the same line."
2580toCharReport :: Code.Source -> Char -> Row -> Col -> Report.Report
2581toCharReport source char row col =
2585 region = toRegion row col
2587 Report.Report "MISSING SINGLE QUOTE" region [] $
2588 Code.toSnippet source region Nothing
2591 "I thought I was parsing a character, but I got to the end of\
2592 \ the line without seeing the closing single quote:"
2595 "Add a closing single quote here!"
2598 CharEscape escape ->
2599 toEscapeReport source escape row col
2601 CharNotString width ->
2603 region = toWiderRegion row col width
2605 Report.Report "NEEDS DOUBLE QUOTES" region [] $
2606 Code.toSnippet source region Nothing
2608 "The following string uses single quotes:"
2611 [ "Please switch to double quotes instead:"
2613 D.dullyellow "'this'" <> " => " <> D.green "\"this\""
2615 "Elm uses double quotes for strings like \"hello\", whereas it uses single\
2616 \ quotes for individual characters like 'a' and 'ø'. This distinction helps with\
2617 \ code like (String.any (\\c -> c == 'X') \"90210\") where you are inspecting\
2618 \ individual characters."
2627toStringReport :: Code.Source -> String -> Row -> Col -> Report.Report
2628toStringReport source string row col =
2630 StringEndless_Single ->
2632 region = toRegion row col
2634 Report.Report "ENDLESS STRING" region [] $
2635 Code.toSnippet source region Nothing
2638 "I got to the end of the line without seeing the closing double quote:"
2642 ["Strings","look","like",D.green "\"this\"","with","double"
2643 ,"quotes","on","each","end.","Is","the","closing","double"
2644 ,"quote","missing","in","your","code?"
2647 "For a string that spans multiple lines, you can use the multi-line string\
2648 \ syntax like this:"
2650 [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2652 , D.dullyellow "# Multi-line Strings"
2654 , D.dullyellow "- start with triple double quotes"
2655 , D.dullyellow "- write whatever you want"
2656 , D.dullyellow "- no need to escape newlines or double quotes"
2657 , D.dullyellow "- end with triple double quotes"
2659 , D.dullyellow "\"\"\""
2664 StringEndless_Multi ->
2666 region = toWiderRegion row col 3
2668 Report.Report "ENDLESS STRING" region [] $
2669 Code.toSnippet source region Nothing
2672 "I cannot find the end of this multi-line string:"
2675 [ D.reflow "Add a \"\"\" somewhere after this to end the string."
2677 "Here is a valid multi-line string for reference:"
2679 [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
2681 , D.dullyellow "# Multi-line Strings"
2683 , D.dullyellow "- start with triple double quotes"
2684 , D.dullyellow "- write whatever you want"
2685 , D.dullyellow "- no need to escape newlines or double quotes"
2686 , D.dullyellow "- end with triple double quotes"
2688 , D.dullyellow "\"\"\""
2693 StringEscape escape ->
2694 toEscapeReport source escape row col
2701toEscapeReport :: Code.Source -> Escape -> Row -> Col -> Report.Report
2702toEscapeReport source escape row col =
2706 region = toWiderRegion row col 2
2708 Report.Report "UNKNOWN ESCAPE" region [] $
2709 Code.toSnippet source region Nothing
2712 "Backslashes always start escaped characters, but I do not recognize this one:"
2716 "Valid escape characters include:"
2717 , D.dullyellow $ D.indent 4 $ D.vcat $
2727 "Do you want one of those instead? Maybe you need \\\\ to escape a backslash?"
2729 "The last style lets encode ANY character by its Unicode code\
2730 \ point. That means \\u{0009} and \\t are the same. You can use\
2731 \ that style for anything not covered by the other six escapes!"
2735 BadUnicodeFormat width ->
2737 region = toWiderRegion row col width
2739 Report.Report "BAD UNICODE ESCAPE" region [] $
2740 Code.toSnippet source region Nothing
2743 "I ran into an invalid Unicode escape:"
2747 "Here are some examples of valid Unicode escapes:"
2748 , D.dullyellow $ D.indent 4 $ D.vcat $
2755 "Notice that the code point is always surrounded by curly braces.\
2756 \ Maybe you are missing the opening or closing curly brace?"
2759 BadUnicodeCode width ->
2761 region = toWiderRegion row col width
2763 Report.Report "BAD UNICODE ESCAPE" region [] $
2764 Code.toSnippet source region Nothing
2767 "This is not a valid code point:"
2770 "The valid code points are between 0 and 10FFFF inclusive."
2773 BadUnicodeLength width numDigits badCode ->
2775 region = toWiderRegion row col width
2777 Report.Report "BAD UNICODE ESCAPE" region [] $
2778 Code.toSnippet source region Nothing $
2779 if numDigits < 4 then
2782 "Every code point needs at least four digits:"
2785 goodCode = replicate (4 - numDigits) '0' ++ map Char.toUpper (showHex badCode "")
2786 suggestion = "\\u{" <> D.fromChars goodCode <> "}"
2788 D.fillSep ["Try",D.green suggestion,"instead?"]
2794 "This code point has too many digits:"
2797 ["Valid","code","points","are","between"
2798 ,D.green "\\u{0000}","and",D.green "\\u{10FFFF}" <> ","
2799 ,"so","try","trimming","any","leading","zeros","until"
2800 ,"you","have","between","four","and","six","digits."
2809toNumberReport :: Code.Source -> Number -> Row -> Col -> Report.Report
2810toNumberReport source number row col =
2812 region = toRegion row col
2816 Report.Report "WEIRD NUMBER" region [] $
2817 Code.toSnippet source region Nothing
2820 "I thought I was reading a number, but I ran into some weird stuff here:"
2824 "I recognize numbers in the following formats:"
2825 , D.indent 4 $ D.vcat [ "42", "3.14", "6.022e23", "0x002B" ]
2827 "So is there a way to write it like one of those?"
2832 Report.Report "WEIRD NUMBER" region [] $
2833 Code.toSnippet source region Nothing
2836 "Numbers cannot end with a dot like this:"
2839 ["Switching","to",D.green (D.fromChars (show int))
2840 ,"or",D.green (D.fromChars (show int ++ ".0"))
2841 ,"will","work","though!"
2846 Report.Report "WEIRD HEXIDECIMAL" region [] $
2847 Code.toSnippet source region Nothing
2850 "I thought I was reading a hexidecimal number until I got here:"
2854 "Valid hexidecimal digits include 0123456789abcdefABCDEF, so I can\
2855 \ only recognize things like this:"
2856 , D.indent 4 $ D.vcat [ "0x2B", "0x002B", "0x00ffb3" ]
2860 NumberNoLeadingZero ->
2861 Report.Report "LEADING ZEROS" region [] $
2862 Code.toSnippet source region Nothing
2865 "I do not accept numbers with leading zeros:"
2869 "Just delete the leading zeros and it should work!"
2871 "Some languages let you to specify octal numbers by adding a leading zero.\
2872 \ So in C, writing 0111 is the same as writing 73. Some people are used to\
2873 \ that, but others probably want it to equal 111. Either path is going to\
2874 \ surprise people from certain backgrounds, so Elm tries to avoid this whole\
2884toOperatorReport :: Code.Source -> Context -> BadOperator -> Row -> Col -> Report.Report
2885toOperatorReport source context operator row col =
2889 region = toRegion row col
2891 Report.Report "UNEXPECTED SYMBOL" region [] $
2892 Code.toSnippet source region Nothing
2894 "I was not expecting this dot:"
2897 "Dots are for record access and decimal points, so\
2898 \ they cannot float around on their own. Maybe\
2899 \ there is some extra whitespace?"
2904 region = toRegion row col
2906 Report.Report "UNEXPECTED SYMBOL" region [] $
2907 Code.toSnippet source region Nothing
2910 "I was not expecting this vertical bar:"
2913 "Vertical bars should only appear in custom type declarations. Maybe you want || instead?"
2918 region = toWiderRegion row col 2
2920 Report.Report "UNEXPECTED ARROW" region [] $
2921 Code.toSnippet source region Nothing $
2922 if isWithin NCase context then
2925 "I am parsing a `case` expression right now, but this arrow is confusing me:"
2928 [ D.reflow "Maybe the `of` keyword is missing on a previous line?"
2933 else if isWithin NBranch context then
2936 "I am parsing a `case` expression right now, but this arrow is confusing me:"
2940 "It makes sense to see arrows around here, so I suspect it is something earlier. Maybe this pattern is indented a bit farther than the previous patterns?"
2941 , noteForCaseIndentError
2948 "I was partway through parsing an expression when I got stuck on this arrow:"
2951 [ "Arrows should only appear in `case` expressions and anonymous functions.\n\
2952 \Maybe it was supposed to be a > sign instead?"
2954 "The syntax for anonymous functions is (\\x -> x + 1) so the arguments all appear\
2955 \ after the backslash and before the arrow. Maybe a backslash is missing earlier?"
2961 region = toRegion row col
2963 Report.Report "UNEXPECTED EQUALS" region [] $
2964 Code.toSnippet source region Nothing
2967 "I was not expecting to see this equals sign:"
2971 D.reflow "Maybe you want == instead? To check if two values are equal?"
2974 if isWithin NRecord context then
2975 "Records look like { x = 3, y = 4 } with the equals sign right\
2976 \ after the field name. So maybe you forgot a comma?"
2978 case getDefName context of
2980 "I may be getting confused by your indentation. I need all definitions to be indented\
2981 \ exactly the same amount, so if this is meant to be a new definition, it may have too\
2982 \ many spaces in front of it."
2985 "I may be getting confused by your indentation. I think I am still parsing the `"
2986 ++ Name.toChars name ++ "` definition. Is this supposed to be part of a definition\
2987 \ after that? If so, the problem may be a bit before the equals sign. I need all\
2988 \ definitions to be indented exactly the same amount, so the problem may be that\
2989 \ this new definition has too many spaces in front of it."
2995 region = toRegion row col
2997 Report.Report "UNEXPECTED SYMBOL" region [] $
2998 Code.toSnippet source region Nothing $
3001 "I was not expecting to run into the \"has type\" symbol here:"
3003 case getDefName context of
3006 ["Maybe","you","want",D.green "::","instead?"
3007 ,"To","put","something","on","the","front","of","a","list?"
3014 ["Maybe","you","want",D.green "::","instead?"
3015 ,"To","put","something","on","the","front","of","a","list?"
3018 "The single colon is reserved for type annotations and record types, but I think\
3019 \ I am parsing the definition of `" ++ Name.toChars name ++ "` right now."
3022 "I may be getting confused by your indentation. Is this supposed to be part of\
3023 \ a type annotation AFTER the `" ++ Name.toChars name ++ "` definition? If so,\
3024 \ the problem may be a bit before the \"has type\" symbol. I need all definitions to\
3025 \ be exactly aligned (with exactly the same indentation) so the problem may be that\
3026 \ this new definition is indented a bit too much."
3035toLetReport :: Code.Source -> Context -> Let -> Row -> Col -> Report.Report
3036toLetReport source context let_ startRow startCol =
3038 LetSpace space row col ->
3039 toSpaceReport source space row col
3043 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3044 region = toRegion row col
3046 Report.Report "LET PROBLEM" region [] $
3047 Code.toSnippet source surroundings (Just region)
3050 "I was partway through parsing a `let` expression, but I got stuck here:"
3054 ["Based","on","the","indentation,","I","was","expecting","to","see","the",D.cyan "in"
3055 ,"keyword","next.","Is","there","a","typo?"
3058 "This can also happen if you are trying to define another value within the `let` but\
3059 \ it is not indented enough. Make sure each definition has exactly the same amount of\
3060 \ spaces before it. They should line up exactly!"
3064 LetDefAlignment _ row col ->
3066 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3067 region = toRegion row col
3069 Report.Report "LET PROBLEM" region [] $
3070 Code.toSnippet source surroundings (Just region)
3073 "I was partway through parsing a `let` expression, but I got stuck here:"
3077 ["Based","on","the","indentation,","I","was","expecting","to","see","the",D.cyan "in"
3078 ,"keyword","next.","Is","there","a","typo?"
3081 "This can also happen if you are trying to define another value within the `let` but\
3082 \ it is not indented enough. Make sure each definition has exactly the same amount of\
3083 \ spaces before it. They should line up exactly!"
3087 LetDefName row col ->
3088 case Code.whatIsNext source row col of
3089 Code.Keyword keyword ->
3091 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3092 region = toKeywordRegion row col keyword
3094 Report.Report "RESERVED WORD" region [] $
3095 Code.toSnippet source surroundings (Just region)
3098 "I was partway through parsing a `let` expression, but I got stuck here:"
3101 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name, but\
3102 \ it is a reserved word! Try using a different name instead."
3106 toUnfinishLetReport source row col startRow startCol $
3108 "I was expecting the name of a definition next."
3110 LetDef name def row col ->
3111 toLetDefReport source name def row col
3113 LetDestruct destruct row col ->
3114 toLetDestructReport source destruct row col
3116 LetBody expr row col ->
3117 toExprReport source context expr row col
3119 LetIndentDef row col ->
3120 toUnfinishLetReport source row col startRow startCol $
3122 "I was expecting a value to be defined here."
3124 LetIndentIn row col ->
3125 toUnfinishLetReport source row col startRow startCol $
3127 ["I","was","expecting","to","see","the",D.cyan "in","keyword","next."
3128 ,"Or","maybe","more","of","that","expression?"
3131 LetIndentBody row col ->
3132 toUnfinishLetReport source row col startRow startCol $
3134 "I was expecting an expression next. Tell me what should happen with the value you just defined!"
3137toUnfinishLetReport :: Code.Source -> Row -> Col -> Row -> Col -> D.Doc -> Report.Report
3138toUnfinishLetReport source row col startRow startCol message =
3140 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3141 region = toRegion row col
3143 Report.Report "UNFINISHED LET" region [] $
3144 Code.toSnippet source surroundings (Just region)
3147 "I was partway through parsing a `let` expression, but I got stuck here:"
3152 "Here is an example with a valid `let` expression for reference:"
3154 [ D.indent 0 $ D.fillSep [D.green "viewPerson","person","="]
3155 , D.indent 2 $ D.fillSep [D.cyan "let"]
3156 , D.indent 4 $ D.fillSep ["fullName","="]
3157 , D.indent 6 $ D.fillSep ["person.firstName","++",D.dullyellow "\" \"","++","person.lastName"]
3158 , D.indent 2 $ D.fillSep [D.cyan "in"]
3159 , D.indent 2 $ D.fillSep ["div","[]","[","text","fullName","]"]
3162 "Here we defined a `viewPerson` function that turns a person into some HTML. We use\
3163 \ a `let` expression to define the `fullName` we want to show. Notice the indentation! The\
3164 \ `fullName` is indented more than the `let` keyword, and the actual value of `fullName` is\
3165 \ indented a bit more than that. That is important!"
3170toLetDefReport :: Code.Source -> Name.Name -> Def -> Row -> Col -> Report.Report
3171toLetDefReport source name def startRow startCol =
3173 DefSpace space row col ->
3174 toSpaceReport source space row col
3176 DefType tipe row col ->
3177 toTypeReport source (TC_Annotation name) tipe row col
3179 DefNameRepeat row col ->
3181 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3182 region = toRegion row col
3184 Report.Report "EXPECTING DEFINITION" region [] $
3185 Code.toSnippet source surroundings (Just region)
3188 "I just saw the type annotation for `" ++ Name.toChars name
3189 ++ "` so I was expecting to see its definition here:"
3193 "Type annotations always appear directly above the relevant\
3194 \ definition, without anything else in between."
3199 DefNameMatch defName row col ->
3201 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3202 region = toRegion row col
3204 Report.Report "NAME MISMATCH" region [] $
3205 Code.toSnippet source surroundings (Just region)
3208 "I just saw a type annotation for `" ++ Name.toChars name ++ "`, but it is followed by a definition for `" ++ Name.toChars defName ++ "`:"
3212 "These names do not match! Is there a typo?"
3213 , D.indent 4 $ D.fillSep $
3214 [D.dullyellow (D.fromName defName),"->",D.green (D.fromName name)]
3218 DefArg pattern row col ->
3219 toPatternReport source PArg pattern row col
3221 DefEquals row col ->
3222 case Code.whatIsNext source row col of
3223 Code.Keyword keyword ->
3225 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3226 region = toKeywordRegion row col keyword
3228 Report.Report "RESERVED WORD" region [] $
3229 Code.toSnippet source surroundings (Just region)
3233 ,"`" <> D.cyan (D.fromChars keyword) <> "`"
3234 ,"is","reserved","in","Elm,","so","it","cannot"
3235 ,"be","used","as","an","argument","here:"
3240 "Try renaming it to something else."
3244 ["This","keyword","is","reserved","for","pattern","matches","like"
3245 ,"((x,y)",D.cyan "as","point)","where","you","want","to","name","a","tuple","and"
3246 ,"the","values","it","contains."
3251 "The `" ++ keyword ++ "` keyword has a special meaning in Elm, so it can only be used in certain situations."
3255 Code.Operator "->" ->
3257 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3258 region = toWiderRegion row col 2
3260 Report.Report "MISSING COLON?" region [] $
3261 Code.toSnippet source surroundings (Just region)
3264 "I was not expecting to see an arrow here:"
3268 ["This","usually","means","a",D.green ":","is","missing","a","bit","earlier","in"
3269 ,"a","type","annotation.","It","could","be","something","else","though,","so"
3270 ,"here","is","a","valid","definition","for","reference:"
3273 [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3274 , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3275 , D.indent 6 $ D.fillSep ["x","+","y"]
3278 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
3284 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3285 region = toKeywordRegion row col op
3287 Report.Report "UNEXPECTED SYMBOL" region [] $
3288 Code.toSnippet source surroundings (Just region)
3291 "I was not expecting to see this symbol here:"
3295 "I am not sure what is going wrong exactly, so here is a valid\
3296 \ definition (with an optional type annotation) for reference:"
3298 [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3299 , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3300 , D.indent 6 $ D.fillSep ["x","+","y"]
3303 "Try to use that format with your `" ++ Name.toChars name ++ "` definition!"
3309 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3310 region = toRegion row col
3312 Report.Report "PROBLEM IN DEFINITION" region [] $
3313 Code.toSnippet source surroundings (Just region)
3316 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3320 "I am not sure what is going wrong exactly, so here is a valid\
3321 \ definition (with an optional type annotation) for reference:"
3323 [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3324 , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3325 , D.indent 4 $ D.fillSep ["x","+","y"]
3328 "Try to use that format!"
3332 DefBody expr row col ->
3333 toExprReport source (InDef name startRow startCol) expr row col
3335 DefIndentEquals row col ->
3337 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3338 region = toRegion row col
3340 Report.Report "UNFINISHED DEFINITION" region [] $
3341 Code.toSnippet source surroundings (Just region)
3344 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3348 "I was expecting to see an argument or an equals sign next."
3353 DefIndentType row col ->
3355 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3356 region = toRegion row col
3358 Report.Report "UNFINISHED DEFINITION" region [] $
3359 Code.toSnippet source surroundings (Just region)
3362 "I got stuck while parsing the `" ++ Name.toChars name ++ "` type annotation:"
3366 "I just saw a colon, so I am expecting to see a type next."
3371 DefIndentBody row col ->
3373 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3374 region = toRegion row col
3376 Report.Report "UNFINISHED DEFINITION" region [] $
3377 Code.toSnippet source surroundings (Just region)
3380 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3384 "I was expecting to see an expression next. What is it equal to?"
3389 DefAlignment indent row col ->
3391 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3392 region = toRegion row col
3393 offset = indent - col
3395 Report.Report "PROBLEM IN DEFINITION" region [] $
3396 Code.toSnippet source surroundings (Just region)
3399 "I got stuck while parsing the `" ++ Name.toChars name ++ "` definition:"
3402 "I just saw a type annotation indented " ++ show indent ++ " spaces, so I was\
3403 \ expecting to see the corresponding definition next with the exact same amount\
3404 \ of indentation. It looks like this line needs "
3405 ++ show offset ++ " more " ++ (if offset == 1 then "space" else "spaces") ++ "?"
3414 "Here is a valid definition (with a type annotation) for reference:"
3416 [ D.indent 4 $ D.fillSep [D.green "add",":","Int","->","Int","->","Int"]
3417 , D.indent 4 $ D.fillSep [D.green "add","x","y","="]
3418 , D.indent 6 $ D.fillSep ["x","+","y"]
3421 "The top line (called a \"type annotation\") is optional. You can leave it off\
3422 \ if you want. As you get more comfortable with Elm and as your project grows,\
3423 \ it becomes more and more valuable to add them though! They work great as\
3424 \ compiler-verified documentation, and they often improve error messages!"
3428toLetDestructReport :: Code.Source -> Destruct -> Row -> Col -> Report.Report
3429toLetDestructReport source destruct startRow startCol =
3431 DestructSpace space row col ->
3432 toSpaceReport source space row col
3434 DestructPattern pattern row col ->
3435 toPatternReport source PLet pattern row col
3437 DestructEquals row col ->
3439 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3440 region = toRegion row col
3442 Report.Report "PROBLEM IN DEFINITION" region [] $
3443 Code.toSnippet source surroundings (Just region)
3446 "I got stuck trying to parse this definition:"
3448 case Code.whatIsNext source row col of
3449 Code.Operator ":" ->
3452 "I was expecting to see an equals sign next, followed by an expression\
3453 \ telling me what to compute."
3455 "It looks like you may be trying to write a type annotation? It is not\
3456 \ possible to add type annotations on destructuring definitions like this.\
3457 \ You can assign a name to the overall structure, put a type annotation on\
3458 \ that, and then destructure separately though."
3463 "I was expecting to see an equals sign next, followed by an expression\
3464 \ telling me what to compute."
3467 DestructBody expr row col ->
3468 toExprReport source (InDestruct startRow startCol) expr row col
3470 DestructIndentEquals row col ->
3472 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3473 region = toRegion row col
3475 Report.Report "UNFINISHED DEFINITION" region [] $
3476 Code.toSnippet source surroundings (Just region)
3479 "I got stuck trying to parse this definition:"
3482 "I was expecting to see an equals sign next, followed by an expression\
3483 \ telling me what to compute."
3486 DestructIndentBody row col ->
3488 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3489 region = toRegion row col
3491 Report.Report "UNFINISHED DEFINITION" region [] $
3492 Code.toSnippet source surroundings (Just region)
3495 "I got stuck while parsing this definition:"
3498 "I was expecting to see an expression next. What is it equal to?"
3506toCaseReport :: Code.Source -> Context -> Case -> Row -> Col -> Report.Report
3507toCaseReport source context case_ startRow startCol =
3509 CaseSpace space row col ->
3510 toSpaceReport source space row col
3513 toUnfinishCaseReport source row col startRow startCol $
3514 D.fillSep ["I","was","expecting","to","see","the",D.dullyellow "of","keyword","next."]
3516 CasePattern pattern row col ->
3517 toPatternReport source PCase pattern row col
3519 CaseArrow row col ->
3520 case Code.whatIsNext source row col of
3521 Code.Keyword keyword ->
3523 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3524 region = toKeywordRegion row col keyword
3526 Report.Report "RESERVED WORD" region [] $
3527 Code.toSnippet source surroundings (Just region)
3530 "I am partway through parsing a `case` expression, but I got stuck here:"
3533 "It looks like you are trying to use `" ++ keyword ++ "` in one of your\
3534 \ patterns, but it is a reserved word. Try using a different name?"
3537 Code.Operator ":" ->
3539 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3540 region = toRegion row col
3542 Report.Report "UNEXPECTED OPERATOR" region [] $
3543 Code.toSnippet source surroundings (Just region)
3546 "I am partway through parsing a `case` expression, but I got stuck here:"
3549 ["I","am","seeing",D.dullyellow ":","but","maybe","you","want",D.green "::","instead?"
3550 ,"For","pattern","matching","on","lists?"
3554 Code.Operator "=" ->
3556 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3557 region = toRegion row col
3559 Report.Report "UNEXPECTED OPERATOR" region [] $
3560 Code.toSnippet source surroundings (Just region)
3563 "I am partway through parsing a `case` expression, but I got stuck here:"
3566 ["I","am","seeing",D.dullyellow "=","but","maybe","you","want",D.green "->","instead?"
3572 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3573 region = toRegion row col
3575 Report.Report "MISSING ARROW" region [] $
3576 Code.toSnippet source surroundings (Just region)
3579 "I am partway through parsing a `case` expression, but I got stuck here:"
3582 [ D.reflow "I was expecting to see an arrow next."
3583 , noteForCaseIndentError
3587 CaseExpr expr row col ->
3588 toExprReport source (InNode NCase startRow startCol context) expr row col
3590 CaseBranch expr row col ->
3591 toExprReport source (InNode NBranch startRow startCol context) expr row col
3593 CaseIndentOf row col ->
3594 toUnfinishCaseReport source row col startRow startCol $
3595 D.fillSep ["I","was","expecting","to","see","the",D.dullyellow "of","keyword","next."]
3597 CaseIndentExpr row col ->
3598 toUnfinishCaseReport source row col startRow startCol $
3599 D.reflow "I was expecting to see a expression next."
3601 CaseIndentPattern row col ->
3602 toUnfinishCaseReport source row col startRow startCol $
3603 D.reflow "I was expecting to see a pattern next."
3605 CaseIndentArrow row col ->
3606 toUnfinishCaseReport source row col startRow startCol $
3608 ["I","just","saw","a","pattern,","so","I","was","expecting"
3609 ,"to","see","a",D.dullyellow "->","next."
3612 CaseIndentBranch row col ->
3613 toUnfinishCaseReport source row col startRow startCol $
3615 "I was expecting to see an expression next. What should I do when\
3616 \ I run into this particular pattern?"
3618 CasePatternAlignment indent row col ->
3619 toUnfinishCaseReport source row col startRow startCol $
3621 "I suspect this is a pattern that is not indented far enough? (" ++ show indent ++ " spaces)"
3624toUnfinishCaseReport :: Code.Source -> Row -> Col -> Row -> Col -> D.Doc -> Report.Report
3625toUnfinishCaseReport source row col startRow startCol message =
3627 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3628 region = toRegion row col
3630 Report.Report "UNFINISHED CASE" region [] $
3631 Code.toSnippet source surroundings (Just region)
3634 "I was partway through parsing a `case` expression, but I got stuck here:"
3643noteForCaseError :: D.Doc
3647 "Here is an example of a valid `case` expression for reference."
3649 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3650 , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
3651 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3653 , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
3654 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3657 "Notice the indentation. Each pattern is aligned, and each branch is indented\
3658 \ a bit more than the corresponding pattern. That is important!"
3662noteForCaseIndentError :: D.Doc
3663noteForCaseIndentError =
3666 "Sometimes I get confused by indentation, so try to make your `case` look\
3667 \ something like this:"
3669 [ D.indent 4 $ D.fillSep [D.cyan "case","maybeWidth",D.cyan "of"]
3670 , D.indent 6 $ D.fillSep [D.blue "Just","width","->"]
3671 , D.indent 8 $ D.fillSep ["width","+",D.dullyellow "200"]
3673 , D.indent 6 $ D.fillSep [D.blue "Nothing","->"]
3674 , D.indent 8 $ D.fillSep [D.dullyellow "400"]
3677 "Notice the indentation! Patterns are aligned with each other. Same indentation.\
3678 \ The expressions after each arrow are all indented a bit more than the patterns.\
3679 \ That is important!"
3687toIfReport :: Code.Source -> Context -> If -> Row -> Col -> Report.Report
3688toIfReport source context if_ startRow startCol =
3690 IfSpace space row col ->
3691 toSpaceReport source space row col
3695 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3696 region = toRegion row col
3698 Report.Report "UNFINISHED IF" region [] $
3699 Code.toSnippet source surroundings (Just region)
3702 "I was expecting to see more of this `if` expression, but I got stuck here:"
3705 ["I","was","expecting","to","see","the",D.cyan "then","keyword","next."
3711 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3712 region = toRegion row col
3714 Report.Report "UNFINISHED IF" region [] $
3715 Code.toSnippet source surroundings (Just region)
3718 "I was expecting to see more of this `if` expression, but I got stuck here:"
3721 ["I","was","expecting","to","see","the",D.cyan "else","keyword","next."
3725 IfElseBranchStart row col ->
3727 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3728 region = toRegion row col
3730 Report.Report "UNFINISHED IF" region [] $
3731 Code.toSnippet source surroundings (Just region)
3734 "I just saw the start of an `else` branch, but then I got stuck here:"
3737 "I was expecting to see an expression next. Maybe it is not filled in yet?"
3740 IfCondition expr row col ->
3741 toExprReport source (InNode NCond startRow startCol context) expr row col
3743 IfThenBranch expr row col ->
3744 toExprReport source (InNode NThen startRow startCol context) expr row col
3746 IfElseBranch expr row col ->
3747 toExprReport source (InNode NElse startRow startCol context) expr row col
3749 IfIndentCondition row col ->
3751 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3752 region = toRegion row col
3754 Report.Report "UNFINISHED IF" region [] $
3755 Code.toSnippet source surroundings (Just region)
3758 "I was expecting to see more of this `if` expression, but I got stuck here:"
3762 ["I","was","expecting","to","see","an","expression","like",D.dullyellow "x < 0"
3763 ,"that","evaluates","to","True","or","False."
3766 "I can be confused by indentation. Maybe something is not indented enough?"
3770 IfIndentThen row col ->
3772 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3773 region = toRegion row col
3775 Report.Report "UNFINISHED IF" region [] $
3776 Code.toSnippet source surroundings (Just region)
3779 "I was expecting to see more of this `if` expression, but I got stuck here:"
3783 ["I","was","expecting","to","see","the",D.cyan "then","keyword","next."
3786 "I can be confused by indentation. Maybe something is not indented enough?"
3790 IfIndentThenBranch row col ->
3792 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3793 region = toRegion row col
3795 Report.Report "UNFINISHED IF" region [] $
3796 Code.toSnippet source surroundings (Just region)
3799 "I got stuck after the start of this `then` branch:"
3803 "I was expecting to see an expression next. Maybe it is not filled in yet?"
3805 "I can be confused by indentation, so if the `then` branch is already\
3806 \ present, it may not be indented enough for me to recognize it."
3810 IfIndentElseBranch row col ->
3812 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3813 region = toRegion row col
3815 Report.Report "UNFINISHED IF" region [] $
3816 Code.toSnippet source surroundings (Just region)
3819 "I got stuck after the start of this `else` branch:"
3823 "I was expecting to see an expression next. Maybe it is not filled in yet?"
3825 "I can be confused by indentation, so if the `else` branch is already\
3826 \ present, it may not be indented enough for me to recognize it."
3830 IfIndentElse row col ->
3831 case Code.nextLineStartsWithKeyword "else" source row of
3832 Just (elseRow, elseCol) ->
3834 surroundings = A.Region (A.Position startRow startCol) (A.Position elseRow elseCol)
3835 region = toWiderRegion elseRow elseCol 4
3837 Report.Report "WEIRD ELSE BRANCH" region [] $
3838 Code.toSnippet source surroundings (Just region)
3841 "I was partway through an `if` expression when I got stuck here:"
3844 ["I","think","this",D.cyan "else","keyword","needs","to","be","indented","more."
3845 ,"Try","adding","some","spaces","before","it."
3851 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3852 region = toRegion row col
3854 Report.Report "UNFINISHED IF" region [] $
3855 Code.toSnippet source surroundings (Just region)
3858 "I was expecting to see an `else` branch after this:"
3862 ["I","know","what","to","do","when","the","condition","is","True,"
3863 ,"but","what","happens","when","it","is","False?"
3864 ,"Add","an",D.cyan "else","branch","to","handle","that","scenario!"
3874toRecordReport :: Code.Source -> Context -> Record -> Row -> Col -> Report.Report
3875toRecordReport source context record startRow startCol =
3877 RecordOpen row col ->
3878 case Code.whatIsNext source row col of
3879 Code.Keyword keyword ->
3881 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3882 region = toKeywordRegion row col keyword
3884 Report.Report "RESERVED WORD" region [] $
3885 Code.toSnippet source surroundings (Just region)
3888 "I just started parsing a record, but I got stuck on this field name:"
3891 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3892 \ that is a reserved word. Try using a different name!"
3897 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3898 region = toRegion row col
3900 Report.Report "PROBLEM IN RECORD" region [] $
3901 Code.toSnippet source surroundings (Just region)
3904 "I just started parsing a record, but I got stuck here:"
3908 ["I","was","expecting","to","see","a","record","field","defined","next,"
3909 ,"so","I","am","looking","for","a","name","like"
3910 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
3913 "Field names must start with a lower-case letter. After that, you can use\
3914 \ any sequence of letters, numbers, and underscores."
3915 , noteForRecordError
3919 RecordEnd row col ->
3921 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3922 region = toRegion row col
3924 Report.Report "PROBLEM IN RECORD" region [] $
3925 Code.toSnippet source surroundings (Just region)
3928 "I am partway through parsing a record, but I got stuck here:"
3932 ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
3933 ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
3936 "When I get stuck like this, it usually means that there is a missing parenthesis\
3937 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
3941 RecordField row col ->
3942 case Code.whatIsNext source row col of
3943 Code.Keyword keyword ->
3945 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3946 region = toKeywordRegion row col keyword
3948 Report.Report "RESERVED WORD" region [] $
3949 Code.toSnippet source surroundings (Just region)
3952 "I am partway through parsing a record, but I got stuck on this field name:"
3955 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3956 \ that is a reserved word. Try using a different name!"
3959 Code.Other (Just ',') ->
3961 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3962 region = toRegion row col
3964 Report.Report "EXTRA COMMA" region [] $
3965 Code.toSnippet source surroundings (Just region)
3968 "I am partway through parsing a record, but I got stuck here:"
3972 "I am seeing two commas in a row. This is the second one!"
3974 "Just delete one of the commas and you should be all set!"
3975 , noteForRecordError
3981 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3982 region = toRegion row col
3984 Report.Report "EXTRA COMMA" region [] $
3985 Code.toSnippet source surroundings (Just region)
3988 "I am partway through parsing a record, but I got stuck here:"
3992 "Trailing commas are not allowed in records. Try deleting the comma that appears\
3993 \ before this closing curly brace."
3994 , noteForRecordError
4000 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4001 region = toRegion row col
4003 Report.Report "PROBLEM IN RECORD" region [] $
4004 Code.toSnippet source surroundings (Just region)
4007 "I am partway through parsing a record, but I got stuck here:"
4011 ["I","was","expecting","to","see","another","record","field","defined","next,"
4012 ,"so","I","am","looking","for","a","name","like"
4013 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
4016 "Field names must start with a lower-case letter. After that, you can use\
4017 \ any sequence of letters, numbers, and underscores."
4018 , noteForRecordError
4022 RecordEquals row col ->
4024 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4025 region = toRegion row col
4027 Report.Report "PROBLEM IN RECORD" region [] $
4028 Code.toSnippet source surroundings (Just region)
4031 "I am partway through parsing a record, but I got stuck here:"
4035 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
4036 ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
4038 , noteForRecordError
4042 RecordExpr expr row col ->
4043 toExprReport source (InNode NRecord startRow startCol context) expr row col
4045 RecordSpace space row col ->
4046 toSpaceReport source space row col
4048 RecordIndentOpen row col ->
4050 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4051 region = toRegion row col
4053 Report.Report "UNFINISHED RECORD" region [] $
4054 Code.toSnippet source surroundings (Just region)
4057 "I just saw the opening curly brace of a record, but then I got stuck here:"
4059 addNoteForRecordIndentError $
4061 ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
4062 ,"Try","defining","some","fields","of","your","own?"
4066 RecordIndentEnd row col ->
4067 case Code.nextLineStartsWithCloseCurly source row of
4068 Just (curlyRow, curlyCol) ->
4070 surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
4071 region = toRegion curlyRow curlyCol
4073 Report.Report "NEED MORE INDENTATION" region [] $
4074 Code.toSnippet source surroundings (Just region)
4077 "I was partway through parsing a record, but I got stuck here:"
4081 "I need this curly brace to be indented more. Try adding some spaces before it!"
4082 , noteForRecordError
4088 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4089 region = toRegion row col
4091 Report.Report "UNFINISHED RECORD" region [] $
4092 Code.toSnippet source surroundings (Just region)
4095 "I was partway through parsing a record, but I got stuck here:"
4097 addNoteForRecordIndentError $
4099 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4100 ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
4104 RecordIndentField row col ->
4106 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4107 region = toRegion row col
4109 Report.Report "UNFINISHED RECORD" region [] $
4110 Code.toSnippet source surroundings (Just region)
4113 "I am partway through parsing a record, but I got stuck after that last comma:"
4117 "Trailing commas are not allowed in records, so the fix may be to\
4118 \ delete that last comma? Or maybe you were in the middle of defining\
4119 \ an additional field?"
4120 , noteForRecordError
4124 RecordIndentEquals row col ->
4126 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4127 region = toRegion row col
4129 Report.Report "UNFINISHED RECORD" region [] $
4130 Code.toSnippet source surroundings (Just region)
4133 "I am partway through parsing a record. I just saw a record\
4134 \ field, so I was expecting to see an equals sign next:"
4136 addNoteForRecordIndentError $
4138 ["Try","putting","an",D.green "=","followed","by","an","expression?"
4142 RecordIndentExpr row col ->
4144 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4145 region = toRegion row col
4147 Report.Report "UNFINISHED RECORD" region [] $
4148 Code.toSnippet source surroundings (Just region)
4151 "I am partway through parsing a record, and I was expecting to run into an expression next:"
4153 addNoteForRecordIndentError $
4155 ["Try","putting","something","like"
4156 ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
4161noteForRecordError :: D.Doc
4165 "If you are trying to define a record across multiple lines, I recommend using this format:"
4166 , D.indent 4 $ D.vcat $
4167 [ "{ name = \"Alice\""
4173 "Notice that each line starts with some indentation. Usually two or four spaces.\
4174 \ This is the stylistic convention in the Elm ecosystem."
4178addNoteForRecordIndentError :: D.Doc -> D.Doc
4179addNoteForRecordIndentError normalRecommendation =
4181 normalRecommendation
4184 "I may be confused by indentation. For example, if you are trying to define\
4185 \ a record across multiple lines, I recommend using this format:"
4186 , D.indent 4 $ D.vcat $
4187 [ "{ name = \"Alice\""
4193 "Notice that each line starts with some indentation. Usually two or four spaces.\
4194 \ This is the stylistic convention in the Elm ecosystem!"
4202toTupleReport :: Code.Source -> Context -> Tuple -> Row -> Col -> Report.Report
4203toTupleReport source context tuple startRow startCol =
4205 TupleExpr expr row col ->
4206 toExprReport source (InNode NParens startRow startCol context) expr row col
4208 TupleSpace space row col ->
4209 toSpaceReport source space row col
4213 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4214 region = toRegion row col
4216 Report.Report "UNFINISHED PARENTHESES" region [] $
4217 Code.toSnippet source surroundings (Just region)
4220 "I was expecting to see a closing parentheses next, but I got stuck here:"
4223 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
4225 "I can get stuck when I run into keywords, operators, parentheses, or brackets\
4226 \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
4227 \ or missing brackets) that is confusing me."
4231 TupleOperatorClose row col ->
4233 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4234 region = toRegion row col
4236 Report.Report "UNFINISHED OPERATOR FUNCTION" region [] $
4237 Code.toSnippet source surroundings (Just region)
4239 D.reflow "I was expecting a closing parenthesis here:"
4242 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
4244 "I think I am parsing an operator function right now, so I am expecting to see\
4245 \ something like (+) or (&&) where an operator is surrounded by parentheses with\
4250 TupleOperatorReserved operator row col ->
4252 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4253 region = toRegion row col
4255 Report.Report "UNEXPECTED SYMBOL" region [] $
4256 Code.toSnippet source surroundings (Just region)
4259 "I ran into an unexpected symbol here:"
4263 BadDot -> ["Maybe","you","wanted","a","record","accessor","like",D.dullyellow ".x","or",D.dullyellow ".name","instead?"]
4264 BadPipe -> ["Try",D.dullyellow "(||)","instead?","To","turn","boolean","OR","into","a","function?"]
4265 BadArrow -> ["Maybe","you","wanted",D.dullyellow "(>)","or",D.dullyellow "(>=)","instead?"]
4266 BadEquals -> ["Try",D.dullyellow "(==)","instead?","To","make","a","function","that","checks","equality?"]
4267 BadHasType -> ["Try",D.dullyellow "(::)","instead?","To","add","values","to","the","front","of","lists?"]
4270 TupleIndentExpr1 row col ->
4272 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4273 region = toRegion row col
4275 Report.Report "UNFINISHED PARENTHESES" region [] $
4276 Code.toSnippet source surroundings (Just region)
4279 "I just saw an open parenthesis, so I was expecting to see an expression next."
4283 ["Something","like",D.dullyellow "(4 + 5)","or"
4284 ,D.dullyellow "(String.reverse \"desserts\")" <> "."
4285 ,"Anything","where","you","are","putting","parentheses","around","normal","expressions."
4288 "I can get confused by indentation in cases like this, so\
4289 \ maybe you have an expression but it is not indented enough?"
4293 TupleIndentExprN row col ->
4295 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4296 region = toRegion row col
4298 Report.Report "UNFINISHED TUPLE" region [] $
4299 Code.toSnippet source surroundings (Just region)
4302 "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."
4306 ["A","tuple","looks","like",D.dullyellow "(3,4)","or"
4307 ,D.dullyellow "(\"Tom\",42)" <> ","
4308 ,"so","I","think","there","is","an","expression","missing","here?"
4311 "I can get confused by indentation in cases like this, so\
4312 \ maybe you have an expression but it is not indented enough?"
4316 TupleIndentEnd row col ->
4318 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4319 region = toRegion row col
4321 Report.Report "UNFINISHED PARENTHESES" region [] $
4322 Code.toSnippet source surroundings (Just region)
4325 "I was expecting to see a closing parenthesis next:"
4328 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
4330 "I can get confused by indentation in cases like this, so\
4331 \ maybe you have a closing parenthesis but it is not indented enough?"
4336toListReport :: Code.Source -> Context -> List -> Row -> Col -> Report.Report
4337toListReport source context list startRow startCol =
4339 ListSpace space row col ->
4340 toSpaceReport source space row col
4344 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4345 region = toRegion row col
4347 Report.Report "UNFINISHED LIST" region [] $
4348 Code.toSnippet source surroundings (Just region)
4351 "I am partway through parsing a list, but I got stuck here:"
4355 ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
4356 ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
4359 "When I get stuck like this, it usually means that there is a missing parenthesis\
4360 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
4364 ListExpr expr row col ->
4368 surroundings = A.Region (A.Position startRow startCol) (A.Position r c)
4369 region = toRegion r c
4371 Report.Report "UNFINISHED LIST" region [] $
4372 Code.toSnippet source surroundings (Just region)
4375 "I was expecting to see another list entry after that last comma:"
4379 "Trailing commas are not allowed in lists, so the fix may be to delete the comma?"
4381 "I recommend using the following format for lists that span multiple lines:"
4382 , D.indent 4 $ D.vcat $
4389 "Notice that each line starts with some indentation. Usually two or four spaces.\
4390 \ This is the stylistic convention in the Elm ecosystem."
4395 toExprReport source (InNode NList startRow startCol context) expr row col
4399 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4400 region = toRegion row col
4402 Report.Report "UNFINISHED LIST" region [] $
4403 Code.toSnippet source surroundings (Just region)
4406 "I am partway through parsing a list, but I got stuck here:"
4410 ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
4411 ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
4414 "When I get stuck like this, it usually means that there is a missing parenthesis\
4415 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
4419 ListIndentOpen row col ->
4421 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4422 region = toRegion row col
4424 Report.Report "UNFINISHED LIST" region [] $
4425 Code.toSnippet source surroundings (Just region)
4428 "I cannot find the end of this list:"
4432 ["You","could","change","it","to","something","like"
4433 ,D.dullyellow "[3,4,5]"
4435 ,D.dullyellow "[]" <> "."
4436 ,"Anything","where","there","is","an","open","and","close","square","brace,"
4437 ,"and","where","the","elements","of","the","list","are","separated","by","commas."
4440 "I may be confused by indentation. For example, if you are trying to define\
4441 \ a list across multiple lines, I recommend using this format:"
4442 , D.indent 4 $ D.vcat $
4449 "Notice that each line starts with some indentation. Usually two or four spaces.\
4450 \ This is the stylistic convention in the Elm ecosystem."
4454 ListIndentEnd row col ->
4456 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4457 region = toRegion row col
4459 Report.Report "UNFINISHED LIST" region [] $
4460 Code.toSnippet source surroundings (Just region)
4463 "I cannot find the end of this list:"
4467 ["You","can","just","add","a","closing",D.dullyellow "]"
4468 ,"right","here,","and","I","will","be","all","set!"
4471 "I may be confused by indentation. For example, if you are trying to define\
4472 \ a list across multiple lines, I recommend using this format:"
4473 , D.indent 4 $ D.vcat $
4480 "Notice that each line starts with some indentation. Usually two or four spaces.\
4481 \ This is the stylistic convention in the Elm ecosystem."
4485 ListIndentExpr row col ->
4487 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4488 region = toRegion row col
4490 Report.Report "UNFINISHED LIST" region [] $
4491 Code.toSnippet source surroundings (Just region)
4494 "I was expecting to see another list entry after this comma:"
4498 "Trailing commas are not allowed in lists, so the fix may be to delete the comma?"
4500 "I recommend using the following format for lists that span multiple lines:"
4501 , D.indent 4 $ D.vcat $
4508 "Notice that each line starts with some indentation. Usually two or four spaces.\
4509 \ This is the stylistic convention in the Elm ecosystem."
4514toFuncReport :: Code.Source -> Context -> Func -> Row -> Col -> Report.Report
4515toFuncReport source context func startRow startCol =
4517 FuncSpace space row col ->
4518 toSpaceReport source space row col
4520 FuncArg pattern row col ->
4521 toPatternReport source PArg pattern row col
4523 FuncBody expr row col ->
4524 toExprReport source (InNode NFunc startRow startCol context) expr row col
4526 FuncArrow row col ->
4527 case Code.whatIsNext source row col of
4528 Code.Keyword keyword ->
4530 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4531 region = toKeywordRegion row col keyword
4533 Report.Report "RESERVED WORD" region [] $
4534 Code.toSnippet source surroundings (Just region)
4537 "I was parsing an anonymous function, but I got stuck here:"
4540 "It looks like you are trying to use `" ++ keyword ++ "` as an argument, but\
4541 \ it is a reserved word in this language. Try using a different argument name!"
4546 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4547 region = toRegion row col
4549 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4550 Code.toSnippet source surroundings (Just region)
4553 "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
4556 ["The","syntax","for","anonymous","functions","is"
4557 ,D.dullyellow "(\\x -> x + 1)"
4558 ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
4562 FuncIndentArg row col ->
4564 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4565 region = toRegion row col
4567 Report.Report "MISSING ARGUMENT" region [] $
4568 Code.toSnippet source surroundings (Just region)
4571 "I just saw the beginning of an anonymous function, so I was expecting to see an argument next:"
4575 ["Something","like",D.dullyellow"x","or",D.dullyellow "name" <> "."
4576 ,"Anything","that","starts","with","a","lower","case","letter!"
4579 "The syntax for anonymous functions is (\\x -> x + 1) where the backslash\
4580 \ is meant to look a bit like a lambda if you squint. This visual pun seemed\
4581 \ like a better idea at the time!"
4585 FuncIndentArrow row col ->
4587 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4588 region = toRegion row col
4590 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4591 Code.toSnippet source surroundings (Just region)
4594 "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
4598 ["The","syntax","for","anonymous","functions","is"
4599 ,D.dullyellow "(\\x -> x + 1)"
4600 ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
4603 "It is possible that I am confused about indetation! I generally recommend\
4604 \ switching to named functions if the definition cannot fit inline nicely, so\
4605 \ either (1) try to fit the whole anonymous function on one line or (2) break\
4606 \ the whole thing out into a named function. Things tend to be clearer that way!"
4610 FuncIndentBody row col ->
4612 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4613 region = toRegion row col
4615 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4616 Code.toSnippet source surroundings (Just region)
4619 "I was expecting to see the body of your anonymous function next:"
4623 ["The","syntax","for","anonymous","functions","is"
4624 ,D.dullyellow "(\\x -> x + 1)"
4625 ,"so","I","am","missing","all","the","stuff","after","the","arrow!"
4628 "It is possible that I am confused about indetation! I generally recommend\
4629 \ switching to named functions if the definition cannot fit inline nicely, so\
4630 \ either (1) try to fit the whole anonymous function on one line or (2) break\
4631 \ the whole thing out into a named function. Things tend to be clearer that way!"
4646toPatternReport :: Code.Source -> PContext -> Pattern -> Row -> Col -> Report.Report
4647toPatternReport source context pattern startRow startCol =
4649 PRecord record row col ->
4650 toPRecordReport source record row col
4652 PTuple tuple row col ->
4653 toPTupleReport source context tuple row col
4655 PList list row col ->
4656 toPListReport source context list row col
4659 case Code.whatIsNext source row col of
4660 Code.Keyword keyword ->
4662 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4663 region = toKeywordRegion row col keyword
4666 PArg -> "as an argument"
4667 PCase -> "in this pattern"
4668 PLet -> "in this pattern"
4670 Report.Report "RESERVED WORD" region [] $
4671 Code.toSnippet source surroundings (Just region)
4674 "It looks like you are trying to use `" ++ keyword ++ "` " ++ inThisThing ++ ":"
4677 "This is a reserved word! Try using some other name?"
4680 Code.Operator "-" ->
4682 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4683 region = toRegion row col
4685 Report.Report "UNEXPECTED SYMBOL" region [] $
4686 Code.toSnippet source surroundings (Just region)
4689 "I ran into a minus sign unexpectedly in this pattern:"
4692 "It is not possible to pattern match on negative numbers at this\
4693 \ time. Try using an `if` expression for that sort of thing for now."
4698 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4699 region = toRegion row col
4701 Report.Report "PROBLEM IN PATTERN" region [] $
4702 Code.toSnippet source surroundings (Just region)
4705 "I wanted to parse a pattern next, but I got stuck here:"
4708 ["I","am","not","sure","why","I","am","getting","stuck","exactly."
4709 ,"I","just","know","that","I","want","a","pattern","next."
4710 ,"Something","as","simple","as"
4711 ,D.dullyellow "maybeHeight","or",D.dullyellow "result"
4716 PChar char row col ->
4717 toCharReport source char row col
4719 PString string row col ->
4720 toStringReport source string row col
4722 PNumber number row col ->
4723 toNumberReport source number row col
4725 PFloat width row col ->
4727 region = toWiderRegion row col width
4729 Report.Report "UNEXPECTED PATTERN" region [] $
4730 Code.toSnippet source region Nothing
4733 "I cannot pattern match with floating point numbers:"
4736 ["Equality","on","floats","can","be","unreliable,","so","you","usually","want"
4737 ,"to","check","that","they","are","nearby","with","some","sort","of"
4738 ,D.dullyellow "(abs (actual - expected) < 0.001)","check."
4744 region = toRegion row col
4746 Report.Report "UNFINISHED PATTERN" region [] $
4747 Code.toSnippet source region Nothing $
4750 "I was expecting to see a variable name after the `as` keyword:"
4754 ["The","`as`","keyword","lets","you","write","patterns","like"
4755 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4756 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4757 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4758 ,"thing","with",D.dullyellow "point" <> "."
4761 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
4762 \ people just want to use `as` as a variable name though. Try using a different name\
4767 PWildcardNotVar name width row col ->
4769 region = toWiderRegion row col (fromIntegral width)
4771 case dropWhile (=='_') (Name.toChars name) of
4772 [] -> [D.dullyellow "x","or",D.dullyellow "age"]
4773 c:cs -> [D.dullyellow (D.fromChars (Char.toLower c : cs))]
4775 Report.Report "UNEXPECTED NAME" region [] $
4776 Code.toSnippet source region Nothing $
4779 "Variable names cannot start with underscores like this:"
4782 ["You","can","either","have","an","underscore","like",D.dullyellow "_","to"
4783 ,"ignore","the","value,","or","you","can","have","a","name","like"
4784 ] ++ examples ++ ["to","use","the","matched","value." ]
4787 PSpace space row col ->
4788 toSpaceReport source space row col
4790 PIndentStart row col ->
4792 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4793 region = toRegion row col
4795 Report.Report "UNFINISHED PATTERN" region [] $
4796 Code.toSnippet source surroundings (Just region)
4799 "I wanted to parse a pattern next, but I got stuck here:"
4803 ["I","am","not","sure","why","I","am","getting","stuck","exactly."
4804 ,"I","just","know","that","I","want","a","pattern","next."
4805 ,"Something","as","simple","as"
4806 ,D.dullyellow "maybeHeight","or",D.dullyellow "result"
4810 "I can get confused by indentation. If you think there is a pattern next, maybe\
4811 \ it needs to be indented a bit more?"
4815 PIndentAlias row col ->
4817 region = toRegion row col
4819 Report.Report "UNFINISHED PATTERN" region [] $
4820 Code.toSnippet source region Nothing $
4823 "I was expecting to see a variable name after the `as` keyword:"
4827 ["The","`as`","keyword","lets","you","write","patterns","like"
4828 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4829 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4830 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4831 ,"thing","with",D.dullyellow "point."
4834 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
4835 \ people just want to use `as` as a variable name though. Try using a different name\
4841toPRecordReport :: Code.Source -> PRecord -> Row -> Col -> Report.Report
4842toPRecordReport source record startRow startCol =
4844 PRecordOpen row col ->
4845 toUnfinishRecordPatternReport source row col startRow startCol $
4846 D.reflow "I was expecting to see a field name next."
4848 PRecordEnd row col ->
4849 toUnfinishRecordPatternReport source row col startRow startCol $
4851 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4852 ,"Try","adding","a",D.dullyellow "}","here?"
4855 PRecordField row col ->
4856 case Code.whatIsNext source row col of
4857 Code.Keyword keyword ->
4859 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4860 region = toKeywordRegion row col keyword
4862 Report.Report "RESERVED WORD" region [] $
4863 Code.toSnippet source surroundings (Just region)
4866 "I was not expecting to see `" ++ keyword ++ "` as a record field name:"
4869 "This is a reserved word, not available for variable names. Try another name!"
4873 toUnfinishRecordPatternReport source row col startRow startCol $
4874 D.reflow "I was expecting to see a field name next."
4876 PRecordSpace space row col ->
4877 toSpaceReport source space row col
4879 PRecordIndentOpen row col ->
4880 toUnfinishRecordPatternReport source row col startRow startCol $
4881 D.reflow "I was expecting to see a field name next."
4883 PRecordIndentEnd row col ->
4884 toUnfinishRecordPatternReport source row col startRow startCol $
4886 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4887 ,"Try","adding","a",D.dullyellow "}","here?"
4890 PRecordIndentField row col ->
4891 toUnfinishRecordPatternReport source row col startRow startCol $
4892 D.reflow "I was expecting to see a field name next."
4895toUnfinishRecordPatternReport :: Code.Source -> Row -> Col -> Row -> Col -> D.Doc -> Report.Report
4896toUnfinishRecordPatternReport source row col startRow startCol message =
4898 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4899 region = toRegion row col
4901 Report.Report "UNFINISHED RECORD PATTERN" region [] $
4902 Code.toSnippet source surroundings (Just region)
4905 "I was partway through parsing a record pattern, but I got stuck here:"
4910 ["A","record","pattern","looks","like",D.dullyellow "{x,y}","or",D.dullyellow "{name,age}"
4911 ,"where","you","list","the","field","names","you","want","to","access."
4918toPTupleReport :: Code.Source -> PContext -> PTuple -> Row -> Col -> Report.Report
4919toPTupleReport source context tuple startRow startCol =
4921 PTupleOpen row col ->
4922 case Code.whatIsNext source row col of
4923 Code.Keyword keyword ->
4925 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4926 region = toKeywordRegion row col keyword
4928 Report.Report "RESERVED WORD" region [] $
4929 Code.toSnippet source surroundings (Just region)
4932 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name:"
4935 "This is a reserved word! Try using some other name?"
4940 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4941 region = toRegion row col
4943 Report.Report "UNFINISHED PARENTHESES" region [] $
4944 Code.toSnippet source surroundings (Just region)
4947 "I just saw an open parenthesis, but I got stuck here:"
4950 ["I","was","expecting","to","see","a","pattern","next."
4951 ,"Maybe","it","will","end","up","being","something"
4952 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
4956 PTupleEnd row col ->
4957 case Code.whatIsNext source row col of
4958 Code.Keyword keyword ->
4960 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4961 region = toKeywordRegion row col keyword
4963 Report.Report "RESERVED WORD" region [] $
4964 Code.toSnippet source surroundings (Just region) $
4967 "I ran into a reserved word in this pattern:"
4970 "The `" ++ keyword ++ "` keyword is reserved. Try using a different name instead!"
4975 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4976 region = toKeywordRegion row col op
4978 Report.Report "UNEXPECTED SYMBOL" region [] $
4979 Code.toSnippet source surroundings (Just region) $
4982 "I ran into the " ++ op ++ " symbol unexpectedly in this pattern:"
4985 "Only the :: symbol that works in patterns. It is useful if you\
4986 \ are pattern matching on lists, trying to get the first element\
4987 \ off the front. Did you want that instead?"
4990 Code.Close term bracket ->
4992 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4993 region = toRegion row col
4995 Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
4996 Code.toSnippet source surroundings (Just region) $
4999 "I ran into a an unexpected " ++ term ++ " in this pattern:"
5002 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
5007 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5008 region = toRegion row col
5010 Report.Report "UNFINISHED PARENTHESES" region [] $
5011 Code.toSnippet source surroundings (Just region) $
5014 "I was partway through parsing a pattern, but I got stuck here:"
5017 ["I","was","expecting","a","closing","parenthesis","next,","so"
5018 ,"try","adding","a",D.dullyellow ")","to","see","if","that","helps?"
5022 PTupleExpr pattern row col ->
5023 toPatternReport source context pattern row col
5025 PTupleSpace space row col ->
5026 toSpaceReport source space row col
5028 PTupleIndentEnd row col ->
5030 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5031 region = toRegion row col
5033 Report.Report "UNFINISHED PARENTHESES" region [] $
5034 Code.toSnippet source surroundings (Just region) $
5037 "I was expecting a closing parenthesis next:"
5040 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
5042 "I can get confused by indentation in cases like this, so\
5043 \ maybe you have a closing parenthesis but it is not indented enough?"
5047 PTupleIndentExpr1 row col ->
5049 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5050 region = toRegion row col
5052 Report.Report "UNFINISHED PARENTHESES" region [] $
5053 Code.toSnippet source surroundings (Just region) $
5056 "I just saw an open parenthesis, but then I got stuck here:"
5059 ["I","was","expecting","to","see","a","pattern","next."
5060 ,"Maybe","it","will","end","up","being","something"
5061 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
5065 PTupleIndentExprN row col ->
5067 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5068 region = toRegion row col
5070 Report.Report "UNFINISHED TUPLE PATTERN" region [] $
5071 Code.toSnippet source surroundings (Just region) $
5074 "I am partway through parsing a tuple pattern, but I got stuck here:"
5078 ["I","was","expecting","to","see","a","pattern","next."
5079 ,"I","am","expecting","the","final","result","to","be","something"
5080 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "."
5083 "I can get confused by indentation in cases like this, so the problem\
5084 \ may be that the next part is not indented enough?"
5089toPListReport :: Code.Source -> PContext -> PList -> Row -> Col -> Report.Report
5090toPListReport source context list startRow startCol =
5092 PListOpen row col ->
5093 case Code.whatIsNext source row col of
5094 Code.Keyword keyword ->
5096 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5097 region = toKeywordRegion row col keyword
5099 Report.Report "RESERVED WORD" region [] $
5100 Code.toSnippet source surroundings (Just region)
5103 "It looks like you are trying to use `" ++ keyword ++ "` to name an element of a list:"
5106 "This is a reserved word though! Try using some other name?"
5111 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5112 region = toRegion row col
5114 Report.Report "UNFINISHED LIST PATTERN" region [] $
5115 Code.toSnippet source surroundings (Just region) $
5118 "I just saw an open square bracket, but then I got stuck here:"
5120 D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5125 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5126 region = toRegion row col
5128 Report.Report "UNFINISHED LIST PATTERN" region [] $
5129 Code.toSnippet source surroundings (Just region) $
5132 "I was expecting a closing square bracket to end this list pattern:"
5134 D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5137 PListExpr pattern row col ->
5138 toPatternReport source context pattern row col
5140 PListSpace space row col ->
5141 toSpaceReport source space row col
5143 PListIndentOpen row col ->
5145 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5146 region = toRegion row col
5148 Report.Report "UNFINISHED LIST PATTERN" region [] $
5149 Code.toSnippet source surroundings (Just region) $
5152 "I just saw an open square bracket, but then I got stuck here:"
5155 [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5157 "I can get confused by indentation in cases like this, so\
5158 \ maybe there is something next, but it is not indented enough?"
5162 PListIndentEnd row col ->
5164 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5165 region = toRegion row col
5167 Report.Report "UNFINISHED LIST PATTERN" region [] $
5168 Code.toSnippet source surroundings (Just region) $
5171 "I was expecting a closing square bracket to end this list pattern:"
5174 [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5176 "I can get confused by indentation in cases like this, so\
5177 \ maybe you have a closing square bracket but it is not indented enough?"
5181 PListIndentExpr row col ->
5183 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5184 region = toRegion row col
5186 Report.Report "UNFINISHED LIST PATTERN" region [] $
5187 Code.toSnippet source surroundings (Just region) $
5190 "I am partway through parsing a list pattern, but I got stuck here:"
5194 "I was expecting to see another pattern next. Maybe a variable name."
5196 "I can get confused by indentation in cases like this, so\
5197 \ maybe there is more to this pattern but it is not indented enough?"
5207 = TC_Annotation Name.Name
5213toTypeReport :: Code.Source -> TContext -> Type -> Row -> Col -> Report.Report
5214toTypeReport source context tipe startRow startCol =
5216 TRecord record row col ->
5217 toTRecordReport source context record row col
5219 TTuple tuple row col ->
5220 toTTupleReport source context tuple row col
5223 case Code.whatIsNext source row col of
5224 Code.Keyword keyword ->
5226 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5227 region = toKeywordRegion row col keyword
5229 Report.Report "RESERVED WORD" region [] $
5230 Code.toSnippet source surroundings (Just region)
5233 "I was expecting to see a type next, but I got stuck on this reserved word:"
5236 "It looks like you are trying to use `" ++ keyword ++ "` as a type variable, but \
5237 \ it is a reserved word. Try using a different name!"
5242 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5243 region = toRegion row col
5247 TC_Annotation _ -> "type annotation"
5248 TC_CustomType -> "custom type"
5249 TC_TypeAlias -> "type alias"
5254 TC_Annotation name -> "the `" ++ Name.toChars name ++ "` type annotation"
5255 TC_CustomType -> "a custom type"
5256 TC_TypeAlias -> "a type alias"
5259 Report.Report ("PROBLEM IN " ++ map Char.toUpper thing) region [] $
5260 Code.toSnippet source surroundings (Just region)
5263 "I was partway through parsing " ++ something ++ ", but I got stuck here:"
5266 ["I","was","expecting","to","see","a","type","next."
5267 ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5271 TSpace space row col ->
5272 toSpaceReport source space row col
5274 TIndentStart row col ->
5276 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5277 region = toRegion row col
5281 TC_Annotation _ -> "type annotation"
5282 TC_CustomType -> "custom type"
5283 TC_TypeAlias -> "type alias"
5286 Report.Report ("UNFINISHED " ++ map Char.toUpper thing) region [] $
5287 Code.toSnippet source surroundings (Just region)
5290 "I was partway through parsing a " ++ thing ++ ", but I got stuck here:"
5294 ["I","was","expecting","to","see","a","type","next."
5295 ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5298 "I can get confused by indentation. If you think there is already a type\
5299 \ next, maybe it is not indented enough?"
5304toTRecordReport :: Code.Source -> TContext -> TRecord -> Row -> Col -> Report.Report
5305toTRecordReport source context record startRow startCol =
5307 TRecordOpen row col ->
5308 case Code.whatIsNext source row col of
5309 Code.Keyword keyword ->
5311 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5312 region = toKeywordRegion row col keyword
5314 Report.Report "RESERVED WORD" region [] $
5315 Code.toSnippet source surroundings (Just region)
5318 "I just started parsing a record type, but I got stuck on this field name:"
5321 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
5322 \ that is a reserved word. Try using a different name!"
5327 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5328 region = toRegion row col
5330 Report.Report "UNFINISHED RECORD TYPE" region [] $
5331 Code.toSnippet source surroundings (Just region)
5334 "I just started parsing a record type, but I got stuck here:"
5337 ["Record","types","look","like",D.dullyellow "{ name : String, age : Int },"
5338 ,"so","I","was","expecting","to","see","a","field","name","next."
5342 TRecordEnd row col ->
5344 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5345 region = toRegion row col
5347 Report.Report "UNFINISHED RECORD TYPE" region [] $
5348 Code.toSnippet source surroundings (Just region)
5351 "I am partway through parsing a record type, but I got stuck here:"
5355 ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
5356 ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
5359 "When I get stuck like this, it usually means that there is a missing parenthesis\
5360 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
5364 TRecordField row col ->
5365 case Code.whatIsNext source row col of
5366 Code.Keyword keyword ->
5368 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5369 region = toKeywordRegion row col keyword
5371 Report.Report "RESERVED WORD" region [] $
5372 Code.toSnippet source surroundings (Just region)
5375 "I am partway through parsing a record type, but I got stuck on this field name:"
5378 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
5379 \ that is a reserved word. Try using a different name!"
5382 Code.Other (Just ',') ->
5384 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5385 region = toRegion row col
5387 Report.Report "EXTRA COMMA" region [] $
5388 Code.toSnippet source surroundings (Just region)
5391 "I am partway through parsing a record type, but I got stuck here:"
5395 "I am seeing two commas in a row. This is the second one!"
5397 "Just delete one of the commas and you should be all set!"
5398 , noteForRecordTypeError
5404 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5405 region = toRegion row col
5407 Report.Report "EXTRA COMMA" region [] $
5408 Code.toSnippet source surroundings (Just region)
5411 "I am partway through parsing a record type, but I got stuck here:"
5415 "Trailing commas are not allowed in record types. Try deleting the comma that\
5416 \ appears before this closing curly brace."
5417 , noteForRecordTypeError
5423 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5424 region = toRegion row col
5426 Report.Report "PROBLEM IN RECORD TYPE" region [] $
5427 Code.toSnippet source surroundings (Just region)
5430 "I am partway through parsing a record type, but I got stuck here:"
5434 ["I","was","expecting","to","see","another","record","field","defined","next,"
5435 ,"so","I","am","looking","for","a","name","like"
5436 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
5438 , noteForRecordTypeError
5442 TRecordColon row col ->
5444 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5445 region = toRegion row col
5447 Report.Report "UNFINISHED RECORD TYPE" region [] $
5448 Code.toSnippet source surroundings (Just region)
5451 "I am partway through parsing a record type, but I got stuck here:"
5455 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5456 ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5458 , noteForRecordTypeError
5462 TRecordType tipe row col ->
5463 toTypeReport source context tipe row col
5465 TRecordSpace space row col ->
5466 toSpaceReport source space row col
5468 TRecordIndentOpen row col ->
5470 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5471 region = toRegion row col
5473 Report.Report "UNFINISHED RECORD TYPE" region [] $
5474 Code.toSnippet source surroundings (Just region)
5477 "I just saw the opening curly brace of a record type, but then I got stuck here:"
5481 ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5482 ,"Try","defining","some","fields","of","your","own?"
5484 , noteForRecordTypeIndentError
5488 TRecordIndentEnd row col ->
5489 case Code.nextLineStartsWithCloseCurly source row of
5490 Just (curlyRow, curlyCol) ->
5492 surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
5493 region = toRegion curlyRow curlyCol
5495 Report.Report "NEED MORE INDENTATION" region [] $
5496 Code.toSnippet source surroundings (Just region)
5499 "I was partway through parsing a record type, but I got stuck here:"
5503 "I need this curly brace to be indented more. Try adding some spaces before it!"
5504 , noteForRecordTypeError
5510 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5511 region = toRegion row col
5513 Report.Report "UNFINISHED RECORD TYPE" region [] $
5514 Code.toSnippet source surroundings (Just region)
5517 "I was partway through parsing a record type, but I got stuck here:"
5521 ["I","was","expecting","to","see","a","closing","curly","brace","next."
5522 ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
5524 , noteForRecordTypeIndentError
5528 TRecordIndentField row col ->
5530 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5531 region = toRegion row col
5533 Report.Report "UNFINISHED RECORD TYPE" region [] $
5534 Code.toSnippet source surroundings (Just region)
5537 "I am partway through parsing a record type, but I got stuck after that last comma:"
5541 "Trailing commas are not allowed in record types, so the fix may be to\
5542 \ delete that last comma? Or maybe you were in the middle of defining\
5543 \ an additional field?"
5544 , noteForRecordTypeIndentError
5548 TRecordIndentColon row col ->
5550 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5551 region = toRegion row col
5553 Report.Report "UNFINISHED RECORD TYPE" region [] $
5554 Code.toSnippet source surroundings (Just region)
5557 "I am partway through parsing a record type. I just saw a record\
5558 \ field, so I was expecting to see a colon next:"
5562 ["Try","putting","an",D.green ":","followed","by","a","type?"
5564 , noteForRecordTypeIndentError
5568 TRecordIndentType row col ->
5570 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5571 region = toRegion row col
5573 Report.Report "UNFINISHED RECORD TYPE" region [] $
5574 Code.toSnippet source surroundings (Just region)
5577 "I am partway through parsing a record type, and I was expecting to run into a type next:"
5581 ["Try","putting","something","like"
5582 ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5584 , noteForRecordTypeIndentError
5589noteForRecordTypeError :: D.Doc
5590noteForRecordTypeError =
5593 "If you are trying to define a record type across multiple lines, I recommend using this format:"
5594 , D.indent 4 $ D.vcat $
5597 , ", height : Float"
5601 "Notice that each line starts with some indentation. Usually two or four spaces.\
5602 \ This is the stylistic convention in the Elm ecosystem."
5606noteForRecordTypeIndentError :: D.Doc
5607noteForRecordTypeIndentError =
5610 "I may be confused by indentation. For example, if you are trying to define\
5611 \ a record type across multiple lines, I recommend using this format:"
5612 , D.indent 4 $ D.vcat $
5615 , ", height : Float"
5619 "Notice that each line starts with some indentation. Usually two or four spaces.\
5620 \ This is the stylistic convention in the Elm ecosystem."
5624toTTupleReport :: Code.Source -> TContext -> TTuple -> Row -> Col -> Report.Report
5625toTTupleReport source context tuple startRow startCol =
5627 TTupleOpen row col ->
5628 case Code.whatIsNext source row col of
5629 Code.Keyword keyword ->
5631 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5632 region = toKeywordRegion row col keyword
5634 Report.Report "RESERVED WORD" region [] $
5635 Code.toSnippet source surroundings (Just region)
5638 "I ran into a reserved word unexpectedly:"
5641 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name, but \
5642 \ it is a reserved word. Try using a different name!"
5647 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5648 region = toRegion row col
5650 Report.Report "UNFINISHED PARENTHESES" region [] $
5651 Code.toSnippet source surroundings (Just region)
5654 "I just saw an open parenthesis, so I was expecting to see a type next."
5657 ["Something","like",D.dullyellow "(Maybe Int)","or"
5658 ,D.dullyellow "(List Person)" <> "."
5659 ,"Anything","where","you","are","putting","parentheses","around","normal","types."
5663 TTupleEnd row col ->
5665 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5666 region = toRegion row col
5668 Report.Report "UNFINISHED PARENTHESES" region [] $
5669 Code.toSnippet source surroundings (Just region)
5672 "I was expecting to see a closing parenthesis next, but I got stuck here:"
5675 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
5677 "I can get stuck when I run into keywords, operators, parentheses, or brackets\
5678 \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
5679 \ or missing brackets) that is confusing me."
5683 TTupleType tipe row col ->
5684 toTypeReport source context tipe row col
5686 TTupleSpace space row col ->
5687 toSpaceReport source space row col
5689 TTupleIndentType1 row col ->
5691 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5692 region = toRegion row col
5694 Report.Report "UNFINISHED PARENTHESES" region [] $
5695 Code.toSnippet source surroundings (Just region)
5698 "I just saw an open parenthesis, so I was expecting to see a type next."
5702 ["Something","like",D.dullyellow "(Maybe Int)","or"
5703 ,D.dullyellow "(List Person)" <> "."
5704 ,"Anything","where","you","are","putting","parentheses","around","normal","types."
5707 "I can get confused by indentation in cases like this, so\
5708 \ maybe you have a type but it is not indented enough?"
5712 TTupleIndentTypeN row col ->
5714 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5715 region = toRegion row col
5717 Report.Report "UNFINISHED TUPLE TYPE" region [] $
5718 Code.toSnippet source surroundings (Just region)
5721 "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."
5725 ["A","tuple","type","looks","like",D.dullyellow "(Float,Float)","or"
5726 ,D.dullyellow "(String,Int)" <> ","
5727 ,"so","I","think","there","is","a","type","missing","here?"
5730 "I can get confused by indentation in cases like this, so\
5731 \ maybe you have an expression but it is not indented enough?"
5735 TTupleIndentEnd row col ->
5737 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5738 region = toRegion row col
5740 Report.Report "UNFINISHED PARENTHESES" region [] $
5741 Code.toSnippet source surroundings (Just region)
5744 "I was expecting to see a closing parenthesis next:"
5747 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
5749 "I can get confused by indentation in cases like this, so\
5750 \ 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