mirror of
https://github.com/github/semantic.git
synced 2024-12-26 00:12:29 +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.Error
|
||||||
, Syntax.Field
|
, Syntax.Field
|
||||||
, Syntax.FunctionConstructor
|
, Syntax.FunctionConstructor
|
||||||
|
, Syntax.FunctionType
|
||||||
, Syntax.GADT
|
, Syntax.GADT
|
||||||
, Syntax.Identifier
|
, Syntax.Identifier
|
||||||
, Syntax.ListConstructor
|
, Syntax.ListConstructor
|
||||||
@ -51,6 +52,7 @@ type Syntax = '[
|
|||||||
, Syntax.StrictTypeVariable
|
, Syntax.StrictTypeVariable
|
||||||
, Syntax.TupleConstructor
|
, Syntax.TupleConstructor
|
||||||
, Syntax.Type
|
, Syntax.Type
|
||||||
|
, Syntax.TypeSignature
|
||||||
, Syntax.TypeSynonym
|
, Syntax.TypeSynonym
|
||||||
, Syntax.UnitConstructor
|
, Syntax.UnitConstructor
|
||||||
, Type.TypeParameters
|
, Type.TypeParameters
|
||||||
@ -87,6 +89,7 @@ expressionChoices = [
|
|||||||
, float
|
, float
|
||||||
, functionConstructor
|
, functionConstructor
|
||||||
, functionDeclaration
|
, functionDeclaration
|
||||||
|
, functionType
|
||||||
, gadtDeclaration
|
, gadtDeclaration
|
||||||
, integer
|
, integer
|
||||||
, listConstructor
|
, listConstructor
|
||||||
@ -161,6 +164,9 @@ typeClassIdentifier = makeTerm <$> symbol TypeClassIdentifier <*> (Syntax.Identi
|
|||||||
typeConstructorIdentifier :: Assignment
|
typeConstructorIdentifier :: Assignment
|
||||||
typeConstructorIdentifier = makeTerm <$> symbol TypeConstructorIdentifier <*> (Syntax.Identifier . Name.name <$> source)
|
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 :: Assignment
|
||||||
typeVariableIdentifier = makeTerm <$> symbol TypeVariableIdentifier <*> (Syntax.Identifier . Name.name <$> source)
|
typeVariableIdentifier = makeTerm <$> symbol TypeVariableIdentifier <*> (Syntax.Identifier . Name.name <$> source)
|
||||||
|
|
||||||
@ -182,6 +188,9 @@ functionDeclaration = makeTerm
|
|||||||
<*> (manyTermsTill expression (symbol FunctionBody) <|> pure [])
|
<*> (manyTermsTill expression (symbol FunctionBody) <|> pure [])
|
||||||
<*> functionBody)
|
<*> functionBody)
|
||||||
|
|
||||||
|
functionType :: Assignment
|
||||||
|
functionType = makeTerm <$> symbol FunctionType <*> children (Syntax.FunctionType <$> type' <*> type')
|
||||||
|
|
||||||
gadtDeclaration :: Assignment
|
gadtDeclaration :: Assignment
|
||||||
gadtDeclaration = makeTerm
|
gadtDeclaration = makeTerm
|
||||||
<$> symbol GadtDeclaration
|
<$> symbol GadtDeclaration
|
||||||
@ -226,16 +235,26 @@ tuplingConstructor = makeTerm <$> symbol TuplingConstructor <*> (tupleWithArity
|
|||||||
where tupleWithArity = Syntax.TupleConstructor . succ . count ','
|
where tupleWithArity = Syntax.TupleConstructor . succ . count ','
|
||||||
|
|
||||||
type' :: Assignment
|
type' :: Assignment
|
||||||
type' = (makeTerm <$> symbol Type <*> children (Syntax.Type <$> typeConstructor <*> typeParameters))
|
type' = class'
|
||||||
<|> (makeTerm <$> symbol TypePattern <*> children (Syntax.Type <$> typeConstructor <*> typeParameters))
|
<|> functionType
|
||||||
<|> parenthesizedTypePattern
|
<|> parenthesizedTypePattern
|
||||||
<|> strictType
|
<|> strictType
|
||||||
<|> typeConstructor
|
<|> typeConstructor
|
||||||
<|> class'
|
<|> typePattern
|
||||||
|
|
||||||
|
type'' :: Assignment
|
||||||
|
type'' = makeTerm
|
||||||
|
<$> symbol Type
|
||||||
|
<*> children (Syntax.Type
|
||||||
|
<$> (typeConstructor <|> typeVariableIdentifier)
|
||||||
|
<*> typeParameters)
|
||||||
|
|
||||||
typeParameters :: Assignment
|
typeParameters :: Assignment
|
||||||
typeParameters = makeTerm <$> location <*> (Type.TypeParameters <$> many expression)
|
typeParameters = makeTerm <$> location <*> (Type.TypeParameters <$> many expression)
|
||||||
|
|
||||||
|
typePattern :: Assignment
|
||||||
|
typePattern = makeTerm <$> symbol TypePattern <*> children (Syntax.Type <$> typeConstructor <*> typeParameters)
|
||||||
|
|
||||||
float :: Assignment
|
float :: Assignment
|
||||||
float = makeTerm <$> symbol Float <*> (Literal.Float <$> source)
|
float = makeTerm <$> symbol Float <*> (Literal.Float <$> source)
|
||||||
|
|
||||||
|
@ -153,3 +153,13 @@ instance Ord1 GADT where liftCompare = genericLiftCompare
|
|||||||
instance Show1 GADT where liftShowsPrec = genericLiftShowsPrec
|
instance Show1 GADT where liftShowsPrec = genericLiftShowsPrec
|
||||||
|
|
||||||
instance Evaluatable GADT
|
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)
|
||||||
->(Identifier) }
|
->(Identifier) }
|
||||||
(TypeParameters))
|
(TypeParameters))
|
||||||
(Constructor
|
{+(Constructor
|
||||||
(Empty)
|
{+(Empty)+}
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) }
|
{+(TypeParameters)+})+}
|
||||||
(TypeParameters))
|
{+(Constructor
|
||||||
(Constructor
|
{+(Empty)+}
|
||||||
(Empty)
|
{+(Identifier)+}
|
||||||
{ (Identifier)
|
{+(TypeParameters)+})+}
|
||||||
->(Identifier) }
|
{+(Constructor
|
||||||
(TypeParameters))
|
{+(Empty)+}
|
||||||
(Constructor
|
{+(Identifier)+}
|
||||||
(Empty)
|
{+(TypeParameters)+})+}
|
||||||
{ (Identifier)
|
{+(Constructor
|
||||||
->(Identifier) }
|
{+(Empty)+}
|
||||||
(TypeParameters))
|
{+(Identifier)+}
|
||||||
(Constructor
|
{+(TypeParameters)+})+}
|
||||||
(Empty)
|
{+(Constructor
|
||||||
{ (Identifier)
|
{+(Empty)+}
|
||||||
->(Identifier) }
|
{+(Identifier)+}
|
||||||
(TypeParameters))
|
{+(TypeParameters)+})+}
|
||||||
(Constructor
|
{-(Constructor
|
||||||
(Empty)
|
{-(Empty)-}
|
||||||
{ (Identifier)
|
{-(Identifier)-}
|
||||||
->(Identifier) }
|
{-(TypeParameters)-})-}
|
||||||
(TypeParameters))
|
{-(Constructor
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(TypeParameters)-})-}
|
||||||
|
{-(Constructor
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(TypeParameters)-})-}
|
||||||
|
{-(Constructor
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(TypeParameters)-})-}
|
||||||
|
{-(Constructor
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(TypeParameters)-})-}
|
||||||
(Empty))
|
(Empty))
|
||||||
(Datatype
|
(Datatype
|
||||||
(Empty)
|
(Empty)
|
||||||
|
@ -65,31 +65,43 @@
|
|||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) }
|
->(Identifier) }
|
||||||
(TypeParameters))
|
(TypeParameters))
|
||||||
|
{+(Constructor
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(TypeParameters)+})+}
|
||||||
|
{+(Constructor
|
||||||
|
{+(Empty)+}
|
||||||
|
{+(Identifier)+}
|
||||||
|
{+(TypeParameters)+})+}
|
||||||
(Constructor
|
(Constructor
|
||||||
(Empty)
|
(Empty)
|
||||||
{ (Identifier)
|
{ (Identifier)
|
||||||
->(Identifier) }
|
->(Identifier) }
|
||||||
(TypeParameters))
|
(TypeParameters))
|
||||||
(Constructor
|
{+(Constructor
|
||||||
(Empty)
|
{+(Empty)+}
|
||||||
{ (Identifier)
|
{+(Identifier)+}
|
||||||
->(Identifier) }
|
{+(TypeParameters)+})+}
|
||||||
(TypeParameters))
|
{+(Constructor
|
||||||
(Constructor
|
{+(Empty)+}
|
||||||
(Empty)
|
{+(Identifier)+}
|
||||||
{ (Identifier)
|
{+(TypeParameters)+})+}
|
||||||
->(Identifier) }
|
{-(Constructor
|
||||||
(TypeParameters))
|
{-(Empty)-}
|
||||||
(Constructor
|
{-(Identifier)-}
|
||||||
(Empty)
|
{-(TypeParameters)-})-}
|
||||||
{ (Identifier)
|
{-(Constructor
|
||||||
->(Identifier) }
|
{-(Empty)-}
|
||||||
(TypeParameters))
|
{-(Identifier)-}
|
||||||
(Constructor
|
{-(TypeParameters)-})-}
|
||||||
(Empty)
|
{-(Constructor
|
||||||
{ (Identifier)
|
{-(Empty)-}
|
||||||
->(Identifier) }
|
{-(Identifier)-}
|
||||||
(TypeParameters))
|
{-(TypeParameters)-})-}
|
||||||
|
{-(Constructor
|
||||||
|
{-(Empty)-}
|
||||||
|
{-(Identifier)-}
|
||||||
|
{-(TypeParameters)-})-}
|
||||||
(Empty))
|
(Empty))
|
||||||
(Datatype
|
(Datatype
|
||||||
(Empty)
|
(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