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:
parent
3e9827a890
commit
dd464f01d5
@ -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)
|
||||
|
7
test/fixtures/ruby/lambda.A.rb
vendored
7
test/fixtures/ruby/lambda.A.rb
vendored
@ -1 +1,8 @@
|
||||
lambda {}
|
||||
lambda { foo }
|
||||
lambda { |a, b: false, c = nil| 1 }
|
||||
|
||||
-> {}
|
||||
-> { foo }
|
||||
-> foo { 1 }
|
||||
-> (d, *f, (x, y)) {}
|
||||
|
26
test/fixtures/ruby/lambda.diff+A.txt
vendored
26
test/fixtures/ruby/lambda.diff+A.txt
vendored
@ -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)))))+}
|
||||
|
26
test/fixtures/ruby/lambda.diff-A.txt
vendored
26
test/fixtures/ruby/lambda.diff-A.txt
vendored
@ -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)))))-}
|
||||
|
35
test/fixtures/ruby/lambda.diffA-B.txt
vendored
35
test/fixtures/ruby/lambda.diffA-B.txt
vendored
@ -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))))-})
|
||||
|
28
test/fixtures/ruby/lambda.diffB-A.txt
vendored
28
test/fixtures/ruby/lambda.diffB-A.txt
vendored
@ -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))))+})
|
||||
|
26
test/fixtures/ruby/lambda.parseA.txt
vendored
26
test/fixtures/ruby/lambda.parseA.txt
vendored
@ -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)))))
|
||||
|
15
test/fixtures/ruby/method-declaration.A.rb
vendored
15
test/fixtures/ruby/method-declaration.A.rb
vendored
@ -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
|
||||
|
30
test/fixtures/ruby/method-declaration.diff+A.txt
vendored
30
test/fixtures/ruby/method-declaration.diff+A.txt
vendored
@ -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)))))+}
|
||||
|
30
test/fixtures/ruby/method-declaration.diff-A.txt
vendored
30
test/fixtures/ruby/method-declaration.diff-A.txt
vendored
@ -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)))))-}
|
||||
|
@ -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))))-})
|
||||
|
@ -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))))+})
|
||||
|
30
test/fixtures/ruby/method-declaration.parseA.txt
vendored
30
test/fixtures/ruby/method-declaration.parseA.txt
vendored
@ -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)))))
|
||||
|
Loading…
Reference in New Issue
Block a user