1
1
mirror of https://github.com/github/semantic.git synced 2024-11-29 02:44:36 +03:00

Merge pull request #2250 from github/python-functions-wo-annotations

Python assignment: conditionally include annotation on functions
This commit is contained in:
Patrick Thomson 2018-11-02 16:42:25 -04:00 committed by GitHub
commit a720cf06d4
22 changed files with 277 additions and 372 deletions

View File

@ -46,6 +46,7 @@ type Syntax =
, Expression.Times
, Literal.Integer
, Literal.Boolean
, Literal.TextElement
, Statement.If
, Statement.Return
, Statement.Statements
@ -77,6 +78,7 @@ expressionChoices =
, functionDefinition
, identifier
, integer
, string
, returnStatement
, ifStatement
]
@ -96,7 +98,9 @@ functionDefinition =
makeFunctionDeclaration <$> symbol FunctionDefinition <*> children ((,,,) <$> term expression <* symbol Parameters <*> children (manyTerm expression) <*> optional (symbol Type *> children (term expression)) <*> expressions)
<|> makeFunctionDeclaration <$> (symbol Lambda' <|> symbol Lambda) <*> children ((,,,) <$ token AnonLambda <*> emptyTerm <*> (symbol LambdaParameters *> children (manyTerm expression) <|> pure []) <*> optional (symbol Type *> children (term expression)) <*> expressions)
where
makeFunctionDeclaration loc (functionName', functionParameters, ty, functionBody) = makeTerm loc $ Type.Annotation (makeTerm loc $ Declaration.Function [] functionName' functionParameters functionBody) (fromMaybe (makeTerm loc Syntax.Empty) ty)
makeFunctionDeclaration loc (functionName', functionParameters, ty, functionBody)
= let fn = makeTerm loc (Declaration.Function [] functionName' functionParameters functionBody)
in maybe fn (makeTerm loc . Type.Annotation fn) ty
binaryOperator :: Assignment Term
binaryOperator = makeTerm' <$> symbol BinaryOperator <*> children (infixTerm expression (term expression)
@ -111,6 +115,9 @@ identifier = makeTerm <$> (symbol Identifier <|> symbol Identifier' <|> symbol D
integer :: Assignment Term
integer = makeTerm <$> symbol Integer <*> (Literal.Integer <$> source)
string :: Assignment Term
string = makeTerm <$> symbol String <*> (Literal.TextElement <$> source)
comment :: Assignment Term
comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)

View File

@ -280,7 +280,9 @@ functionDefinition =
makeFunctionDeclaration <$> symbol FunctionDefinition <*> children ((,,,) <$> term expression <* symbol Parameters <*> children (manyTerm expression) <*> optional (symbol Type *> children (term expression)) <*> expressions)
<|> makeFunctionDeclaration <$> (symbol Lambda' <|> symbol Lambda) <*> children ((,,,) <$ token AnonLambda <*> emptyTerm <*> (symbol LambdaParameters *> children (manyTerm expression) <|> pure []) <*> optional (symbol Type *> children (term expression)) <*> expressions)
where
makeFunctionDeclaration loc (functionName', functionParameters, ty, functionBody) = makeTerm loc $ Type.Annotation (makeTerm loc $ Declaration.Function [] functionName' functionParameters functionBody) (fromMaybe (makeTerm loc Syntax.Empty) ty)
makeFunctionDeclaration loc (functionName', functionParameters, ty, functionBody)
= let fn = makeTerm loc (Declaration.Function [] functionName' functionParameters functionBody)
in maybe fn (makeTerm loc . Type.Annotation fn) ty
classDefinition :: Assignment Term
classDefinition = makeTerm <$> symbol ClassDefinition <*> children (Declaration.Class [] <$> term expression <*> argumentList <*> expressions)

View File

@ -1,30 +1,22 @@
(Statements
{+(Annotation
{+(Function
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+})+}
{+(Empty)+})+}
(Annotation
(Function
(Identifier)
{ (Identifier)
->(Identifier) })
(Empty))
(Annotation
(Function
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{-(Identifier)-}
{ (Identifier)
->(Identifier) })
(Empty))
{-(Annotation
{-(Function
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-})-}
{-(Empty)-})-})
{+(Function
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+})+}
(Function
(Identifier)
{ (Identifier)
->(Identifier) })
(Function
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{-(Identifier)-}
{ (Identifier)
->(Identifier) })
{-(Function
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-})-})

View File

@ -1,30 +1,22 @@
(Statements
{-(Annotation
{-(Function
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-})-}
{-(Empty)-})-}
(Annotation
(Function
(Identifier)
{ (Identifier)
->(Identifier) })
(Empty))
(Annotation
(Function
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{+(Identifier)+}
{ (Identifier)
->(Identifier) })
(Empty))
{+(Annotation
{+(Function
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+})+}
{+(Empty)+})+})
{-(Function
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-})-}
(Function
(Identifier)
{ (Identifier)
->(Identifier) })
(Function
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{+(Identifier)+}
{ (Identifier)
->(Identifier) })
{+(Function
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+})+})

