@@ -53,9 +53,8 @@ import Data.Word (Word16)
54import qualified Elm.ModuleName as ModuleName
54import qualified Elm.ModuleName as ModuleName
55import Parse.Primitives (Row, Col)
55import Parse.Primitives (Row, Col)
56−--import qualified Parse.Primitives as P
57import qualified Reporting.Annotation as A
56import qualified Reporting.Annotation as A
58−--import qualified Reporting.Doc as D
57+import qualified Reporting.Doc as D
59import qualified Reporting.Report as Report
58import qualified Reporting.Report as Report
60import qualified Reporting.Render.Code as Code
59import qualified Reporting.Render.Code as Code
@@ -159,8 +158,8 @@ data DeclDef
159 | DeclDefType Type Row Col
158 | DeclDefType Type Row Col
160 | DeclDefArg Pattern Row Col
159 | DeclDefArg Pattern Row Col
161 | DeclDefBody Expr Row Col
160 | DeclDefBody Expr Row Col
162− | DeclDefNameRepeat Name.Name Row Col
161+ | DeclDefNameRepeat Row Col
163− | DeclDefNameMatch Name.Name Name.Name Row Col
162+ | DeclDefNameMatch Name.Name Row Col
165 | DeclDefIndentType Row Col
164 | DeclDefIndentType Row Col
166 | DeclDefIndentEquals Row Col
165 | DeclDefIndentEquals Row Col
@@ -501,7 +500,6 @@ data Number
501data Space
500data Space
503 | EndlessMultiComment
502 | EndlessMultiComment
504− | UnexpectedDocComment
507data Operator
505data Operator
@@ -518,7 +516,446 @@ data Operator
519toReport :: Code.Source -> Error -> Report.Report
517toReport :: Code.Source -> Error -> Report.Report
520toReport source err =
518toReport source err =
521− error "TODO" source err
519+ case err of
520+ ModuleNameUnspecified name ->
522+ region = toRegion 1 1
524+ Report.Report "MODULE NAME MISSING" region [] $
527+ "I need the module name to be declared at the top of this file, like this:"
528+ , D.indent 4 $ D.green $ D.fromChars $
529+ "module " ++ ModuleName.toChars name ++ " exposing (..)"
531+ "Try adding that as the first line of your file!"
533+ "It is best to replace (..) with an explicit list of types and\
534+ \ functions you want to expose. When you know a value is only used\
535+ \ within this module, you can refactor without worrying about uses\
536+ \ elsewhere. Limiting exposed values can also speed up compilation\
537+ \ because I can skip a bunch of work if I see that the exposed API\
541+ ModuleNameMismatch expectedName (A.At region actualName) ->
542+ Report.Report "MODULE NAME MISMATCH" region [ModuleName.toChars expectedName] $
543+ Report.toCodeSnippet source region Nothing
545+ "It looks like this module name is out of sync:"
549+ "I need it to match the file path, so I was expecting it to see `"
550+ ++ ModuleName.toChars expectedName
551+ ++ "` here. Make the following change, and you should be all set!"
553+ D.red (D.fromName actualName) <> " -> " <> D.green (D.fromName expectedName)
555+ "I require that module names correspond to file paths. This makes it much\
556+ \ easier to explore unfamiliar codebases! So if you want to keep the current\
557+ \ module name, try renaming the file instead."
561+ UnexpectedPort region ->
562+ error "TODO UnexpectedPort" region
565+ error "TODO NoPorts" region
568+ toParseErrorReport source modul
571+toParseErrorReport :: Code.Source -> Module -> Report.Report
572+toParseErrorReport source modul =
574+ ModuleSpace space row col ->
575+ toSpaceReport source space row col
577+ ModuleEndOfFile row col ->
579+ region = toRegion row col
581+ Report.Report "EXPECTING END OF FILE" region [] $
582+ Report.toCodeSnippet source region Nothing
585+ "I was not expecting to see anything more here:"
588+ "I think I have read all the declarations in the file and that there is nothing\
589+ \ left to see, so whatever I am running into is confusing me a lot!"
593+ error "TODO Module" row col
595+ ModuleName row col ->
596+ error "TODO ModuleName" row col
598+ ModuleExposing row col ->
599+ error "TODO ModuleExposing" row col
601+ ModuleExposingList exposing row col ->
602+ error "TODO ModuleExposingList" exposing row col
605+ ModulePortModule row col ->
606+ error "TODO ModulePortModule" row col
608+ ModuleEffect row col ->
609+ error "TODO ModuleEffect" row col
611+ ModuleIndentStart row col ->
612+ error "TODO ModuleIndentStart" row col
614+ ModuleIndentName row col ->
615+ error "TODO ModuleIndentName" row col
617+ ModuleIndentExposing row col ->
618+ error "TODO ModuleIndentExposing" row col
620+ ModuleIndentExposingList row col ->
621+ error "TODO ModuleIndentExposingList" row col
623+ ModuleIndentPortModule row col ->
624+ error "TODO ModuleIndentPortModule" row col
626+ FreshLineModuleStart row col ->
627+ error "TODO FreshLineModuleStart" row col
629+ FreshLineAfterModuleLine row col ->
630+ error "TODO FreshLineAfterModuleLine" row col
632+ FreshLineAfterDocComment row col ->
633+ error "TODO FreshLineAfterDocComment" row col
635+ ImportStart row col ->
636+ error "TODO ImportStart" row col
638+ ImportName row col ->
639+ error "TODO ImportName" row col
642+ error "TODO ImportAs" row col
644+ ImportAlias row col ->
645+ error "TODO ImportAlias" row col
647+ ImportExposing row col ->
648+ error "TODO ImportExposing" row col
650+ ImportExposingList exposing row col ->
651+ error "TODO ImportExposingList" exposing row col
653+ ImportEnd row col ->
654+ error "TODO ImportEnd" row col
656+ ImportIndentName row col ->
657+ error "TODO ImportIndentName" row col
659+ ImportIndentAs row col ->
660+ error "TODO ImportIndentAs" row col
662+ ImportIndentAlias row col ->
663+ error "TODO ImportIndentAlias" row col
665+ ImportIndentExposing row col ->
666+ error "TODO ImportIndentExposing" row col
668+ ImportIndentExposingList row col ->
669+ error "TODO ImportIndentExposingList" row col
672+ error "TODO Infix" row col
674+ Declarations decl _ _ ->
675+ toDeclarationsReport source decl
678+toSpaceReport :: Code.Source -> Space -> Row -> Col -> Report.Report
679+toSpaceReport source space row col =
683+ region = toRegion row col
685+ Report.Report "NO TABS" region [] $
686+ Report.toCodeSnippet source region Nothing
689+ "I ran into a tab, but tabs are not allowed in Elm files."
692+ "Replace the tab with spaces."
695+ EndlessMultiComment ->
697+ region = toWiderRegion row col 2
699+ Report.Report "ENDLESS COMMENT" region [] $
700+ Report.toCodeSnippet source region Nothing
703+ "I cannot find the end of this multi-line comment:"
706+ [ D.reflow "Add a -} somewhere after this to end the comment."
708+ "Multi-line comments can be nested in Elm, so {- {- -} -} is a comment\
709+ \ that happens to contain another comment. Like parentheses and curly braces,\
710+ \ the start and end markers must always be balanced. Maybe that is the problem?"
715+toRegion :: Row -> Col -> A.Region
718+ pos = A.Position row col
723+toWiderRegion :: Row -> Col -> Word16 -> A.Region
724+toWiderRegion row col extra =
726+ (A.Position row col)
727+ (A.Position row (col + extra))
730+toDeclarationsReport :: Code.Source -> Decl -> Report.Report
731+toDeclarationsReport source decl =
733+ DeclStart row col ->
734+ error "TODO DeclStart" row col
736+ DeclSpace space row col ->
737+ toSpaceReport source space row col
739+ Port port row col ->
740+ error "TODO Port" port row col
742+ DeclType declType row col ->
743+ error "TODO DeclType" declType row col
745+ DeclDef name declDef row col ->
746+ toDeclDefReport source name declDef row col
748+ DeclFreshLineStart row col ->
749+ error "TODO DeclFreshLineStart" row col
751+ DeclFreshLineAfterDocComment row col ->
752+ error "TODO DeclFreshLineAfterDocComment" row col
755+toDeclDefReport :: Code.Source -> Name.Name -> DeclDef -> Row -> Col -> Report.Report
756+toDeclDefReport source name declDef _ _ =
758+ DeclDefSpace space row col ->
759+ toSpaceReport source space row col
761+ DeclDefEquals row col ->
762+ error "TODO DeclDefEquals" row col
764+ DeclDefType tipe row col ->
765+ error "TODO DeclDefType" tipe row col
767+ DeclDefArg pattern row col ->
768+ error "TODO DeclDefArg" pattern row col
770+ DeclDefBody expr row col ->
771+ toExprReport source name expr row col
773+ DeclDefNameRepeat row col ->
774+ error "TODO DeclDefNameRepeat" name row col
776+ DeclDefNameMatch defName row col ->
777+ error "TODO DeclDefNameMatch" name defName row col
779+ DeclDefIndentType row col ->
780+ error "TODO DeclDefIndentType" row col
782+ DeclDefIndentEquals row col ->
783+ error "TODO DeclDefIndentEquals" row col
785+ DeclDefIndentBody row col ->
786+ error "TODO DeclDefIndentBody" row col
788+ DeclDefFreshLineAfterType row col ->
789+ error "TODO DeclDefFreshLineAfterType" row col
793+toExprReport :: Code.Source -> Name.Name -> Expr -> Row -> Col -> Report.Report
794+toExprReport source _ expr _ _ =
827+ error "TODO OperatorRHS"
829+ OperatorRight _ _ ->
830+ error "TODO OperatorRight"
832+ OperatorReserved _ _ _ ->
833+ error "TODO OperatorReserved"
844+ Number number row col ->
845+ toNumberReport source number row col
847+ Space space row col ->
848+ toSpaceReport source space row col
850+ EndlessShader row col ->
852+ region = toWiderRegion row col 6
854+ Report.Report "ENDLESS SHADER" region [] $
855+ Report.toCodeSnippet source region Nothing
857+ D.reflow "I cannot find the end of this shader:"
859+ D.reflow "Add a |] somewhere after this to end the shader."
862+ ShaderProblem problem row col ->
864+ region = toRegion row col
866+ Report.Report "SHADER PROBLEM" region [] $
867+ Report.toCodeSnippet source region Nothing
870+ "I ran into a problem while parsing this GLSL block."
874+ "I use a 3rd party GLSL parser for now, and I did my best to extract their error message:"
875+ , D.indent 4 $ D.vcat $
876+ map D.fromChars (filter (/="") (lines problem))
880+ IndentOperatorRight _ _ ->
881+ error "TODO IndentOperatorRight"
883+ IndentMoreExpr _ _ ->
884+ error "TODO IndentMoreExpr"
887+toNumberReport :: Code.Source -> Number -> Row -> Col -> Report.Report
888+toNumberReport source number row col =
890+ region = toRegion row col
894+ Report.Report "WEIRD NUMBER" region [] $
895+ Report.toCodeSnippet source region Nothing
898+ "I thought I was reading a number, but I ran into some weird stuff here:"
902+ "I recognize numbers in the following formats:"
903+ , D.indent 4 $ D.vcat [ "42", "3.14", "6.022e23", "0x002B" ]
905+ "So is there a way to write it like one of those?"
910+ Report.Report "WEIRD NUMBER" region [] $
911+ Report.toCodeSnippet source region Nothing
914+ "Numbers cannot end with a dot like this:"
917+ ["Switching","to",D.green (D.fromChars (show int))
918+ ,"or",D.green (D.fromChars (show int ++ ".0"))
919+ ,"will","work","though!"
924+ Report.Report "WEIRD HEXIDECIMAL" region [] $
925+ Report.toCodeSnippet source region Nothing
928+ "I thought I was reading a hexidecimal number until I got here:"
932+ "Valid hexidecimal digits include 0123456789abcdefABCDEF, so I can\
933+ \ only recognize things like this:"
934+ , D.indent 4 $ D.vcat [ "0x2B", "0x002B", "0x00ffb3" ]
938+ NumberNoLeadingZero ->
939+ Report.Report "LEADING ZEROS" region [] $
940+ Report.toCodeSnippet source region Nothing
943+ "I do not accept numbers with leading zeros:"
947+ "Just delete the leading zeros and it should work!"
949+ "Some languages let you to specify octal numbers by adding a leading zero.\
950+ \ So in C, writing 0111 is the same as writing 73. Some people are used to\
951+ \ that, but others probably want it to equal 111. Either path is going to\
952+ \ surprise people from certain backgrounds, so Elm tries to avoid this whole\
523 case err of
960 case err of
524 CommentOnNothing region ->
961 CommentOnNothing region ->
@@ -601,110 +1038,8 @@ toReport source err =
601 "Check out" "TODO" "for examples of doc comments."
1038 "Check out" "TODO" "for examples of doc comments."
604− MultiCommentEnd startRow startCol ->
608− (A.Position startRow startCol)
609− (A.Position startRow (startCol + 3))
611− Report.Report "ENDLESS COMMENT" startRegion [] $
612− Report.toCodeSnippet source startRegion Nothing
615− "I cannot find the end of this multi-line comment:"
618− [ D.reflow "Add a -} somewhere after this to end the comment."
620− "Multi-line comments can be nested in Elm, so {- {- -} -} is a comment\
621− \ that happens to contain another comment. Like parentheses and curly braces,\
622− \ the start and end markers must always be balanced. Maybe that is the problem?"
626 -- Parse.Number
1041 -- Parse.Number
629− Report.Report "EXPECTING NUMBER" region [] $
630− Report.toCodeSnippet source region Nothing
633− "I was expecting to see a number here:"
637− "I recognize numbers in the following formats:"
638− , D.indent 4 $ D.vcat [ "42", "3.14", "6.022e23", "0x002B" ]
640− "So is there a way to write it like one of those?"
645− Report.Report "WEIRD NUMBER" region [] $
646− Report.toCodeSnippet source region Nothing
649− "I thought I was reading a number, but I ran into some weird stuff here:"
653− "I recognize numbers in the following formats:"
654− , D.indent 4 $ D.vcat [ "42", "3.14", "6.022e23", "0x002B" ]
656− "So is there a way to write it like one of those?"
661− Report.Report "WEIRD NUMBER" region [] $
662− Report.toCodeSnippet source region Nothing
665− "Numbers cannot end with a dot like this:"
668− ["Switching","to",D.green (D.fromChars (show int))
669− ,"or",D.green (D.fromChars (show int ++ ".0"))
670− ,"will","work","though!"
675− Report.Report "WEIRD HEXIDECIMAL" region [] $
676− Report.toCodeSnippet source region Nothing
679− "I thought I was reading a hexidecimal number until I got here:"
683− "Valid hexidecimal digits include 0123456789abcdefABCDEF, so I can\
684− \ only recognize things like this:"
685− , D.indent 4 $ D.vcat [ "0x2B", "0x002B", "0x00ffb3" ]
689− Number_NoLeadingZero ->
690− Report.Report "LEADING ZEROS" region [] $
691− Report.toCodeSnippet source region Nothing
694− "I do not accept numbers with leading zeros:"
698− "Just delete the leading zeros and it should work!"
700− "Some languages let you to specify octal numbers by adding a leading zero.\
701− \ So in C, writing 0111 is the same as writing 73. Some people are used to\
702− \ that, but others probably want it to equal 111. Either path is going to\
703− \ surprise people from certain backgrounds, so Elm tries to avoid this whole\
708 Precedence ->
1043 Precedence ->
709 Report.Report "EXPECTING PRECEDENCE" region [] $
1044 Report.Report "EXPECTING PRECEDENCE" region [] $
710 Report.toCodeSnippet source region Nothing
1045 Report.toCodeSnippet source region Nothing
@@ -943,43 +1278,6 @@ toReport source err =
949− Report.Report "EXPECTING A SHADER" region [] $
950− Report.toCodeSnippet source region Nothing $
953− "I was expecting a GLSL shader block here:"
956− "These blocks start with [glsl| and end with |] and should be\
957− \ filled with GLSL code."
960− ShaderEnd startCol endCol ->
963− A.Region (A.Position row startCol) (A.Position row endCol)
965− Report.Report "ENDLESS SHADER" shaderRegion [] $
966− Report.toCodeSnippet source shaderRegion Nothing
968− D.reflow "I cannot find the end of this shader:"
970− D.reflow "Add a |] somewhere after this to end the shader."
973− ShaderProblem problem ->
974− Report.Report "SHADER PROBLEM" region [] $
975− Report.toCodeSnippet source region Nothing
978− "I ran into a problem while parsing this GLSL block."
983 Operator ->
1281 Operator ->
984 Report.Report "EXPECTING AN OPERATOR" region [] $
1282 Report.Report "EXPECTING AN OPERATOR" region [] $
985 Report.toCodeSnippet source region Nothing
1283 Report.toCodeSnippet source region Nothing
@@ -1027,14 +1325,6 @@ toReport source err =
1028 -- Parse.Pattern
1326 -- Parse.Pattern
1031− error "TODO" context
1038 FloatInPattern ->
1328 FloatInPattern ->
1039 Report.Report "INVALID PATTERN" region [] $
1329 Report.Report "INVALID PATTERN" region [] $
1040 Report.toCodeSnippet source region Nothing
1330 Report.toCodeSnippet source region Nothing
@@ -1076,20 +1366,6 @@ toReport source err =
1081− Report.Report "EXPECTING END OF FILE" region [] $
1082− Report.toCodeSnippet source region Nothing
1085− "I was not expecting to see anything more here:"
1088− "I think I have read all the declarations in the file and that there is nothing\
1089− \ left to see, so whatever I am running into is confusing me a lot!"
1095 TypeWithBadDefinition region annName defName ->
1371 TypeWithBadDefinition region annName defName ->