on master help sign in
fix typos in syntax errors and add messages for ;,`$#@!~
7cceaacEvan Czaplicki
compiler/src/Reporting/Error/Syntax.hs+106−14
@@ -616,20 +616,112 @@ toParseErrorReport source modul =
616 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
616 "This " ++ bracket : " does not match up with an earlier open " ++ term ++ ". Try deleting it?"
617 )
617 )
618
618
619− Code.Other ->
619+ Code.Other maybeChar ->
620 let
620 let
621 region = toRegion row col
621 region = toRegion row col
622 in
622 in
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+ _ ->
623− Report.Report "SYNTAX PROBLEM" region [] $
715+ Report.Report "SYNTAX PROBLEM" region [] $
624− Code.toSnippet source region Nothing
716+ Code.toSnippet source region Nothing
625− (
717+ (
626− D.reflow $
718+ D.reflow $
627− "I got stuck here:"
719+ "I got stuck here:"
628− ,
720+ ,
629− D.reflow $
721+ D.reflow $
630− "Whatever I am running into is confusing me a lot! Normally I can give fairly\
722+ "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."
723+ \ specific hints, but something is really tripping me up this time."
632− )
724+ )
633
725
634 ModuleProblem row col ->
726 ModuleProblem row col ->
635 let
727 let
@@ -823,7 +915,7 @@ toParseErrorReport source modul =
823 let
915 let
824 region = toRegion row col
916 region = toRegion row col
825 in
917 in
826− Report.Report "EXECTING IMPORT ALIAS" region [] $
918+ Report.Report "EXPECTING IMPORT ALIAS" region [] $
827 Code.toSnippet source region Nothing
919 Code.toSnippet source region Nothing
828 (
920 (
829 D.reflow $
921 D.reflow $
@@ -1329,7 +1421,7 @@ toDeclarationsReport source decl =
1329 , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1421 , D.fillSep [D.cyan "type",D.green "User","=","Anonymous","|","LoggedIn String"]
1330 , D.reflow $
1422 , D.reflow $
1331 "Note that all declarations start with lower-case letters in Elm. Capitalization\
1423 "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!"
1333 ]
1425 ]
1334 )
1426 )
1335
1427
@@ -5226,7 +5318,7 @@ toTTupleReport source context tuple startRow startCol =
5226 Code.toSnippet source surroundings (Just region)
5318 Code.toSnippet source surroundings (Just region)
5227 (
5319 (
5228 D.reflow $
5320 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:"
5230 ,
5322 ,
5231 D.stack
5323 D.stack
5232 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
5324 [ 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
199 = Keyword [Char]
199 = Keyword [Char]
200 | Operator [Char]
200 | Operator [Char]
201 | Close [Char] Char
201 | Close [Char] Char
202− | Other
202+ | Other (Maybe Char)
203
203
204
204
205whatIsNext :: Source -> Row -> Col -> Next
205whatIsNext :: Source -> Row -> Col -> Next
206whatIsNext (Source sourceLines) row col =
206whatIsNext (Source sourceLines) row col =
207 case List.lookup row sourceLines of
207 case List.lookup row sourceLines of
208 Nothing ->
208 Nothing ->
209− Other
209+ Other Nothing
210
210
211 Just line ->
211 Just line ->
212 let
212 let
@@ -220,14 +220,14 @@ whatIsNext (Source sourceLines) row col =
220 Nothing ->
220 Nothing ->
221 case chars of
221 case chars of
222 [] ->
222 [] ->
223− Other
223+ Other Nothing
224
224
225 c:cs
225 c:cs
226 | isSymbol c -> Operator (c : takeWhile isSymbol cs)
226 | isSymbol c -> Operator (c : takeWhile isSymbol cs)
227 | c == ')' -> Close "parenthesis" ')'
227 | c == ')' -> Close "parenthesis" ')'
228 | c == ']' -> Close "square bracket" ']'
228 | c == ']' -> Close "square bracket" ']'
229 | c == '}' -> Close "curly brace" '}'
229 | c == '}' -> Close "curly brace" '}'
230− | otherwise -> Other
230+ | otherwise -> Other (Just c)
231
231
232
232
233isSymbol :: Char -> Bool
233isSymbol :: Char -> Bool