1
1
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:
Rick Winfrey 2018-06-05 16:01:37 -07:00
parent 97c71544ea
commit 4c162ab20d
10 changed files with 325 additions and 48 deletions

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -0,0 +1,2 @@
bar :: a -> b -> c -> Int -> Maybe Int
bar :: a -> b -> c -> [Int] -> Maybe Int

View File

@ -0,0 +1 @@
foo :: a -> b -> c -> Int -> Maybe Int

View 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)+})+})+})+})+})+})+}) })

View 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)+})+})+})+})+})+})+})+}) })

View 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))))))))))

View 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)))))))))