1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Merge remote-tracking branch 'origin/master' into charliesome/ruby-method-calls

This commit is contained in:
joshvera 2018-04-09 16:09:48 -04:00
commit 7e1330c5e8
48 changed files with 269 additions and 211 deletions

View File

@ -74,7 +74,6 @@ type Syntax = '[
, Syntax.Identifier
, Syntax.Paren
, Syntax.Program
, Ruby.Syntax.Send
, Ruby.Syntax.Class
, Ruby.Syntax.Load
, Ruby.Syntax.LowPrecedenceBoolean
@ -84,8 +83,7 @@ type Syntax = '[
]
type Term = Term.Term (Union Syntax) (Record Location)
type Assignment' a = HasCallStack => Assignment.Assignment [] Grammar a
type Assignment = Assignment' Term
type Assignment = HasCallStack => Assignment.Assignment [] Grammar Term
-- | Assignment from AST in Rubys grammar onto a program in Rubys syntax.
assignment :: Assignment
@ -293,12 +291,9 @@ pair :: Assignment
pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> expression <*> (expression <|> emptyTerm))
methodCall :: Assignment
methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> funcCall <|> regularCall)
methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> regularCall)
where
funcCall = inj <$> (Ruby.Syntax.Send Nothing <$> methodSelector <*> args <*> optional block)
regularCall = inj <$> (symbol Call *> children (Ruby.Syntax.Send <$> (Just <$> expression) <*> methodSelector) <*> args <*> optional block)
regularCall = inj <$> (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm))
require = inj <$> (symbol Identifier *> do
s <- source
guard (s `elem` ["require", "require_relative"])
@ -307,17 +302,14 @@ methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|>
s <- source
guard (s == "load")
Ruby.Syntax.Load <$> loadArgs)
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> many expression
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (many expression) <|> pure []
loadArgs = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (some expression)
nameExpression = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expression
methodSelector :: Assignment
methodSelector = mk Identifier <|> mk Identifier'
where
mk s = makeTerm <$> symbol s <*> (Syntax.Identifier <$> (name <$> source))
call :: Assignment
call = makeTerm <$> symbol Call <*> children (Ruby.Syntax.Send <$> (Just <$> expression) <*> methodSelector <*> pure [] <*> optional block)
call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expressions <|> args))
where
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expressions
rescue :: Assignment
rescue = rescue'

View File

@ -36,22 +36,6 @@ maybeFailNotFound name = maybeFail notFound
cleanNameOrPath :: ByteString -> String
cleanNameOrPath = BC.unpack . dropRelativePrefix . stripQuotes
data Send a = Send { sendReceiver :: Maybe a, sendSelector :: a, sendArgs :: [a], sendBlock :: Maybe a }
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
instance Eq1 Send where liftEq = genericLiftEq
instance Ord1 Send where liftCompare = genericLiftCompare
instance Show1 Send where liftShowsPrec = genericLiftShowsPrec
instance Evaluatable Send where
eval Send{..} = do
func <- case sendReceiver of
Just recv -> do
recvEnv <- subtermValue recv >>= scopedEnvironment
localEnv (mappend recvEnv) (subtermValue sendSelector)
Nothing -> subtermValue sendSelector -- TODO Does this require `localize` so we don't leak terms when resolving `sendSelector`?
call func (map subtermValue sendArgs) -- TODO pass through sendBlock
data Require a = Require { requireRelative :: Bool, requirePath :: !a }
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)

View File

@ -5,6 +5,7 @@
(
(Try
{ ([])
->(Send
->(Call
{+(Identifier)+}
{+(TextElement)+}) }))))
{+(TextElement)+}
{+(Empty)+}) }))))

View File

@ -4,7 +4,8 @@
(Identifier)
(
(Try
{ (Send
{ (Call
{-(Identifier)-}
{-(TextElement)-})
{-(TextElement)-}
{-(Empty)-})
->([]) }))))

View File

@ -4,6 +4,7 @@
(Identifier)
(
(Try
(Send
(Call
(Identifier)
(TextElement))))))
(TextElement)
(Empty))))))

View File

@ -1,10 +1,12 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
{ ([])
->(Send
{+(Identifier)+}) }))))
->(Call
{+(Identifier)+}
{+(Empty)+}) }))))

View File

@ -1,10 +1,12 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
{ (Send
{-(Identifier)-})
{ (Call
{-(Identifier)-}
{-(Empty)-})
->([]) }))))

View File

