mirror of
https://github.com/github/semantic.git
synced 2024-12-22 06:11:49 +03:00
Add extractLeafValue and maybeIdentifier to Syntax
This commit is contained in:
parent
0481faab83
commit
e22b723b6a
@ -109,6 +109,28 @@ data Syntax a f
|
|||||||
deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON, NFData)
|
deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON, NFData)
|
||||||
|
|
||||||
|
|
||||||
|
extractLeafValue :: forall b leaf. S.Syntax leaf b -> Maybe leaf
|
||||||
|
extractLeafValue syntax = case syntax of
|
||||||
|
S.Leaf a -> Just a
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
|
maybeIdentifier :: forall leaf identifier. S.Syntax leaf identifier -> Maybe identifier
|
||||||
|
maybeIdentifier syntax = case syntax of
|
||||||
|
S.Assignment f _ -> Just f
|
||||||
|
S.Class f _ _ -> Just f
|
||||||
|
S.Export f _ -> f
|
||||||
|
S.Function f _ _ _ -> Just f
|
||||||
|
S.FunctionCall f _ -> Just f
|
||||||
|
S.Import f _ -> Just f
|
||||||
|
S.Method f _ _ _ _ -> Just f
|
||||||
|
S.MethodCall _ f _ -> Just f
|
||||||
|
S.Module f _ -> Just f
|
||||||
|
S.OperatorAssignment f _ -> Just f
|
||||||
|
S.SubscriptAccess f _ -> Just f
|
||||||
|
S.TypeDecl f _ -> Just f
|
||||||
|
S.VarAssignment f _ -> Just f
|
||||||
|
_ -> Nothing
|
||||||
|
|
||||||
-- Instances
|
-- Instances
|
||||||
|
|
||||||
instance Listable2 Syntax where
|
instance Listable2 Syntax where
|
||||||
|
Loading…
Reference in New Issue
Block a user