mirror of
https://github.com/github/semantic.git
synced 2024-11-24 17:04:47 +03:00
Back to a single Rescue syntax
This commit is contained in:
parent
345d4ed12e
commit
c02c32ac7c
@ -55,7 +55,6 @@ identifiable term = isIdentifiable (unwrap term) term
|
||||
S.Export{} -> Identifiable
|
||||
S.BlockExpression{} -> Identifiable
|
||||
S.Rescue{} -> Identifiable
|
||||
S.RescueModifier{} -> Identifiable
|
||||
_ -> Unidentifiable
|
||||
|
||||
data JSONSummary summary span = JSONSummary { summary :: summary, span :: span }
|
||||
@ -163,7 +162,6 @@ toLeafInfos leaf = pure . flip JSONSummary (sourceSpan leaf) $ case leaf of
|
||||
(LeafInfo cName@"else block" _ _) -> toDoc cName
|
||||
(LeafInfo cName@"ensure block" _ _) -> toDoc cName
|
||||
(LeafInfo cName@"when block" _ _) -> toDoc cName
|
||||
(LeafInfo "rescue modifier" termName _) -> squotes ("rescue" <+> toDoc termName) <+> "modifier"
|
||||
(LeafInfo cName@"string" termName _) -> toDoc termName <+> toDoc cName
|
||||
(LeafInfo cName@"export statement" termName _) -> toDoc termName <+> toDoc cName
|
||||
(LeafInfo cName@"import statement" termName _) -> toDoc termName <+> toDoc cName
|
||||
@ -243,12 +241,7 @@ toTermName source term = case unwrap term of
|
||||
S.BlockExpression maybeExpr children -> case maybeExpr of
|
||||
Just expr -> termNameFromSource expr
|
||||
Nothing -> fromMaybe "branch" $ (toCategoryName . category) . extract <$> head children
|
||||
S.Rescue maybeArgs maybeEx _ -> case (maybeArgs, maybeEx) of
|
||||
(Just args, Just ex) -> toTermName' args <> " => " <> toTermName' ex
|
||||
(Just args, Nothing) -> toTermName' args
|
||||
_ -> ""
|
||||
S.RescueModifier _ rhs -> termNameFromSource rhs
|
||||
S.LastException expr -> termNameFromSource expr
|
||||
S.Rescue args _ -> intercalate ", " $ toTermName' <$> args
|
||||
S.Params args -> mconcat $ toTermName' <$> args
|
||||
where toTermName' = toTermName source
|
||||
termNameFromChildren term children = termNameFromRange (unionRangesFrom (range term) (range <$> children))
|
||||
|
@ -59,8 +59,6 @@ termConstructor source sourceSpan name range children
|
||||
("element_reference", _ ) -> S.Error children
|
||||
("for_statement", lhs : expr : rest ) -> S.For [lhs, expr] rest
|
||||
("for_statement", _ ) -> S.Error children
|
||||
("last_exception", [ ex ]) -> S.LastException ex
|
||||
("last_exception", _ ) -> S.Error children
|
||||
("math_assignment", [ identifier, value ]) -> S.MathAssignment identifier value
|
||||
("math_assignment", _ ) -> S.Error children
|
||||
("member_access", [ base, property ]) -> S.MemberAccess base property
|
||||
@ -73,11 +71,15 @@ termConstructor source sourceSpan name range children
|
||||
_ -> S.Error children
|
||||
("module_declaration", identifier : body ) -> S.Module identifier body
|
||||
("module_declaration", _ ) -> S.Error children
|
||||
("rescue_block", _) -> case runCofree <$> children of
|
||||
(args@(_ :< S.Args _) : e@(_ :< S.LastException _) : rest) -> S.Rescue (Just (cofree args)) (Just (cofree e)) (cofree <$> rest)
|
||||
(args@(_ :< S.Args _) : rest) -> S.Rescue (Just (cofree args)) Nothing (cofree <$> rest)
|
||||
_ -> S.Rescue Nothing Nothing children
|
||||
("rescue_modifier", [lhs, rhs] ) -> S.RescueModifier lhs rhs
|
||||
("rescue_block", _) -> case children of
|
||||
args : lastException : rest |
|
||||
category (extract args) == Args,
|
||||
category (extract lastException) == LastException ->
|
||||
S.Rescue (toList (unwrap args) <> [lastException]) rest
|
||||
lastException : rest | category (extract lastException) == LastException -> S.Rescue [lastException] rest
|
||||
args : body | category (extract args) == Args -> S.Rescue (toList (unwrap args)) body
|
||||
body -> S.Rescue [] body
|
||||
("rescue_modifier", [lhs, rhs] ) -> S.Rescue [lhs] [rhs]
|
||||
("rescue_modifier", _ ) -> S.Error children
|
||||
("return_statement", _ ) -> S.Return (listToMaybe children)
|
||||
("unless_modifier", [ lhs, condition ]) -> S.Unless condition [lhs]
|
||||
|
@ -131,8 +131,6 @@ syntaxToTermField syntax = case syntax of
|
||||
S.Until expr body -> [ "untilExpr" .= expr ] <> [ "untilBody" .= body ]
|
||||
S.Unless expr clauses -> [ "unless" .= expr ] <> childrenFields clauses
|
||||
S.BlockExpression condition expressions -> [ "condition" .= condition ] <> childrenFields expressions
|
||||
S.Rescue args ex expressions -> [ "args" .= args ] <> [ "ex" .= ex ] <> childrenFields expressions
|
||||
S.RescueModifier lhs rhs -> [ "lhs" .= lhs ] <> [ "rhs" .= rhs ]
|
||||
S.LastException e -> [ "ex" .= e ]
|
||||
S.Rescue args expressions -> [ "args" .= args ] <> childrenFields expressions
|
||||
S.Params c -> childrenFields c
|
||||
where childrenFields c = [ "children" .= c ]
|
||||
|
@ -86,12 +86,8 @@ data Syntax a f
|
||||
| Unless f [f]
|
||||
-- | A block expression might have a conditional expression and always has a list of expressions (e.g. begin, else, ensure in Ruby).
|
||||
| BlockExpression (Maybe f) [f]
|
||||
-- | A rescue block: maybe Args to rescue, maybe a local var for the last exception, and a list of expressions.
|
||||
| Rescue (Maybe f) (Maybe f) [f]
|
||||
-- | A rescue modifier has a left and right expression (e.g. in Ruby foo rescue nil).
|
||||
| RescueModifier f f
|
||||
-- | The last exception captured in a rescue block to a local variable (e.g. in Ruby rescue => x).
|
||||
| LastException f
|
||||
-- | A rescue block has a list of arguments to rescue and a list of expressions.
|
||||
| Rescue [f] [f]
|
||||
-- | Parameters in a method/function definition
|
||||
| Params [f]
|
||||
deriving (Eq, Foldable, Functor, Generic, Generic1, Mergeable, Ord, Show, Traversable, ToJSON)
|
||||
|
@ -16,7 +16,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue nil' modifier"
|
||||
"summary": "Added the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -34,7 +34,7 @@
|
||||
"+foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "875face60282636c8ba6fbd9db4a50c6b8b38fd2..08e8f151a897162bcc784bf475633d3b383d622c"
|
||||
"shas": "dbbf1ed8a8cafe556ea468af463f118f3ca0f4ba..ee8d8559b436b4434abf6fb62e720fd2b2e25e67"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier-replacement-insert-test",
|
||||
@ -54,7 +54,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue false' modifier"
|
||||
"summary": "Added the 'foo' rescue modifier"
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -69,7 +69,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue nil' modifier"
|
||||
"summary": "Added the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -89,7 +89,7 @@
|
||||
" foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "08e8f151a897162bcc784bf475633d3b383d622c..6dd1eeaed545d30b4013e2afaa27e5eab0fd0e71"
|
||||
"shas": "ee8d8559b436b4434abf6fb62e720fd2b2e25e67..f757d66e78f7d4e6497ce72a70017e34180e6ed7"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier-delete-insert-test",
|
||||
@ -121,7 +121,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"summary": "Replaced the 'rescue false' modifier with the 'rescue nil' modifier"
|
||||
"summary": "Replaced the 'foo' rescue modifier with the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -142,7 +142,7 @@
|
||||
" foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "6dd1eeaed545d30b4013e2afaa27e5eab0fd0e71..2de1d6af1e7c40afe318d9d73d6296bce398aca3"
|
||||
"shas": "f757d66e78f7d4e6497ce72a70017e34180e6ed7..48cf3c8ae9539479ada31649b7907f45750d3587"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier-replacement-test",
|
||||
@ -174,7 +174,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"summary": "Replaced the 'rescue nil' modifier with the 'rescue false' modifier"
|
||||
"summary": "Replaced the 'foo' rescue modifier with the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -195,7 +195,7 @@
|
||||
" foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "2de1d6af1e7c40afe318d9d73d6296bce398aca3..7446beb4ceb30fca9b6fe2a50aa3af2b7974f94b"
|
||||
"shas": "48cf3c8ae9539479ada31649b7907f45750d3587..e27305bea14543e812e35efdfad8e15916b44bce"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier-delete-replacement-test",
|
||||
@ -215,7 +215,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue false' modifier"
|
||||
"summary": "Deleted the 'foo' rescue modifier"
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -230,7 +230,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue nil' modifier"
|
||||
"summary": "Deleted the 'foo' rescue modifier"
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -245,7 +245,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue false' modifier"
|
||||
"summary": "Added the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -266,7 +266,7 @@
|
||||
"+foo rescue false"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "7446beb4ceb30fca9b6fe2a50aa3af2b7974f94b..da15018c29958edbc41e34ca412c990df7b3c0a2"
|
||||
"shas": "e27305bea14543e812e35efdfad8e15916b44bce..8448399194931991c532e1431d5bb57feec7e9d2"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier-delete-test",
|
||||
@ -286,7 +286,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue nil' modifier"
|
||||
"summary": "Deleted the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -305,7 +305,7 @@
|
||||
" foo rescue false"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "da15018c29958edbc41e34ca412c990df7b3c0a2..51c759c77ac04eb4b2d197b3aecabc971d439cde"
|
||||
"shas": "8448399194931991c532e1431d5bb57feec7e9d2..0aa3073a2d457a147b4ce034ab0576694ff7ed6d"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier-delete-rest-test",
|
||||
@ -325,7 +325,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue false' modifier"
|
||||
"summary": "Deleted the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -343,5 +343,5 @@
|
||||
"-foo rescue false"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "51c759c77ac04eb4b2d197b3aecabc971d439cde..6c195e290e7613379817885b55119b8158a86bb2"
|
||||
"shas": "0aa3073a2d457a147b4ce034ab0576694ff7ed6d..89be77a7b4f5ee9670276a33a97a6aa3941c9cfb"
|
||||
}]
|
||||
|
@ -16,7 +16,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue nil' modifier"
|
||||
"summary": "Added the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -34,7 +34,7 @@
|
||||
"+foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "6c195e290e7613379817885b55119b8158a86bb2..ccbc5b1238c33590f2f2d8de25cc77a39a322352"
|
||||
"shas": "89be77a7b4f5ee9670276a33a97a6aa3941c9cfb..55cdbc8c69ef00db47f231d904f083eb28f50160"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier2-replacement-insert-test",
|
||||
@ -54,7 +54,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue nil' modifier"
|
||||
"summary": "Added the 'bar' rescue modifier"
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -69,7 +69,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue nil' modifier"
|
||||
"summary": "Added the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -89,7 +89,7 @@
|
||||
" foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "ccbc5b1238c33590f2f2d8de25cc77a39a322352..bdc004cefba4d7a9462c07a1cc2344b6d436acf4"
|
||||
"shas": "55cdbc8c69ef00db47f231d904f083eb28f50160..198f5f3b96b3f405c1ff2081a511fac17edc7c91"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier2-delete-insert-test",
|
||||
@ -121,7 +121,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"summary": "Replaced the 'bar' identifier with the 'foo' identifier in the 'rescue nil' modifier"
|
||||
"summary": "Replaced the 'bar' identifier with the 'foo' identifier in the 'rescue foo' modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -142,7 +142,7 @@
|
||||
" foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "bdc004cefba4d7a9462c07a1cc2344b6d436acf4..0b22cb5a465965c27dd9044b9d89a55caf5ee42b"
|
||||
"shas": "198f5f3b96b3f405c1ff2081a511fac17edc7c91..1e6f032a4125e945220103becbd30842264ab52e"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier2-replacement-test",
|
||||
@ -174,7 +174,7 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"summary": "Replaced the 'foo' identifier with the 'bar' identifier in the 'rescue nil' modifier"
|
||||
"summary": "Replaced the 'foo' identifier with the 'bar' identifier in the 'rescue bar' modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -195,7 +195,7 @@
|
||||
" foo rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "0b22cb5a465965c27dd9044b9d89a55caf5ee42b..b18711120acd0a77e1687a8f1e5ff4044e1ff54c"
|
||||
"shas": "1e6f032a4125e945220103becbd30842264ab52e..a666824e8c4d5b66c6d27e6a0246b63a3042b7a0"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier2-delete-replacement-test",
|
||||
@ -215,7 +215,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue nil' modifier"
|
||||
"summary": "Deleted the 'bar' rescue modifier"
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -230,7 +230,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue nil' modifier"
|
||||
"summary": "Deleted the 'foo' rescue modifier"
|
||||
},
|
||||
{
|
||||
"span": {
|
||||
@ -245,7 +245,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Added the 'rescue nil' modifier"
|
||||
"summary": "Added the 'bar' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -266,7 +266,7 @@
|
||||
"+bar rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "b18711120acd0a77e1687a8f1e5ff4044e1ff54c..dd5754f0a62ca3ebc8b724e37745873953c7493a"
|
||||
"shas": "a666824e8c4d5b66c6d27e6a0246b63a3042b7a0..14d5975cd55f2b7d27ce40f3491786b5644c10a6"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier2-delete-test",
|
||||
@ -286,7 +286,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue nil' modifier"
|
||||
"summary": "Deleted the 'foo' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -305,7 +305,7 @@
|
||||
" bar rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "dd5754f0a62ca3ebc8b724e37745873953c7493a..1e5ba2921990ac256abe41be03b236a701541d9d"
|
||||
"shas": "14d5975cd55f2b7d27ce40f3491786b5644c10a6..0446bcdbd6fc1e4f75ecdd984d9428c2d82e4c2a"
|
||||
}
|
||||
,{
|
||||
"testCaseDescription": "ruby-rescue-modifier2-delete-rest-test",
|
||||
@ -325,7 +325,7 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"summary": "Deleted the 'rescue nil' modifier"
|
||||
"summary": "Deleted the 'bar' rescue modifier"
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -343,5 +343,5 @@
|
||||
"-bar rescue nil"
|
||||
],
|
||||
"gitDir": "test/corpus/repos/ruby",
|
||||
"shas": "1e5ba2921990ac256abe41be03b236a701541d9d..dc9d24ac927d2ba1f4d7331d5edcf9888c6bfbdf"
|
||||
"shas": "0446bcdbd6fc1e4f75ecdd984d9428c2d82e4c2a..375e457b7d8886bdbdb8b3e131a0c001d20ac41c"
|
||||
}]
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit dbbf1ed8a8cafe556ea468af463f118f3ca0f4ba
|
||||
Subproject commit 375e457b7d8886bdbdb8b3e131a0c001d20ac41c
|
2
vendor/tree-sitter-parsers
vendored
2
vendor/tree-sitter-parsers
vendored
@ -1 +1 @@
|
||||
Subproject commit 7dfb3f7ed5a00f516859cf60f2861dd3b41fe28f
|
||||
Subproject commit a4ad596558dfbd9eceddec364e13201727777706
|
Loading…
Reference in New Issue
Block a user