1
1
mirror of https://github.com/github/semantic.git synced 2024-12-01 00:33:59 +03:00

Merge branch 'normalize-unevaluated-module-tables' of https://github.com/github/semantic into normalize-unevaluated-module-tables

This commit is contained in:
Rob Rix 2018-06-05 09:49:13 -04:00
commit f55200ede4
31 changed files with 22 additions and 62 deletions

View File

@ -145,13 +145,12 @@ expressionChoices =
, continue , continue
, constructorDeclaration , constructorDeclaration
, explicitConstructorInvocation , explicitConstructorInvocation
-- , constantDeclaration -- , TODO: constantDeclaration
, doWhile , doWhile
, fieldDeclaration , fieldDeclaration
, float , float
, for , for
, enum , enum
-- , hexadecimal
, if' , if'
, interface , interface
, identifier , identifier
@ -239,16 +238,6 @@ scopedIdentifier = makeTerm <$> symbol ScopedIdentifier <*> children (Expression
superInterfaces :: Assignment.Assignment [] Grammar [Term] superInterfaces :: Assignment.Assignment [] Grammar [Term]
superInterfaces = symbol SuperInterfaces *> children (symbol InterfaceTypeList *> children(manyTerm type')) 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 -- Declarations
class' :: Assignment 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 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) classBody = makeTerm <$> symbol ClassBody <*> children (manyTerm expression)
superClass = symbol Superclass *> children type' superClass = symbol Superclass *> children type'
-- matching term expression won't work since there is no node for that; it's AnonExtends -- TODO: superclass
-- superClass = makeTerm <$> symbol SuperClass <*> children (Java.Syntax.SuperClass <$> term expression <*> type') -- 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)
-- We'd still like to match the SuperClass node, but we don't need to create a syntax to make a term -- optional, when we have a single term
-- Do you lose info by omitting the superclass term? No... -- 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
-- 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
-- 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 :: Assignment
fieldDeclaration = makeTerm <$> symbol FieldDeclaration <*> children ((,) <$> manyTerm modifier <*> type' <**> variableDeclaratorList) 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 [])) 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 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 :: Assignment
generic = makeTerm <$> symbol Grammar.GenericType <*> children(Java.Syntax.GenericType <$> term type' <*> manyTerm type') 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 :: Assignment
methodInvocation = makeTerm <$> symbol MethodInvocation <*> children (Expression.Call [] <$> (callFunction <$> expression <*> optional (token AnonDot *> expression)) <*> (argumentList <|> pure []) <*> emptyTerm) 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) annotationType = symbol AnnotationTypeDeclaration *> children (Declaration.InterfaceDeclaration [] <$> identifier <*> annotationTypeBody)
annotationTypeBody = makeTerm <$> symbol AnnotationTypeBody <*> children (many expression) annotationTypeBody = makeTerm <$> symbol AnnotationTypeBody <*> children (many expression)
interfaceMemberDeclaration = symbol InterfaceMemberDeclaration *> children (term 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 :: Assignment
-- package = makeTerm <$> symbol PackageDeclaration <*> children (Java.Syntax.Package <$> someTerm expression) 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)
enum :: Assignment enum :: Assignment
enum = makeTerm <$> symbol Grammar.EnumDeclaration <*> children (Java.Syntax.EnumDeclaration <$> term identifier <*> manyTerm enumConstant) 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 constructor modifiers (typeParameters, identifier, formalParameters) = Java.Syntax.Constructor modifiers typeParameters identifier formalParameters -- let partial application do its thing
typeParameters :: Assignment.Assignment [] Grammar [Term] 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 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') 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 :: Assignment
annotation = makeTerm <$> symbol NormalAnnotation <*> children (Java.Syntax.Annotation <$> term expression <*> (elementValuePairList <|> pure [])) 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) parameter = makeTerm <$> symbol FormalParameter <*> children (makeAnnotation <$> manyTerm modifier <*> type' <* symbol VariableDeclaratorId <*> children identifier)
makeAnnotation [] type' variableName = Type.Annotation variableName type' makeAnnotation [] type' variableName = Type.Annotation variableName type'
makeAnnotation modifiers type' variableName = Type.Annotation variableName (makeTerm1 (Java.Syntax.TypeWithModifiers modifiers 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 :: Assignment
castExpression = makeTerm <$> symbol CastExpression <*> children (flip Type.Annotation <$> type' <*> term expression) castExpression = makeTerm <$> symbol CastExpression <*> children (flip Type.Annotation <$> type' <*> term expression)
-- term expression, because we can deal with comments

View File

@ -7,7 +7,7 @@ import Prologue hiding (Constructor)
import Data.JSON.Fields import Data.JSON.Fields
newtype Import a = Import [a] 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 Eq1 Import where liftEq = genericLiftEq
instance Ord1 Import where liftCompare = genericLiftCompare instance Ord1 Import where liftCompare = genericLiftCompare
@ -17,7 +17,7 @@ instance Show1 Import where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Import instance Evaluatable Import
data Module a = Module { moduleIdentifier :: !a, moduleStatements :: ![a] } 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 Eq1 Module where liftEq = genericLiftEq
instance Ord1 Module where liftCompare = genericLiftCompare instance Ord1 Module where liftCompare = genericLiftCompare
@ -26,7 +26,7 @@ instance Show1 Module where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Module instance Evaluatable Module
newtype Package a = Package [a] 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 Eq1 Package where liftEq = genericLiftEq
instance Ord1 Package where liftCompare = genericLiftCompare instance Ord1 Package where liftCompare = genericLiftCompare
@ -36,7 +36,7 @@ instance Show1 Package where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Package instance Evaluatable Package
data EnumDeclaration a = EnumDeclaration { _enumDeclarationIdentifier :: !a, _enumDeclarationBody :: ![a] } 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 Eq1 EnumDeclaration where liftEq = genericLiftEq
instance Ord1 EnumDeclaration where liftCompare = genericLiftCompare instance Ord1 EnumDeclaration where liftCompare = genericLiftCompare
@ -45,7 +45,7 @@ instance Evaluatable EnumDeclaration
data Variable a = Variable { variableModifiers :: ![a], variableType :: !a, variableName :: !a} 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 Eq1 Variable where liftEq = genericLiftEq
instance Ord1 Variable where liftCompare = genericLiftCompare instance Ord1 Variable where liftCompare = genericLiftCompare
@ -55,7 +55,7 @@ instance Show1 Variable where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Variable instance Evaluatable Variable
data Synchronized a = Synchronized { synchronizedSubject :: !a, synchronizedBody :: !a} 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 Eq1 Synchronized where liftEq = genericLiftEq
instance Ord1 Synchronized where liftCompare = genericLiftCompare instance Ord1 Synchronized where liftCompare = genericLiftCompare
@ -65,7 +65,7 @@ instance Show1 Synchronized where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Synchronized instance Evaluatable Synchronized
data New a = New { newType :: !a, newArgs :: ![a] } 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 Eq1 New where liftEq = genericLiftEq
instance Ord1 New where liftCompare = genericLiftCompare instance Ord1 New where liftCompare = genericLiftCompare
@ -75,7 +75,7 @@ instance Show1 New where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable New instance Evaluatable New
data Asterisk a = Asterisk 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 Eq1 Asterisk where liftEq = genericLiftEq
instance Ord1 Asterisk where liftCompare = genericLiftCompare 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} 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 Eq1 Constructor where liftEq = genericLiftEq
instance Ord1 Constructor where liftCompare = genericLiftCompare instance Ord1 Constructor where liftCompare = genericLiftCompare
@ -96,7 +96,7 @@ instance Show1 Constructor where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Constructor instance Evaluatable Constructor
data TypeParameter a = TypeParameter { typeParamAnnotation :: ![a], typeParamIdentifier :: !a, typeParamTypeBound :: ![a]} 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 Eq1 TypeParameter where liftEq = genericLiftEq
instance Ord1 TypeParameter where liftCompare = genericLiftCompare instance Ord1 TypeParameter where liftCompare = genericLiftCompare
@ -106,7 +106,7 @@ instance Show1 TypeParameter where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable TypeParameter instance Evaluatable TypeParameter
data Annotation a = Annotation { annotationName :: !a, annotationField :: [a]} 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 Eq1 Annotation where liftEq = genericLiftEq
instance Ord1 Annotation where liftCompare = genericLiftCompare instance Ord1 Annotation where liftCompare = genericLiftCompare
@ -116,7 +116,7 @@ instance Show1 Annotation where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Annotation instance Evaluatable Annotation
data AnnotationField a = AnnotationField { annotationFieldName :: a, annotationFieldValue :: a } 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 Eq1 AnnotationField where liftEq = genericLiftEq
instance Ord1 AnnotationField where liftCompare = genericLiftCompare instance Ord1 AnnotationField where liftCompare = genericLiftCompare
@ -126,7 +126,7 @@ instance Show1 AnnotationField where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable AnnotationField instance Evaluatable AnnotationField
data GenericType a = GenericType { genericTypeIdentifier :: a, genericTypeArguments :: [a] } 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 Eq1 GenericType where liftEq = genericLiftEq
instance Ord1 GenericType where liftCompare = genericLiftCompare instance Ord1 GenericType where liftCompare = genericLiftCompare
@ -136,7 +136,7 @@ instance Show1 GenericType where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable GenericType instance Evaluatable GenericType
data TypeWithModifiers a = TypeWithModifiers [a] a 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 Eq1 TypeWithModifiers where liftEq = genericLiftEq
instance Ord1 TypeWithModifiers where liftCompare = genericLiftCompare instance Ord1 TypeWithModifiers where liftCompare = genericLiftCompare