mirror of
https://github.com/github/semantic.git
synced 2024-11-24 17:04:47 +03:00
Keep track of clauses before a Method identifier
This commit is contained in:
parent
eb512a6acf
commit
81e178fc61
@ -89,8 +89,9 @@ algorithmWithTerms t1 t2 = maybe (linearly t1 t2) (fmap annotate) $ case (unwrap
|
||||
S.Class <$> linearly identifierA identifierB
|
||||
<*> byRWS clausesA clausesB
|
||||
<*> byRWS expressionsA expressionsB
|
||||
(S.Method identifierA receiverA paramsA expressionsA, S.Method identifierB receiverB paramsB expressionsB) -> Just $
|
||||
S.Method <$> linearly identifierA identifierB
|
||||
(S.Method clausesA identifierA receiverA paramsA expressionsA, S.Method clausesB identifierB receiverB paramsB expressionsB) -> Just $
|
||||
S.Method <$> byRWS clausesA clausesB
|
||||
<*> linearly identifierA identifierB
|
||||
<*> maybeLinearly receiverA receiverB
|
||||
<*> byRWS paramsA paramsB
|
||||
<*> byRWS expressionsA expressionsB
|
||||
|
@ -58,11 +58,11 @@ termAssignment source category children = case (category, children) of
|
||||
(IncrementStatement, _) -> Just $ S.Leaf (toText source)
|
||||
(DecrementStatement, _) -> Just $ S.Leaf (toText source)
|
||||
(QualifiedIdentifier, _) -> Just $ S.Leaf (toText source)
|
||||
(Method, [receiverParams, name, body]) -> Just (S.Method name (Just receiverParams) [] (toList (unwrap body)))
|
||||
(Method, [receiverParams, name, body]) -> Just (S.Method [] name (Just receiverParams) [] (toList (unwrap body)))
|
||||
(Method, [receiverParams, name, params, body])
|
||||
-> Just (S.Method name (Just receiverParams) [params] (toList (unwrap body)))
|
||||
-> Just (S.Method [] name (Just receiverParams) [params] (toList (unwrap body)))
|
||||
(Method, [receiverParams, name, params, ty, body])
|
||||
-> Just (S.Method name (Just receiverParams) [params, ty] (toList (unwrap body)))
|
||||
-> Just (S.Method [] name (Just receiverParams) [params, ty] (toList (unwrap body)))
|
||||
_ -> Nothing
|
||||
|
||||
categoryForGoName :: Text -> Category
|
||||
|
@ -43,8 +43,8 @@ termAssignment _ category children
|
||||
, Finally <- Info.category (extract finally)
|
||||
-> Just $ S.Try [body] [catch] Nothing (Just finally)
|
||||
(ArrayLiteral, _) -> Just $ S.Array Nothing children
|
||||
(Method, [ identifier, params, exprs ]) -> Just $ S.Method identifier Nothing [params] (toList (unwrap exprs))
|
||||
(Method, [ identifier, exprs ]) -> Just $ S.Method identifier Nothing [] (toList (unwrap exprs))
|
||||
(Method, [ identifier, params, exprs ]) -> Just $ S.Method [] identifier Nothing [params] (toList (unwrap exprs))
|
||||
(Method, [ identifier, exprs ]) -> Just $ S.Method [] identifier Nothing [] (toList (unwrap exprs))
|
||||
(Class, [ identifier, superclass, definitions ]) -> Just $ S.Class identifier [superclass] (toList (unwrap definitions))
|
||||
(Class, [ identifier, definitions ]) -> Just $ S.Class identifier [] (toList (unwrap definitions))
|
||||
(Import, [ statements, identifier ] ) -> Just $ S.Import identifier (toList (unwrap statements))
|
||||
|
@ -67,15 +67,15 @@ termAssignment _ category children
|
||||
(SingletonMethod, expr : methodName : rest)
|
||||
| params : body <- rest
|
||||
, Params <- Info.category (extract params)
|
||||
-> Just $ S.Method methodName (Just expr) [params] body
|
||||
-> Just $ S.Method [] methodName (Just expr) [params] body
|
||||
| Identifier <- Info.category (extract methodName)
|
||||
-> Just $ S.Method methodName (Just expr) [] rest
|
||||
-> Just $ S.Method [] methodName (Just expr) [] rest
|
||||
(Method, identifier : rest)
|
||||
| params : body <- rest
|
||||
, Params <- Info.category (extract params)
|
||||
-> Just $ S.Method identifier Nothing [params] body
|
||||
-> Just $ S.Method [] identifier Nothing [params] body
|
||||
| otherwise
|
||||
-> Just $ S.Method identifier Nothing [] rest
|
||||
-> Just $ S.Method [] identifier Nothing [] rest
|
||||
(Module, constant : body ) -> Just $ S.Module constant body
|
||||
(Modifier Rescue, [lhs, rhs] ) -> Just $ S.Rescue [lhs] [rhs]
|
||||
(Rescue, exceptions : exceptionVar : rest)
|
||||
|
@ -7,7 +7,6 @@ import Source
|
||||
import Language
|
||||
import qualified Syntax as S
|
||||
import Term
|
||||
import Data.List (span)
|
||||
|
||||
termAssignment
|
||||
:: Source -- ^ The source of the term.
|
||||
@ -51,8 +50,8 @@ termAssignment _ category children =
|
||||
-> Just $ S.Try [body] [catch] Nothing (Just finally)
|
||||
(ArrayLiteral, _) -> Just $ S.Array Nothing children
|
||||
(Method, children) -> case Prologue.break ((== ExpressionStatements) . Info.category . extract) children of
|
||||
(prev, [body]) -> case span ((== Identifier) . Info.category . extract) prev of
|
||||
([id], [callSignature]) -> Just $ S.Method id Nothing (toList (unwrap callSignature)) (toList (unwrap body))
|
||||
(prev, [body]) -> case Prologue.break ((== Identifier) . Info.category . extract) prev of
|
||||
(prev, [id, callSignature]) -> Just $ S.Method prev id Nothing (toList (unwrap callSignature)) (toList (unwrap body))
|
||||
_ -> Nothing -- No identifier found or callSignature found.
|
||||
_ -> Nothing -- No body found.``
|
||||
(Class, identifier : rest) -> case Prologue.break ((== Other "class_body") . Info.category . extract) rest of
|
||||
@ -71,11 +70,10 @@ termAssignment _ category children =
|
||||
| Just (exprs, body) <- unsnoc children
|
||||
-> Just $ S.For exprs [body]
|
||||
(Function, children) -> case Prologue.break ((== ExpressionStatements) . Info.category . extract) children of
|
||||
(inits, [body]) ->
|
||||
case span ((== Identifier) . Info.category . extract) inits of
|
||||
([id], [callSignature]) -> Just $ S.Function id (toList (unwrap callSignature)) (toList (unwrap body))
|
||||
([], [callSignature]) -> Just $ S.AnonymousFunction (toList (unwrap callSignature)) (toList (unwrap body))
|
||||
_ -> Nothing -- More than 1 identifier found or no call signature found
|
||||
(inits, [body]) -> case inits of
|
||||
[id, callSignature] -> Just $ S.Function id (toList (unwrap callSignature)) (toList (unwrap body))
|
||||
[callSignature] -> Just $ S.AnonymousFunction (toList (unwrap callSignature)) (toList (unwrap body))
|
||||
_ -> Nothing -- More than 1 identifier found or no call signature found
|
||||
_ -> Nothing -- No body found.
|
||||
(Ty, children) -> Just $ S.Ty children
|
||||
(Interface, children) -> toInterface children
|
||||
@ -157,7 +155,6 @@ categoryForTypeScriptName category = case category of
|
||||
"public_field_definition" -> FieldDecl
|
||||
"variable_declarator" -> VarAssignment
|
||||
"type_annotation" -> Ty
|
||||
"accessibility_modifier" -> Identifier
|
||||
"template_chars" -> TemplateString
|
||||
"module" -> Module
|
||||
"ambient_namespace" -> Namespace
|
||||
|
@ -129,7 +129,7 @@ syntaxToTermField syntax = case syntax of
|
||||
S.Try body catchExpression elseExpression finallyExpression -> [ "body" .= body ] <> [ "catchExpression" .= catchExpression ] <> [ "elseExpression" .= elseExpression ] <> [ "finallyExpression" .= finallyExpression ]
|
||||
S.Array ty c -> [ "type" .= ty ] <> childrenFields c
|
||||
S.Class identifier superclass definitions -> [ "identifier" .= identifier ] <> [ "superclass" .= superclass ] <> [ "definitions" .= definitions ]
|
||||
S.Method identifier receiver callSignature definitions -> [ "identifier" .= identifier ] <> [ "receiver" .= receiver ] <> [ "callSignature" .= callSignature ] <> [ "definitions" .= definitions ]
|
||||
S.Method clauses identifier receiver callSignature definitions -> [ "clauses" .= clauses ] <> [ "identifier" .= identifier ] <> [ "receiver" .= receiver ] <> [ "callSignature" .= callSignature ] <> [ "definitions" .= definitions ]
|
||||
S.If expression clauses -> [ "expression" .= expression ] <> childrenFields clauses
|
||||
S.Module identifier definitions -> [ "identifier" .= identifier ] <> [ "definitions" .= definitions ]
|
||||
S.Namespace identifier definitions -> [ "identifier" .= identifier ] <> [ "definitions" .= definitions ]
|
||||
|
@ -269,8 +269,8 @@ toTermName source term = case unwrap term of
|
||||
S.Select clauses -> termNameFromChildren term clauses
|
||||
S.Array ty _ -> maybe (termNameFromSource term) termNameFromSource ty
|
||||
S.Class identifier _ _ -> toTermName' identifier
|
||||
S.Method identifier (Just receiver) args _ -> termNameFromSource receiver <> "." <> toTermName' identifier <> paramsToArgNames args
|
||||
S.Method identifier Nothing args _ -> toTermName' identifier <> paramsToArgNames args
|
||||
S.Method _ identifier (Just receiver) args _ -> termNameFromSource receiver <> "." <> toTermName' identifier <> paramsToArgNames args
|
||||
S.Method _ identifier Nothing args _ -> toTermName' identifier <> paramsToArgNames args
|
||||
S.Comment a -> toS a
|
||||
S.Commented _ _ -> termNameFromChildren term (toList $ unwrap term)
|
||||
S.Module identifier _ -> toTermName' identifier
|
||||
|
@ -166,8 +166,8 @@ termToDiffInfo source term = case unwrap term of
|
||||
toTermName :: forall leaf fields. DefaultFields fields => Int -> Source -> SyntaxTerm leaf fields -> Text
|
||||
toTermName parentOffset parentSource term = case unwrap term of
|
||||
S.Function identifier _ _ -> toTermName' identifier
|
||||
S.Method identifier Nothing _ _ -> toTermName' identifier
|
||||
S.Method identifier (Just receiver) _ _ -> case unwrap receiver of
|
||||
S.Method _ identifier Nothing _ _ -> toTermName' identifier
|
||||
S.Method _ identifier (Just receiver) _ _ -> case unwrap receiver of
|
||||
S.Indexed [receiverParams] -> case unwrap receiverParams of
|
||||
S.ParameterDecl (Just ty) _ -> "(" <> toTermName' ty <> ") " <> toTermName' identifier
|
||||
_ -> toMethodNameWithReceiver receiver identifier
|
||||
|
@ -76,7 +76,7 @@ data Syntax a f
|
||||
-- | A class with an identifier, superclass, and a list of definitions.
|
||||
| Class f [f] [f]
|
||||
-- | A method definition with an identifier, optional receiver, optional type arguments, params, optional return type, and a list of expressions.
|
||||
| Method f (Maybe f) [f] [f]
|
||||
| Method [f] f (Maybe f) [f] [f]
|
||||
-- | An if statement with an expression and maybe more expression clauses.
|
||||
| If f [f]
|
||||
-- | A module with an identifier, and a list of syntaxes.
|
||||
@ -127,7 +127,7 @@ maybeIdentifier syntax = case syntax of
|
||||
Function f _ _ -> Just f
|
||||
FunctionCall f _ _ -> Just f
|
||||
Import f _ -> Just f
|
||||
Method f _ _ _ -> Just f
|
||||
Method _ f _ _ _ -> Just f
|
||||
MethodCall _ f _ _ -> Just f
|
||||
Module f _ -> Just f
|
||||
OperatorAssignment f _ -> Just f
|
||||
@ -172,7 +172,7 @@ instance Listable2 Syntax where
|
||||
\/ liftCons4 (liftTiers recur) (liftTiers recur) (liftTiers recur) (liftTiers recur) Try
|
||||
\/ liftCons2 (liftTiers recur) (liftTiers recur) Syntax.Array
|
||||
\/ liftCons3 recur (liftTiers recur) (liftTiers recur) Class
|
||||
\/ liftCons4 recur (liftTiers recur) (liftTiers recur) (liftTiers recur) Method
|
||||
\/ liftCons5 (liftTiers recur) recur (liftTiers recur) (liftTiers recur) (liftTiers recur) Method
|
||||
\/ liftCons2 recur (liftTiers recur) If
|
||||
\/ liftCons2 recur (liftTiers recur) Module
|
||||
\/ liftCons2 recur (liftTiers recur) Namespace
|
||||
|
Loading…
Reference in New Issue
Block a user