From ea7b6562f41b4f8845828db7ee10e1f9036752e4 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 30 Aug 2022 16:14:09 +0200 Subject: Fixed mixfix matching --- src/Helper.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/Helper.hs') diff --git a/src/Helper.hs b/src/Helper.hs index b0dea79..87ae8fc 100644 --- a/src/Helper.hs +++ b/src/Helper.hs @@ -14,6 +14,9 @@ import Data.List import qualified Data.Map as M import Text.Megaparsec +invalidProgramState :: a +invalidProgramState = error "invalid program state" + data Context = Context { _ctxInput :: String , _ctxPath :: String @@ -36,7 +39,7 @@ printContext (Context inp path) = p $ lines inp errPrefix :: String errPrefix = "\ESC[101m\ESC[30mERROR\ESC[0m " -data Error = SyntaxError String | UndefinedIdentifier Identifier | InvalidIndex Int | FailedTest Expression Expression Expression Expression | ContextualError Error Context | SuggestSolution Error String | ImportError String +data Error = SyntaxError String | UndefinedIdentifier Identifier | UnmatchedMixfix [MixfixIdentifierKind] [Mixfix] | InvalidIndex Int | FailedTest Expression Expression Expression Expression | ContextualError Error Context | SuggestSolution Error String | ImportError String instance Show Error where show (ContextualError err ctx) = show err <> "\n" <> (printContext ctx) show (SuggestSolution err sol) = @@ -47,6 +50,12 @@ instance Show Error where errPrefix <> "invalid syntax\n\ESC[105m\ESC[30mnear\ESC[0m " <> err show (UndefinedIdentifier ident) = errPrefix <> "undefined identifier " <> show ident + show (UnmatchedMixfix ks ms) = + errPrefix + <> "couldn't find matching mixfix for " + <> (intercalate "" (map show ks)) + <> "\n\ESC[105m\ESC[30mnear\ESC[0m " + <> (intercalate " " (map show ms)) show (InvalidIndex err) = errPrefix <> "invalid index " <> show err show (FailedTest exp1 exp2 red1 red2) = errPrefix @@ -97,7 +106,7 @@ printBundle ParseErrorBundle {..} = data MixfixIdentifierKind = MixfixSome String | MixfixNone deriving (Ord, Eq) -instance Show MixfixIdentifierKind where +instance Show MixfixIdentifierKind where -- don't colorize (due to map) show (MixfixSome e) = e show _ = "…" data Identifier = NormalFunction String | MixfixFunction [MixfixIdentifierKind] | PrefixFunction String | NamespacedFunction String Identifier -- cgit v1.2.3