on master help sign in
fix typos in syntax errors and add messages for ;,`$#@!~
commit7cceaacf874d279933b802458a3fe3d2f4ea0a3a authorEvan Czaplicki <evancz@users.noreply.github.com> dateThu 11 Jul 2019, 14:00 (7 years ago) parentad5b254
2 files changed+110−18
compiler/src/Reporting/Error/Syntax.hs+106−14 compiler/src/Reporting/Render/Code.hs+4−4
compiler/src/Reporting/Error/Syntax.hs+106−14
@@ -616,20 +616,112 @@ toParseErrorReport source modul =
616616 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
617617 )
618618
619− Code.Other ->
619+ Code.Other maybeChar ->
620620 let
621621 region = toRegion row col
622622 in
623− Report.Report "SYNTAX PROBLEM" region [] $
624− Code.toSnippet source region Nothing
625− (
626− D.reflow $
627− "I got stuck here:"
628− ,
629− D.reflow $
630− "Whatever I am running into is confusing me a lot! Normally I can give fairly\
631− \ specific hints, but something is really tripping me up this time."
632− )
623+ case maybeChar of
624+ Just ';' ->
625+ Report.Report "UNEXPECTED SEMICOLON" region [] $
626+ Code.toSnippet source region Nothing
627+ (
628+ D.reflow $
629+ "I got stuck on this semicolon:"
630+ ,
631+ D.stack
632+ [ D.reflow $ "Try removing it?"
633+ , D.toSimpleNote $
634+ "Some languages require semicolons at the end of each statement. These are\
635+ \ often called C-like languages, and they usually share a lot of language design\
636+ \ choices. (E.g. side-effects, for loops, etc.) Elm manages effects with commands\
637+ \ and subscriptions instead, so there is no special syntax for \"statements\" and\
638+ \ therefore no need to use semicolons to separate them. I think this will make\
639+ \ more sense as you work through https://guide.elm-lang.org though!"
640+ ]
641+ )
642+
643+ Just ',' ->
644+ Report.Report "UNEXPECTED COMMA" region [] $
645+ Code.toSnippet source region Nothing
646+ (
647+ D.reflow $
648+ "I got stuck on this comma:"
649+ ,
650+ D.stack
651+ [ D.reflow $
652+ "I do not think I am parsing a list or tuple right now. Try deleting the comma?"
653+ , D.toSimpleNote $
654+ "If this is supposed to be part of a list, the problem may be a bit earlier.\
655+ \ Perhaps the opening [ is missing? Or perhaps some value in the list has an extra\
656+ \ closing ] that is making me think the list ended earlier? The same kinds of\
657+ \ things could be going wrong if this is supposed to be a tuple."
658+ ]
659+ )
660+
661+ Just '`' ->
662+ Report.Report "UNEXPECTED CHARACTER" region [] $
663+ Code.toSnippet source region Nothing
664+ (
665+ D.reflow $
666+ "I got stuck on this character:"
667+ ,
668+ D.stack
669+ [ D.reflow $
670+ "It is not used for anything in Elm syntax. It is used for multi-line strings in\
671+ \ some languages though, so if you want a string that spans multiple lines, you\
672+ \ can use Elm's multi-line string syntax like this:"
673+ , D.vcat
674+ [ D.fillSep [D.green "markdown","=",D.dullyellow "\"\"\""]
675+ , mempty
676+ , D.dullyellow "# Multi-line Strings"
677+ , mempty
678+ , D.dullyellow "- start with triple double quotes"
679+ , D.dullyellow "- write whatever you want"
680+ , D.dullyellow "- no need to escape newlines or double quotes"
681+ , D.dullyellow "- end with triple double quotes"
682+ , mempty
683+ , D.dullyellow "\"\"\""
684+ ]
685+ , D.reflow $
686+ "Otherwise I do not know what is going on! Try removing the character?"
687+ ]
688+ )
689+
690+ Just '$' ->
691+ Report.Report "UNEXPECTED SYMBOL" region [] $
692+ Code.toSnippet source region Nothing
693+ (
694+ D.reflow $
695+ "I got stuck on this dollar sign:"
696+ ,
697+ D.reflow $
698+ "It is not used for anything in Elm syntax. Are you coming from a language where\
699+ \ dollar signs can be used in variable names? If so, try a name that (1) starts\
700+ \ with a letter and (2) only contains letters, numbers, and underscores."
701+ )
702+
703+ Just c | elem c ['#','@','!','%','~'] ->
704+ Report.Report "UNEXPECTED SYMBOL" region [] $
705+ Code.toSnippet source region Nothing
706+ (
707+ D.reflow $
708+ "I got stuck on this symbol:"
709+ ,
710+ D.reflow $
711+ "It is not used for anything in Elm syntax. Try removing it?"
712+ )
713+
714+ _ ->
715+ Report.Report "SYNTAX PROBLEM" region [] $
716+ Code.toSnippet source region Nothing
717+ (
718+ D.reflow $
719+ "I got stuck here:"
720+ ,
721+ D.reflow $
722+ "Whatever I am running into is confusing me a lot! Normally I can give fairly\
723+ \ specific hints, but something is really tripping me up this time."
724+ )
633725
634726 ModuleProblem row col ->
635727 let
@@ -823,7 +915,7 @@ toParseErrorReport source modul =
823915 let
824916 region = toRegion row col
825917 in
826− Report.Report "EXECTING IMPORT ALIAS" region [] $
918+ Report.Report "EXPECTING IMPORT ALIAS" region [] $
827919 Code.toSnippet source region Nothing
828920 (
829921 D.reflow $
@@ -1329,7 +1421,7 @@ toDeclarationsReport source decl =
13291421 , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
13301422 , D.reflow $
13311423 "Note that all declarations start with lower-case letters in Elm. Capitalization\
1332− \ makes a difference, so be consious of that if you are working from examples!"
1424+ \ makes a difference, so be conscious of that if you are working from examples!"
13331425 ]
13341426 )
13351427
@@ -5226,7 +5318,7 @@ toTTupleReport source context tuple startRow startCol =
52265318 Code.toSnippet source surroundings (Just region)
52275319 (
52285320 D.reflow $
5229− "I was expecting to see a closing parentheses next, but I got stuck here:"
5321+ "I was expecting to see a closing parenthesis next, but I got stuck here:"
52305322 ,
52315323 D.stack
52325324 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
compiler/src/Reporting/Render/Code.hs+4−4
@@ -199,14 +199,14 @@ data Next
199199 = Keyword [Char]
200200 | Operator [Char]
201201 | Close [Char] Char
202− | Other
202+ | Other (Maybe Char)
203203
204204
205205whatIsNext :: Source -> Row -> Col -> Next
206206whatIsNext (Source sourceLines) row col =
207207 case List.lookup row sourceLines of
208208 Nothing ->
209− Other
209+ Other Nothing
210210
211211 Just line ->
212212 let
@@ -220,14 +220,14 @@ whatIsNext (Source sourceLines) row col =
220220 Nothing ->
221221 case chars of
222222 [] ->
223− Other
223+ Other Nothing
224224
225225 c:cs
226226 | isSymbol c -> Operator (c : takeWhile isSymbol cs)
227227 | c == ')' -> Close "parenthesis" ')'
228228 | c == ']' -> Close "square bracket" ']'
229229 | c == '}' -> Close "curly brace" '}'
230− | otherwise -> Other
230+ | otherwise -> Other (Just c)
231231
232232
233233isSymbol :: Char -> Bool