mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Assign type signatures and function types
This commit is contained in:
parent
97c71544ea
commit
4c162ab20d
@ -41,6 +41,7 @@ type Syntax = '[
|
||||
, Syntax.Error
|
||||
, Syntax.Field
|
||||
, Syntax.FunctionConstructor
|
||||
, Syntax.FunctionType
|
||||
, Syntax.GADT
|
||||
, Syntax.Identifier
|
||||
, Syntax.ListConstructor
|
||||
@ -51,6 +52,7 @@ type Syntax = '[
|
||||
, Syntax.StrictTypeVariable
|
||||
, Syntax.TupleConstructor
|
||||
, Syntax.Type
|
||||
, Syntax.TypeSignature
|
||||
, Syntax.TypeSynonym
|
||||
, Syntax.UnitConstructor
|
||||
, Type.TypeParameters
|
||||
@ -87,6 +89,7 @@ expressionChoices = [
|
||||
, float
|
||||
, functionConstructor
|
||||
, functionDeclaration
|
||||
, functionType
|
||||
, gadtDeclaration
|
||||
, integer
|
||||
, listConstructor
|
||||
@ -161,6 +164,9 @@ typeClassIdentifier = makeTerm <$> symbol TypeClassIdentifier <*> (Syntax.Identi
|
||||
typeConstructorIdentifier :: Assignment
|
||||
typeConstructorIdentifier = makeTerm <$> symbol TypeConstructorIdentifier <*> (Syntax.Identifier . Name.name <$> source)
|
||||
|
||||
typeSignature :: Assignment
|
||||
typeSignature = makeTerm <$> symbol TypeSignature <*> children (Syntax.TypeSignature <$> variableIdentifier <* token Annotation <*> type')
|
||||
|
||||
typeVariableIdentifier :: Assignment
|
||||
typeVariableIdentifier = makeTerm <$> symbol TypeVariableIdentifier <*> (Syntax.Identifier . Name.name <$> source)
|
||||
|
||||
@ -182,6 +188,9 @@ functionDeclaration = makeTerm
|
||||
<*> (manyTermsTill expression (symbol FunctionBody) <|> pure [])
|
||||
<*> functionBody)
|
||||
|
||||
functionType :: Assignment
|
||||
functionType = makeTerm <$> symbol FunctionType <*> children (Syntax.FunctionType <$> type' <*> type')
|
||||
|
||||
gadtDeclaration :: Assignment
|
||||
gadtDeclaration = makeTerm
|
||||
<$> symbol GadtDeclaration
|
||||
@ -226,16 +235,26 @@ tuplingConstructor = makeTerm <$> symbol TuplingConstructor <*> (tupleWithArity
|
||||
where tupleWithArity = Syntax.TupleConstructor . succ . count ','
|
||||
|
||||
type' :: Assignment
|
||||
type' = (makeTerm <$> symbol Type <*> children (Syntax.Type <$> typeConstructor <*> typeParameters))
|
||||
<|> (makeTerm <$> symbol TypePattern <*> children (Syntax.Type <$> typeConstructor <*> typeParameters))
|
||||
type' = class'
|
||||
<|> functionType
|
||||
<|> parenthesizedTypePattern
|
||||
<|> strictType
|
||||
<|> typeConstructor
|
||||
<|> class'
|
||||
<|> typePattern
|
||||
|
||||
type'' :: Assignment
|
||||
type'' = makeTerm
|
||||
<$> symbol Type
|
||||
<*> children (Syntax.Type
|
||||
<$> (typeConstructor <|> typeVariableIdentifier)
|
||||
<*> typeParameters)
|
||||
|
||||
typeParameters :: Assignment
|
||||
typeParameters = makeTerm <$> location <*> (Type.TypeParameters <$> many expression)
|
||||
|
||||
typePattern :: Assignment
|
||||
typePattern = makeTerm <$> symbol TypePattern <*> children (Syntax.Type <$> typeConstructor <*> typeParameters)
|
||||
|
||||
float :: Assignment
|
||||
float = makeTerm <$> symbol Float <*> (Literal.Float <$> source)
|
||||
|
||||
|
@ -153,3 +153,13 @@ instance Ord1 GADT where liftCompare = genericLiftCompare
|
||||
instance Show1 GADT where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance Evaluatable GADT
|
||||
|
||||
data FunctionType a = FunctionType { functionTypeLeft :: a, functionTypeRight :: a }
|
||||
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Mergeable, Ord, Show, ToJSONFields1, Traversable)
|
||||
|
||||
instance Eq1 FunctionType where liftEq = genericLiftEq
|
||||
instance Ord1 FunctionType where liftCompare = genericLiftCompare
|
||||
instance Show1 FunctionType where liftShowsPrec = genericLiftShowsPrec
|
||||
|
||||
instance Evaluatable FunctionType
|
||||
|
||||
|
@ -65,31 +65,46 @@
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
(Empty))
|
||||
(Datatype
|
||||
(Empty)
|
||||
|
@ -65,31 +65,43 @@
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
(Constructor
|
||||
(Empty)
|
||||
{ (Identifier)
|
||||
->(Identifier) }
|
||||
(TypeParameters))
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Constructor
|
||||
{+(Empty)+}
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Constructor
|
||||
{-(Empty)-}
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
(Empty))
|
||||
(Datatype
|
||||
(Empty)
|
||||
|
2
test/fixtures/haskell/corpus/type-signatures.A.hs
vendored
Normal file
2
test/fixtures/haskell/corpus/type-signatures.A.hs
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
bar :: a -> b -> c -> Int -> Maybe Int
|
||||
bar :: a -> b -> c -> [Int] -> Maybe Int
|
1
test/fixtures/haskell/corpus/type-signatures.B.hs
vendored
Normal file
1
test/fixtures/haskell/corpus/type-signatures.B.hs
vendored
Normal file
@ -0,0 +1 @@
|
||||
foo :: a -> b -> c -> Int -> Maybe Int
|
72
test/fixtures/haskell/corpus/type-signatures.diffA-B.txt
vendored
Normal file
72
test/fixtures/haskell/corpus/type-signatures.diffA-B.txt
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
(Module
|
||||
(Empty)
|
||||
{ (Statements
|
||||
{-(TypeSignature
|
||||
{-(Identifier)-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters
|
||||
{-(Identifier)-})-})-})-})-})-})-})-}
|
||||
{-(TypeSignature
|
||||
{-(Identifier)-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Array
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-})-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters
|
||||
{-(Identifier)-})-})-})-})-})-})-})-})
|
||||
->(TypeSignature
|
||||
{+(Identifier)+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters
|
||||
{+(Identifier)+})+})+})+})+})+})+}) })
|
72
test/fixtures/haskell/corpus/type-signatures.diffB-A.txt
vendored
Normal file
72
test/fixtures/haskell/corpus/type-signatures.diffB-A.txt
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
(Module
|
||||
(Empty)
|
||||
{ (TypeSignature
|
||||
{-(Identifier)-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(FunctionType
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters)-})-}
|
||||
{-(Type
|
||||
{-(Identifier)-}
|
||||
{-(TypeParameters
|
||||
{-(Identifier)-})-})-})-})-})-})-})
|
||||
->(Statements
|
||||
{+(TypeSignature
|
||||
{+(Identifier)+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters
|
||||
{+(Identifier)+})+})+})+})+})+})+})+}
|
||||
{+(TypeSignature
|
||||
{+(Identifier)+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(FunctionType
|
||||
{+(Type
|
||||
{+(Array
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters)+})+})+}
|
||||
{+(TypeParameters)+})+}
|
||||
{+(Type
|
||||
{+(Identifier)+}
|
||||
{+(TypeParameters
|
||||
{+(Identifier)+})+})+})+})+})+})+})+}) })
|
50
test/fixtures/haskell/corpus/type-signatures.parseA.txt
vendored
Normal file
50
test/fixtures/haskell/corpus/type-signatures.parseA.txt
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
(Module
|
||||
(Empty)
|
||||
(Statements
|
||||
(TypeSignature
|
||||
(Identifier)
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters
|
||||
(Identifier))))))))
|
||||
(TypeSignature
|
||||
(Identifier)
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Array
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters)))
|
||||
(TypeParameters))
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters
|
||||
(Identifier))))))))))
|
24
test/fixtures/haskell/corpus/type-signatures.parseB.txt
vendored
Normal file
24
test/fixtures/haskell/corpus/type-signatures.parseB.txt
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
(Module
|
||||
(Empty)
|
||||
(TypeSignature
|
||||
(Identifier)
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(FunctionType
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters))
|
||||
(Type
|
||||
(Identifier)
|
||||
(TypeParameters
|
||||
(Identifier)))))))))
|
Loading…
Reference in New Issue
Block a user