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

Update language assignments to use AccessControl

This commit is contained in:
Rick Winfrey 2019-01-15 12:25:21 -08:00
parent dac3b47256
commit 201a305756
6 changed files with 30 additions and 30 deletions

View File

@ -37,7 +37,7 @@ type Syntax =
, Declaration.MethodSignature
, Declaration.Type
, Declaration.TypeAlias
, Declaration.Visibility
, Declaration.AccessControl
, Expression.Plus
, Expression.Minus
, Expression.Times

View File

@ -46,7 +46,7 @@ type Syntax =
, Declaration.InterfaceDeclaration
, Declaration.Method
, Declaration.VariableDeclaration
, Declaration.Visibility
, Declaration.AccessControl
, Expression.Plus
, Expression.Minus
, Expression.Times

View File

@ -41,7 +41,7 @@ type Syntax =
'[ Comment.Comment
, Declaration.Function
, Declaration.Method
, Declaration.Visibility
, Declaration.AccessControl
, Expression.Minus
, Expression.Plus
, Expression.Times

View File

@ -43,7 +43,7 @@ type Syntax = '[
, Declaration.Function
, Declaration.Method
, Declaration.VariableDeclaration
, Declaration.Visibility
, Declaration.AccessControl
, Expression.Plus
, Expression.Minus
, Expression.Times
@ -444,17 +444,17 @@ classMemberDeclaration = choice [
traitUseClause
]
-- TODO: What should the `location` be for implicit `public` visibility modifier?
publicVisibility :: Assignment Term
publicVisibility = makeTerm <$> location <*> pure Declaration.Public
-- TODO: What should the `location` be for implicit `public` access control modifier?
publicAccessControl :: Assignment Term
publicAccessControl = makeTerm <$> location <*> pure Declaration.Public
methodDeclaration :: Assignment Term
methodDeclaration = (makeTerm <$> symbol MethodDeclaration <*> children (makeMethod1 <$> (visibilityModifier <|> publicVisibility) <*> manyTerm methodModifier <*> emptyTerm <*> functionDefinitionParts))
<|> makeTerm <$> symbol MethodDeclaration <*> children (makeMethod2 <$> (visibilityModifier <|> publicVisibility) <*> someTerm methodModifier <*> emptyTerm <*> term name <*> parameters <*> term (returnType <|> emptyTerm) <*> emptyTerm)
methodDeclaration = (makeTerm <$> symbol MethodDeclaration <*> children (makeMethod1 <$> (accessControlModifier <|> publicAccessControl) <*> manyTerm methodModifier <*> emptyTerm <*> functionDefinitionParts))
<|> makeTerm <$> symbol MethodDeclaration <*> children (makeMethod2 <$> (accessControlModifier <|> publicAccessControl) <*> someTerm methodModifier <*> emptyTerm <*> term name <*> parameters <*> term (returnType <|> emptyTerm) <*> emptyTerm)
where
functionDefinitionParts = symbol FunctionDefinition *> children ((,,,) <$> term name <*> parameters <*> term (returnType <|> emptyTerm) <*> (term compoundStatement <|> emptyTerm))
makeMethod1 visibility modifiers receiver (name, params, returnType, compoundStatement) = Declaration.Method (modifiers <> [returnType]) receiver visibility name params compoundStatement
makeMethod2 visibility modifiers receiver name params returnType compoundStatement = Declaration.Method (modifiers <> [returnType]) receiver visibility name params compoundStatement
makeMethod1 accessControl modifiers receiver (name, params, returnType, compoundStatement) = Declaration.Method (modifiers <> [returnType]) receiver accessControl name params compoundStatement
makeMethod2 accessControl modifiers receiver name params returnType compoundStatement = Declaration.Method (modifiers <> [returnType]) receiver accessControl name params compoundStatement
classBaseClause :: Assignment Term
classBaseClause = makeTerm <$> symbol ClassBaseClause <*> children (Syntax.ClassBaseClause <$> term qualifiedName)
@ -463,10 +463,10 @@ classInterfaceClause :: Assignment Term
classInterfaceClause = makeTerm <$> symbol ClassInterfaceClause <*> children (Syntax.ClassInterfaceClause <$> someTerm qualifiedName)
classConstDeclaration :: Assignment Term
classConstDeclaration = makeTerm <$> symbol ClassConstDeclaration <*> children (Syntax.ClassConstDeclaration <$> (term visibilityModifier <|> emptyTerm) <*> manyTerm constElement)
classConstDeclaration = makeTerm <$> symbol ClassConstDeclaration <*> children (Syntax.ClassConstDeclaration <$> (term accessControlModifier <|> emptyTerm) <*> manyTerm constElement)
visibilityModifier :: Assignment Term
visibilityModifier = makeTerm <$> symbol VisibilityModifier <*> (Syntax.Identifier . Name.name <$> source)
accessControlModifier :: Assignment Term
accessControlModifier = makeTerm <$> symbol VisibilityModifier <*> (Syntax.Identifier . Name.name <$> source)
constElement :: Assignment Term
constElement = makeTerm <$> symbol ConstElement <*> children (Statement.Assignment [] <$> term name <*> term expression)
@ -678,7 +678,7 @@ propertyDeclaration :: Assignment Term
propertyDeclaration = makeTerm <$> symbol PropertyDeclaration <*> children (Syntax.PropertyDeclaration <$> term propertyModifier <*> someTerm propertyElement)
propertyModifier :: Assignment Term
propertyModifier = (makeTerm <$> symbol PropertyModifier <*> children (Syntax.PropertyModifier <$> (term visibilityModifier <|> emptyTerm) <*> (term staticModifier <|> emptyTerm))) <|> term (makeTerm <$> symbol PropertyModifier <*> (Syntax.Identifier . Name.name <$> source))
propertyModifier = (makeTerm <$> symbol PropertyModifier <*> children (Syntax.PropertyModifier <$> (term accessControlModifier <|> emptyTerm) <*> (term staticModifier <|> emptyTerm))) <|> term (makeTerm <$> symbol PropertyModifier <*> (Syntax.Identifier . Name.name <$> source))
propertyElement :: Assignment Term
propertyElement = makeTerm <$> symbol PropertyElement <*> children (Statement.Assignment [] <$> term variableName <*> term propertyInitializer) <|> (symbol PropertyElement *> children (term variableName))
@ -692,7 +692,7 @@ destructorDeclaration = makeTerm <$> symbol DestructorDeclaration <*> children (
methodModifier :: Assignment Term
methodModifier = choice [
visibilityModifier,
accessControlModifier,
classModifier,
staticModifier
]
@ -716,7 +716,7 @@ traitSelectInsteadOfClause :: Assignment Term
traitSelectInsteadOfClause = makeTerm <$> symbol TraitSelectInsteadOfClause <*> children (Syntax.InsteadOf <$> term (classConstantAccessExpression <|> name) <*> term name)
traitAliasAsClause :: Assignment Term
traitAliasAsClause = makeTerm <$> symbol TraitAliasAsClause <*> children (Syntax.AliasAs <$> term (classConstantAccessExpression <|> name) <*> (term visibilityModifier <|> emptyTerm) <*> (term name <|> emptyTerm))
traitAliasAsClause = makeTerm <$> symbol TraitAliasAsClause <*> children (Syntax.AliasAs <$> term (classConstantAccessExpression <|> name) <*> (term accessControlModifier <|> emptyTerm) <*> (term name <|> emptyTerm))
namespaceDefinition :: Assignment Term
namespaceDefinition = makeTerm <$> symbol NamespaceDefinition <*> children (Syntax.Namespace <$> (toList <$> namespaceName' <|> pure []) <*> (term compoundStatement <|> emptyTerm))

View File

@ -44,7 +44,7 @@ type Syntax = '[
Comment.Comment
, Declaration.Function
, Declaration.Method
, Declaration.Visibility
, Declaration.AccessControl
, Directive.File
, Directive.Line
, Expression.Plus
@ -333,15 +333,15 @@ parameter = postContextualize comment (term uncontextualizedParameter)
optionalParameter = symbol OptionalParameter *> children (lhsIdent <* expression)
method :: Assignment Term
method = makeTerm <$> symbol Method <*> (withNewScope . children) (Declaration.Method [] <$> emptyTerm <*> visibility <*> methodSelector <*> params <*> expressions')
method = makeTerm <$> symbol Method <*> (withNewScope . children) (Declaration.Method [] <$> emptyTerm <*> accessControl <*> methodSelector <*> params <*> expressions')
where params = symbol MethodParameters *> children (many parameter) <|> pure []
expressions' = makeTerm <$> location <*> many expression
visibility = makeTerm <$> location <*> pure Declaration.Unknown
accessControl = makeTerm <$> location <*> pure Declaration.Unknown
singletonMethod :: Assignment Term
singletonMethod = makeTerm <$> symbol SingletonMethod <*> (withNewScope . children) (Declaration.Method [] <$> expression <*> visibility <*> methodSelector <*> params <*> expressions)
singletonMethod = makeTerm <$> symbol SingletonMethod <*> (withNewScope . children) (Declaration.Method [] <$> expression <*> accessControl <*> methodSelector <*> params <*> expressions)
where params = symbol MethodParameters *> children (many parameter) <|> pure []
visibility = makeTerm <$> location <*> pure Declaration.Unknown
accessControl = makeTerm <$> location <*> pure Declaration.Unknown
lambda :: Assignment Term
lambda = makeTerm <$> symbol Lambda <*> (withExtendedScope . children) (

View File

@ -50,7 +50,7 @@ type Syntax = '[
, Declaration.PublicFieldDefinition
, Declaration.VariableDeclaration
, Declaration.TypeAlias
, Declaration.Visibility
, Declaration.AccessControl
, Expression.Plus
, Expression.Minus
, Expression.Times
@ -484,13 +484,13 @@ parameter = requiredParameter
accessibilityModifier' :: Assignment Term
accessibilityModifier' = makeTerm'
<$> symbol AccessibilityModifier
<*> children (inject <$> (textToVisibility <$> source))
<*> children (inject <$> (textToAccessControl <$> source))
textToVisibility :: Text -> Declaration.Visibility a
textToVisibility = \case
textToAccessControl :: Text -> Declaration.AccessControl a
textToAccessControl = \case
"protected" -> Declaration.Protected
"private" -> Declaration.Private
-- | The catchall case is public visibility.
-- | The catchall case is public.
_ -> Declaration.Public
destructuringPattern :: Assignment Term
@ -674,11 +674,11 @@ classBodyStatements = makeTerm'' <$> symbol ClassBody <*> children (contextualiz
Just cs -> formalParams <> toList cs
Nothing -> formalParams
publicVisibility :: Assignment Term
publicVisibility = makeTerm <$> location <*> pure Declaration.Public
publicAccessControl :: Assignment Term
publicAccessControl = makeTerm <$> location <*> pure Declaration.Public
publicFieldDefinition :: Assignment Term
publicFieldDefinition = makeField <$> symbol Grammar.PublicFieldDefinition <*> children ((,,,,) <$> (term accessibilityModifier' <|> term publicVisibility) <*> (term readonly' <|> emptyTerm) <*> term propertyName <*> (term typeAnnotation' <|> emptyTerm) <*> (term expression <|> emptyTerm))
publicFieldDefinition = makeField <$> symbol Grammar.PublicFieldDefinition <*> children ((,,,,) <$> (term accessibilityModifier' <|> term publicAccessControl) <*> (term readonly' <|> emptyTerm) <*> term propertyName <*> (term typeAnnotation' <|> emptyTerm) <*> (term expression <|> emptyTerm))
where makeField loc (modifier, readonly, propertyName, annotation, expression) = makeTerm loc (Declaration.PublicFieldDefinition [readonly, annotation] propertyName modifier expression)