View File

@ -1,19 +1,13 @@
(Statements
(Annotation
(Function
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier))
(Empty)))
(Function
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier)
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier)
(Identifier)))

View File

@ -1,19 +1,13 @@
(Statements
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier))
(Empty)))
(Function
(Identifier)
(Identifier)
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier)
(Identifier)))

View File

@ -3,15 +3,13 @@
{ (Identifier)
->(Identifier) }
{+(Identifier)+}
(Annotation
(Function
(Function
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Identifier)
->(Empty) }))
(Empty)))
->(Empty) })))
{-(Class
{-(Identifier)-}
{-(NoOp
@ -19,12 +17,10 @@
(Class
(Identifier)
{-(Identifier)-}
(Annotation
(Function
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Empty)
->(Identifier) }))
(Empty))))
(Function
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Empty)
->(Identifier) }))))

View File

@ -3,15 +3,13 @@
{ (Identifier)
->(Identifier) }
{-(Identifier)-}
(Annotation
(Function
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Empty)
->(Identifier) }))
(Empty)))
(Function
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Empty)
->(Identifier) })))
{+(Class
{+(Identifier)+}
{+(NoOp
@ -19,12 +17,10 @@
(Class
(Identifier)
{+(Identifier)+}
(Annotation
(Function
(Function
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Identifier)
->(Identifier) }
(Identifier)
(Return
{ (Identifier)
->(Empty) }))
(Empty))))
->(Empty) }))))

View File

@ -1,13 +1,11 @@
(Statements
(Class
(Identifier)
(Annotation
(Function
(Identifier)
(Identifier)
(Return
(Identifier)))
(Empty)))
(Function
(Identifier)
(Identifier)
(Return
(Identifier))))
(Class
(Identifier)
(NoOp
@ -15,10 +13,8 @@
(Class
(Identifier)
(Identifier)
(Annotation
(Function
(Identifier)
(Identifier)
(Return
(Empty)))
(Empty))))
(Function
(Identifier)
(Identifier)
(Return
(Empty)))))

View File

@ -2,19 +2,15 @@
(Class
(Identifier)
(Identifier)
(Annotation
(Function
(Identifier)
(Identifier)
(Return
(Empty)))
(Empty)))
(Function
(Identifier)
(Identifier)
(Return
(Empty))))
(Class
(Identifier)
(Annotation
(Function
(Identifier)
(Identifier)
(Return
(Identifier)))
(Empty))))
(Function
(Identifier)
(Identifier)
(Return
(Identifier)))))

View File

@ -46,13 +46,9 @@
{-(Boolean)-})-}
{-(Identifier)-}
{-(Identifier)-})-}
{-(Annotation
{-(Function
{-(Identifier)-}
{-(Identifier)-})-}
{-(Empty)-})-})-})-})
->(Annotation
{+(Function
{+(Identifier)+}
{+(Identifier)+})+}
{+(Empty)+}) })))))))
{-(Function
{-(Identifier)-}
{-(Identifier)-})-})-})-})
->(Function
{+(Identifier)+}
{+(Identifier)+}) })))))))

View File

@ -31,11 +31,9 @@
{-(Boolean)-})-}
{-(Identifier)-}
{-(Identifier)-})-}
{ (Annotation
{-(Function
{-(Identifier)-}
{-(Identifier)-})-}
{-(Empty)-})
{ (Function
{-(Identifier)-}
{-(Identifier)-})
->(Decorator
{+(Identifier)+}
{+(Identifier)+}
@ -51,8 +49,6 @@
{+(Boolean)+})+}
{+(Identifier)+}
{+(Identifier)+})+}
{+(Annotation
{+(Function
{+(Identifier)+}
{+(Identifier)+})+}
{+(Empty)+})+})+})+}) })))))))
{+(Function
{+(Identifier)+}
{+(Identifier)+})+})+})+}) })))))))

View File

@ -34,8 +34,6 @@
(Boolean))
(Identifier)
(Identifier))
(Annotation
(Function
(Identifier)
(Identifier))
(Empty))))))))))))
(Function
(Identifier)
(Identifier))))))))))))

View File

@ -21,8 +21,6 @@
(Boolean))
(Identifier)
(Identifier))
(Annotation
(Function
(Identifier)
(Identifier))
(Empty)))))))))
(Function
(Identifier)
(Identifier)))))))))

View File