@ -1,8 +1,9 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
([])))))

View File

@ -1,9 +1,11 @@
(Program
(Try
(
(Send
(Identifier))
(Call
(Identifier)
(Empty))
(Else
(Empty)
(Send
(Identifier))))))
(Call
(Identifier)
(Empty))))))

View File

@ -2,11 +2,13 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
(
{+(Send
{+(Identifier)+})+})
{+(Call
{+(Identifier)+}
{+(Empty)+})+})
(Empty))))

View File

@ -2,11 +2,13 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
([]
{-(Send
{-(Identifier)-})-})
{-(Call
{-(Identifier)-}
{-(Empty)-})-})
(Empty))))

View File

@ -2,8 +2,9 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
([])

View File

@ -2,11 +2,13 @@
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(If
(Identifier)
(
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))
(Empty))))

View File

@ -6,9 +6,10 @@
{+(Integer)+}
{+(Integer)+}
{+(Integer)+})+}
{+(Send
{+(Call
{+(Identifier)+}
{+(Identifier)+})+})+}
{+(Identifier)+}
{+(Empty)+})+})+}
{-(ForEach
{-(
{-(Identifier)-})-}

View File

@ -22,9 +22,10 @@
{+(Integer)+}
{+(Integer)+}
{+(Empty)+}) }
{ (Send
{ (Call
{-(Identifier)-}
{-(Identifier)-})
{-(Identifier)-}
{-(Empty)-})
->(Boolean) })
{+(ForEach
{+(

View File

@ -6,6 +6,7 @@
(Integer)
(Integer)
(Integer))
(Send
(Call
(Identifier)
(Identifier))))
(Identifier)
(Empty))))

View File

@ -1,9 +1,12 @@
(Program
{+(Send
{+(Send
{+(Identifier)+}
{+(TextElement)+}
{+(TextElement)+})+}
{+(Identifier)+})+}
{+(Call
{+(MemberAccess
{+(Call
{+(Identifier)+}
{+(TextElement)+}
{+(TextElement)+}
{+(Empty)+})+}
{+(Identifier)+})+}
{+(Empty)+})+}
{-(TextElement)-}
{-(TextElement)-})

View File

@ -1,9 +1,12 @@
(Program
{+(TextElement)+}
{+(TextElement)+}
{-(Send
{-(Send
{-(Identifier)-}
{-(TextElement)-}
{-(TextElement)-})-}
{-(Identifier)-})-})
{-(Call
{-(MemberAccess
{-(Call
{-(Identifier)-}
{-(TextElement)-}
{-(TextElement)-}
{-(Empty)-})-}
{-(Identifier)-})-}
{-(Empty)-})-})

View File

@ -1,7 +1,10 @@
(Program
(Send
(Send
(Identifier)
(TextElement)
(TextElement))
(Identifier)))
(Call
(MemberAccess
(Call
(Identifier)
(TextElement)
(TextElement)
(Empty))
(Identifier))
(Empty)))

View File

@ -1,8 +1,9 @@
(Program
{-(Send
{-(Call
{-(Identifier)-}
{-(Hash)-})-}
(Send
{-(Hash)-}
{-(Empty)-})-}
(Call
(Identifier)
(Function
(Empty)
@ -11,7 +12,7 @@
->(Plus
{+(Identifier)+}
{+(Integer)+}) }))
{-(Send
{-(Call
{-(Identifier)-}
{-(Function
{-(Empty)-}

View File

@ -1,8 +1,9 @@
(Program
{+(Send
{+(Call
{+(Identifier)+}
{+(Hash)+})+}
(Send
{+(Hash)+}
{+(Empty)+})+}
(Call
(Identifier)
(Function
(Empty)
@ -11,7 +12,7 @@
{-(Identifier)-}
{-(Integer)-})
->(Identifier) }))
{+(Send
{+(Call
{+(Identifier)+}
{+(Function
{+(Empty)+}

View File

@ -1,13 +1,14 @@
(Program
(Send
(Call
(Identifier)
(Hash))
(Send
(Hash)
(Empty))
(Call
(Identifier)
(Function
(Empty)
(Identifier)))
(Send
(Call
(Identifier)
(Function
(Empty)

View File

@ -1,5 +1,5 @@
(Program
(Send
(Call
(Identifier)
(Function
(Empty)

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))
{+(KeyValue
{+(Symbol)+}
{+(Integer)+})+}))
{+(Integer)+})+}
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))
{-(KeyValue
{-(Symbol)-}
{-(Integer)-})-}))
{-(Integer)-})-}
(Empty)))

View File

@ -1,6 +1,7 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))))
(Boolean))
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Symbol)
(Boolean))
(KeyValue
(Symbol)
(Integer))))
(Integer))
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))
{+(KeyValue
{+(Identifier)+}
{+(Integer)+})+}))
{+(Integer)+})+}
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))
{-(KeyValue
{-(Identifier)-}
{-(Integer)-})-}))
{-(Integer)-})-}
(Empty)))

