Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial LSP Server (Linting, Parsing, Typecheck) #8

Closed
wants to merge 18 commits into from
Closed
Prev Previous commit
Next Next commit
Address review comments, fix object pretty instance
  • Loading branch information
rsoeldner committed Mar 22, 2023
commit e37963d7de996ab0d2308bede941f13c017a4711
30 changes: 22 additions & 8 deletions pact-core-tests/Pact/Core/Test/LexerParserTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import qualified Pact.Core.Syntax.Lisp.Parser as Lisp
import Pact.Core.Syntax.Lisp.LexUtils (Token(..))
import Pact.Core.Literal


showPretty :: Pretty a => a -> BS.ByteString
showPretty = BS.pack . show . pretty

Expand Down Expand Up @@ -115,15 +114,23 @@ parsedExprToSrc :: Lisp.Expr () -> BS.ByteString
parsedExprToSrc = BS.pack . show . pretty

varGen :: ParserGen
varGen = Gen.choice [bn, qn]
varGen = (`Lisp.Var` ()) <$> parsedNameGen

parsedNameGen :: Gen ParsedName
parsedNameGen = Gen.choice [qn, bn]
where
bn = (\n -> Lisp.Var (BN $ BareName n) ()) <$> identGen
bn = BN . BareName <$> identGen
qn = do
modName <- identGen
name <- identGen
modNs <- Gen.maybe (NamespaceName <$> identGen)
let qname = QualifiedName name (ModuleName modName modNs)
pure $ Lisp.Var (QN qname) ()
mn <- moduleNameGen
let qname = QualifiedName name mn
pure (QN qname)

moduleNameGen :: Gen ModuleName
moduleNameGen = do
modName <- identGen
modNS <- Gen.maybe (NamespaceName <$> identGen)
pure (ModuleName modName modNS)

constantGen :: ParserGen
constantGen = (`Lisp.Constant` ()) <$> Gen.choice
Expand Down Expand Up @@ -178,7 +185,14 @@ exprGen = Gen.recursive Gen.choice
typeGen :: Gen Lisp.Type
typeGen = Gen.recursive Gen.choice
(Gen.constant . Lisp.TyPrim <$> [minBound ..])
[Lisp.TyList <$> typeGen]
[Lisp.TyList <$> typeGen
,pure Lisp.TyPolyList
,Lisp.TyModRef <$> moduleNameGen
,pure Lisp.TyGuard
,pure Lisp.TyKeyset
,Lisp.TyObject <$> parsedNameGen
,pure Lisp.TyTime
,pure Lisp.TyPolyObject]

binderGen = do
name <- identGen
Expand Down
3 changes: 0 additions & 3 deletions pact-core-tests/PactCoreTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import Test.Tasty
import qualified Pact.Core.Test.ReplTests as ReplTests
import qualified Pact.Core.Test.LexerParserTests as LexerParserTests
import qualified Pact.Core.Test.LexerTests as LexerTests
import qualified Pact.Core.Test.ParserTests as ParserTests


main :: IO ()
main = do
replTests <- ReplTests.tests
defaultMain $ testGroup "pactTests"
[ replTests
, LexerTests.tests
, ParserTests.tests
, LexerParserTests.tests
]
1 change: 0 additions & 1 deletion pact-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,3 @@ test-suite core-tests
, Pact.Core.Test.ReplTests
, Pact.Core.Test.LexerParserTests
, Pact.Core.Test.LexerTests
, Pact.Core.Test.ParserTests
2 changes: 1 addition & 1 deletion pact-core/Pact/Core/Syntax/Lisp/ParseTree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ instance Pretty Type where
TyPolyList -> "list"
TyGuard -> "guard"
TyKeyset -> "keyset"
TyObject qn -> "object" <> brackets (pretty qn)
TyObject qn -> "object" <> braces (pretty qn)
TyPolyObject -> "object"
TyTime -> "time"

Expand Down