diff --git a/src/Language/Java/Assignment.hs b/src/Language/Java/Assignment.hs index 4d60b93e4..b12592ed5 100644 --- a/src/Language/Java/Assignment.hs +++ b/src/Language/Java/Assignment.hs @@ -145,13 +145,12 @@ expressionChoices = , continue , constructorDeclaration , explicitConstructorInvocation - -- , constantDeclaration + -- , TODO: constantDeclaration , doWhile , fieldDeclaration , float , for , enum - -- , hexadecimal , if' , interface , identifier @@ -239,16 +238,6 @@ scopedIdentifier = makeTerm <$> symbol ScopedIdentifier <*> children (Expression superInterfaces :: Assignment.Assignment [] Grammar [Term] superInterfaces = symbol SuperInterfaces *> children (symbol InterfaceTypeList *> children(manyTerm type')) --- a *> b --- both of these are impure --- getLine *> getLine --- in half apply, they're both monadic impure actions --- :t (<$) --- :t (*>) - --- what does it mean to say monadic action? more precise term: sequence-able --- a sequence of applicative actions can be executed left to right --- applicative computations can't do branch and control flow; applicative computations can only compute in a direct line, monadic can compute arbitrary branches -- Declarations class' :: Assignment @@ -257,19 +246,11 @@ class' = makeTerm <$> symbol ClassDeclaration <*> children (makeClass <$> many m makeClass modifiers identifier typeParams superClass superInterfaces = Declaration.Class (modifiers ++ typeParams) identifier (maybeToList superClass ++ superInterfaces) -- not doing an assignment, just straight up function classBody = makeTerm <$> symbol ClassBody <*> children (manyTerm expression) superClass = symbol Superclass *> children type' - -- matching term expression won't work since there is no node for that; it's AnonExtends - -- superClass = makeTerm <$> symbol SuperClass <*> children (Java.Syntax.SuperClass <$> term expression <*> type') - -- We'd still like to match the SuperClass node, but we don't need to create a syntax to make a term - -- Do you lose info by omitting the superclass term? No... - -- Don't need to make a term since we're not using syntax - -- what's the difference between using tokens: AnonExtends GenericType? - -- optional: when something can or can't exist and you want to produce a Maybe --- TODO: superclass -- need to match the superclass node when it exists (which will be a rule, similar to how the type params rule matches the typeparams node when it exists) --- optional, when we have a single term --- superInterfaces is also optional but since it produces a list, lists already have an empty value so we don't need to wrap it up in a maybe to get an empty value +-- TODO: superclass +-- need to match the superclass node when it exists (which will be a rule, similar to how the type params rule matches the typeparams node when it exists) +-- optional, when we have a single term +-- superInterfaces is also optional but since it produces a list, lists already have an empty value so we don't need to wrap it up in a maybe to get an empty value --- define this at the top level, we may change TS grammar so that if someone wants to write a Java snippet we could assign --- it correctly; fieldDeclaration is standalone (compared to a type, which doesn't say anything by itself) fieldDeclaration :: Assignment fieldDeclaration = makeTerm <$> symbol FieldDeclaration <*> children ((,) <$> manyTerm modifier <*> type' <**> variableDeclaratorList) @@ -281,14 +262,8 @@ method = makeTerm <$> symbol MethodDeclaration <*> children (makeMethod <$> many methodHeader = symbol MethodHeader *> children ((,,,,) <$> (typeParameters <|> pure []) <*> manyTerm annotation <*> type' <*> methodDeclarator <*> (throws <|> pure [])) makeMethod modifiers receiver (typeParams, annotations, returnType, (name, params), throws) = Declaration.Method (returnType : modifiers ++ typeParams ++ annotations ++ throws) receiver name params --- TODO: add genericType --- Question: should this genericType be part of type or not? Its own type because it's different structurally - generic :: Assignment generic = makeTerm <$> symbol Grammar.GenericType <*> children(Java.Syntax.GenericType <$> term type' <*> manyTerm type') --- when do we make a term again? - if we want to wrap something in a syntax constructor, because each piece of syntax --- will be populated by further terms inside it. in this case, we wrap two terms in a piece of syntax. --- Q to help decide: do we lose anything by omitting the term? methodInvocation :: Assignment methodInvocation = makeTerm <$> symbol MethodInvocation <*> children (Expression.Call [] <$> (callFunction <$> expression <*> optional (token AnonDot *> expression)) <*> (argumentList <|> pure []) <*> emptyTerm) @@ -318,14 +293,9 @@ interface = makeTerm <$> symbol InterfaceDeclaration <*> children (normal <|> an annotationType = symbol AnnotationTypeDeclaration *> children (Declaration.InterfaceDeclaration [] <$> identifier <*> annotationTypeBody) annotationTypeBody = makeTerm <$> symbol AnnotationTypeBody <*> children (many expression) interfaceMemberDeclaration = symbol InterfaceMemberDeclaration *> children (term expression) - -- we won't make a term because we have a choice of a bunch of things package :: Assignment --- package = makeTerm <$> symbol PackageDeclaration <*> children (Java.Syntax.Package <$> someTerm expression) -package = do - loc <- symbol PackageDeclaration -- location which is calling the symbol API - c <- children $ do Java.Syntax.Package <$> someTerm expression - pure (makeTerm loc c) -- pure is re-wrapping it back into the outer context, which in this case is Assignment (ie., the return type of the function) +package = makeTerm <$> symbol PackageDeclaration <*> children (Java.Syntax.Package <$> someTerm expression) enum :: Assignment enum = makeTerm <$> symbol Grammar.EnumDeclaration <*> children (Java.Syntax.EnumDeclaration <$> term identifier <*> manyTerm enumConstant) @@ -515,12 +485,10 @@ constructorDeclaration = makeTerm <$> symbol ConstructorDeclaration <*> children constructor modifiers (typeParameters, identifier, formalParameters) = Java.Syntax.Constructor modifiers typeParameters identifier formalParameters -- let partial application do its thing typeParameters :: Assignment.Assignment [] Grammar [Term] -typeParameters = symbol TypeParameters *> children (manyTerm typeParam) -- this produces a list, which is what we need to return given by the type definition +typeParameters = symbol TypeParameters *> children (manyTerm typeParam) where - typeParam = makeTerm <$> symbol Grammar.TypeParameter <*> children (Java.Syntax.TypeParameter <$> manyTerm annotation <*> term identifier <*> (typeBound <|> pure [])) -- wrapping up all three of those fields so we need to makeTerm (producing a term here) + typeParam = makeTerm <$> symbol Grammar.TypeParameter <*> children (Java.Syntax.TypeParameter <$> manyTerm annotation <*> term identifier <*> (typeBound <|> pure [])) typeBound = symbol TypeBound *> children (manyTerm type') - -- manyTerm typeParam made sense because each type Parameter was wrapped up into a Grammar.TypeParameter node, dissimilar - -- to superInterfaces annotation :: Assignment annotation = makeTerm <$> symbol NormalAnnotation <*> children (Java.Syntax.Annotation <$> term expression <*> (elementValuePairList <|> pure [])) @@ -540,14 +508,6 @@ formalParameters = manyTerm parameter parameter = makeTerm <$> symbol FormalParameter <*> children (makeAnnotation <$> manyTerm modifier <*> type' <* symbol VariableDeclaratorId <*> children identifier) makeAnnotation [] type' variableName = Type.Annotation variableName type' makeAnnotation modifiers type' variableName = Type.Annotation variableName (makeTerm1 (Java.Syntax.TypeWithModifiers modifiers type')) --- know when we are in a functor context and fmap is all gravy --- we're just wrapping stuff up in data, we aren't building a pattern (assignment) so we aren't in an applicative context --- when in an applicative context, we're also in a functor context (ie., defining how fmap will work over it) --- sometimes it is nice to be able to say you're in an applicative context without refering to any particular applicative instance - --- constantDeclaration :: Assignment --- constantDeclaration = makeTerm <$> symbol ConstantDeclaration <*> castExpression :: Assignment castExpression = makeTerm <$> symbol CastExpression <*> children (flip Type.Annotation <$> type' <*> term expression) --- term expression, because we can deal with comments diff --git a/src/Language/Java/Syntax.hs b/src/Language/Java/Syntax.hs index e9f08ce85..bd963ffe0 100644 --- a/src/Language/Java/Syntax.hs +++ b/src/Language/Java/Syntax.hs @@ -7,7 +7,7 @@ import Prologue hiding (Constructor) import Data.JSON.Fields newtype Import a = Import [a] - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Import where liftEq = genericLiftEq instance Ord1 Import where liftCompare = genericLiftCompare @@ -17,7 +17,7 @@ instance Show1 Import where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Import data Module a = Module { moduleIdentifier :: !a, moduleStatements :: ![a] } - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Module where liftEq = genericLiftEq instance Ord1 Module where liftCompare = genericLiftCompare @@ -26,7 +26,7 @@ instance Show1 Module where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Module newtype Package a = Package [a] - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Package where liftEq = genericLiftEq instance Ord1 Package where liftCompare = genericLiftCompare @@ -36,7 +36,7 @@ instance Show1 Package where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Package data EnumDeclaration a = EnumDeclaration { _enumDeclarationIdentifier :: !a, _enumDeclarationBody :: ![a] } - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 EnumDeclaration where liftEq = genericLiftEq instance Ord1 EnumDeclaration where liftCompare = genericLiftCompare @@ -45,7 +45,7 @@ instance Evaluatable EnumDeclaration data Variable a = Variable { variableModifiers :: ![a], variableType :: !a, variableName :: !a} - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Variable where liftEq = genericLiftEq instance Ord1 Variable where liftCompare = genericLiftCompare @@ -55,7 +55,7 @@ instance Show1 Variable where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Variable data Synchronized a = Synchronized { synchronizedSubject :: !a, synchronizedBody :: !a} - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Synchronized where liftEq = genericLiftEq instance Ord1 Synchronized where liftCompare = genericLiftCompare @@ -65,7 +65,7 @@ instance Show1 Synchronized where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Synchronized data New a = New { newType :: !a, newArgs :: ![a] } - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 New where liftEq = genericLiftEq instance Ord1 New where liftCompare = genericLiftCompare @@ -75,7 +75,7 @@ instance Show1 New where liftShowsPrec = genericLiftShowsPrec instance Evaluatable New data Asterisk a = Asterisk - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Asterisk where liftEq = genericLiftEq instance Ord1 Asterisk where liftCompare = genericLiftCompare @@ -86,7 +86,7 @@ instance Evaluatable Asterisk data Constructor a = Constructor { constructorModifiers :: ![a], constructorTypeParams :: ![a], constructorIdentifier :: !a, constructorParams :: ![a], constructorThrows :: ![a], constructorBody :: a} - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Constructor where liftEq = genericLiftEq instance Ord1 Constructor where liftCompare = genericLiftCompare @@ -96,7 +96,7 @@ instance Show1 Constructor where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Constructor data TypeParameter a = TypeParameter { typeParamAnnotation :: ![a], typeParamIdentifier :: !a, typeParamTypeBound :: ![a]} - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 TypeParameter where liftEq = genericLiftEq instance Ord1 TypeParameter where liftCompare = genericLiftCompare @@ -106,7 +106,7 @@ instance Show1 TypeParameter where liftShowsPrec = genericLiftShowsPrec instance Evaluatable TypeParameter data Annotation a = Annotation { annotationName :: !a, annotationField :: [a]} - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 Annotation where liftEq = genericLiftEq instance Ord1 Annotation where liftCompare = genericLiftCompare @@ -116,7 +116,7 @@ instance Show1 Annotation where liftShowsPrec = genericLiftShowsPrec instance Evaluatable Annotation data AnnotationField a = AnnotationField { annotationFieldName :: a, annotationFieldValue :: a } - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 AnnotationField where liftEq = genericLiftEq instance Ord1 AnnotationField where liftCompare = genericLiftCompare @@ -126,7 +126,7 @@ instance Show1 AnnotationField where liftShowsPrec = genericLiftShowsPrec instance Evaluatable AnnotationField data GenericType a = GenericType { genericTypeIdentifier :: a, genericTypeArguments :: [a] } - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 GenericType where liftEq = genericLiftEq instance Ord1 GenericType where liftCompare = genericLiftCompare @@ -136,7 +136,7 @@ instance Show1 GenericType where liftShowsPrec = genericLiftShowsPrec instance Evaluatable GenericType data TypeWithModifiers a = TypeWithModifiers [a] a - deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) + deriving (Diffable, Eq, FreeVariables1, Foldable, Functor, Generic1, Mergeable, Ord, Show, Traversable, Declarations1, ToJSONFields1, Hashable1) instance Eq1 TypeWithModifiers where liftEq = genericLiftEq instance Ord1 TypeWithModifiers where liftCompare = genericLiftCompare diff --git a/test/fixtures/java/binary.java b/test/fixtures/java/corpus/binary.java similarity index 100% rename from test/fixtures/java/binary.java rename to test/fixtures/java/corpus/binary.java diff --git a/test/fixtures/java/boolean.java b/test/fixtures/java/corpus/boolean.java similarity index 100% rename from test/fixtures/java/boolean.java rename to test/fixtures/java/corpus/boolean.java diff --git a/test/fixtures/java/char.java b/test/fixtures/java/corpus/char.java similarity index 100% rename from test/fixtures/java/char.java rename to test/fixtures/java/corpus/char.java diff --git a/test/fixtures/java/comment.java b/test/fixtures/java/corpus/comment.java similarity index 100% rename from test/fixtures/java/comment.java rename to test/fixtures/java/corpus/comment.java diff --git a/test/fixtures/java/continue.java b/test/fixtures/java/corpus/continue.java similarity index 100% rename from test/fixtures/java/continue.java rename to test/fixtures/java/corpus/continue.java diff --git a/test/fixtures/java/dims.java b/test/fixtures/java/corpus/dims.java similarity index 100% rename from test/fixtures/java/dims.java rename to test/fixtures/java/corpus/dims.java diff --git a/test/fixtures/java/do-while.java b/test/fixtures/java/corpus/do-while.java similarity index 100% rename from test/fixtures/java/do-while.java rename to test/fixtures/java/corpus/do-while.java diff --git a/test/fixtures/java/enum.java b/test/fixtures/java/corpus/enum.java similarity index 100% rename from test/fixtures/java/enum.java rename to test/fixtures/java/corpus/enum.java diff --git a/test/fixtures/java/float.java b/test/fixtures/java/corpus/float.java similarity index 100% rename from test/fixtures/java/float.java rename to test/fixtures/java/corpus/float.java diff --git a/test/fixtures/java/for.java b/test/fixtures/java/corpus/for.java similarity index 100% rename from test/fixtures/java/for.java rename to test/fixtures/java/corpus/for.java diff --git a/test/fixtures/java/if.java b/test/fixtures/java/corpus/if.java similarity index 100% rename from test/fixtures/java/if.java rename to test/fixtures/java/corpus/if.java diff --git a/test/fixtures/java/import.java b/test/fixtures/java/corpus/import.java similarity index 100% rename from test/fixtures/java/import.java rename to test/fixtures/java/corpus/import.java diff --git a/test/fixtures/java/int.java b/test/fixtures/java/corpus/int.java similarity index 100% rename from test/fixtures/java/int.java rename to test/fixtures/java/corpus/int.java diff --git a/test/fixtures/java/interface.java b/test/fixtures/java/corpus/interface.java similarity index 100% rename from test/fixtures/java/interface.java rename to test/fixtures/java/corpus/interface.java diff --git a/test/fixtures/java/modifier-abstract.java b/test/fixtures/java/corpus/modifier-abstract.java similarity index 100% rename from test/fixtures/java/modifier-abstract.java rename to test/fixtures/java/corpus/modifier-abstract.java diff --git a/test/fixtures/java/modifier-private.java b/test/fixtures/java/corpus/modifier-private.java similarity index 100% rename from test/fixtures/java/modifier-private.java rename to test/fixtures/java/corpus/modifier-private.java diff --git a/test/fixtures/java/modifier-protected.java b/test/fixtures/java/corpus/modifier-protected.java similarity index 100% rename from test/fixtures/java/modifier-protected.java rename to test/fixtures/java/corpus/modifier-protected.java diff --git a/test/fixtures/java/modifier-public.java b/test/fixtures/java/corpus/modifier-public.java similarity index 100% rename from test/fixtures/java/modifier-public.java rename to test/fixtures/java/corpus/modifier-public.java diff --git a/test/fixtures/java/modifier-static.java b/test/fixtures/java/corpus/modifier-static.java similarity index 100% rename from test/fixtures/java/modifier-static.java rename to test/fixtures/java/corpus/modifier-static.java diff --git a/test/fixtures/java/null.java b/test/fixtures/java/corpus/null.java similarity index 100% rename from test/fixtures/java/null.java rename to test/fixtures/java/corpus/null.java diff --git a/test/fixtures/java/package.java b/test/fixtures/java/corpus/package.java similarity index 100% rename from test/fixtures/java/package.java rename to test/fixtures/java/corpus/package.java diff --git a/test/fixtures/java/return.java b/test/fixtures/java/corpus/return.java similarity index 100% rename from test/fixtures/java/return.java rename to test/fixtures/java/corpus/return.java diff --git a/test/fixtures/java/string.java b/test/fixtures/java/corpus/string.java similarity index 100% rename from test/fixtures/java/string.java rename to test/fixtures/java/corpus/string.java diff --git a/test/fixtures/java/switch.java b/test/fixtures/java/corpus/switch.java similarity index 100% rename from test/fixtures/java/switch.java rename to test/fixtures/java/corpus/switch.java diff --git a/test/fixtures/java/throws.java b/test/fixtures/java/corpus/throws.java similarity index 100% rename from test/fixtures/java/throws.java rename to test/fixtures/java/corpus/throws.java diff --git a/test/fixtures/java/try-catches.java b/test/fixtures/java/corpus/try-catches.java similarity index 100% rename from test/fixtures/java/try-catches.java rename to test/fixtures/java/corpus/try-catches.java diff --git a/test/fixtures/java/update.java b/test/fixtures/java/corpus/update.java similarity index 100% rename from test/fixtures/java/update.java rename to test/fixtures/java/corpus/update.java diff --git a/test/fixtures/java/variable-declaration.java b/test/fixtures/java/corpus/variable-declaration.java similarity index 100% rename from test/fixtures/java/variable-declaration.java rename to test/fixtures/java/corpus/variable-declaration.java diff --git a/test/fixtures/java/while.java b/test/fixtures/java/corpus/while.java similarity index 100% rename from test/fixtures/java/while.java rename to test/fixtures/java/corpus/while.java