diff --git a/src/Language/Haskell/Assignment.hs b/src/Language/Haskell/Assignment.hs index cc24bc24f..2d51ba5b3 100644 --- a/src/Language/Haskell/Assignment.hs +++ b/src/Language/Haskell/Assignment.hs @@ -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) diff --git a/src/Language/Haskell/Syntax.hs b/src/Language/Haskell/Syntax.hs index a215a1041..0dd555b14 100644 --- a/src/Language/Haskell/Syntax.hs +++ b/src/Language/Haskell/Syntax.hs @@ -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 + diff --git a/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffA-B.txt b/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffA-B.txt index 5a1531a9a..bb2ecfc5e 100644 --- a/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffA-B.txt +++ b/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffA-B.txt @@ -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) diff --git a/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffB-A.txt b/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffB-A.txt index dc109a703..274fb42c3 100644 --- a/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffB-A.txt +++ b/test/fixtures/haskell/corpus/algebraic-datatype-declarations.diffB-A.txt @@ -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) diff --git a/test/fixtures/haskell/corpus/type-signatures.A.hs b/test/fixtures/haskell/corpus/type-signatures.A.hs new file mode 100644 index 000000000..181bdea3a --- /dev/null +++ b/test/fixtures/haskell/corpus/type-signatures.A.hs @@ -0,0 +1,2 @@ +bar :: a -> b -> c -> Int -> Maybe Int +bar :: a -> b -> c -> [Int] -> Maybe Int diff --git a/test/fixtures/haskell/corpus/type-signatures.B.hs b/test/fixtures/haskell/corpus/type-signatures.B.hs new file mode 100644 index 000000000..bf0f94e19 --- /dev/null +++ b/test/fixtures/haskell/corpus/type-signatures.B.hs @@ -0,0 +1 @@ +foo :: a -> b -> c -> Int -> Maybe Int diff --git a/test/fixtures/haskell/corpus/type-signatures.diffA-B.txt b/test/fixtures/haskell/corpus/type-signatures.diffA-B.txt new file mode 100644 index 000000000..3ff813744 --- /dev/null +++ b/test/fixtures/haskell/corpus/type-signatures.diffA-B.txt @@ -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)+})+})+})+})+})+})+}) }) diff --git a/test/fixtures/haskell/corpus/type-signatures.diffB-A.txt b/test/fixtures/haskell/corpus/type-signatures.diffB-A.txt new file mode 100644 index 000000000..1d8eb2ff0 --- /dev/null +++ b/test/fixtures/haskell/corpus/type-signatures.diffB-A.txt @@ -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)+})+})+})+})+})+})+})+}) }) diff --git a/test/fixtures/haskell/corpus/type-signatures.parseA.txt b/test/fixtures/haskell/corpus/type-signatures.parseA.txt new file mode 100644 index 000000000..c9291b776 --- /dev/null +++ b/test/fixtures/haskell/corpus/type-signatures.parseA.txt @@ -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)))))))))) diff --git a/test/fixtures/haskell/corpus/type-signatures.parseB.txt b/test/fixtures/haskell/corpus/type-signatures.parseB.txt new file mode 100644 index 000000000..016943570 --- /dev/null +++ b/test/fixtures/haskell/corpus/type-signatures.parseB.txt @@ -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)))))))))