1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 09:55:52 +03:00

Assign lambdas and methods (with parameters)

This commit is contained in:
Timothy Clem 2017-07-05 14:51:12 -07:00
parent 3e9827a890
commit dd464f01d5
13 changed files with 327 additions and 23 deletions

View File

@ -26,6 +26,7 @@ import qualified Term
type Syntax = '[
Comment.Comment
, Declaration.Class
, Declaration.Function
, Declaration.Method
, Expression.Arithmetic
, Expression.Bitwise
@ -99,6 +100,7 @@ statement = -- handleError $
<|> for
<|> class'
<|> method
<|> lambda
<|> identifier
<|> scopeResolution
<|> conditional
@ -171,8 +173,27 @@ class' = makeTerm <$> symbol Class <*> children (Declaration.Class <$> (identifi
scopeResolution :: Assignment
scopeResolution = symbol ScopeResolution *> children identifier
parameter :: Assignment
parameter =
identifier
<|> mk SplatParameter
<|> mk HashSplatParameter
<|> mk BlockParameter
<|> mk KeywordParameter
<|> mk OptionalParameter
<|> makeTerm <$> symbol DestructuredParameter <*> children (many parameter)
where mk s = makeTerm <$> symbol s <*> (Syntax.Identifier <$> source)
method :: Assignment
method = makeTerm <$> symbol Method <*> children (Declaration.Method <$> methodName <*> pure [] <*> statements)
method = makeTerm <$> symbol Method <*> children (Declaration.Method <$> methodName <*> params <*> statements)
where params = optional (symbol BlockParameters <|> symbol LambdaParameters) >>= \ _ -> children (many parameter)
lambda :: Assignment
lambda = symbol Lambda >>= \ location -> children $ do
iden <- makeTerm location <$> (Syntax.Identifier <$> source)
params <- optional (symbol BlockParameters <|> symbol LambdaParameters) >>= \ _ -> children (many parameter)
body <- statements
pure $ makeTerm location (Declaration.Function iden params body)
comment :: Assignment
comment = makeTerm <$> symbol Comment <*> (Comment.Comment <$> source)

View File

@ -1 +1,8 @@
lambda {}
lambda { foo }
lambda { |a, b: false, c = nil| 1 }
-> {}
-> { foo }
-> foo { 1 }
-> (d, *f, (x, y)) {}

View File

@ -1,3 +1,27 @@
{+(Program
(AnonymousFunction)
(AnonymousFunction
(Identifier)))+}
(Identifier))
(AnonymousFunction
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(OptionalParameter
(Identifier)
(Identifier))
(IntegerLiteral))
(AnonymousFunction)
(AnonymousFunction
(Identifier))
(AnonymousFunction
(Identifier)
(IntegerLiteral))
(AnonymousFunction
(Params
(Identifier)
(SplatParameter
(Identifier))
(Other "destructured_parameter"
(Identifier)
(Identifier)))))+}

View File

@ -1,3 +1,27 @@
{-(Program
(AnonymousFunction)
(AnonymousFunction
(Identifier)))-}
(Identifier))
(AnonymousFunction
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(OptionalParameter
(Identifier)
(Identifier))
(IntegerLiteral))
(AnonymousFunction)
(AnonymousFunction
(Identifier))
(AnonymousFunction
(Identifier)
(IntegerLiteral))
(AnonymousFunction
(Params
(Identifier)
(SplatParameter
(Identifier))
(Other "destructured_parameter"
(Identifier)
(Identifier)))))-}

View File

@ -1,8 +1,33 @@
(Program
(AnonymousFunction
{+(Identifier)+}
{ (Identifier)
->(Binary
{+(AnonymousFunction
(Identifier)
(Binary
(Identifier)
(Other "+")
(IntegerLiteral)) }))
(IntegerLiteral)))+}
{-(AnonymousFunction)-}
{-(AnonymousFunction
(Identifier))-}
{-(AnonymousFunction
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(OptionalParameter
(Identifier)
(Identifier))
(IntegerLiteral))-}
{-(AnonymousFunction)-}
{-(AnonymousFunction
(Identifier))-}
{-(AnonymousFunction
(Identifier)
(IntegerLiteral))-}
{-(AnonymousFunction
(Params
(Identifier)
(SplatParameter
(Identifier))
(Other "destructured_parameter"
(Identifier)
(Identifier))))-})

View File

