@@ -50,6 +50,7 @@ import qualified Unison.Util.ColorText as CT
5050import Unison.Util.Monoid (intercalateMap )
5151import qualified Unison.Util.Pretty as P
5252import qualified Unison.Util.Relation as R
53+ import qualified Unison.Util.Pretty as P
5354
5455showPatternHelp :: InputPattern -> P. Pretty CT. ColorText
5556showPatternHelp i =
@@ -1165,28 +1166,40 @@ loadPullRequest =
11651166 )
11661167
11671168parseUri :: String -> String -> Either (P. Pretty P. ColorText ) ReadRemoteNamespace
1168- parseUri label input = do
1169- first
1170- prettyPrint
1171- (P. parse UriParser. repoPath label (Text. pack input))
1169+ parseUri label input =
1170+ let printError err = P. lines [ P. string " I couldn't parse the repository address given above." , prettyPrintParseError input err]
1171+ in first printError (P. parse UriParser. repoPath label (Text. pack input))
1172+
1173+ prettyPrintParseError :: String -> P. ParseError Char Void -> P. Pretty P. ColorText
1174+ prettyPrintParseError input = \ case
1175+ P. TrivialError sp ue ee ->
1176+ P. lines [ printLocation sp,
1177+ P. newline,
1178+ printTrivial ue ee
1179+ ]
1180+ P. FancyError sp ee ->
1181+ let errors = foldMap (P. string . mappend " \n " . P. showErrorComponent) ee
1182+ in P. lines
1183+ [ printLocation sp,
1184+ errors
1185+ ]
11721186 where
1173- prettyPrint :: P. ParseError Char Void -> P. Pretty P. ColorText
1174- prettyPrint ( P. TrivialError sp _ _) =
1187+ printLocation :: NE. NonEmpty P. SourcePos -> P. Pretty P. ColorText
1188+ printLocation sp =
11751189 let col = (P. unPos $ P. sourceColumn $ NE. head sp) - 1
11761190 row = (P. unPos $ P. sourceLine $ NE. head sp) - 1
11771191 errorLine = lines input !! row
1178- in P. lines [" I couldn't parse the repository address given above." ,
1179- P. newline,
1180- P. string errorLine,
1181- P. string $ replicate col ' ' <> " ^-- This is where I gave up."
1182- ]
1183- prettyPrint (P. FancyError sp _) =
1184- let col = (P. unPos $ P. sourceColumn $ NE. head sp) - 1
1185- in P. lines [" I couldn't parse the repository address given above." ,
1186- P. newline,
1187- P. string input,
1188- P. string $ replicate col ' ' <> " ^-- This is where I gave up."
1189- ]
1192+ in P. lines [ P. newline,
1193+ P. string errorLine,
1194+ P. string $ replicate col ' ' <> " ^-- This is where I gave up."
1195+ ]
1196+
1197+ printTrivial :: (Maybe (P. ErrorItem Char )) -> (Set (P. ErrorItem Char )) -> P. Pretty P. ColorText
1198+ printTrivial ue ee =
1199+ let expected = " I expected " <> foldMap (P. singleQuoted . P. string . P. showErrorComponent) ee
1200+ found = P. string . mappend " I found " . P. showErrorComponent <$> ue
1201+ message = [expected] <> catMaybes [found]
1202+ in P. oxfordCommasWith " ." message
11901203
11911204parseWriteRepo :: String -> String -> Either (P. Pretty P. ColorText ) WriteRepo
11921205parseWriteRepo label input = do
0 commit comments