mirror of
https://github.com/github/semantic.git
synced 2024-12-25 07:55:12 +03:00
Properly parse classes (with new tree-sitter trees)
This commit is contained in:
parent
8db7340746
commit
aa26c5472e
@ -167,6 +167,10 @@ data Category
|
||||
| Binary
|
||||
-- | A unary statement, e.g. !a in Ruby.
|
||||
| Unary
|
||||
-- | A constant, e.g `Foo::Bar` in Ruby.
|
||||
| Constant
|
||||
-- | A superclass, e.g `< Foo` in Ruby.
|
||||
| Superclass
|
||||
deriving (Eq, Generic, Ord, Show)
|
||||
|
||||
-- Instances
|
||||
@ -256,6 +260,8 @@ instance Arbitrary Category where
|
||||
, pure Continue
|
||||
, pure Binary
|
||||
, pure Unary
|
||||
, pure Constant
|
||||
, pure Superclass
|
||||
, Other <$> arbitrary
|
||||
]
|
||||
|
||||
|
@ -428,6 +428,8 @@ instance HasCategory Category where
|
||||
C.Continue -> "continue statement"
|
||||
C.Binary -> "binary statement"
|
||||
C.Unary -> "unary statement"
|
||||
C.Constant -> "constant"
|
||||
C.Superclass -> "superclass"
|
||||
|
||||
instance HasField fields Category => HasCategory (SyntaxTerm leaf fields) where
|
||||
toCategoryName = toCategoryName . category . extract
|
||||
|
@ -71,12 +71,14 @@ termConstructor source sourceSpan name range children allChildren
|
||||
("case", _ ) -> S.Error children
|
||||
("when", condition : body ) -> S.Case condition body
|
||||
("when", _ ) -> S.Error children
|
||||
("class", [ identifier, superclass, definitions ]) -> S.Class identifier (Just superclass) (toList (unwrap definitions))
|
||||
("class", [ identifier, definitions ]) -> S.Class identifier Nothing (toList (unwrap definitions))
|
||||
("class", constant : rest ) -> case rest of
|
||||
( superclass : body ) | Superclass <- category (extract superclass) -> S.Class constant (Just superclass) body
|
||||
_ -> S.Class constant Nothing rest
|
||||
("class", _ ) -> S.Error children
|
||||
("comment", _ ) -> S.Comment . toText $ slice range source
|
||||
("conditional", condition : cases) -> S.Ternary condition cases
|
||||
("conditional", _ ) -> S.Error children
|
||||
("constant", _ ) -> S.Fixed children
|
||||
("method_call", _ ) -> case children of
|
||||
member : args | MemberAccess <- category (extract member) -> case toList (unwrap member) of
|
||||
[target, method] -> S.MethodCall target method (toList . unwrap =<< args)
|
||||
@ -106,7 +108,7 @@ termConstructor source sourceSpan name range children allChildren
|
||||
identifier : params : body | Params <- category (extract params) -> S.Method identifier (toList (unwrap params)) body
|
||||
identifier : body -> S.Method identifier [] body
|
||||
_ -> S.Error children
|
||||
("module", identifier : body ) -> S.Module identifier body
|
||||
("module", constant : body ) -> S.Module constant body
|
||||
("module", _ ) -> S.Error children
|
||||
("rescue", _ ) -> case children of
|
||||
exceptions : exceptionVar : rest
|
||||
@ -149,6 +151,7 @@ categoryForRubyName = \case
|
||||
"class" -> Class
|
||||
"comment" -> Comment
|
||||
"conditional" -> Ternary
|
||||
"constant" -> Constant
|
||||
"element_reference" -> SubscriptAccess
|
||||
"else" -> Else
|
||||
"elsif" -> Elsif
|
||||
@ -183,6 +186,7 @@ categoryForRubyName = \case
|
||||
"splat_parameter" -> SplatParameter
|
||||
"string" -> StringLiteral
|
||||
"subshell" -> Subshell
|
||||
"superclass" -> Superclass
|
||||
"symbol" -> SymbolLiteral
|
||||
"true" -> Boolean
|
||||
"unary" -> Unary
|
||||
|
@ -116,6 +116,8 @@ styleName category = "category-" <> case category of
|
||||
C.Continue -> "continue_statement"
|
||||
C.Binary -> "binary"
|
||||
C.Unary -> "unary"
|
||||
C.Constant -> "constant"
|
||||
C.Superclass -> "superclass"
|
||||
|
||||
-- | Pick the class name for a split patch.
|
||||
splitPatchToClassName :: SplitPatch a -> AttributeValue
|
||||
|
2
vendor/tree-sitter-parsers
vendored
2
vendor/tree-sitter-parsers
vendored
@ -1 +1 @@
|
||||
Subproject commit 1709d9799d4e05799fd9ae1d9ee22bf8f0214c79
|
||||
Subproject commit 831c0f3a302e1bfc6439bb7f6be5ea557aeec03a
|
Loading…
Reference in New Issue
Block a user