From eb6d054661a2f3196f9e0a3ea51939bde06d4166 Mon Sep 17 00:00:00 2001 From: Pieter Goetschalckx Date: Tue, 8 Sep 2020 17:52:19 +0200 Subject: [PATCH] Add OCaml support --- cabal.project | 4 + cabal.project.ci | 4 + script/ghci-flags | 3 + script/ghci-flags-dependencies | 3 +- semantic-ocaml/BUILD.bazel | 16 ++ semantic-ocaml/LICENSE | 21 ++ semantic-ocaml/README.md | 3 + semantic-ocaml/Setup.hs | 2 + semantic-ocaml/semantic-ocaml.cabal | 75 +++++ semantic-ocaml/src/Language/OCaml.hs | 27 ++ semantic-ocaml/src/Language/OCaml/AST.hs | 33 +++ semantic-ocaml/src/Language/OCaml/Grammar.hs | 12 + semantic-ocaml/src/Language/OCaml/Tags.hs | 279 +++++++++++++++++++ semantic-ocaml/test/PreciseTest.hs | 30 ++ semantic/semantic.cabal | 1 + 15 files changed, 512 insertions(+), 1 deletion(-) create mode 100644 semantic-ocaml/BUILD.bazel create mode 100644 semantic-ocaml/LICENSE create mode 100644 semantic-ocaml/README.md create mode 100644 semantic-ocaml/Setup.hs create mode 100644 semantic-ocaml/semantic-ocaml.cabal create mode 100644 semantic-ocaml/src/Language/OCaml.hs create mode 100644 semantic-ocaml/src/Language/OCaml/AST.hs create mode 100644 semantic-ocaml/src/Language/OCaml/Grammar.hs create mode 100644 semantic-ocaml/src/Language/OCaml/Tags.hs create mode 100644 semantic-ocaml/test/PreciseTest.hs diff --git a/cabal.project b/cabal.project index a94cead21f..75c6d232f5 100644 --- a/cabal.project +++ b/cabal.project @@ -9,6 +9,7 @@ packages: semantic semantic-go semantic-java semantic-json + semantic-ocaml semantic-parse semantic-php semantic-proto @@ -21,6 +22,9 @@ packages: semantic semantic-tsx semantic-typescript +package semantic-ocaml + ghc-options: -freduction-depth=300 + source-repository-package type: git location: https://github.com/antitypical/fused-syntax.git diff --git a/cabal.project.ci b/cabal.project.ci index 7062ce8b0f..9a4ab28805 100644 --- a/cabal.project.ci +++ b/cabal.project.ci @@ -9,6 +9,7 @@ packages: semantic semantic-go semantic-java semantic-json + semantic-ocaml semantic-parse semantic-php semantic-proto @@ -51,6 +52,9 @@ package semantic-java package semantic-json ghc-options: -Werror +package semantic-ocaml + ghc-options: -Werror -freduction-depth=300 + package semantic-parse ghc-options: -Werror diff --git a/script/ghci-flags b/script/ghci-flags index 83b0f095b9..86ba200a58 100755 --- a/script/ghci-flags +++ b/script/ghci-flags @@ -63,6 +63,8 @@ function flags { echo "-isemantic-java/src" echo "-isemantic-json/src" echo "-isemantic-json/test" + echo "-isemantic-ocaml/src" + echo "-isemantic-ocaml/test" echo "-isemantic-parse/src" echo "-isemantic-php/src" echo "-isemantic-proto/src" @@ -103,6 +105,7 @@ function flags { [[ "$ghc_version" = 8.6.* ]] || [[ "$ghc_version" = 8.8.* ]] || [[ "$ghc_version" = 8.10.* ]] && echo "-Wno-star-is-type" || true [[ "$ghc_version" = 8.8.* ]] || [[ "$ghc_version" = 8.10.* ]] && echo "-Wno-missing-deriving-strategies" || true [[ "$ghc_version" = 8.10.* ]] && echo "-Wno-missing-safe-haskell-mode" && echo "-Wno-prepositive-qualified-module" && echo "-Wno-unused-packages" + echo "-freduction-depth=300" } flags > "$output_file" diff --git a/script/ghci-flags-dependencies b/script/ghci-flags-dependencies index cd8c87ebc7..77662f0a82 100755 --- a/script/ghci-flags-dependencies +++ b/script/ghci-flags-dependencies @@ -15,7 +15,8 @@ echo "semantic-tags/semantic-tags.cabal" echo "semantic-go/semantic-go.cabal" echo "semantic-java/semantic-java.cabal" echo "semantic-json/semantic-json.cabal" -echo "semantic-python/semantic-php.cabal" +echo "semantic-ocaml/semantic-ocaml.cabal" +echo "semantic-php/semantic-php.cabal" echo "semantic-python/semantic-python.cabal" echo "semantic-ruby/semantic-ruby.cabal" echo "semantic-tsx/semantic-tsx.cabal" diff --git a/semantic-ocaml/BUILD.bazel b/semantic-ocaml/BUILD.bazel new file mode 100644 index 0000000000..24d43e9118 --- /dev/null +++ b/semantic-ocaml/BUILD.bazel @@ -0,0 +1,16 @@ +package(default_visibility = ["//visibility:public"]) + +load( + "//:build/common.bzl", + "semantic_language_library", + "semantic_language_parsing_test", +) + +semantic_language_library( + name = "semantic-ocaml", + srcs = glob(["src/**/*.hs"]), + language = "ocaml", + nodetypes = "@tree-sitter-ocaml//:vendor/tree-sitter-ocaml/ocaml/src/node-types.json", +) + +semantic_language_parsing_test(language = "ocaml") diff --git a/semantic-ocaml/LICENSE b/semantic-ocaml/LICENSE new file mode 100644 index 0000000000..331b241b36 --- /dev/null +++ b/semantic-ocaml/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 GitHub + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/semantic-ocaml/README.md b/semantic-ocaml/README.md new file mode 100644 index 0000000000..0eed56029b --- /dev/null +++ b/semantic-ocaml/README.md @@ -0,0 +1,3 @@ +# Semantic support for OCaml + +This package implements `semantic` support for OCaml using the `semantic-core` intermediate language. diff --git a/semantic-ocaml/Setup.hs b/semantic-ocaml/Setup.hs new file mode 100644 index 0000000000..9a994af677 --- /dev/null +++ b/semantic-ocaml/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/semantic-ocaml/semantic-ocaml.cabal b/semantic-ocaml/semantic-ocaml.cabal new file mode 100644 index 0000000000..e797d6f4c6 --- /dev/null +++ b/semantic-ocaml/semantic-ocaml.cabal @@ -0,0 +1,75 @@ +cabal-version: 2.4 + +name: semantic-ocaml +version: 0.0.0.0 +synopsis: Semantic support for OCaml. +description: Semantic support for OCaml using the semantic-core intermediate language. +homepage: https://github.com/github/semantic/tree/master/semantic-ocaml#readme +bug-reports: https://github.com/github/semantic/issues +license: MIT +license-file: LICENSE +author: The Semantic authors +maintainer: opensource+semantic@github.com +copyright: (c) 2019 GitHub, Inc. +category: Language +build-type: Simple +stability: alpha +extra-source-files: README.md + +tested-with: GHC == 8.6.5 + +common haskell + default-language: Haskell2010 + ghc-options: + -Weverything + -Wno-missing-local-signatures + -Wno-missing-import-lists + -Wno-implicit-prelude + -Wno-safe + -Wno-unsafe + -Wno-name-shadowing + -Wno-monomorphism-restriction + -Wno-missed-specialisations + -Wno-all-missed-specialisations + -Wno-star-is-type + if (impl(ghc >= 8.8)) + ghc-options: -Wno-missing-deriving-strategies + if (impl(ghc >= 8.10)) + ghc-options: + -Wno-missing-safe-haskell-mode + -Wno-prepositive-qualified-module + cpp-options: + -DBAZEL_BUILD=0 + +library + import: haskell + exposed-modules: + Language.OCaml + Language.OCaml.AST + Language.OCaml.Grammar + Language.OCaml.Tags + hs-source-dirs: src + build-depends: + , base >= 4.13 && < 5 + , fused-effects ^>= 1.1 + , semantic-ast + , semantic-proto ^>= 0 + , semantic-source ^>= 0.1.0.1 + , semantic-tags ^>= 0.0 + , template-haskell >= 2.15 && < 2.17 + , text ^>= 1.2.3 + , tree-sitter ^>= 0.9.0.0 + , tree-sitter-ocaml ^>= 0.1 + +test-suite test + import: haskell + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: PreciseTest.hs + build-depends: + , base + , pathtype ^>= 0.8.1 + , semantic-ast + , semantic-ocaml + , tasty + , tree-sitter-ocaml ^>= 0.1 diff --git a/semantic-ocaml/src/Language/OCaml.hs b/semantic-ocaml/src/Language/OCaml.hs new file mode 100644 index 0000000000..e6a7b5669f --- /dev/null +++ b/semantic-ocaml/src/Language/OCaml.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +-- | Semantic functionality for OCaml programs. +module Language.OCaml +( Term(..) +, Language.OCaml.Grammar.tree_sitter_ocaml +) where + +import AST.Marshal.JSON +import qualified AST.Unmarshal as TS +import Data.Proxy +import qualified Language.OCaml.AST as OCaml +import qualified Language.OCaml.Grammar (tree_sitter_ocaml) +import qualified Language.OCaml.Tags as OCamlTags +import qualified Tags.Tagging.Precise as Tags + +newtype Term a = Term { getTerm :: OCaml.CompilationUnit a } + deriving MarshalJSON + +instance TS.SymbolMatching Term where + matchedSymbols _ = TS.matchedSymbols (Proxy :: Proxy OCaml.CompilationUnit) + showFailure _ = TS.showFailure (Proxy :: Proxy OCaml.CompilationUnit) + +instance TS.Unmarshal Term where + matchers = fmap (fmap (TS.hoist Term)) TS.matchers + +instance Tags.ToTags Term where + tags src = Tags.runTagging src . OCamlTags.tags . getTerm diff --git a/semantic-ocaml/src/Language/OCaml/AST.hs b/semantic-ocaml/src/Language/OCaml/AST.hs new file mode 100644 index 0000000000..1a303d35fe --- /dev/null +++ b/semantic-ocaml/src/Language/OCaml/AST.hs @@ -0,0 +1,33 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveTraversable #-} +{-# LANGUAGE DerivingStrategies #-} +{-# LANGUAGE DuplicateRecordFields #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE QuantifiedConstraints #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeOperators #-} +{-# OPTIONS_GHC -fno-warn-unused-imports #-} + +module Language.OCaml.AST +( module Language.OCaml.AST +, OCaml.getTestCorpusDir +) where + +import Prelude hiding (False, Float, Integer, String, True, Functor) +import AST.GenerateSyntax +import Language.Haskell.TH.Syntax (runIO) +import qualified TreeSitter.OCaml as OCaml (getNodeTypesPath, getTestCorpusDir, tree_sitter_ocaml) + +#ifdef NODE_TYPES_PATH +astDeclarationsForLanguage OCaml.tree_sitter_ocaml +#else +runIO OCaml.getNodeTypesPath >>= astDeclarationsForLanguage OCaml.tree_sitter_ocaml +#endif diff --git a/semantic-ocaml/src/Language/OCaml/Grammar.hs b/semantic-ocaml/src/Language/OCaml/Grammar.hs new file mode 100644 index 0000000000..a4d4107d7b --- /dev/null +++ b/semantic-ocaml/src/Language/OCaml/Grammar.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE TemplateHaskell #-} +module Language.OCaml.Grammar +( tree_sitter_ocaml +, Grammar(..) +) where + +import AST.Grammar.TH +import Language.Haskell.TH +import TreeSitter.OCaml (tree_sitter_ocaml) + +-- | Statically-known rules corresponding to symbols in the grammar. +mkStaticallyKnownRuleGrammarData (mkName "Grammar") tree_sitter_ocaml diff --git a/semantic-ocaml/src/Language/OCaml/Tags.hs b/semantic-ocaml/src/Language/OCaml/Tags.hs new file mode 100644 index 0000000000..d2c3aeb04a --- /dev/null +++ b/semantic-ocaml/src/Language/OCaml/Tags.hs @@ -0,0 +1,279 @@ +{-# LANGUAGE DefaultSignatures #-} +{-# LANGUAGE DisambiguateRecordFields #-} +{-# LANGUAGE FlexibleContexts #-} +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeOperators #-} + + +module Language.OCaml.Tags + ( ToTags (..), + ) +where + +import AST.Element +import qualified AST.Parse as Parse +import AST.Token +import AST.Traversable1 +import Control.Effect.Reader +import Control.Effect.Writer +import Control.Effect.State +import Data.Foldable +import Data.Text as Text +import qualified Language.OCaml.AST as OCaml +import Proto.Semantic as P +import Source.Loc +import Source.Range +import Source.Source as Source +import qualified Tags.Tagging.Precise as Tags + +class ToTags t where + tags :: + ( Has (Reader Source) sig m, + Has (State Tags.LineIndices) sig m, + Has (Writer Tags.Tags) sig m + ) => + t Loc -> + m () + default tags :: + ( Has (Reader Source) sig m, + Has (State Tags.LineIndices) sig m, + Has (Writer Tags.Tags) sig m, + Traversable1 ToTags t + ) => + t Loc -> + m () + tags = gtags + +instance (ToTags l, ToTags r) => ToTags (l :+: r) where + tags (L1 l) = tags l + tags (R1 r) = tags r + +instance ToTags (Token sym n) where tags _ = pure () + +gtags :: + ( Has (Reader Source) sig m, + Has (State Tags.LineIndices) sig m, + Has (Writer Tags.Tags) sig m, + Traversable1 ToTags t + ) => + t Loc -> + m () +gtags = traverse1_ @ToTags (const (pure ())) tags + +instance ToTags OCaml.AbstractType +instance ToTags OCaml.AliasedType +instance ToTags OCaml.AliasPattern +instance ToTags OCaml.AndOperator +instance ToTags OCaml.ApplicationExpression +instance ToTags OCaml.ArrayExpression +instance ToTags OCaml.ArrayGetExpression +instance ToTags OCaml.ArrayPattern +instance ToTags OCaml.AssertExpression +instance ToTags OCaml.AttributeId +instance ToTags OCaml.AttributePayload +instance ToTags OCaml.BigarrayGetExpression +instance ToTags OCaml.Boolean +instance ToTags OCaml.Character +instance ToTags OCaml.ClassApplication +instance ToTags OCaml.ClassBinding +instance ToTags OCaml.ClassBodyType +instance ToTags OCaml.ClassDefinition +instance ToTags OCaml.ClassFunction +instance ToTags OCaml.ClassFunctionType +instance ToTags OCaml.ClassInitializer +instance ToTags OCaml.ClassName +instance ToTags OCaml.ClassPath +instance ToTags OCaml.ClassTypeBinding +instance ToTags OCaml.ClassTypeDefinition +instance ToTags OCaml.ClassTypePath +instance ToTags OCaml.CoercionExpression +instance ToTags OCaml.CompilationUnit +instance ToTags OCaml.ConsExpression +instance ToTags OCaml.ConsPattern +instance ToTags OCaml.ConstrainModule +instance ToTags OCaml.ConstrainType +instance ToTags OCaml.ConstructedType +instance ToTags OCaml.ConstructorDeclaration +instance ToTags OCaml.ConstructorName +instance ToTags OCaml.ConstructorPath +instance ToTags OCaml.ConstructorPattern +instance ToTags OCaml.ConversionSpecification +instance ToTags OCaml.Directive +instance ToTags OCaml.DoClause +instance ToTags OCaml.ElseClause +instance ToTags OCaml.EscapeSequence +instance ToTags OCaml.ExceptionDefinition +instance ToTags OCaml.ExceptionPattern +instance ToTags OCaml.ExpressionItem +instance ToTags OCaml.ExtendedModulePath +instance ToTags OCaml.Extension +instance ToTags OCaml.External +instance ToTags OCaml.FieldDeclaration +instance ToTags OCaml.FieldExpression +instance ToTags OCaml.FieldGetExpression +instance ToTags OCaml.FieldName +instance ToTags OCaml.FieldPath +instance ToTags OCaml.FieldPattern +instance ToTags OCaml.FloatingAttribute +instance ToTags OCaml.ForExpression +instance ToTags OCaml.FunctionExpression +instance ToTags OCaml.FunctionType +instance ToTags OCaml.Functor +instance ToTags OCaml.FunctorType +instance ToTags OCaml.FunExpression +instance ToTags OCaml.Guard +instance ToTags OCaml.HashType +instance ToTags OCaml.IfExpression +instance ToTags OCaml.IncludeModule +instance ToTags OCaml.IncludeModuleType +instance ToTags OCaml.IndexingOperator +instance ToTags OCaml.IndexingOperatorPath +instance ToTags OCaml.InfixExpression +instance ToTags OCaml.InfixOperator +instance ToTags OCaml.InheritanceDefinition +instance ToTags OCaml.InheritanceSpecification +instance ToTags OCaml.InstanceVariableDefinition +instance ToTags OCaml.InstanceVariableExpression +instance ToTags OCaml.InstanceVariableName +instance ToTags OCaml.InstanceVariableSpecification +instance ToTags OCaml.InstantiatedClass +instance ToTags OCaml.InstantiatedClassType +instance ToTags OCaml.ItemAttribute +instance ToTags OCaml.ItemExtension +instance ToTags OCaml.Label +instance ToTags OCaml.LabeledArgument +instance ToTags OCaml.LabelName +instance ToTags OCaml.LazyExpression +instance ToTags OCaml.LazyPattern +instance ToTags OCaml.LetBinding +instance ToTags OCaml.LetClassExpression +instance ToTags OCaml.LetExceptionExpression +instance ToTags OCaml.LetExpression +instance ToTags OCaml.LetModuleExpression +instance ToTags OCaml.LetOpenClassExpression +instance ToTags OCaml.LetOpenClassType +instance ToTags OCaml.LetOpenExpression +instance ToTags OCaml.LetOperator +instance ToTags OCaml.ListExpression +instance ToTags OCaml.ListPattern +instance ToTags OCaml.LocalOpenExpression +instance ToTags OCaml.LocalOpenPattern +instance ToTags OCaml.MatchCase +instance ToTags OCaml.MatchExpression +instance ToTags OCaml.MatchOperator +instance ToTags OCaml.MethodDefinition +instance ToTags OCaml.MethodInvocation +instance ToTags OCaml.MethodName +instance ToTags OCaml.MethodSpecification +instance ToTags OCaml.MethodType +instance ToTags OCaml.ModuleApplication +instance ToTags OCaml.ModuleBinding +instance ToTags OCaml.ModuleDefinition +instance ToTags OCaml.ModuleName +instance ToTags OCaml.ModuleParameter +instance ToTags OCaml.ModulePath +instance ToTags OCaml.ModuleTypeConstraint +instance ToTags OCaml.ModuleTypeDefinition +instance ToTags OCaml.ModuleTypeName +instance ToTags OCaml.ModuleTypeOf +instance ToTags OCaml.ModuleTypePath +instance ToTags OCaml.NewExpression +instance ToTags OCaml.Number +instance ToTags OCaml.ObjectCopyExpression +instance ToTags OCaml.ObjectExpression +instance ToTags OCaml.ObjectType +instance ToTags OCaml.OcamlyaccValue +instance ToTags OCaml.OpenModule +instance ToTags OCaml.OperatorName +instance ToTags OCaml.OrPattern +instance ToTags OCaml.PackageExpression +instance ToTags OCaml.PackagePattern +instance ToTags OCaml.PackageType +instance ToTags OCaml.PackedModule +instance ToTags OCaml.Parameter +instance ToTags OCaml.ParenthesizedClassExpression +instance ToTags OCaml.ParenthesizedExpression +instance ToTags OCaml.ParenthesizedModuleExpression +instance ToTags OCaml.ParenthesizedModuleType +instance ToTags OCaml.ParenthesizedPattern +instance ToTags OCaml.ParenthesizedType +instance ToTags OCaml.PolymorphicType +instance ToTags OCaml.PolymorphicVariantPattern +instance ToTags OCaml.PolymorphicVariantType +instance ToTags OCaml.PrefixExpression +instance ToTags OCaml.PrefixOperator +instance ToTags OCaml.PrettyPrintingIndication +instance ToTags OCaml.ProductExpression +instance ToTags OCaml.QuotedExtension +instance ToTags OCaml.QuotedItemExtension +instance ToTags OCaml.QuotedString +instance ToTags OCaml.RangePattern +instance ToTags OCaml.RecordDeclaration +instance ToTags OCaml.RecordExpression +instance ToTags OCaml.RecordPattern +instance ToTags OCaml.RefutationCase +instance ToTags OCaml.SequenceExpression +instance ToTags OCaml.SetExpression +instance ToTags OCaml.Shebang +instance ToTags OCaml.Signature +instance ToTags OCaml.SignedNumber +instance ToTags OCaml.String +instance ToTags OCaml.StringGetExpression +instance ToTags OCaml.Structure +instance ToTags OCaml.SuperArgument +instance ToTags OCaml.SuperClassExpression +instance ToTags OCaml.SuperClassField +instance ToTags OCaml.SuperClassFieldSpecification +instance ToTags OCaml.SuperClassType +instance ToTags OCaml.SuperConstant +instance ToTags OCaml.SuperExpression +instance ToTags OCaml.SuperExtension +instance ToTags OCaml.SuperItemExtension +instance ToTags OCaml.SuperModuleExpression +instance ToTags OCaml.SuperModuleType +instance ToTags OCaml.SuperParameter +instance ToTags OCaml.SuperPattern +instance ToTags OCaml.SuperPatternNoExn +instance ToTags OCaml.SuperPolymorphicType +instance ToTags OCaml.SuperSequenceExpression +instance ToTags OCaml.SuperSignedConstant +instance ToTags OCaml.SuperSimpleClassExpression +instance ToTags OCaml.SuperSimpleClassType +instance ToTags OCaml.SuperSimpleExpression +instance ToTags OCaml.SuperSimpleModuleExpression +instance ToTags OCaml.SuperSimplePattern +instance ToTags OCaml.SuperSimpleType +instance ToTags OCaml.SuperStructureItem +instance ToTags OCaml.SuperTagSpec +instance ToTags OCaml.SuperTupleType +instance ToTags OCaml.SuperType +instance ToTags OCaml.SuperValueName +instance ToTags OCaml.Tag +instance ToTags OCaml.TagPattern +instance ToTags OCaml.TagSpecification +instance ToTags OCaml.ThenClause +instance ToTags OCaml.ToplevelDirective +instance ToTags OCaml.TryExpression +instance ToTags OCaml.TuplePattern +instance ToTags OCaml.TupleType +instance ToTags OCaml.TypeBinding +instance ToTags OCaml.TypeConstraint +instance ToTags OCaml.TypeConstructor +instance ToTags OCaml.TypeConstructorPath +instance ToTags OCaml.TypedClassExpression +instance ToTags OCaml.TypeDefinition +instance ToTags OCaml.TypedExpression +instance ToTags OCaml.TypedLabel +instance ToTags OCaml.TypedModuleExpression +instance ToTags OCaml.TypedPattern +instance ToTags OCaml.TypeParameterConstraint +instance ToTags OCaml.TypeVariable +instance ToTags OCaml.Unit +instance ToTags OCaml.ValueDefinition +instance ToTags OCaml.ValueName +instance ToTags OCaml.ValuePath +instance ToTags OCaml.ValueSpecification +instance ToTags OCaml.VariantDeclaration +instance ToTags OCaml.WhileExpression diff --git a/semantic-ocaml/test/PreciseTest.hs b/semantic-ocaml/test/PreciseTest.hs new file mode 100644 index 0000000000..51dd5889aa --- /dev/null +++ b/semantic-ocaml/test/PreciseTest.hs @@ -0,0 +1,30 @@ +{-# LANGUAGE CPP, DisambiguateRecordFields, OverloadedStrings, TypeApplications, ImplicitParams #-} +{-# OPTIONS_GHC -Wno-unused-imports #-} +module Main (main) where + +import TreeSitter.OCaml +import AST.TestHelpers +import AST.Unmarshal +import qualified Language.OCaml.AST as Ts +import qualified System.Path as Path +import Test.Tasty +import qualified System.Path.Fixture as Fixture + +main :: IO () +main = do +#if BAZEL_BUILD + rf <- Fixture.create + let ?project = Path.relDir "external/tree-sitter-ocaml" + ?runfiles = rf + let dirs = Fixture.absRelDir "ocaml/corpus" +#else + dirs <- Path.absRel <$> Ts.getTestCorpusDir +#endif + + readCorpusFiles' dirs + >>= traverse (testCorpus parse) + >>= defaultMain . tests + where parse = parseByteString @Ts.CompilationUnit @() tree_sitter_ocaml + +tests :: [TestTree] -> TestTree +tests = testGroup "tree-sitter-ocaml corpus tests" diff --git a/semantic/semantic.cabal b/semantic/semantic.cabal index 0e0938b321..a2009c0979 100644 --- a/semantic/semantic.cabal +++ b/semantic/semantic.cabal @@ -129,6 +129,7 @@ library , semantic-go ^>= 0 , semantic-java ^>= 0 , semantic-json ^>= 0 + , semantic-ocaml ^>= 0 , semantic-php ^>= 0 , semantic-proto ^>= 0 , semantic-python ^>= 0