mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
ruby: add special Send node type for method calls
This commit is contained in:
parent
b39b2685fb
commit
08b581c02b
@ -74,6 +74,7 @@ type Syntax = '[
|
|||||||
, Syntax.Identifier
|
, Syntax.Identifier
|
||||||
, Syntax.Paren
|
, Syntax.Paren
|
||||||
, Syntax.Program
|
, Syntax.Program
|
||||||
|
, Ruby.Syntax.Send
|
||||||
, Ruby.Syntax.Class
|
, Ruby.Syntax.Class
|
||||||
, Ruby.Syntax.Load
|
, Ruby.Syntax.Load
|
||||||
, Ruby.Syntax.LowPrecedenceBoolean
|
, Ruby.Syntax.LowPrecedenceBoolean
|
||||||
@ -83,7 +84,8 @@ type Syntax = '[
|
|||||||
]
|
]
|
||||||
|
|
||||||
type Term = Term.Term (Union Syntax) (Record Location)
|
type Term = Term.Term (Union Syntax) (Record Location)
|
||||||
type Assignment = HasCallStack => Assignment.Assignment [] Grammar Term
|
type Assignment' a = HasCallStack => Assignment.Assignment [] Grammar a
|
||||||
|
type Assignment = Assignment' Term
|
||||||
|
|
||||||
-- | Assignment from AST in Ruby’s grammar onto a program in Ruby’s syntax.
|
-- | Assignment from AST in Ruby’s grammar onto a program in Ruby’s syntax.
|
||||||
assignment :: Assignment
|
assignment :: Assignment
|
||||||
@ -291,9 +293,12 @@ pair :: Assignment
|
|||||||
pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> expression <*> (expression <|> emptyTerm))
|
pair = makeTerm <$> symbol Pair <*> children (Literal.KeyValue <$> expression <*> (expression <|> emptyTerm))
|
||||||
|
|
||||||
methodCall :: Assignment
|
methodCall :: Assignment
|
||||||
methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> regularCall)
|
methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|> funcCall <|> regularCall)
|
||||||
where
|
where
|
||||||
regularCall = inj <$> (Expression.Call <$> pure [] <*> expression <*> args <*> (block <|> emptyTerm))
|
funcCall = inj <$> (Ruby.Syntax.Send Nothing <$> methodSelector <*> args) -- TODO block
|
||||||
|
|
||||||
|
regularCall = inj <$> (symbol Call *> children (Ruby.Syntax.Send <$> (Just <$> expression) <*> methodSelector) <*> args) -- TODO block
|
||||||
|
|
||||||
require = inj <$> (symbol Identifier *> do
|
require = inj <$> (symbol Identifier *> do
|
||||||
s <- source
|
s <- source
|
||||||
guard (s `elem` ["require", "require_relative"])
|
guard (s `elem` ["require", "require_relative"])
|
||||||
@ -306,10 +311,13 @@ methodCall = makeTerm' <$> symbol MethodCall <*> children (require <|> load <|>
|
|||||||
loadArgs = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (some expression)
|
loadArgs = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children (some expression)
|
||||||
nameExpression = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expression
|
nameExpression = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expression
|
||||||
|
|
||||||
call :: Assignment
|
methodSelector :: Assignment
|
||||||
call = makeTerm <$> symbol Call <*> children (Expression.MemberAccess <$> expression <*> (expression <|> args))
|
methodSelector = mk Identifier <|> mk Identifier'
|
||||||
where
|
where
|
||||||
args = (symbol ArgumentList <|> symbol ArgumentListWithParens) *> children expressions
|
mk s = makeTerm <$> symbol s <*> (Syntax.Identifier <$> (name <$> source))
|
||||||
|
|
||||||
|
call :: Assignment
|
||||||
|
call = makeTerm <$> symbol Call <*> children (Ruby.Syntax.Send <$> (Just <$> expression) <*> methodSelector <*> pure [])
|
||||||
|
|
||||||
rescue :: Assignment
|
rescue :: Assignment
|
||||||
rescue = rescue'
|
rescue = rescue'
|
||||||
|
@ -36,6 +36,16 @@ maybeFailNotFound name = maybeFail notFound
|
|||||||
cleanNameOrPath :: ByteString -> String
|
cleanNameOrPath :: ByteString -> String
|
||||||
cleanNameOrPath = BC.unpack . dropRelativePrefix . stripQuotes
|
cleanNameOrPath = BC.unpack . dropRelativePrefix . stripQuotes
|
||||||
|
|
||||||
|
data Send a = Send { sendReceiver :: Maybe a, sendSelector :: a, sendArgs :: [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 _ _ _) = fail "send unimplemented!"
|
||||||
|
|
||||||
data Require a = Require { requireRelative :: Bool, requirePath :: !a }
|
data Require a = Require { requireRelative :: Bool, requirePath :: !a }
|
||||||
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
deriving (Diffable, Eq, Foldable, Functor, GAlign, Generic1, Mergeable, Ord, Show, Traversable, FreeVariables1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user