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 (like code that runs side-effects on install) and that you\
630 \ are not going to get any runtime exceptions coming from your new dependency.\
631 \ This design also sets the Elm ecosystem up well to target other platforms (like\
632 \ mobile phones, WebAssembly, etc.) since no community code explicitly depends on\
633 \ JavaScript even existing."
635 "Given that overall goal, allowing ports in packages would lead to some pretty\
636 \ surprising behavior. If ports were allowed in packages, you could install a\
637 \ package but not realize that it brings in an indirect dependency that defines a\
638 \ port. Now you have a program that does not work and the fix is to realize that\
639 \ some JavaScript needs to be added. That would be extremely frustrating! So why\
640 \ not allow the package author to include the necessary JS code as well? Now we\
641 \ are back in conflict with our goals for the ecosystem overall."
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 "UNFINISHED RECORD" region [] $
3901 Code.toSnippet source surroundings (Just region)
3904 "I just started parsing a record, but I got stuck here:"
3907 ["Records","look","like",D.dullyellow "{ x = 3, y = 4 },"
3908 ,"so","I","was","expecting","to","see","a","field","name","next."
3912 RecordEnd row col ->
3914 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3915 region = toRegion row col
3917 Report.Report "UNFINISHED RECORD" region [] $
3918 Code.toSnippet source surroundings (Just region)
3921 "I am partway through parsing a record, but I got stuck here:"
3925 ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
3926 ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
3929 "When I get stuck like this, it usually means that there is a missing parenthesis\
3930 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
3934 RecordField row col ->
3935 case Code.whatIsNext source row col of
3936 Code.Keyword keyword ->
3938 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3939 region = toKeywordRegion row col keyword
3941 Report.Report "RESERVED WORD" region [] $
3942 Code.toSnippet source surroundings (Just region)
3945 "I am partway through parsing a record, but I got stuck on this field name:"
3948 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3949 \ that is a reserved word. Try using a different name!"
3952 Code.Other (Just ',') ->
3954 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3955 region = toRegion row col
3957 Report.Report "EXTRA COMMA" region [] $
3958 Code.toSnippet source surroundings (Just region)
3961 "I am partway through parsing a record, but I got stuck here:"
3965 "I am seeing two commas in a row. This is the second one!"
3967 "Just delete one of the commas and you should be all set!"
3968 , noteForRecordError
3974 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3975 region = toRegion row col
3977 Report.Report "EXTRA COMMA" region [] $
3978 Code.toSnippet source surroundings (Just region)
3981 "I am partway through parsing a record, but I got stuck here:"
3985 "Trailing commas are not allowed in records. Try deleting the comma that appears\
3986 \ before this closing curly brace."
3987 , noteForRecordError
3993 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3994 region = toRegion row col
3996 Report.Report "PROBLEM IN RECORD" region [] $
3997 Code.toSnippet source surroundings (Just region)
4000 "I am partway through parsing a record, but I got stuck here:"
4004 ["I","was","expecting","to","see","another","record","field","defined","next,"
4005 ,"so","I","am","looking","for","a","lower-case","name","like"
4006 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
4008 , noteForRecordError
4012 RecordEquals row col ->
4014 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4015 region = toRegion row col
4017 Report.Report "UNFINISHED RECORD" region [] $
4018 Code.toSnippet source surroundings (Just region)
4021 "I am partway through parsing a record, but I got stuck here:"
4025 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
4026 ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign","here?"
4028 , noteForRecordError
4032 RecordExpr expr row col ->
4033 toExprReport source (InNode NRecord startRow startCol context) expr row col
4035 RecordSpace space row col ->
4036 toSpaceReport source space row col
4038 RecordIndentOpen row col ->
4040 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4041 region = toRegion row col
4043 Report.Report "UNFINISHED RECORD" region [] $
4044 Code.toSnippet source surroundings (Just region)
4047 "I just saw the opening curly brace of a record, but then I got stuck here:"
4049 addNoteForRecordIndentError $
4051 ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
4052 ,"Try","defining","some","fields","of","your","own?"
4056 RecordIndentEnd row col ->
4057 case Code.nextLineStartsWithCloseCurly source row of
4058 Just (curlyRow, curlyCol) ->
4060 surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
4061 region = toRegion curlyRow curlyCol
4063 Report.Report "NEED MORE INDENTATION" region [] $
4064 Code.toSnippet source surroundings (Just region)
4067 "I was partway through parsing a record, but I got stuck here:"
4071 "I need this curly brace to be indented more. Try adding some spaces before it!"
4072 , noteForRecordError
4078 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4079 region = toRegion row col
4081 Report.Report "UNFINISHED RECORD" region [] $
4082 Code.toSnippet source surroundings (Just region)
4085 "I was partway through parsing a record, but I got stuck here:"
4087 addNoteForRecordIndentError $
4089 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4090 ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
4094 RecordIndentField row col ->
4096 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4097 region = toRegion row col
4099 Report.Report "UNFINISHED RECORD" region [] $
4100 Code.toSnippet source surroundings (Just region)
4103 "I am partway through parsing a record, but I got stuck after that last comma:"
4107 "Trailing commas are not allowed in records, so the fix may be to\
4108 \ delete that last comma? Or maybe you were in the middle of defining\
4109 \ an additional field?"
4110 , noteForRecordError
4114 RecordIndentEquals row col ->
4116 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4117 region = toRegion row col
4119 Report.Report "UNFINISHED RECORD" region [] $
4120 Code.toSnippet source surroundings (Just region)
4123 "I am partway through parsing a record. I just saw a record\
4124 \ field, so I was expecting to see an equals sign next:"
4126 addNoteForRecordIndentError $
4128 ["Try","putting","an",D.green "=","followed","by","an","expression?"
4132 RecordIndentExpr row col ->
4134 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4135 region = toRegion row col
4137 Report.Report "UNFINISHED RECORD" region [] $
4138 Code.toSnippet source surroundings (Just region)
4141 "I am partway through parsing a record, and I was expecting to run into an expression next:"
4143 addNoteForRecordIndentError $
4145 ["Try","putting","something","like"
4146 ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
4151noteForRecordError :: D.Doc
4155 "If you are trying to define a record across multiple lines, I recommend using this format:"
4156 , D.indent 4 $ D.vcat $
4157 [ "{ name = \"Alice\""
4163 "Notice that each line starts with some indentation. Usually two or four spaces. I\
4164 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
4165 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4169addNoteForRecordIndentError :: D.Doc -> D.Doc
4170addNoteForRecordIndentError normalRecommendation =
4172 normalRecommendation
4175 "I may be confused by indentation. For example, if you are trying to define\
4176 \ a record across multiple lines, I recommend using this format:"
4177 , D.indent 4 $ D.vcat $
4178 [ "{ name = \"Alice\""
4184 "Notice that each line starts with some indentation. Usually two or four spaces. I\
4185 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
4186 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4194toTupleReport :: Code.Source -> Context -> Tuple -> Row -> Col -> Report.Report
4195toTupleReport source context tuple startRow startCol =
4197 TupleExpr expr row col ->
4198 toExprReport source (InNode NParens startRow startCol context) expr row col
4200 TupleSpace space row col ->
4201 toSpaceReport source space row col
4205 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4206 region = toRegion row col
4208 Report.Report "UNFINISHED PARENTHESES" region [] $
4209 Code.toSnippet source surroundings (Just region)
4212 "I was expecting to see a closing parentheses next, but I got stuck here:"
4215 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
4217 "I can get stuck when I run into keywords, operators, parentheses, or brackets\
4218 \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
4219 \ or missing brackets) that is confusing me."
4223 TupleOperatorClose row col ->
4225 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4226 region = toRegion row col
4228 Report.Report "UNFINISHED OPERATOR FUNCTION" region [] $
4229 Code.toSnippet source surroundings (Just region)
4231 D.reflow "I was expecting a closing parenthesis here:"
4234 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
4236 "I think I am parsing an operator function right now, so I am expecting to see\
4237 \ something like (+) or (&&) where an operator is surrounded by parentheses with\
4242 TupleOperatorReserved operator row col ->
4244 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4245 region = toRegion row col
4247 Report.Report "UNEXPECTED SYMBOL" region [] $
4248 Code.toSnippet source surroundings (Just region)
4251 "I ran into an unexpected symbol here:"
4255 BadDot -> ["Maybe","you","wanted","a","record","accessor","like",D.dullyellow ".x","or",D.dullyellow ".name","instead?"]
4256 BadPipe -> ["Try",D.dullyellow "(||)","instead?","To","turn","boolean","OR","into","a","function?"]
4257 BadArrow -> ["Maybe","you","wanted",D.dullyellow "(>)","or",D.dullyellow "(>=)","instead?"]
4258 BadEquals -> ["Try",D.dullyellow "(==)","instead?","To","make","a","function","that","checks","equality?"]
4259 BadHasType -> ["Try",D.dullyellow "(::)","instead?","To","add","values","to","the","front","of","lists?"]
4262 TupleIndentExpr1 row col ->
4264 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4265 region = toRegion row col
4267 Report.Report "UNFINISHED PARENTHESES" region [] $
4268 Code.toSnippet source surroundings (Just region)
4271 "I just saw an open parenthesis, so I was expecting to see an expression next."
4275 ["Something","like",D.dullyellow "(4 + 5)","or"
4276 ,D.dullyellow "(String.reverse \"desserts\")" <> "."
4277 ,"Anything","where","you","are","putting","parentheses","around","normal","expressions."
4280 "I can get confused by indentation in cases like this, so\
4281 \ maybe you have an expression but it is not indented enough?"
4285 TupleIndentExprN row col ->
4287 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4288 region = toRegion row col
4290 Report.Report "UNFINISHED TUPLE" region [] $
4291 Code.toSnippet source surroundings (Just region)
4294 "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."
4298 ["A","tuple","looks","like",D.dullyellow "(3,4)","or"
4299 ,D.dullyellow "(\"Tom\",42)" <> ","
4300 ,"so","I","think","there","is","an","expression","missing","here?"
4303 "I can get confused by indentation in cases like this, so\
4304 \ maybe you have an expression but it is not indented enough?"
4308 TupleIndentEnd row col ->
4310 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4311 region = toRegion row col
4313 Report.Report "UNFINISHED PARENTHESES" region [] $
4314 Code.toSnippet source surroundings (Just region)
4317 "I was expecting to see a closing parenthesis next:"
4320 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
4322 "I can get confused by indentation in cases like this, so\
4323 \ maybe you have a closing parenthesis but it is not indented enough?"
4328toListReport :: Code.Source -> Context -> List -> Row -> Col -> Report.Report
4329toListReport source context list startRow startCol =
4331 ListSpace space row col ->
4332 toSpaceReport source space row col
4336 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4337 region = toRegion row col
4339 Report.Report "UNFINISHED LIST" region [] $
4340 Code.toSnippet source surroundings (Just region)
4343 "I am partway through parsing a list, but I got stuck here:"
4347 ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
4348 ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
4351 "When I get stuck like this, it usually means that there is a missing parenthesis\
4352 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
4356 ListExpr expr row col ->
4360 surroundings = A.Region (A.Position startRow startCol) (A.Position r c)
4361 region = toRegion r c
4363 Report.Report "UNFINISHED LIST" region [] $
4364 Code.toSnippet source surroundings (Just region)
4367 "I was expecting to see another list entry after that last comma:"
4371 "Trailing commas are not allowed in lists, so the fix may be to delete the comma?"
4373 "I recommend using the following format for lists that span multiple lines:"
4374 , D.indent 4 $ D.vcat $
4381 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4382 \ This style can be jarring for people coming from C-like syntax, but folks generally\
4383 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4388 toExprReport source (InNode NList startRow startCol context) expr row col
4392 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4393 region = toRegion row col
4395 Report.Report "UNFINISHED LIST" region [] $
4396 Code.toSnippet source surroundings (Just region)
4399 "I am partway through parsing a list, but I got stuck here:"
4403 ["I","was","expecting","to","see","a","closing","square","bracket","before","this,"
4404 ,"so","try","adding","a",D.dullyellow "]","and","see","if","that","helps?"
4407 "When I get stuck like this, it usually means that there is a missing parenthesis\
4408 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
4412 ListIndentOpen row col ->
4414 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4415 region = toRegion row col
4417 Report.Report "UNFINISHED LIST" region [] $
4418 Code.toSnippet source surroundings (Just region)
4421 "I cannot find the end of this list:"
4425 ["You","could","change","it","to","something","like"
4426 ,D.dullyellow "[3,4,5]"
4428 ,D.dullyellow "[]" <> "."
4429 ,"Anything","where","there","is","an","open","and","close","square","brace,"
4430 ,"and","where","the","elements","of","the","list","are","separated","by","commas."
4433 "I may be confused by indentation. For example, if you are trying to define\
4434 \ a list across multiple lines, I recommend using this format:"
4435 , D.indent 4 $ D.vcat $
4442 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4443 \ This style can be jarring for people coming from C-like syntax, but folks generally\
4444 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4448 ListIndentEnd row col ->
4450 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4451 region = toRegion row col
4453 Report.Report "UNFINISHED LIST" region [] $
4454 Code.toSnippet source surroundings (Just region)
4457 "I cannot find the end of this list:"
4461 ["You","can","just","add","a","closing",D.dullyellow "]"
4462 ,"right","here,","and","I","will","be","all","set!"
4465 "I may be confused by indentation. For example, if you are trying to define\
4466 \ a list across multiple lines, I recommend using this format:"
4467 , D.indent 4 $ D.vcat $
4474 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4475 \ This style can be jarring for people coming from C-like syntax, but folks generally\
4476 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4480 ListIndentExpr row col ->
4482 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4483 region = toRegion row col
4485 Report.Report "UNFINISHED LIST" region [] $
4486 Code.toSnippet source surroundings (Just region)
4489 "I was expecting to see another list entry after this comma:"
4493 "Trailing commas are not allowed in lists, so the fix may be to delete the comma?"
4495 "I recommend using the following format for lists that span multiple lines:"
4496 , D.indent 4 $ D.vcat $
4503 "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
4504 \ This style can be jarring for people coming from C-like syntax, but folks generally\
4505 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
4510toFuncReport :: Code.Source -> Context -> Func -> Row -> Col -> Report.Report
4511toFuncReport source context func startRow startCol =
4513 FuncSpace space row col ->
4514 toSpaceReport source space row col
4516 FuncArg pattern row col ->
4517 toPatternReport source PArg pattern row col
4519 FuncBody expr row col ->
4520 toExprReport source (InNode NFunc startRow startCol context) expr row col
4522 FuncArrow row col ->
4523 case Code.whatIsNext source row col of
4524 Code.Keyword keyword ->
4526 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4527 region = toKeywordRegion row col keyword
4529 Report.Report "RESERVED WORD" region [] $
4530 Code.toSnippet source surroundings (Just region)
4533 "I was parsing an anonymous function, but I got stuck here:"
4536 "It looks like you are trying to use `" ++ keyword ++ "` as an argument, but\
4537 \ it is a reserved word in this language. Try using a different argument name!"
4542 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4543 region = toRegion row col
4545 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4546 Code.toSnippet source surroundings (Just region)
4549 "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
4552 ["The","syntax","for","anonymous","functions","is"
4553 ,D.dullyellow "(\\x -> x + 1)"
4554 ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
4558 FuncIndentArg row col ->
4560 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4561 region = toRegion row col
4563 Report.Report "MISSING ARGUMENT" region [] $
4564 Code.toSnippet source surroundings (Just region)
4567 "I just saw the beginning of an anonymous function, so I was expecting to see an argument next:"
4571 ["Something","like",D.dullyellow"x","or",D.dullyellow "name" <> "."
4572 ,"Anything","that","starts","with","a","lower","case","letter!"
4575 "The syntax for anonymous functions is (\\x -> x + 1) where the backslash\
4576 \ is meant to look a bit like a lambda if you squint. This visual pun seemed\
4577 \ like a better idea at the time!"
4581 FuncIndentArrow row col ->
4583 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4584 region = toRegion row col
4586 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4587 Code.toSnippet source surroundings (Just region)
4590 "I just saw the beginning of an anonymous function, so I was expecting to see an arrow next:"
4594 ["The","syntax","for","anonymous","functions","is"
4595 ,D.dullyellow "(\\x -> x + 1)"
4596 ,"so","I","am","missing","the","arrow","and","the","body","of","the","function."
4599 "It is possible that I am confused about indetation! I generally recommend\
4600 \ switching to named functions if the definition cannot fit inline nicely, so\
4601 \ either (1) try to fit the whole anonymous function on one line or (2) break\
4602 \ the whole thing out into a named function. Things tend to be clearer that way!"
4606 FuncIndentBody row col ->
4608 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4609 region = toRegion row col
4611 Report.Report "UNFINISHED ANONYMOUS FUNCTION" region [] $
4612 Code.toSnippet source surroundings (Just region)
4615 "I was expecting to see the body of your anonymous function next:"
4619 ["The","syntax","for","anonymous","functions","is"
4620 ,D.dullyellow "(\\x -> x + 1)"
4621 ,"so","I","am","missing","all","the","stuff","after","the","arrow!"
4624 "It is possible that I am confused about indetation! I generally recommend\
4625 \ switching to named functions if the definition cannot fit inline nicely, so\
4626 \ either (1) try to fit the whole anonymous function on one line or (2) break\
4627 \ the whole thing out into a named function. Things tend to be clearer that way!"
4642toPatternReport :: Code.Source -> PContext -> Pattern -> Row -> Col -> Report.Report
4643toPatternReport source context pattern startRow startCol =
4645 PRecord record row col ->
4646 toPRecordReport source record row col
4648 PTuple tuple row col ->
4649 toPTupleReport source context tuple row col
4651 PList list row col ->
4652 toPListReport source context list row col
4655 case Code.whatIsNext source row col of
4656 Code.Keyword keyword ->
4658 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4659 region = toKeywordRegion row col keyword
4662 PArg -> "as an argument"
4663 PCase -> "in this pattern"
4664 PLet -> "in this pattern"
4666 Report.Report "RESERVED WORD" region [] $
4667 Code.toSnippet source surroundings (Just region)
4670 "It looks like you are trying to use `" ++ keyword ++ "` " ++ inThisThing ++ ":"
4673 "This is a reserved word! Try using some other name?"
4676 Code.Operator "-" ->
4678 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4679 region = toRegion row col
4681 Report.Report "UNEXPECTED SYMBOL" region [] $
4682 Code.toSnippet source surroundings (Just region)
4685 "I ran into a minus sign unexpectedly in this pattern:"
4688 "It is not possible to pattern match on negative numbers at this\
4689 \ time. Try using an `if` expression for that sort of thing for now."
4694 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4695 region = toRegion row col
4697 Report.Report "PROBLEM IN PATTERN" region [] $
4698 Code.toSnippet source surroundings (Just region)
4701 "I wanted to parse a pattern next, but I got stuck here:"
4704 ["I","am","not","sure","why","I","am","getting","stuck","exactly."
4705 ,"I","just","know","that","I","want","a","pattern","next."
4706 ,"Something","as","simple","as"
4707 ,D.dullyellow "maybeHeight","or",D.dullyellow "result"
4712 PChar char row col ->
4713 toCharReport source char row col
4715 PString string row col ->
4716 toStringReport source string row col
4718 PNumber number row col ->
4719 toNumberReport source number row col
4721 PFloat width row col ->
4723 region = toWiderRegion row col width
4725 Report.Report "UNEXPECTED PATTERN" region [] $
4726 Code.toSnippet source region Nothing
4729 "I cannot pattern match with floating point numbers:"
4732 ["Equality","on","floats","can","be","unreliable,","so","you","usually","want"
4733 ,"to","check","that","they","are","nearby","with","some","sort","of"
4734 ,D.dullyellow "(abs (actual - expected) < 0.001)","check."
4740 region = toRegion row col
4742 Report.Report "UNFINISHED PATTERN" region [] $
4743 Code.toSnippet source region Nothing $
4746 "I was expecting to see a variable name after the `as` keyword:"
4750 ["The","`as`","keyword","lets","you","write","patterns","like"
4751 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4752 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4753 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4754 ,"thing","with",D.dullyellow "point" <> "."
4757 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
4758 \ people just want to use `as` as a variable name though. Try using a different name\
4763 PWildcardNotVar name width row col ->
4765 region = toWiderRegion row col (fromIntegral width)
4767 case dropWhile (=='_') (Name.toChars name) of
4768 [] -> [D.dullyellow "x","or",D.dullyellow "age"]
4769 c:cs -> [D.dullyellow (D.fromChars (Char.toLower c : cs))]
4771 Report.Report "UNEXPECTED NAME" region [] $
4772 Code.toSnippet source region Nothing $
4775 "Variable names cannot start with underscores like this:"
4778 ["You","can","either","have","an","underscore","like",D.dullyellow "_","to"
4779 ,"ignore","the","value,","or","you","can","have","a","name","like"
4780 ] ++ examples ++ ["to","use","the","matched","value." ]
4783 PSpace space row col ->
4784 toSpaceReport source space row col
4786 PIndentStart row col ->
4788 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4789 region = toRegion row col
4791 Report.Report "UNFINISHED PATTERN" region [] $
4792 Code.toSnippet source surroundings (Just region)
4795 "I wanted to parse a pattern next, but I got stuck here:"
4799 ["I","am","not","sure","why","I","am","getting","stuck","exactly."
4800 ,"I","just","know","that","I","want","a","pattern","next."
4801 ,"Something","as","simple","as"
4802 ,D.dullyellow "maybeHeight","or",D.dullyellow "result"
4806 "I can get confused by indentation. If you think there is a pattern next, maybe\
4807 \ it needs to be indented a bit more?"
4811 PIndentAlias row col ->
4813 region = toRegion row col
4815 Report.Report "UNFINISHED PATTERN" region [] $
4816 Code.toSnippet source region Nothing $
4819 "I was expecting to see a variable name after the `as` keyword:"
4823 ["The","`as`","keyword","lets","you","write","patterns","like"
4824 ,"((" <> D.dullyellow "x" <> "," <> D.dullyellow "y" <> ") " <> D.cyan "as" <> D.dullyellow " point" <> ")"
4825 ,"so","you","can","refer","to","individual","parts","of","the","tuple","with"
4826 ,D.dullyellow "x","and",D.dullyellow "y","or","you","refer","to","the","whole"
4827 ,"thing","with",D.dullyellow "point."
4830 "So I was expecting to see a variable name after the `as` keyword here. Sometimes\
4831 \ people just want to use `as` as a variable name though. Try using a different name\
4837toPRecordReport :: Code.Source -> PRecord -> Row -> Col -> Report.Report
4838toPRecordReport source record startRow startCol =
4840 PRecordOpen row col ->
4841 toUnfinishRecordPatternReport source row col startRow startCol $
4842 D.reflow "I was expecting to see a field name next."
4844 PRecordEnd row col ->
4845 toUnfinishRecordPatternReport source row col startRow startCol $
4847 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4848 ,"Try","adding","a",D.dullyellow "}","here?"
4851 PRecordField row col ->
4852 case Code.whatIsNext source row col of
4853 Code.Keyword keyword ->
4855 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4856 region = toKeywordRegion row col keyword
4858 Report.Report "RESERVED WORD" region [] $
4859 Code.toSnippet source surroundings (Just region)
4862 "I was not expecting to see `" ++ keyword ++ "` as a record field name:"
4865 "This is a reserved word, not available for variable names. Try another name!"
4869 toUnfinishRecordPatternReport source row col startRow startCol $
4870 D.reflow "I was expecting to see a field name next."
4872 PRecordSpace space row col ->
4873 toSpaceReport source space row col
4875 PRecordIndentOpen row col ->
4876 toUnfinishRecordPatternReport source row col startRow startCol $
4877 D.reflow "I was expecting to see a field name next."
4879 PRecordIndentEnd row col ->
4880 toUnfinishRecordPatternReport source row col startRow startCol $
4882 ["I","was","expecting","to","see","a","closing","curly","brace","next."
4883 ,"Try","adding","a",D.dullyellow "}","here?"
4886 PRecordIndentField row col ->
4887 toUnfinishRecordPatternReport source row col startRow startCol $
4888 D.reflow "I was expecting to see a field name next."
4891toUnfinishRecordPatternReport :: Code.Source -> Row -> Col -> Row -> Col -> D.Doc -> Report.Report
4892toUnfinishRecordPatternReport source row col startRow startCol message =
4894 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4895 region = toRegion row col
4897 Report.Report "UNFINISHED RECORD PATTERN" region [] $
4898 Code.toSnippet source surroundings (Just region)
4901 "I was partway through parsing a record pattern, but I got stuck here:"
4906 ["A","record","pattern","looks","like",D.dullyellow "{x,y}","or",D.dullyellow "{name,age}"
4907 ,"where","you","list","the","field","names","you","want","to","access."
4914toPTupleReport :: Code.Source -> PContext -> PTuple -> Row -> Col -> Report.Report
4915toPTupleReport source context tuple startRow startCol =
4917 PTupleOpen row col ->
4918 case Code.whatIsNext source row col of
4919 Code.Keyword keyword ->
4921 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4922 region = toKeywordRegion row col keyword
4924 Report.Report "RESERVED WORD" region [] $
4925 Code.toSnippet source surroundings (Just region)
4928 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name:"
4931 "This is a reserved word! Try using some other name?"
4936 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4937 region = toRegion row col
4939 Report.Report "UNFINISHED PARENTHESES" region [] $
4940 Code.toSnippet source surroundings (Just region)
4943 "I just saw an open parenthesis, but I got stuck here:"
4946 ["I","was","expecting","to","see","a","pattern","next."
4947 ,"Maybe","it","will","end","up","being","something"
4948 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
4952 PTupleEnd row col ->
4953 case Code.whatIsNext source row col of
4954 Code.Keyword keyword ->
4956 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4957 region = toKeywordRegion row col keyword
4959 Report.Report "RESERVED WORD" region [] $
4960 Code.toSnippet source surroundings (Just region) $
4963 "I ran into a reserved word in this pattern:"
4966 "The `" ++ keyword ++ "` keyword is reserved. Try using a different name instead!"
4971 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4972 region = toKeywordRegion row col op
4974 Report.Report "UNEXPECTED SYMBOL" region [] $
4975 Code.toSnippet source surroundings (Just region) $
4978 "I ran into the " ++ op ++ " symbol unexpectedly in this pattern:"
4981 "Only the :: symbol that works in patterns. It is useful if you\
4982 \ are pattern matching on lists, trying to get the first element\
4983 \ off the front. Did you want that instead?"
4986 Code.Close term bracket ->
4988 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
4989 region = toRegion row col
4991 Report.Report ("STRAY " ++ map Char.toUpper term) region [] $
4992 Code.toSnippet source surroundings (Just region) $
4995 "I ran into a an unexpected " ++ term ++ " in this pattern:"
4998 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
5003 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5004 region = toRegion row col
5006 Report.Report "UNFINISHED PARENTHESES" region [] $
5007 Code.toSnippet source surroundings (Just region) $
5010 "I was partway through parsing a pattern, but I got stuck here:"
5013 ["I","was","expecting","a","closing","parenthesis","next,","so"
5014 ,"try","adding","a",D.dullyellow ")","to","see","if","that","helps?"
5018 PTupleExpr pattern row col ->
5019 toPatternReport source context pattern row col
5021 PTupleSpace space row col ->
5022 toSpaceReport source space row col
5024 PTupleIndentEnd row col ->
5026 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5027 region = toRegion row col
5029 Report.Report "UNFINISHED PARENTHESES" region [] $
5030 Code.toSnippet source surroundings (Just region) $
5033 "I was expecting a closing parenthesis next:"
5036 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
5038 "I can get confused by indentation in cases like this, so\
5039 \ maybe you have a closing parenthesis but it is not indented enough?"
5043 PTupleIndentExpr1 row col ->
5045 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5046 region = toRegion row col
5048 Report.Report "UNFINISHED PARENTHESES" region [] $
5049 Code.toSnippet source surroundings (Just region) $
5052 "I just saw an open parenthesis, but then I got stuck here:"
5055 ["I","was","expecting","to","see","a","pattern","next."
5056 ,"Maybe","it","will","end","up","being","something"
5057 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "?"
5061 PTupleIndentExprN row col ->
5063 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5064 region = toRegion row col
5066 Report.Report "UNFINISHED TUPLE PATTERN" region [] $
5067 Code.toSnippet source surroundings (Just region) $
5070 "I am partway through parsing a tuple pattern, but I got stuck here:"
5074 ["I","was","expecting","to","see","a","pattern","next."
5075 ,"I","am","expecting","the","final","result","to","be","something"
5076 ,"like",D.dullyellow "(x,y)","or",D.dullyellow "(name, _)" <> "."
5079 "I can get confused by indentation in cases like this, so the problem\
5080 \ may be that the next part is not indented enough?"
5085toPListReport :: Code.Source -> PContext -> PList -> Row -> Col -> Report.Report
5086toPListReport source context list startRow startCol =
5088 PListOpen row col ->
5089 case Code.whatIsNext source row col of
5090 Code.Keyword keyword ->
5092 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5093 region = toKeywordRegion row col keyword
5095 Report.Report "RESERVED WORD" region [] $
5096 Code.toSnippet source surroundings (Just region)
5099 "It looks like you are trying to use `" ++ keyword ++ "` to name an element of a list:"
5102 "This is a reserved word though! Try using some other name?"
5107 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5108 region = toRegion row col
5110 Report.Report "UNFINISHED LIST PATTERN" region [] $
5111 Code.toSnippet source surroundings (Just region) $
5114 "I just saw an open square bracket, but then I got stuck here:"
5116 D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5121 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5122 region = toRegion row col
5124 Report.Report "UNFINISHED LIST PATTERN" region [] $
5125 Code.toSnippet source surroundings (Just region) $
5128 "I was expecting a closing square bracket to end this list pattern:"
5130 D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5133 PListExpr pattern row col ->
5134 toPatternReport source context pattern row col
5136 PListSpace space row col ->
5137 toSpaceReport source space row col
5139 PListIndentOpen row col ->
5141 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5142 region = toRegion row col
5144 Report.Report "UNFINISHED LIST PATTERN" region [] $
5145 Code.toSnippet source surroundings (Just region) $
5148 "I just saw an open square bracket, but then I got stuck here:"
5151 [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5153 "I can get confused by indentation in cases like this, so\
5154 \ maybe there is something next, but it is not indented enough?"
5158 PListIndentEnd row col ->
5160 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5161 region = toRegion row col
5163 Report.Report "UNFINISHED LIST PATTERN" region [] $
5164 Code.toSnippet source surroundings (Just region) $
5167 "I was expecting a closing square bracket to end this list pattern:"
5170 [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
5172 "I can get confused by indentation in cases like this, so\
5173 \ maybe you have a closing square bracket but it is not indented enough?"
5177 PListIndentExpr row col ->
5179 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5180 region = toRegion row col
5182 Report.Report "UNFINISHED LIST PATTERN" region [] $
5183 Code.toSnippet source surroundings (Just region) $
5186 "I am partway through parsing a list pattern, but I got stuck here:"
5190 "I was expecting to see another pattern next. Maybe a variable name."
5192 "I can get confused by indentation in cases like this, so\
5193 \ maybe there is more to this pattern but it is not indented enough?"
5203 = TC_Annotation Name.Name
5209toTypeReport :: Code.Source -> TContext -> Type -> Row -> Col -> Report.Report
5210toTypeReport source context tipe startRow startCol =
5212 TRecord record row col ->
5213 toTRecordReport source context record row col
5215 TTuple tuple row col ->
5216 toTTupleReport source context tuple row col
5219 case Code.whatIsNext source row col of
5220 Code.Keyword keyword ->
5222 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5223 region = toKeywordRegion row col keyword
5225 Report.Report "RESERVED WORD" region [] $
5226 Code.toSnippet source surroundings (Just region)
5229 "I was expecting to see a type next, but I got stuck on this reserved word:"
5232 "It looks like you are trying to use `" ++ keyword ++ "` as a type variable, but \
5233 \ it is a reserved word. Try using a different name!"
5238 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5239 region = toRegion row col
5243 TC_Annotation _ -> "type annotation"
5244 TC_CustomType -> "custom type"
5245 TC_TypeAlias -> "type alias"
5250 TC_Annotation name -> "the `" ++ Name.toChars name ++ "` type annotation"
5251 TC_CustomType -> "a custom type"
5252 TC_TypeAlias -> "a type alias"
5255 Report.Report ("PROBLEM IN " ++ map Char.toUpper thing) region [] $
5256 Code.toSnippet source surroundings (Just region)
5259 "I was partway through parsing " ++ something ++ ", but I got stuck here:"
5262 ["I","was","expecting","to","see","a","type","next."
5263 ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5267 TSpace space row col ->
5268 toSpaceReport source space row col
5270 TIndentStart row col ->
5272 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5273 region = toRegion row col
5277 TC_Annotation _ -> "type annotation"
5278 TC_CustomType -> "custom type"
5279 TC_TypeAlias -> "type alias"
5282 Report.Report ("UNFINISHED " ++ map Char.toUpper thing) region [] $
5283 Code.toSnippet source surroundings (Just region)
5286 "I was partway through parsing a " ++ thing ++ ", but I got stuck here:"
5290 ["I","was","expecting","to","see","a","type","next."
5291 ,"Try","putting",D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5294 "I can get confused by indentation. If you think there is already a type\
5295 \ next, maybe it is not indented enough?"
5300toTRecordReport :: Code.Source -> TContext -> TRecord -> Row -> Col -> Report.Report
5301toTRecordReport source context record startRow startCol =
5303 TRecordOpen row col ->
5304 case Code.whatIsNext source row col of
5305 Code.Keyword keyword ->
5307 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5308 region = toKeywordRegion row col keyword
5310 Report.Report "RESERVED WORD" region [] $
5311 Code.toSnippet source surroundings (Just region)
5314 "I just started parsing a record type, but I got stuck on this field name:"
5317 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
5318 \ that is a reserved word. Try using a different name!"
5323 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5324 region = toRegion row col
5326 Report.Report "UNFINISHED RECORD TYPE" region [] $
5327 Code.toSnippet source surroundings (Just region)
5330 "I just started parsing a record type, but I got stuck here:"
5333 ["Record","types","look","like",D.dullyellow "{ name : String, age : Int },"
5334 ,"so","I","was","expecting","to","see","a","field","name","next."
5338 TRecordEnd row col ->
5340 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5341 region = toRegion row col
5343 Report.Report "UNFINISHED RECORD TYPE" region [] $
5344 Code.toSnippet source surroundings (Just region)
5347 "I am partway through parsing a record type, but I got stuck here:"
5351 ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
5352 ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
5355 "When I get stuck like this, it usually means that there is a missing parenthesis\
5356 \ or bracket somewhere earlier. It could also be a stray keyword or operator."
5360 TRecordField row col ->
5361 case Code.whatIsNext source row col of
5362 Code.Keyword keyword ->
5364 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5365 region = toKeywordRegion row col keyword
5367 Report.Report "RESERVED WORD" region [] $
5368 Code.toSnippet source surroundings (Just region)
5371 "I am partway through parsing a record type, but I got stuck on this field name:"
5374 "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
5375 \ that is a reserved word. Try using a different name!"
5378 Code.Other (Just ',') ->
5380 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5381 region = toRegion row col
5383 Report.Report "EXTRA COMMA" region [] $
5384 Code.toSnippet source surroundings (Just region)
5387 "I am partway through parsing a record type, but I got stuck here:"
5391 "I am seeing two commas in a row. This is the second one!"
5393 "Just delete one of the commas and you should be all set!"
5394 , noteForRecordTypeError
5400 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5401 region = toRegion row col
5403 Report.Report "EXTRA COMMA" region [] $
5404 Code.toSnippet source surroundings (Just region)
5407 "I am partway through parsing a record type, but I got stuck here:"
5411 "Trailing commas are not allowed in record types. Try deleting the comma that\
5412 \ appears before this closing curly brace."
5413 , noteForRecordTypeError
5419 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5420 region = toRegion row col
5422 Report.Report "PROBLEM IN RECORD TYPE" region [] $
5423 Code.toSnippet source surroundings (Just region)
5426 "I am partway through parsing a record type, but I got stuck here:"
5430 ["I","was","expecting","to","see","another","record","field","defined","next,"
5431 ,"so","I","am","looking","for","a","lower-case","name","like"
5432 ,D.dullyellow "userName","or",D.dullyellow "plantHeight" <> "."
5434 , noteForRecordTypeError
5438 TRecordColon row col ->
5440 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5441 region = toRegion row col
5443 Report.Report "UNFINISHED RECORD TYPE" region [] $
5444 Code.toSnippet source surroundings (Just region)
5447 "I am partway through parsing a record type, but I got stuck here:"
5451 ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
5452 ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
5454 , noteForRecordTypeError
5458 TRecordType tipe row col ->
5459 toTypeReport source context tipe row col
5461 TRecordSpace space row col ->
5462 toSpaceReport source space row col
5464 TRecordIndentOpen row col ->
5466 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5467 region = toRegion row col
5469 Report.Report "UNFINISHED RECORD TYPE" region [] $
5470 Code.toSnippet source surroundings (Just region)
5473 "I just saw the opening curly brace of a record type, but then I got stuck here:"
5477 ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
5478 ,"Try","defining","some","fields","of","your","own?"
5480 , noteForRecordTypeIndentError
5484 TRecordIndentEnd row col ->
5485 case Code.nextLineStartsWithCloseCurly source row of
5486 Just (curlyRow, curlyCol) ->
5488 surroundings = A.Region (A.Position startRow startCol) (A.Position curlyRow curlyCol)
5489 region = toRegion curlyRow curlyCol
5491 Report.Report "NEED MORE INDENTATION" region [] $
5492 Code.toSnippet source surroundings (Just region)
5495 "I was partway through parsing a record type, but I got stuck here:"
5499 "I need this curly brace to be indented more. Try adding some spaces before it!"
5500 , noteForRecordTypeError
5506 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5507 region = toRegion row col
5509 Report.Report "UNFINISHED RECORD TYPE" region [] $
5510 Code.toSnippet source surroundings (Just region)
5513 "I was partway through parsing a record type, but I got stuck here:"
5517 ["I","was","expecting","to","see","a","closing","curly","brace","next."
5518 ,"Try","putting","a",D.green "}","next","and","see","if","that","helps?"
5520 , noteForRecordTypeIndentError
5524 TRecordIndentField row col ->
5526 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5527 region = toRegion row col
5529 Report.Report "UNFINISHED RECORD TYPE" region [] $
5530 Code.toSnippet source surroundings (Just region)
5533 "I am partway through parsing a record type, but I got stuck after that last comma:"
5537 "Trailing commas are not allowed in record types, so the fix may be to\
5538 \ delete that last comma? Or maybe you were in the middle of defining\
5539 \ an additional field?"
5540 , noteForRecordTypeIndentError
5544 TRecordIndentColon row col ->
5546 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5547 region = toRegion row col
5549 Report.Report "UNFINISHED RECORD TYPE" region [] $
5550 Code.toSnippet source surroundings (Just region)
5553 "I am partway through parsing a record type. I just saw a record\
5554 \ field, so I was expecting to see a colon next:"
5558 ["Try","putting","an",D.green ":","followed","by","a","type?"
5560 , noteForRecordTypeIndentError
5564 TRecordIndentType row col ->
5566 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5567 region = toRegion row col
5569 Report.Report "UNFINISHED RECORD TYPE" region [] $
5570 Code.toSnippet source surroundings (Just region)
5573 "I am partway through parsing a record type, and I was expecting to run into a type next:"
5577 ["Try","putting","something","like"
5578 ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
5580 , noteForRecordTypeIndentError
5585noteForRecordTypeError :: D.Doc
5586noteForRecordTypeError =
5589 "If you are trying to define a record type across multiple lines, I recommend using this format:"
5590 , D.indent 4 $ D.vcat $
5593 , ", height : Float"
5597 "Notice that each line starts with some indentation. Usually two or four spaces. I\
5598 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5599 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
5603noteForRecordTypeIndentError :: D.Doc
5604noteForRecordTypeIndentError =
5607 "I may be confused by indentation. For example, if you are trying to define\
5608 \ a record type across multiple lines, I recommend using this format:"
5609 , D.indent 4 $ D.vcat $
5612 , ", height : Float"
5616 "Notice that each line starts with some indentation. Usually two or four spaces. I\
5617 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
5618 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
5622toTTupleReport :: Code.Source -> TContext -> TTuple -> Row -> Col -> Report.Report
5623toTTupleReport source context tuple startRow startCol =
5625 TTupleOpen row col ->
5626 case Code.whatIsNext source row col of
5627 Code.Keyword keyword ->
5629 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5630 region = toKeywordRegion row col keyword
5632 Report.Report "RESERVED WORD" region [] $
5633 Code.toSnippet source surroundings (Just region)
5636 "I ran into a reserved word unexpectedly:"
5639 "It looks like you are trying to use `" ++ keyword ++ "` as a variable name, but \
5640 \ it is a reserved word. Try using a different name!"
5645 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5646 region = toRegion row col
5648 Report.Report "UNFINISHED PARENTHESES" region [] $
5649 Code.toSnippet source surroundings (Just region)
5652 "I just saw an open parenthesis, so I was expecting to see a type next."
5655 ["Something","like",D.dullyellow "(Maybe Int)","or"
5656 ,D.dullyellow "(List Person)" <> "."
5657 ,"Anything","where","you","are","putting","parentheses","around","normal","types."
5661 TTupleEnd row col ->
5663 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5664 region = toRegion row col
5666 Report.Report "UNFINISHED PARENTHESES" region [] $
5667 Code.toSnippet source surroundings (Just region)
5670 "I was expecting to see a closing parenthesis next, but I got stuck here:"
5673 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
5675 "I can get stuck when I run into keywords, operators, parentheses, or brackets\
5676 \ unexpectedly. So there may be some earlier syntax trouble (like extra parenthesis\
5677 \ or missing brackets) that is confusing me."
5681 TTupleType tipe row col ->
5682 toTypeReport source context tipe row col
5684 TTupleSpace space row col ->
5685 toSpaceReport source space row col
5687 TTupleIndentType1 row col ->
5689 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5690 region = toRegion row col
5692 Report.Report "UNFINISHED PARENTHESES" region [] $
5693 Code.toSnippet source surroundings (Just region)
5696 "I just saw an open parenthesis, so I was expecting to see a type next."
5700 ["Something","like",D.dullyellow "(Maybe Int)","or"
5701 ,D.dullyellow "(List Person)" <> "."
5702 ,"Anything","where","you","are","putting","parentheses","around","normal","types."
5705 "I can get confused by indentation in cases like this, so\
5706 \ maybe you have a type but it is not indented enough?"
5710 TTupleIndentTypeN row col ->
5712 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5713 region = toRegion row col
5715 Report.Report "UNFINISHED TUPLE TYPE" region [] $
5716 Code.toSnippet source surroundings (Just region)
5719 "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."
5723 ["A","tuple","type","looks","like",D.dullyellow "(Float,Float)","or"
5724 ,D.dullyellow "(String,Int)" <> ","
5725 ,"so","I","think","there","is","a","type","missing","here?"
5728 "I can get confused by indentation in cases like this, so\
5729 \ maybe you have an expression but it is not indented enough?"
5733 TTupleIndentEnd row col ->
5735 surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
5736 region = toRegion row col
5738 Report.Report "UNFINISHED PARENTHESES" region [] $
5739 Code.toSnippet source surroundings (Just region)
5742 "I was expecting to see a closing parenthesis next:"
5745 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
5747 "I can get confused by indentation in cases like this, so\
5748 \ 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