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

Add ZSuper syntax node (#2292)

Previously, invocations of `super` were captured as an `Identifier`.
It is straightforward enough to return a ZSuper instead.
This commit is contained in:
Patrick Thomson 2018-12-07 12:21:32 -05:00
parent 844664f636
commit 0d361e9b0b
5 changed files with 23 additions and 2 deletions

View File

@ -126,6 +126,7 @@ type Syntax = '[
, Ruby.Syntax.Module
, Ruby.Syntax.Require
, Ruby.Syntax.Send
, Ruby.Syntax.ZSuper
, []
]
@ -214,12 +215,12 @@ withNewScope inner = withExtendedScope $ do
identifier :: Assignment Term
identifier =
vcallOrLocal
<|> zsuper
<|> mk Constant
<|> mk InstanceVariable
<|> mk ClassVariable
<|> mk GlobalVariable
<|> mk Operator
<|> mk Super
<|> mk Setter
<|> mk SplatArgument
<|> mk HashSplatArgument
@ -227,6 +228,7 @@ identifier =
<|> mk Uninterpreted
where
mk s = makeTerm <$> symbol s <*> (Syntax.Identifier . name <$> source)
zsuper = makeTerm <$> symbol Super <*> (Ruby.Syntax.ZSuper <$ source)
vcallOrLocal = do
(loc, ident, locals) <- identWithLocals
case ident of

View File

@ -245,3 +245,18 @@ instance Show1 LowPrecedenceOr where liftShowsPrec = genericLiftShowsPrec
instance Tokenize LowPrecedenceOr where
tokenize LowPrecedenceOr{..} = lhs *> yield (Token.Run "or") <* rhs
-- | A call to @super@ without parentheses in Ruby is known as "zsuper", which has
-- the semantics of invoking @super()@ but implicitly passing the current function's
-- arguments to the @super()@ invocation.
data ZSuper a = ZSuper
deriving (Declarations1, Diffable, Eq, Foldable, FreeVariables1, Functor, Generic1, Hashable1, Ord, Show, ToJSONFields1, Traversable, Named1, Message1, NFData1)
instance Evaluatable ZSuper
instance Eq1 ZSuper where liftEq = genericLiftEq
instance Ord1 ZSuper where liftCompare = genericLiftCompare
instance Show1 ZSuper where liftShowsPrec = genericLiftShowsPrec
instance Tokenize ZSuper where
tokenize _ = yield $ Run "super"

View File

@ -609,6 +609,7 @@ instance Taggable Ruby.Require
instance Taggable Ruby.Load
instance Taggable Ruby.LowPrecedenceAnd
instance Taggable Ruby.LowPrecedenceOr
instance Taggable Ruby.ZSuper
instance Taggable TypeScript.JavaScriptRequire
instance Taggable TypeScript.Debugger

View File

@ -474,6 +474,9 @@ instance Listable1 Ruby.Syntax.Module where
instance Listable1 Ruby.Syntax.Require where
liftTiers tiers' = liftCons2 tiers tiers' Ruby.Syntax.Require
instance Listable1 Ruby.Syntax.ZSuper where
liftTiers tiers = cons0 Ruby.Syntax.ZSuper
instance Listable1 Ruby.Syntax.Send where
liftTiers tiers = liftCons4 (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) (liftTiers tiers) Ruby.Syntax.Send

View File

@ -5,7 +5,7 @@
(SymbolElement)
(Integer)
(This)
(Identifier)
(ZSuper)
(Enumeration
(Integer)
(Integer)