View File

@ -1,6 +1,7 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))))
(Boolean))
(Empty)))

View File

@ -1,9 +1,10 @@
(Program
(Send
(Call
(Identifier)
(KeyValue
(Identifier)
(Boolean))
(KeyValue
(Identifier)
(Integer))))
(Integer))
(Empty)))

View File

@ -1,9 +1,11 @@
(Program
(Send
{-(Identifier)-}
{ (Identifier)
->(Identifier) })
{-(Send
(Call
{ (MemberAccess
{-(Identifier)-}
{-(Identifier)-})
->(Identifier) }
(Empty))
{-(Call
{-(Identifier)-}
{-(Identifier)-}
{-(Identifier)-}
@ -12,13 +14,16 @@
{-(Integer)-})-}
{-(KeyValue
{-(Identifier)-}
{-(Integer)-})-})-}
{-(Send
{-(Integer)-})-}
{-(Empty)-})-}
{-(Call
{-(Identifier)-}
{-(Send
{-(Call
{-(Identifier)-}
{-(Identifier)-})-})-}
{-(Send
{-(Identifier)-}
{-(Empty)-})-}
{-(Empty)-})-}
{-(Call
{-(Identifier)-}
{-(KeyValue
{-(Array)-}
@ -30,4 +35,5 @@
{-(Identifier)-}
{-(Function
{-(Empty)-}
{-(Integer)-})-})-})-})
{-(Integer)-})-})-}
{-(Empty)-})-})

View File

@ -1,9 +1,11 @@
(Program
(Send
{+(Identifier)+}
(Call
{ (Identifier)
->(Identifier) })
{+(Send
->(MemberAccess
{+(Identifier)+}
{+(Identifier)+}) }
(Empty))
{+(Call
{+(Identifier)+}
{+(Identifier)+}
{+(Identifier)+}
@ -12,13 +14,16 @@
{+(Integer)+})+}
{+(KeyValue
{+(Identifier)+}
{+(Integer)+})+})+}
{+(Send
{+(Integer)+})+}
{+(Empty)+})+}
{+(Call
{+(Identifier)+}
{+(Send
{+(Call
{+(Identifier)+}
{+(Identifier)+})+})+}
{+(Send
{+(Identifier)+}
{+(Empty)+})+}
{+(Empty)+})+}
{+(Call
{+(Identifier)+}
{+(KeyValue
{+(Array)+}
@ -30,4 +35,5 @@
{+(Identifier)+}
{+(Function
{+(Empty)+}
{+(Integer)+})+})+})+})
{+(Integer)+})+})+}
{+(Empty)+})+})

View File

@ -1,8 +1,10 @@
(Program
(Send
(Identifier)
(Identifier))
(Send
(Call
(MemberAccess
(Identifier)
(Identifier))
(Empty))
(Call
(Identifier)
(Identifier)
(Identifier)
@ -11,13 +13,16 @@
(Integer))
(KeyValue
(Identifier)
(Integer)))
(Send
(Integer))
(Empty))
(Call
(Identifier)
(Send
(Call
(Identifier)
(Identifier)))
(Send
(Identifier)
(Empty))
(Empty))
(Call
(Identifier)
(KeyValue
(Array)
@ -29,4 +34,5 @@
(Identifier)
(Function
(Empty)
(Integer)))))
(Integer)))
(Empty)))

View File

@ -1,3 +1,4 @@
(Program
(Send
(Identifier)))
(Call
(Identifier)
(Empty)))

View File

@ -1,17 +1,25 @@
(Program
{+(Send
{+(Call
{+(Identifier)+}
{+(TextElement)+})+}
{+(TextElement)+}
{+(Empty)+})+}
{+(Call
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Empty)+})+}
{+(Call
{+(Identifier)+}
{+(Integer)+}
{+(Integer)+}
{+(Empty)+})+}
{+(Call
{+(Identifier)+}
{+(Integer)+}
{+(Integer)+}
{+(Empty)+})+}
{-(Identifier)-}
(Send
(Identifier)
(Identifier))
{+(Send
{+(Identifier)+}
{+(Integer)+}
{+(Integer)+})+}
{+(Send
{+(Identifier)+}
{+(Integer)+}
{+(Integer)+})+}
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Identifier)-})

