mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
Proper source ranges for Negate
This commit is contained in:
parent
ba9e0424ff
commit
41442873e0
@ -134,6 +134,7 @@ data Category
|
||||
| RescueModifier
|
||||
| When
|
||||
| RescuedException
|
||||
| Negate
|
||||
deriving (Eq, Generic, Ord, Show)
|
||||
|
||||
-- Instances
|
||||
@ -202,6 +203,7 @@ instance Arbitrary Category where
|
||||
, pure RescueModifier
|
||||
, pure When
|
||||
, pure RescuedException
|
||||
, pure Negate
|
||||
, Other <$> arbitrary
|
||||
]
|
||||
|
||||
|
@ -392,6 +392,7 @@ instance HasCategory Category where
|
||||
C.RescueModifier -> "rescue modifier"
|
||||
C.When -> "when comparison"
|
||||
C.RescuedException -> "last exception"
|
||||
C.Negate -> "negate"
|
||||
|
||||
instance HasField fields Category => HasCategory (SyntaxTerm leaf fields) where
|
||||
toCategoryName = toCategoryName . category . extract
|
||||
|
@ -27,22 +27,22 @@ termConstructor source sourceSpan name range children
|
||||
| name == "ERROR" = withDefaultInfo (S.Error children)
|
||||
| name == "unless_modifier" = case children of
|
||||
[ lhs, rhs ] -> do
|
||||
condition <- withDefaultInfo (S.Negate rhs)
|
||||
condition <- withRecord (setCategory (extract rhs) Negate) (S.Negate rhs)
|
||||
withDefaultInfo $ S.If condition [lhs]
|
||||
_ -> withDefaultInfo $ S.Error children
|
||||
| name == "unless_statement" = case children of
|
||||
( expr : rest ) -> do
|
||||
condition <- withDefaultInfo (S.Negate expr)
|
||||
condition <- withRecord (setCategory (extract expr) Negate) (S.Negate expr)
|
||||
withDefaultInfo $ S.If condition rest
|
||||
_ -> withDefaultInfo $ S.Error children
|
||||
| name == "until_modifier" = case children of
|
||||
[ lhs, rhs ] -> do
|
||||
condition <- withDefaultInfo (S.Negate rhs)
|
||||
condition <- withRecord (setCategory (extract rhs) Negate) (S.Negate rhs)
|
||||
withDefaultInfo $ S.While condition [lhs]
|
||||
_ -> withDefaultInfo $ S.Error children
|
||||
| name == "until_statement" = case children of
|
||||
( expr : rest ) -> do
|
||||
condition <- withDefaultInfo (S.Negate expr)
|
||||
condition <- withRecord (setCategory (extract expr) Negate) (S.Negate expr)
|
||||
withDefaultInfo $ S.While condition rest
|
||||
_ -> withDefaultInfo $ S.Error children
|
||||
| otherwise = withDefaultInfo $ case (name, children) of
|
||||
@ -123,11 +123,13 @@ termConstructor source sourceSpan name range children
|
||||
(_, []) -> S.Leaf . toText $ slice range source
|
||||
_ -> S.Indexed children
|
||||
where
|
||||
withDefaultInfo syntax = do
|
||||
withRecord record syntax = pure $! cofree (record :< syntax)
|
||||
withCategory category syntax = do
|
||||
sourceSpan' <- sourceSpan
|
||||
pure $! case syntax of
|
||||
S.MethodCall{} -> cofree ((range .: MethodCall .: sourceSpan' .: RNil) :< syntax)
|
||||
_ -> cofree ((range .: categoryForRubyName name .: sourceSpan' .: RNil) :< syntax)
|
||||
pure $! cofree ((range .: category .: sourceSpan' .: RNil) :< syntax)
|
||||
withDefaultInfo syntax = case syntax of
|
||||
S.MethodCall{} -> withCategory MethodCall syntax
|
||||
_ -> withCategory (categoryForRubyName name) syntax
|
||||
|
||||
categoryForRubyName :: Text -> Category
|
||||
categoryForRubyName = \case
|
||||
|
@ -97,6 +97,7 @@ styleName category = "category-" <> case category of
|
||||
C.RescueModifier -> "rescue_modifier"
|
||||
C.When -> "when_block"
|
||||
C.RescuedException -> "last_exception"
|
||||
C.Negate -> "negate"
|
||||
|
||||
-- | Pick the class name for a split patch.
|
||||
splitPatchToClassName :: SplitPatch a -> AttributeValue
|
||||
|
Loading…
Reference in New Issue
Block a user