@ -1,8 +1,32 @@
(Program
{+(AnonymousFunction)+}
{+(AnonymousFunction
(Identifier))+}
(AnonymousFunction
{-(Identifier)-}
{ (Identifier)
->(Identifier) }
{+(KeywordParameter
(Identifier)
(Boolean))+}
{+(OptionalParameter
(Identifier)
(Identifier))+}
{ (Binary
(Identifier)
(Other "+")
(IntegerLiteral))
->(Identifier) }))
->(IntegerLiteral) })
{+(AnonymousFunction)+}
{+(AnonymousFunction
(Identifier))+}
{+(AnonymousFunction
(Identifier)
(IntegerLiteral))+}
{+(AnonymousFunction
(Params
(Identifier)
(SplatParameter
(Identifier))
(Other "destructured_parameter"
(Identifier)
(Identifier))))+})

View File

@ -1,3 +1,27 @@
(Program
(AnonymousFunction)
(AnonymousFunction
(Identifier)))
(Identifier))
(AnonymousFunction
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(OptionalParameter
(Identifier)
(Identifier))
(IntegerLiteral))
(AnonymousFunction)
(AnonymousFunction
(Identifier))
(AnonymousFunction
(Identifier)
(IntegerLiteral))
(AnonymousFunction
(Params
(Identifier)
(SplatParameter
(Identifier))
(Other "destructured_parameter"
(Identifier)
(Identifier)))))

View File

@ -1,2 +1,17 @@
def foo
end
def bar=
end
def -@(a)
end
def foo(a, b: false, c: nil, **)
end
def foo(*args)
end
def foo(&block)
end

View File

@ -1,3 +1,31 @@
{+(Program
(Method
(Identifier)))+}
(Identifier))
(Method
(Other "setter"
(Identifier)))
(Method
(Other "operator")
(Params
(Identifier)))
(Method
(Identifier)
(Params
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(KeywordParameter
(Identifier)
(Identifier))
(HashSplatParameter)))
(Method
(Identifier)
(Params
(SplatParameter
(Identifier))))
(Method
(Identifier)
(Params
(BlockParameter
(Identifier)))))+}

View File

@ -1,3 +1,31 @@
{-(Program
(Method
(Identifier)))-}
(Identifier))
(Method
(Other "setter"
(Identifier)))
(Method
(Other "operator")
(Params
(Identifier)))
(Method
(Identifier)
(Params
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(KeywordParameter
(Identifier)
(Identifier))
(HashSplatParameter)))
(Method
(Identifier)
(Params
(SplatParameter
(Identifier))))
(Method
(Identifier)
(Params
(BlockParameter
(Identifier)))))-}

View File

@ -1,7 +1,36 @@
(Program
(Method
{ (Identifier)
->(Identifier) }
{+(Params
(Identifier))+}
{+(Identifier)+}))
{+(Method
(Identifier)
(Params
(Identifier))
(Identifier))+}
{-(Method
(Identifier))-}
{-(Method
(Other "setter"
(Identifier)))-}
{-(Method
(Other "operator")
(Params
(Identifier)))-}
{-(Method
(Identifier)
(Params
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(KeywordParameter
(Identifier)
(Identifier))
(HashSplatParameter)))-}
{-(Method
(Identifier)
(Params
(SplatParameter
(Identifier))))-}
{-(Method
(Identifier)
(Params
(BlockParameter
(Identifier))))-})

View File

@ -1,7 +1,34 @@
(Program
{+(Method
(Identifier))+}
{+(Method
(Other "setter"
(Identifier)))+}
{+(Method
(Other "operator")
(Params
(Identifier)))+}
{+(Method
(Identifier)
(Params
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(KeywordParameter
(Identifier)
(Identifier))
(HashSplatParameter)))+}
(Method
{ (Identifier)
->(Identifier) }
{-(Params
(Identifier))-}
{-(Identifier)-}))
(Params
{+(SplatParameter
(Identifier))+}
{-(Identifier)-})
{-(Identifier)-})
{+(Method
(Identifier)
(Params
(BlockParameter
(Identifier))))+})

View File

@ -1,3 +1,31 @@
(Program
(Method
(Identifier)))
(Identifier))
(Method
(Other "setter"
(Identifier)))
(Method
(Other "operator")
(Params
(Identifier)))
(Method
(Identifier)
(Params
(Identifier)
(KeywordParameter
(Identifier)
(Boolean))
(KeywordParameter
(Identifier)
(Identifier))
(HashSplatParameter)))
(Method
(Identifier)
(Params
(SplatParameter
(Identifier))))
(Method
(Identifier)
(Params
(BlockParameter
(Identifier)))))