1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 01:42:43 +03:00

Merge branch 'master' into readline-path-types

This commit is contained in:
Rob Rix 2019-10-11 17:32:45 -04:00 committed by GitHub
commit a691ebbe76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 4 deletions

View File

@ -17,9 +17,11 @@ import Core.Core as Core
import Core.Name as Name
import Data.Coerce
import Data.Foldable
import Data.Function
import Data.List.NonEmpty (NonEmpty (..))
import GHC.Records
import Source.Span (Span)
import Syntax.Stack (Stack)
import Syntax.Stack (Stack (..))
import qualified Syntax.Stack as Stack
import qualified TreeSitter.Python.AST as Py
@ -176,7 +178,22 @@ instance Compile Py.Block where
instance Compile Py.BooleanOperator
instance Compile Py.BreakStatement
instance Compile Py.Call
instance Compile Py.Call where
compile it@Py.Call
{ function
, arguments = L1 Py.ArgumentList { extraChildren = args }
} cc next = do
func <- compile function pure next
let compileArg = \case
Prj expr -> compile (expr :: Py.Expression Span) pure next
other -> fail ("Can't compile non-expression function argument: " <> show other)
-- Python function arguments are defined to evaluate left to right.
args <- traverse compileArg args
locate it (func $$* args) & cc
compile it _ _ = fail ("can't compile Call node with generator expression: " <> show it)
instance Compile Py.ClassDefinition
instance Compile Py.ComparisonOperator
@ -185,10 +202,32 @@ deriving instance Compile Py.CompoundStatement
instance Compile Py.ConcatenatedString
instance Compile Py.ConditionalExpression
instance Compile Py.ContinueStatement
instance Compile Py.DecoratedDefinition
instance Compile Py.DecoratedDefinition where
compile it@Py.DecoratedDefinition
{ definition
, extraChildren = [ Py.Decorator { extraChildren } ]
} cc next = do
let thenReassign item = do
_ :> lastbound <- asks unBindings
tocall <- compile extraChildren pure next
let callit go = (pure lastbound .= (tocall $$ pure lastbound)) >>> go
fmap callit (cc item)
locate it <$> compile definition thenReassign next
compile it _ _ = fail ("Can't figure out decorated definition " <> show it)
instance Compile Py.DeleteStatement
instance Compile Py.Dictionary
instance Compile Py.DictionaryComprehension
instance Compile Py.DottedName where
compile it@Py.DottedName
{ extraChildren = Py.Identifier { text } :| rest
} cc _next = do
let aggregate Py.Identifier { text = inner } x = x ... Name inner
composite = foldr aggregate (pure (Name text)) rest
locate it composite & cc
instance Compile Py.Ellipsis
instance Compile Py.ExecStatement
@ -253,6 +292,7 @@ instance Compile Py.IfStatement where
instance Compile Py.ImportFromStatement
instance Compile Py.ImportStatement
instance Compile Py.Integer
instance Compile Py.Lambda
instance Compile Py.List
instance Compile Py.ListComprehension
@ -274,7 +314,11 @@ instance Compile Py.NamedExpression
instance Compile Py.None
instance Compile Py.NonlocalStatement
instance Compile Py.NotOperator
instance Compile Py.ParenthesizedExpression
instance Compile Py.ParenthesizedExpression where
compile it@Py.ParenthesizedExpression { extraChildren } cc
= fmap (locate it)
. compile extraChildren cc
instance Compile Py.PassStatement where
compile it@Py.PassStatement {} cc _ = cc $ locate it Core.unit

View File

@ -0,0 +1,4 @@
# CHECK-TREE: { const <- \x -> \y -> x; y <- const #true #true; z <- const #false #false; #record { const: const, y : y, z: z, }}
def const(x, y): return x
y = const(True, True)
z = const(False, False)

View File

@ -0,0 +1,7 @@
# CHECK-TREE: { const <- \a -> \b -> { identity <- \x -> x; identity a }; #record{ const: const }}
def const(a, b):
def identity(x):
return x
return identity(a)

View File

@ -0,0 +1,11 @@
# CHECK-JQ: .scope.zilch[0].b[0].span == { start: [8, 8], end: [ 8, 16 ] }
# CHECK-JQ: .scope.result[0].a[0].span == { start: [5, 8], end: [ 5, 16 ] }
def const(a, b):
def result():
return a
def zilch(b):
return b
return result()

View File

@ -0,0 +1,7 @@
# CHECK-TREE: { passthru <- \x -> x; decorated <- \x -> x; decorated = passthru(decorated); #record { passthru: passthru, decorated: decorated }}
def passthru(x):
return x
@passthru
def decorated(x):
return x

View File

@ -129,6 +129,7 @@ textToLanguage :: T.Text -> Language
textToLanguage = \case
"Go" -> Go
"Haskell" -> Haskell
"Hack" -> PHP -- working around https://github.com/github/semantic/issues/330
"Java" -> Java
"JavaScript" -> JavaScript
"JSON" -> JSON

View File

@ -8,6 +8,11 @@ testTree :: TestTree
testTree = testGroup "Data.Language"
[ testCase "supportedExts returns expected list" $
supportedExts @=? [".go",".java",".rb",".builder",".eye",".fcgi",".gemspec",".god",".jbuilder",".mspec",".pluginspec",".podspec",".rabl",".rake",".rbuild",".rbw",".rbx",".ru",".ruby",".spec",".thor",".watchr",".py",".bzl",".cgi",".fcgi",".gyp",".gypi",".lmi",".py3",".pyde",".pyi",".pyp",".pyt",".pyw",".rpy",".spec",".tac",".wsgi",".xpy",".js","._js",".bones",".es",".es6",".frag",".gs",".jake",".jsb",".jscad",".jsfl",".jsm",".jss",".mjs",".njs",".pac",".sjs",".ssjs",".xsjs",".xsjslib",".ts",".php",".aw",".ctp",".fcgi",".inc",".php3",".php4",".php5",".phps",".phpt"]
, testCase "codeNavLanguages returns expected list" $
codeNavLanguages @=? [Go, Java, Ruby, Python, JavaScript, TypeScript, PHP]
, testCase "languageForFilePath works for languages with ambiguous lingo extensions" $ do
languageForFilePath "foo.php" @=? PHP
languageForFilePath "foo.md" @=? Markdown
]