@ -1,52 +1,40 @@
(Statements
{-(Annotation
{-(Function
{-(Function
{-(Identifier)-}
{-(Identifier)-})-}
{-(Function
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-})-}
(Function
(Identifier)
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) })
(Function
{ (Identifier)
->(Identifier) }
{-(Assignment
{-(Identifier)-}
{-(Identifier)-})-}
{-(Empty)-})-}
{-(Annotation
{-(Function
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-})-}
{-(Empty)-})-}
(Annotation
(Function
(Identifier)
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) })
{+(Function
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+})+}
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
{ (TextElement)
->(Integer) })
{ (Identifier)
->(Identifier) })
(Empty))
(Annotation
(Function
{ (Identifier)
->(Identifier) }
{-(Assignment
{-(Identifier)-}
{-(Identifier)-})-}
{ (Identifier)
->(Identifier) })
(Empty))
{+(Annotation
{+(Function
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+})+}
{+(Empty)+})+}
(Annotation
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
{ (TextElement)
->(Integer) })
{ (Identifier)
->(Identifier) })
{ (Identifier)
->(Identifier) }
(Identifier))
(Empty)))
{ (Identifier)
->(Identifier) }
(Identifier)))

View File

@ -1,49 +1,39 @@
(Statements
(Annotation
(Function
{ (Identifier)
->(Identifier) }
{-(Identifier)-}
{-(Identifier)-}
{ (Identifier)
->(Identifier) })
(Empty))
(Annotation
(Function
(Identifier)
(Function
{ (Identifier)
->(Identifier) }
{-(Identifier)-}
{-(Identifier)-}
{ (Identifier)
->(Identifier) })
(Function
(Identifier)
{+(Identifier)+}
{ (Identifier)
->(Identifier) })
(Function
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{+(Identifier)+}
{ (Identifier)
->(Identifier) })
{+(Function
{+(Identifier)+}
{+(Assignment
{+(Identifier)+}
{ (Identifier)
->(Identifier) })
(Empty))
(Annotation
(Function
{ (Identifier)
->(Identifier) }
{ (Identifier)
->(Identifier) }
{+(Identifier)+}
{ (Identifier)
->(Identifier) })
(Empty))
{+(Annotation
{+(Function
{+(Identifier)+}
{+(Assignment
{+(Identifier)+}
{+(Identifier)+})+}
{+(Identifier)+})+}
{+(Empty)+})+}
(Annotation
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
{ (Integer)
->(TextElement) })
{ (Identifier)
->(Identifier) })
{+(Identifier)+})+}
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
{ (Integer)
->(TextElement) })
{ (Identifier)
->(Identifier) }
(Identifier))
(Empty)))
->(Identifier) })
{ (Identifier)
->(Identifier) }
(Identifier)))

View File

@ -1,38 +1,28 @@
(Statements
(Annotation
(Function
(Function
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier)
(Identifier)
(Identifier))
(Function
(Identifier)
(Assignment
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier))
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
(Identifier))
(TextElement))
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
(TextElement))
(Identifier))
(Identifier)
(Identifier))
(Empty)))
(Identifier)
(Identifier)))

View File

@ -1,30 +1,22 @@
(Statements
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier)
(Function
(Identifier)
(Identifier)
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier))
(Function
(Identifier)
(Identifier)
(Identifier))
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
(Integer))
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Identifier)
(Identifier))
(Empty))
(Annotation
(Function
(Identifier)
(Annotation
(Assignment
(Identifier)
(Integer))
(Identifier))
(Identifier)
(Identifier))
(Empty)))
(Identifier)
(Identifier)))

View File

@ -1,10 +1,8 @@
(Statements
(Annotation
(Function
(Empty)
{+(Identifier)+}
(Plus
{ (Integer)
->(Identifier) }
(Integer)))
(Empty)))
(Function
(Empty)
{+(Identifier)+}
(Plus
{ (Integer)
->(Identifier) }
(Integer))))

View File

@ -1,10 +1,8 @@
(Statements
(Annotation
(Function
(Empty)
{-(Identifier)-}
(Plus
{ (Identifier)
->(Integer) }
(Integer)))
(Empty)))
(Function
(Empty)
{-(Identifier)-}
(Plus
{ (Identifier)
->(Integer) }
(Integer))))

View File

@ -1,8 +1,6 @@
(Statements
(Annotation
(Function
(Empty)
(Plus
(Integer)
(Integer)))
(Empty)))
(Function
(Empty)
(Plus
(Integer)
(Integer))))

View File

@ -1,9 +1,7 @@
(Statements
(Annotation
(Function
(Empty)
(Function
(Empty)
(Identifier)
(Plus
(Identifier)
(Plus
(Identifier)
(Integer)))
(Empty)))
(Integer))))