View File

@ -1,17 +1,25 @@
(Program
{+(Identifier)+}
{-(Send
{-(Identifier)-}
{-(TextElement)-})-}
(Send
(Identifier)
(Identifier))
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Identifier)+}
{-(Send
{-(Call
{-(Identifier)-}
{-(TextElement)-}
{-(Empty)-})-}
{-(Call
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Empty)-})-}
{-(Call
{-(Identifier)-}
{-(Integer)-}
{-(Integer)-})-}
{-(Send
{-(Integer)-}
{-(Empty)-})-}
{-(Call
{-(Identifier)-}
{-(Integer)-}
{-(Integer)-})-})
{-(Integer)-}
{-(Empty)-})-})

View File

@ -1,6 +1,6 @@
(Program
(Identifier)
(Send
(MemberAccess
(Identifier)
(Identifier))
(Identifier))

View File

@ -1,15 +1,20 @@
(Program
(Send
(Call
(Identifier)
(TextElement))
(Send
(Identifier)
(Identifier))
(Send
(TextElement)
(Empty))
(Call
(MemberAccess
(Identifier)
(Identifier))
(Empty))
(Call
(Identifier)
(Integer)
(Integer))
(Send
(Integer)
(Empty))
(Call
(Identifier)
(Integer)
(Integer)))
(Integer)
(Empty)))

View File

@ -37,17 +37,17 @@
{-(Identifier)-})-}
{-(Assignment
{-(
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-})-}
{-(
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-}
{-(Send
{-(MemberAccess
{-(Identifier)-}
{-(Identifier)-})-})-})-}
{-(Assignment

View File

@ -37,17 +37,17 @@
{+(Identifier)+})+}
{+(Assignment
{+(
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+})+}
{+(
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+}
{+(Send
{+(MemberAccess
{+(Identifier)+}
{+(Identifier)+})+})+})+}
{+(Assignment

View File

@ -36,17 +36,17 @@
(Identifier))
(Assignment
(
(Send
(MemberAccess
(Identifier)
(Identifier))
(Send
(MemberAccess
(Identifier)
(Identifier)))
(
(Send
(MemberAccess
(Identifier)
(Identifier))
(Send
(MemberAccess
(Identifier)
(Identifier))))
(Assignment

View File

@ -1,5 +1,5 @@
(Program
{ (Equal
{(Equal
{-(Identifier)-}
{-(Identifier)-})
->(Comparison
@ -10,12 +10,11 @@
{+(Identifier)+})+}
{+(Assignment
{+(Identifier)+}
{+(Not
{+(Identifier)+})+})+}
{+(Not{+(Identifier)+})+})+}
{-(Not
{-(Equal
{-(Identifier)-}
{-(Identifier)-})-})-}
{-(Equal
{-(Identifier)-}
{-(Identifier)-})-})
{-(Identifier)-})- })

View File

@ -1,5 +1,5 @@
(Program
{ (Comparison
{(Comparison
{-(Identifier)-}
{-(Identifier)-})
->(Equal
@ -17,5 +17,4 @@
{-(Identifier)-})-}
{-(Assignment
{-(Identifier)-}
{-(Not
{-(Identifier)-})-})-})
{-(Not{-(Identifier)-})-})- })

View File

@ -2,9 +2,10 @@
(Require
{ (TextElement)
->(TextElement) })
(Send
(Call
{ (Identifier)
->(Identifier) }
{+(Symbol)+}
{+(TextElement)+}
{-(Identifier)-}))
{-(Identifier)-}
(Empty)))

View File

@ -2,9 +2,10 @@
(Require
{ (TextElement)
->(TextElement) })
(Send
(Call
{ (Identifier)
->(Identifier) }
{+(Identifier)+}
{-(Symbol)-}
{-(TextElement)-}))
{-(TextElement)-}
(Empty)))

View File

@ -1,6 +1,7 @@
(Program
(Require
(TextElement))
(Send
(Call
(Identifier)
(Identifier)))
(Identifier)
(Empty)))

View File

@ -1,7 +1,8 @@
(Program
(Require
(TextElement))
(Send
(Call
(Identifier)
(Symbol)
(TextElement)))
(TextElement)
(Empty)))