diff --git a/smol-backend/test/Test/Helpers.hs b/smol-backend/test/Test/Helpers.hs index 52d0b46dd..b3713a6f7 100644 --- a/smol-backend/test/Test/Helpers.hs +++ b/smol-backend/test/Test/Helpers.hs @@ -31,6 +31,7 @@ import qualified Data.Set.NonEmpty as NES import Data.Text (Text) import Smol.Core import Smol.Core.Modules.FromParts +import Smol.Core.Modules.Parser import Smol.Core.Modules.Types.Module import Smol.Core.Typecheck.FromParsedExpr diff --git a/smol-backend/test/Test/IR/IRSpec.hs b/smol-backend/test/Test/IR/IRSpec.hs index 6562283b0..d82cb86df 100644 --- a/smol-backend/test/Test/IR/IRSpec.hs +++ b/smol-backend/test/Test/IR/IRSpec.hs @@ -14,11 +14,11 @@ import qualified Smol.Backend.Compile.RunLLVM as Run import Smol.Backend.IR.FromExpr.Expr import Smol.Backend.IR.ToLLVM.ToLLVM import Smol.Core.Modules.FromParts +import Smol.Core.Modules.Parser (parseModuleAndFormatError) import Smol.Core.Modules.ResolveDeps import Smol.Core.Modules.Typecheck import Smol.Core.Modules.Types import Smol.Core.Modules.Types.ModuleError -import Smol.Core.Parser (parseModuleAndFormatError) import Smol.Core.Typecheck.Typeclass.Types import Smol.Core.Types import Test.BuiltInTypes diff --git a/smol-core/smol-core.cabal b/smol-core/smol-core.cabal index 370ac9a59..cbb3dc5c1 100644 --- a/smol-core/smol-core.cabal +++ b/smol-core/smol-core.cabal @@ -75,6 +75,7 @@ library Smol.Core.Modules.FromParts Smol.Core.Modules.Helpers Smol.Core.Modules.Interpret + Smol.Core.Modules.Parser Smol.Core.Modules.PrettyPrint Smol.Core.Modules.ResolveDeps Smol.Core.Modules.RunTests @@ -86,7 +87,6 @@ library Smol.Core.Modules.Types.Module Smol.Core.Modules.Types.ModuleError Smol.Core.Modules.Types.ModuleItem - Smol.Core.Modules.Types.ModuleName Smol.Core.Modules.Types.Test Smol.Core.Modules.Types.TestName Smol.Core.Modules.Types.TopLevelExpression @@ -95,7 +95,6 @@ library Smol.Core.Parser.DataType Smol.Core.Parser.Expr Smol.Core.Parser.Identifiers - Smol.Core.Parser.Module Smol.Core.Parser.Op Smol.Core.Parser.Pattern Smol.Core.Parser.Primitives @@ -148,6 +147,7 @@ library Smol.Core.Types.DataType Smol.Core.Types.Expr Smol.Core.Types.Identifier + Smol.Core.Types.ModuleName Smol.Core.Types.Op Smol.Core.Types.ParseDep Smol.Core.Types.Pattern @@ -173,9 +173,9 @@ test-suite smol-core-tests other-modules: Test.BuiltInTypes Test.Helpers - Test.Interpreter.InterpreterSpec Test.Modules.FromPartsSpec Test.Modules.InterpreterSpec + Test.Modules.ParserSpec Test.Modules.ResolveDepsSpec Test.Modules.RunTestsSpec Test.Modules.TypecheckSpec diff --git a/smol-core/src/Smol/Core/Parser/Module.hs b/smol-core/src/Smol/Core/Modules/Parser.hs similarity index 85% rename from smol-core/src/Smol/Core/Parser/Module.hs rename to smol-core/src/Smol/Core/Modules/Parser.hs index 4f8026fc2..9642c9419 100644 --- a/smol-core/src/Smol/Core/Parser/Module.hs +++ b/smol-core/src/Smol/Core/Modules/Parser.hs @@ -1,27 +1,47 @@ {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE OverloadedStrings #-} -module Smol.Core.Parser.Module +module Smol.Core.Modules.Parser ( moduleParser, + parseModule, + parseModuleAndFormatError, ) where +import Data.Bifunctor (first) import qualified Data.List.NonEmpty as NE import Data.Text (Text) +import qualified Data.Text as T import Data.Void import Smol.Core.Modules.Types.ModuleItem +import Smol.Core.Modules.Types.TestName import Smol.Core.Parser.DataType (dataTypeParser) import Smol.Core.Parser.Expr import Smol.Core.Parser.Identifiers +import Smol.Core.Parser.Primitives (textPrim) import Smol.Core.Parser.Shared import Smol.Core.Parser.Type import Smol.Core.Parser.Typeclass import Smol.Core.Typecheck.Typeclass.Types import Smol.Core.Types import Text.Megaparsec hiding (parseTest) +import Text.Megaparsec.Char type Parser = Parsec Void Text +type ParseErrorType = ParseErrorBundle Text Void + +parseAndFormat :: Parser a -> Text -> Either Text a +parseAndFormat p = first (T.pack . errorBundlePretty) . parse (p <* eof) "repl" + +parseModule :: Text -> Either ParseErrorType [ModuleItem Annotation] +parseModule = parse (space *> moduleParser <* eof) "repl" + +parseModuleAndFormatError :: Text -> Either Text [ModuleItem Annotation] +parseModuleAndFormatError = parseAndFormat (space *> moduleParser <* eof) + +------- + -- currently fails at the first hurdle -- since we can parse each thing separately, maybe -- we should be making each throw errors for later, but returning `mempty` so @@ -181,3 +201,6 @@ parseClass = do tcFuncType = ty } ) + +testNameParser :: Parser TestName +testNameParser = myLexeme $ TestName <$> textPrim diff --git a/smol-core/src/Smol/Core/Modules/Types.hs b/smol-core/src/Smol/Core/Modules/Types.hs index 99a6befc5..b31835f48 100644 --- a/smol-core/src/Smol/Core/Modules/Types.hs +++ b/smol-core/src/Smol/Core/Modules/Types.hs @@ -1,7 +1,6 @@ module Smol.Core.Modules.Types ( module Smol.Core.Modules.Types.Entity, module Smol.Core.Modules.Types.Module, - module Smol.Core.Modules.Types.ModuleName, module Smol.Core.Modules.Types.ModuleItem, module Smol.Core.Modules.Types.TestName, module Smol.Core.Modules.Types.DefIdentifier, @@ -14,7 +13,6 @@ import Smol.Core.Modules.Types.DefIdentifier import Smol.Core.Modules.Types.Entity import Smol.Core.Modules.Types.Module import Smol.Core.Modules.Types.ModuleItem -import Smol.Core.Modules.Types.ModuleName import Smol.Core.Modules.Types.Test import Smol.Core.Modules.Types.TestName import Smol.Core.Modules.Types.TopLevelExpression diff --git a/smol-core/src/Smol/Core/Modules/Types/Entity.hs b/smol-core/src/Smol/Core/Modules/Types/Entity.hs index e6ee71272..347584171 100644 --- a/smol-core/src/Smol/Core/Modules/Types/Entity.hs +++ b/smol-core/src/Smol/Core/Modules/Types/Entity.hs @@ -9,10 +9,10 @@ module Smol.Core.Modules.Types.Entity where -- terrible, pls improve import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey) import GHC.Generics (Generic) -import Smol.Core.Modules.Types.ModuleName import Smol.Core.Printer import Smol.Core.Types.Constructor import Smol.Core.Types.Identifier +import Smol.Core.Types.ModuleName import Smol.Core.Types.TypeName data Entity diff --git a/smol-core/src/Smol/Core/Parser.hs b/smol-core/src/Smol/Core/Parser.hs index 23b1f17f3..ffb8d0edf 100644 --- a/smol-core/src/Smol/Core/Parser.hs +++ b/smol-core/src/Smol/Core/Parser.hs @@ -6,9 +6,7 @@ module Smol.Core.Parser parseExprAndFormatError, parseTypeAndFormatError, parseType, - parseModule, parseConstraint, - parseModuleAndFormatError, parseDataTypeAndFormatError, parseConstraintAndFormatError, ParseErrorType, @@ -19,10 +17,8 @@ import Data.Bifunctor (first) import Data.Text (Text) import qualified Data.Text as T import Data.Void -import Smol.Core.Modules.Types import Smol.Core.Parser.DataType (dataTypeParser) import Smol.Core.Parser.Expr -import Smol.Core.Parser.Module import Smol.Core.Parser.Type import Smol.Core.Parser.Typeclass import Smol.Core.Typecheck.Types @@ -46,15 +42,9 @@ parseExpr = parse (space *> expressionParser <* eof) "repl" parseExprAndFormatError :: Text -> Either Text ParserExpr parseExprAndFormatError = parseAndFormat (space *> expressionParser <* eof) -parseModule :: Text -> Either ParseErrorType [ModuleItem Annotation] -parseModule = parse (space *> moduleParser <* eof) "repl" - parseConstraint :: Text -> Either ParseErrorType (Constraint ParseDep Annotation) parseConstraint = parse (space *> constraintParser <* eof) "repl" -parseModuleAndFormatError :: Text -> Either Text [ModuleItem Annotation] -parseModuleAndFormatError = parseAndFormat (space *> moduleParser <* eof) - parseDataTypeAndFormatError :: Text -> Either Text (DataType ParseDep Annotation) parseDataTypeAndFormatError = parseAndFormat (space *> dataTypeParser <* eof) diff --git a/smol-core/src/Smol/Core/Parser/Identifiers.hs b/smol-core/src/Smol/Core/Parser/Identifiers.hs index 2fe153b71..da64926c4 100644 --- a/smol-core/src/Smol/Core/Parser/Identifiers.hs +++ b/smol-core/src/Smol/Core/Parser/Identifiers.hs @@ -10,7 +10,6 @@ module Smol.Core.Parser.Identifiers typeNameParser, plainTypeNameParser, typeclassNameParser, - testNameParser, ) where @@ -20,9 +19,6 @@ import Data.Set (Set) import qualified Data.Set as S import Data.Text (Text) import Data.Void -import Smol.Core.Modules.Types.ModuleName -import Smol.Core.Modules.Types.TestName -import Smol.Core.Parser.Primitives (textPrim) import Smol.Core.Parser.Shared import Smol.Core.Typecheck.Typeclass.Types import Smol.Core.Types @@ -190,8 +186,3 @@ withNamespace p = do myString "." a <- p pure (a, mName) - ------ - -testNameParser :: Parser TestName -testNameParser = myLexeme $ TestName <$> textPrim diff --git a/smol-core/src/Smol/Core/Types.hs b/smol-core/src/Smol/Core/Types.hs index c6ee82b03..4be052b19 100644 --- a/smol-core/src/Smol/Core/Types.hs +++ b/smol-core/src/Smol/Core/Types.hs @@ -6,6 +6,7 @@ module Smol.Core.Types module Smol.Core.Types.Op, module Smol.Core.Types.Expr, module Smol.Core.Types.Identifier, + module Smol.Core.Types.ModuleName, module Smol.Core.Types.ParseDep, module Smol.Core.Types.Pattern, module Smol.Core.Types.Prim, @@ -22,6 +23,7 @@ import Smol.Core.Types.Constructor import Smol.Core.Types.DataType import Smol.Core.Types.Expr import Smol.Core.Types.Identifier +import Smol.Core.Types.ModuleName import Smol.Core.Types.Op import Smol.Core.Types.ParseDep import Smol.Core.Types.Pattern diff --git a/smol-core/src/Smol/Core/Modules/Types/ModuleName.hs b/smol-core/src/Smol/Core/Types/ModuleName.hs similarity index 97% rename from smol-core/src/Smol/Core/Modules/Types/ModuleName.hs rename to smol-core/src/Smol/Core/Types/ModuleName.hs index 1cf3cc9b4..b9c882f66 100644 --- a/smol-core/src/Smol/Core/Modules/Types/ModuleName.hs +++ b/smol-core/src/Smol/Core/Types/ModuleName.hs @@ -3,7 +3,7 @@ {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE OverloadedStrings #-} -module Smol.Core.Modules.Types.ModuleName +module Smol.Core.Types.ModuleName ( ModuleName (..), getModuleName, validModuleName, diff --git a/smol-core/src/Smol/Core/Types/ParseDep.hs b/smol-core/src/Smol/Core/Types/ParseDep.hs index a109fe6e4..e5c2d4b0e 100644 --- a/smol-core/src/Smol/Core/Types/ParseDep.hs +++ b/smol-core/src/Smol/Core/Types/ParseDep.hs @@ -13,8 +13,8 @@ where import Data.Aeson (FromJSON, ToJSON) import Data.String import GHC.Generics (Generic) -import Smol.Core.Modules.Types.ModuleName import Smol.Core.Printer +import Smol.Core.Types.ModuleName --------------------------- diff --git a/smol-core/test/Main.hs b/smol-core/test/Main.hs index 386c93cd5..455a330e6 100644 --- a/smol-core/test/Main.hs +++ b/smol-core/test/Main.hs @@ -5,6 +5,7 @@ import qualified Test.Interpreter.InterpreterSpec import qualified Test.Modules.CheckSpec import qualified Test.Modules.FromPartsSpec import qualified Test.Modules.InterpreterSpec +import qualified Test.Modules.ParserSpec import qualified Test.Modules.PrettyPrintSpec import qualified Test.Modules.ResolveDepsSpec import qualified Test.Modules.RunTestsSpec @@ -29,7 +30,6 @@ main = hspec $ parallel $ do Test.Typecheck.TypeclassSpec.spec Test.Typecheck.ToDictionaryPassingSpec.spec Test.ParserSpec.spec - Test.Interpreter.InterpreterSpec.spec Test.Modules.CheckSpec.spec Test.Modules.FromPartsSpec.spec Test.Modules.InterpreterSpec.spec @@ -37,4 +37,6 @@ main = hspec $ parallel $ do Test.Modules.ResolveDepsSpec.spec Test.Modules.RunTestsSpec.spec Test.Modules.TypecheckSpec.spec + Test.Modules.ParserSpec.spec Test.TransformSpec.spec + Test.Interpreter.InterpreterSpec.spec diff --git a/smol-core/test/Test/Helpers.hs b/smol-core/test/Test/Helpers.hs index 1eeec0554..aa7753b41 100644 --- a/smol-core/test/Test/Helpers.hs +++ b/smol-core/test/Test/Helpers.hs @@ -58,6 +58,7 @@ import Data.Text (Text) import qualified Data.Text as T import Smol.Core import Smol.Core.Modules.FromParts +import Smol.Core.Modules.Parser import Smol.Core.Modules.ResolveDeps import Smol.Core.Modules.Typecheck import Smol.Core.Modules.Types.Module diff --git a/smol-core/test/Test/Interpreter/InterpreterSpec.hs b/smol-core/test/Test/Interpreter/InterpreterSpec.hs index 7b7f1e060..39b11ccd6 100644 --- a/smol-core/test/Test/Interpreter/InterpreterSpec.hs +++ b/smol-core/test/Test/Interpreter/InterpreterSpec.hs @@ -2,16 +2,11 @@ module Test.Interpreter.InterpreterSpec (spec) where -import Control.Monad (void) -import Control.Monad.Reader import Data.Foldable (traverse_) import Data.Text (Text) import Smol.Core import Smol.Core.Interpreter.Types.Stack -import Smol.Core.Modules.Types.Module import Smol.Core.Typecheck.FromParsedExpr -import Smol.Core.Typecheck.Typecheck (typecheck) -import Smol.Core.Typecheck.Typeclass import Test.Helpers import Test.Hspec @@ -29,31 +24,6 @@ discardLeft :: (Show e) => Either e a -> a discardLeft (Left e) = error (show e) discardLeft (Right a) = a -runDictEnv :: ReaderT PassDictEnv m a -> m a -runDictEnv = flip runReaderT emptyPassDictEnv - --- | typecheck, resolve typeclasses, interpret, profit -doInterpret :: Text -> Expr ResolvedDep () -doInterpret input = - let dictEnv = - ToDictEnv - { tdeClasses = tceClasses typecheckEnv, - tdeInstances = fmap void <$> moInstances testModule, - tdeVars = mempty - } - in case typecheck typecheckEnv (fromParsedExpr (unsafeParseExpr input)) of - Right (_constraints, typedExpr) -> - fmap edAnnotation - . discardLeft - . interpret mempty - . addEmptyStackFrames - . void - . discardLeft - . runDictEnv - . passDictionaries dictEnv mempty - $ typedExpr - Left e -> error (show e) - spec :: Spec spec = do describe "InterpreterSpec" $ do @@ -81,18 +51,3 @@ spec = do `shouldBe` fromParsedExpr (unsafeParseExpr expect) ) cases - - -- not sure this is the way - describe "interpret with typeclasses" $ do - let cases = - [ ("equals (1 : Int) (1 : Int)", "True"), -- use Eq Int - ("equals (2 : Int) (1 : Int)", "False"), -- use Eq Int - ("equals ((1 : Int),(1 : Int)) ((1 : Int), (2 : Int))", "False") -- use Eq (a,b) and Eq Int - ] - traverse_ - ( \(input, expect) -> - it (show input <> " = " <> show expect) $ do - doInterpret input - `shouldBe` fromParsedExpr (unsafeParseExpr expect) - ) - cases diff --git a/smol-core/test/Test/Modules/CheckSpec.hs b/smol-core/test/Test/Modules/CheckSpec.hs index a7f793c88..e5c4125d1 100644 --- a/smol-core/test/Test/Modules/CheckSpec.hs +++ b/smol-core/test/Test/Modules/CheckSpec.hs @@ -15,6 +15,7 @@ import Data.Text (Text) import qualified Data.Text.Encoding as T import Smol.Core import Smol.Core.Modules.Check +import Smol.Core.Modules.Parser import Smol.Core.Modules.RunTests import Smol.Core.Modules.Types.ModuleError import Test.Hspec diff --git a/smol-core/test/Test/Modules/InterpreterSpec.hs b/smol-core/test/Test/Modules/InterpreterSpec.hs index e01d74bf6..10e7f99d2 100644 --- a/smol-core/test/Test/Modules/InterpreterSpec.hs +++ b/smol-core/test/Test/Modules/InterpreterSpec.hs @@ -9,6 +9,7 @@ import qualified Error.Diagnose as Diag import Smol.Core import Smol.Core.Modules.Check import Smol.Core.Modules.Interpret +import Smol.Core.Modules.Parser import Smol.Core.Modules.Types.DefIdentifier import Smol.Core.Modules.Types.ModuleError import Smol.Core.Typecheck.FromParsedExpr diff --git a/smol-core/test/Test/Modules/ParserSpec.hs b/smol-core/test/Test/Modules/ParserSpec.hs new file mode 100644 index 000000000..77c7fbb00 --- /dev/null +++ b/smol-core/test/Test/Modules/ParserSpec.hs @@ -0,0 +1,57 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TemplateHaskell #-} + +module Test.Modules.ParserSpec (spec) where + +import Data.Bifunctor (second) +import Data.Either (isRight) +import Data.FileEmbed +import Data.Foldable (traverse_) +import Data.Text (Text) +import qualified Data.Text as T +import qualified Data.Text.Encoding as T +import Smol.Core.Modules.Parser +import Test.Hspec + +-- these are saved in a file that is included in compilation +testInputs :: [(FilePath, Text)] +testInputs = + fmap (second T.decodeUtf8) $(makeRelativeToProject "test/static/" >>= embedDir) + +spec :: Spec +spec = do + describe "Parser" $ do + describe "Module" $ do + let singleDefs = + [ "type Dog a = Woof String | Other a", + "def id : a -> a", + "def id a = a", + "def compose f g a = f (g a)", + "def compose : (c -> b) -> (a -> b) -> (a -> c)", + "def onePlusOneEqualsTwo = 1 + 1 == 2", + "test \"one plus one equals two\" { 1 + 1 == 2 }", + "def usesEquals : (Eq (a,b)) => (a,b) -> (a,b) -> Bool", + "class Eq a { equals: a -> a -> Bool }", + "instance Eq Int { eqInt }", + "instance (Eq a) => Eq (Maybe a) { eqMaybeA }" + ] + + it "All defs" $ do + let result = parseModuleAndFormatError (T.intercalate "\n" (T.pack <$> singleDefs)) + result `shouldSatisfy` isRight + + traverse_ + ( \input -> it ("Parses module item: " <> input) $ do + let result = parseModuleAndFormatError (T.pack input) + + result `shouldSatisfy` isRight + ) + singleDefs + + traverse_ + ( \(filename, contents) -> + it ("Parses " <> filename) $ do + let result = parseModuleAndFormatError contents + result `shouldSatisfy` isRight + ) + testInputs diff --git a/smol-core/test/Test/Modules/PrettyPrintSpec.hs b/smol-core/test/Test/Modules/PrettyPrintSpec.hs index e0e1694e1..a604595df 100644 --- a/smol-core/test/Test/Modules/PrettyPrintSpec.hs +++ b/smol-core/test/Test/Modules/PrettyPrintSpec.hs @@ -12,9 +12,9 @@ import Data.Foldable (traverse_) import Data.Functor import Data.Text (Text) import qualified Data.Text.Encoding as T +import qualified Smol.Core.Modules.Parser as Parse import Smol.Core.Modules.PrettyPrint (printModuleParts) import Smol.Core.Modules.Types.ModuleItem -import qualified Smol.Core.Parser as Parse import Smol.Core.Printer import Test.Hspec diff --git a/smol-core/test/Test/Modules/RunTestsSpec.hs b/smol-core/test/Test/Modules/RunTestsSpec.hs index 318ee3ec6..8d8d29855 100644 --- a/smol-core/test/Test/Modules/RunTestsSpec.hs +++ b/smol-core/test/Test/Modules/RunTestsSpec.hs @@ -5,6 +5,7 @@ module Test.Modules.RunTestsSpec (spec) where import qualified Data.Text as T import Smol.Core import Smol.Core.Modules.Check +import Smol.Core.Modules.Parser import Smol.Core.Modules.RunTests import Smol.Core.Modules.Types import Smol.Core.Modules.Types.ModuleError diff --git a/smol-core/test/Test/Modules/TypecheckSpec.hs b/smol-core/test/Test/Modules/TypecheckSpec.hs index 03679ecf9..84ad5df57 100644 --- a/smol-core/test/Test/Modules/TypecheckSpec.hs +++ b/smol-core/test/Test/Modules/TypecheckSpec.hs @@ -13,6 +13,7 @@ import Data.Text (Text) import qualified Data.Text.Encoding as T import Smol.Core import Smol.Core.Modules.Check +import Smol.Core.Modules.Parser import Smol.Core.Modules.Types hiding (Entity (..)) import Smol.Core.Modules.Types.ModuleError import Test.Helpers diff --git a/smol-core/test/Test/ParserSpec.hs b/smol-core/test/Test/ParserSpec.hs index fae0d10cd..2890413bb 100644 --- a/smol-core/test/Test/ParserSpec.hs +++ b/smol-core/test/Test/ParserSpec.hs @@ -1,28 +1,17 @@ {-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TemplateHaskell #-} module Test.ParserSpec (spec) where -import Data.Bifunctor (second) -import Data.Either (isRight) -import Data.FileEmbed import Data.Foldable (traverse_) import Data.Functor import qualified Data.List.NonEmpty as NE import qualified Data.Map.Strict as M import qualified Data.Sequence as Seq -import Data.Text (Text) import qualified Data.Text as T -import qualified Data.Text.Encoding as T import Smol.Core import Test.Helpers import Test.Hspec --- these are saved in a file that is included in compilation -testInputs :: [(FilePath, Text)] -testInputs = - fmap (second T.decodeUtf8) $(makeRelativeToProject "test/static/" >>= embedDir) - spec :: Spec spec = do describe "Parser" $ do @@ -42,41 +31,6 @@ spec = do ) inputs - describe "Module" $ do - let singleDefs = - [ "type Dog a = Woof String | Other a", - "def id : a -> a", - "def id a = a", - "def compose f g a = f (g a)", - "def compose : (c -> b) -> (a -> b) -> (a -> c)", - "def onePlusOneEqualsTwo = 1 + 1 == 2", - "test \"one plus one equals two\" { 1 + 1 == 2 }", - "def usesEquals : (Eq (a,b)) => (a,b) -> (a,b) -> Bool", - "class Eq a { equals: a -> a -> Bool }", - "instance Eq Int { eqInt }", - "instance (Eq a) => Eq (Maybe a) { eqMaybeA }" - ] - - it "All defs" $ do - let result = parseModuleAndFormatError (T.intercalate "\n" (T.pack <$> singleDefs)) - result `shouldSatisfy` isRight - - traverse_ - ( \input -> it ("Parses module item: " <> input) $ do - let result = parseModuleAndFormatError (T.pack input) - - result `shouldSatisfy` isRight - ) - singleDefs - - traverse_ - ( \(filename, contents) -> - it ("Parses " <> filename) $ do - let result = parseModuleAndFormatError contents - result `shouldSatisfy` isRight - ) - testInputs - describe "Expr" $ do let strings = [ ("True", bool True), diff --git a/smol-repl/src/Smol/Check.hs b/smol-repl/src/Smol/Check.hs index 9743407d0..ee3605013 100644 --- a/smol-repl/src/Smol/Check.hs +++ b/smol-repl/src/Smol/Check.hs @@ -9,11 +9,11 @@ import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.IO as T import Smol.Core.Modules.Check +import Smol.Core.Modules.Parser (parseModule) import Smol.Core.Modules.PrettyPrint (printModuleParts) import Smol.Core.Modules.RunTests import Smol.Core.Modules.Types.ModuleError import Smol.Core.Modules.Types.ModuleItem -import Smol.Core.Parser (parseModule) import Smol.Core.Printer import Smol.Repl.Helpers.Diagnostics import Smol.Repl.Helpers.ShowTestResults diff --git a/smol-repl/src/Smol/Repl.hs b/smol-repl/src/Smol/Repl.hs index 58066ad6b..9daeffbfe 100644 --- a/smol-repl/src/Smol/Repl.hs +++ b/smol-repl/src/Smol/Repl.hs @@ -14,9 +14,9 @@ import qualified Smol.Backend.Compile.RunLLVM as Run import Smol.Backend.IR.FromExpr.Expr import Smol.Backend.IR.ToLLVM.ToLLVM import Smol.Core.Modules.Check +import Smol.Core.Modules.Parser (parseModule) import Smol.Core.Modules.RunTests import Smol.Core.Modules.Types.ModuleError -import Smol.Core.Parser (parseModule) import Smol.Repl.Helpers.Diagnostics import Smol.Repl.Helpers.ShowTestResults import System.Console.Haskeline diff --git a/smol-wasm/test/Test/Wasm/Helpers.hs b/smol-wasm/test/Test/Wasm/Helpers.hs index d8ce6f9ba..f1c4f4efe 100644 --- a/smol-wasm/test/Test/Wasm/Helpers.hs +++ b/smol-wasm/test/Test/Wasm/Helpers.hs @@ -26,8 +26,6 @@ module Test.Wasm.Helpers patternMatch, getRight, unsafeParseExpr, - unsafeParseModule, - unsafeParseModuleItems, unsafeParseType, unsafeParseTypedExpr, joinText, @@ -39,11 +37,9 @@ module Test.Wasm.Helpers unsafeParseInstanceExpr, tcVar, typeForComparison, - testModule, ) where -import Control.Monad.Except import Control.Monad.Reader import Control.Monad.State import Control.Monad.Writer @@ -52,59 +48,17 @@ import Data.Functor import qualified Data.List.NonEmpty as NE import qualified Data.Map.Strict as M import qualified Data.Sequence as Seq -import qualified Data.Set as S import qualified Data.Set.NonEmpty as NES import Data.Text (Text) import qualified Data.Text as T import Smol.Core -import Smol.Core.Modules.FromParts -import Smol.Core.Modules.ResolveDeps -import Smol.Core.Modules.Typecheck -import Smol.Core.Modules.Types.Module -import Smol.Core.Modules.Types.ModuleError -import Smol.Core.Modules.Types.ModuleItem import Smol.Core.Typecheck.FromParsedExpr import Test.Wasm.BuiltInTypes (builtInTypes) -typedModule :: - (MonadError (ModuleError Annotation) m) => - T.Text -> - m (Module ResolvedDep (Type ResolvedDep Annotation)) -typedModule input = do - let moduleItems = case parseModuleAndFormatError input of - Right a -> a - _ -> error "parsing module for typeclass spec" - myModule <- moduleFromModuleParts moduleItems - - let typeClasses = resolveTypeclass <$> moClasses myModule - typeclassMethods = S.fromList . M.elems . fmap tcFuncName $ typeClasses - - (resolvedModule, deps) <- - modifyError ErrorInResolveDeps (resolveModuleDeps typeclassMethods myModule) - - typecheckModule input resolvedModule deps - getRight :: (Show e) => Either e a -> a getRight (Right a) = a getRight (Left e) = error (show e) -testModule :: Module ResolvedDep (Type ResolvedDep Annotation) -testModule = - getRight $ - typedModule $ - joinText - [ "class Eq a { equals: a -> a -> Bool }", - "instance Eq Int { \\a -> \\b -> a == b }", - "instance Eq Bool { \\a -> \\b -> a == b }", - "instance Eq String { \\a -> \\b -> a == b }", - "instance (Eq a, Eq b) => Eq (a,b) { ", - "\\pairA -> \\pairB -> case (pairA, pairB) {((a1, b1), (a2, b2)) -> ", - "if equals a1 a2 then equals b1 b2 else False} }", - "type Natural = Suc Natural | Zero", - "class Show a { show: a -> String }", - "instance Show Natural { \\nat -> case nat { Suc n -> \"S \" + show n , _ -> \"\"} }" - ] - tyBool :: (Monoid ann) => Type dep ann tyBool = TPrim mempty TPBool @@ -204,17 +158,6 @@ unsafeParseType input = case parseTypeAndFormatError input of Right ty -> ty $> () Left e -> error (show e) -unsafeParseModule :: Text -> Module ParseDep () -unsafeParseModule input = - case moduleFromModuleParts (unsafeParseModuleItems input) of - Right a -> a $> () - Left e -> error (show e) - -unsafeParseModuleItems :: Text -> [ModuleItem ()] -unsafeParseModuleItems input = case parseModuleAndFormatError input of - Right parts -> fmap void parts - Left e -> error (show e) - -- | parse a typed expr, ie parse it and fill the type with crap unsafeParseTypedExpr :: Text -> ResolvedExpr (Type ResolvedDep Annotation) unsafeParseTypedExpr input = case parseExprAndFormatError input of