Ruby: add upgrade and downgrade scripts

This commit is contained in:
Arthur Baars
2022-04-26 11:04:26 +02:00
parent d055f9a186
commit ccc18640db
20 changed files with 6059 additions and 0 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,14 @@
class RubyBlockParameters extends @ruby_block_parameters {
string toString() { none() }
}
class RubyBlockParameter extends @ruby_block_parameters_child_type {
string toString() { none() }
}
from RubyBlockParameters ruby_block_parameters, int index, RubyBlockParameter param
where
ruby_block_parameters_child(ruby_block_parameters, index, param) or
ruby_block_parameters_locals(ruby_block_parameters,
index - 1 - max(int i | ruby_block_parameters_child(ruby_block_parameters, i, _)), param)
select ruby_block_parameters, index, param

View File

@@ -0,0 +1,14 @@
class RubyAstNode extends @ruby_ast_node {
string toString() { none() }
}
class RubyCall extends RubyAstNode, @ruby_call { }
from RubyCall ruby_call, RubyAstNode method
where
ruby_call_method(ruby_call, method)
or
ruby_call_def(ruby_call) and
not ruby_call_method(ruby_call, _) and
ruby_call_arguments(ruby_call, method)
select ruby_call, method

View File

@@ -0,0 +1,7 @@
private class RubyAstNode extends @ruby_ast_node {
string toString() { none() }
}
from RubyAstNode node, RubyAstNode child
where ruby_rational_def(node, child) and not ruby_complex_def(_, node)
select node, child

View File

@@ -0,0 +1,37 @@
private class RubyAstNode extends @ruby_ast_node {
string toString() { none() }
}
bindingset[old]
private int newKind(int old) {
old <= 3 and result = old
or
old >= 4 and result = old + 1
}
private predicate complex_token(RubyAstNode node, string value) {
exists(RubyAstNode token, string tokenValue | ruby_tokeninfo(token, _, tokenValue) |
(
ruby_complex_def(node, token) and value = tokenValue + "i"
or
exists(@ruby_rational rational |
ruby_complex_def(node, rational) and
ruby_rational_def(rational, token)
) and
value = tokenValue + "ri"
)
)
}
private RubyAstNode parent(RubyAstNode node) { ruby_ast_node_info(node, result, _, _) }
from RubyAstNode token, int kind, string value
where
exists(int oldKind |
ruby_tokeninfo(token, oldKind, value) and
not complex_token(parent+(token), _) and
kind = newKind(oldKind)
)
or
complex_token(token, value) and kind = 4
select token, kind, value

View File

@@ -0,0 +1,12 @@
description: tree-sitter-ruby update
compatibility: backwards
ruby_tokeninfo.rel: run ruby_tokeninfo.qlo
ruby_block_parameters_child.rel: run ruby_block_parameters_child.qlo
ruby_call_def.rel: run ruby_call_def.qlo
ruby_rational_def.rel: run ruby_rational_def.qlo
ruby_call_method.rel: delete
ruby_complex_def.rel: delete
ruby_block_parameters_locals.rel: delete
ruby_call_operator: delete

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
class ScopeResolutionMethodCall extends @ruby_call {
private @ruby_scope_resolution scope;
ScopeResolutionMethodCall() { ruby_call_def(this, scope) }
@ruby_scope_resolution getScopeResolution() { result = scope }
string toString() { none() }
}
class Location extends @location {
string toString() { none() }
}
class RubyAstNode extends @ruby_ast_node {
string toString() { none() }
}
class RubyAstNodeParent extends @ruby_ast_node_parent {
string toString() { none() }
}
from RubyAstNode node, RubyAstNodeParent parent, int index, Location loc
where
ruby_ast_node_info(node, parent, index, loc) and
not node = any(ScopeResolutionMethodCall c).getScopeResolution() and
not parent = any(ScopeResolutionMethodCall c) and
not parent = any(ScopeResolutionMethodCall c).getScopeResolution()
or
ruby_ast_node_info(node, _, _, loc) and
parent instanceof ScopeResolutionMethodCall and
node =
rank[index + 1](RubyAstNode child, int x, int oldIndex |
exists(RubyAstNodeParent oldParent |
ruby_ast_node_info(child, oldParent, oldIndex, _) and
child != parent.(ScopeResolutionMethodCall).getScopeResolution()
|
oldParent = parent and x = 1
or
oldParent = parent.(ScopeResolutionMethodCall).getScopeResolution() and x = 0
)
|
child order by x, oldIndex
)
select node, parent, index, loc

View File

@@ -0,0 +1,29 @@
class RubyBlockParameters extends @ruby_block_parameters {
string toString() { none() }
}
class RubyIdentifier extends @ruby_token_identifier {
string toString() { none() }
}
predicate blockParametersLocals(RubyBlockParameters params, int index, RubyIdentifier local) {
local =
rank[index + 1](@ruby_token semi, int semiIndex, RubyIdentifier id, int idIndex |
ruby_tokeninfo(semi, _, ";") and
ruby_ast_node_info(semi, params, semiIndex, _) and
ruby_ast_node_info(id, params, idIndex, _) and
idIndex > semiIndex
|
id order by idIndex
)
}
class RubyBlockParameter extends @ruby_block_parameters_child_type {
string toString() { none() }
}
from RubyBlockParameters ruby_block_parameters, int index, RubyBlockParameter param
where
ruby_block_parameters_child(ruby_block_parameters, index, param) and
not blockParametersLocals(ruby_block_parameters, _, param)
select ruby_block_parameters, index, param

View File

@@ -0,0 +1,23 @@
class RubyBlockParameters extends @ruby_block_parameters {
string toString() { none() }
}
class RubyIdentifier extends @ruby_token_identifier {
string toString() { none() }
}
predicate blockParametersLocals(RubyBlockParameters params, int index, RubyIdentifier local) {
local =
rank[index + 1](@ruby_token semi, int semiIndex, RubyIdentifier id, int idIndex |
ruby_tokeninfo(semi, _, ";") and
ruby_ast_node_info(semi, params, semiIndex, _) and
ruby_ast_node_info(id, params, idIndex, _) and
idIndex > semiIndex
|
id order by idIndex
)
}
from RubyBlockParameters ruby_block_parameters, int index, RubyIdentifier local
where blockParametersLocals(ruby_block_parameters, index, local)
select ruby_block_parameters, index, local

View File

@@ -0,0 +1,43 @@
class RubyCallMethodType = @ruby_token_operator or @ruby_underscore_variable;
class RubyArgumentList extends @ruby_argument_list {
string toString() { none() }
}
abstract class RubyCall extends @ruby_ast_node {
string toString() { none() }
abstract RubyArgumentList getArguments();
}
class NormalRubyCall extends RubyCall, @ruby_call {
NormalRubyCall() { ruby_call_def(this, any(RubyCallMethodType m)) }
override RubyArgumentList getArguments() { ruby_call_arguments(this, result) }
}
class ImplicitRubyCall extends RubyCall, @ruby_call {
RubyArgumentList arguments;
ImplicitRubyCall() { ruby_call_def(this, arguments) }
override RubyArgumentList getArguments() { result = arguments }
}
class ScopeResolutionCall extends RubyCall, @ruby_scope_resolution {
ScopeResolutionCall() {
ruby_scope_resolution_def(this, any(@ruby_token_identifier m)) and
not ruby_call_def(_, this)
}
override RubyArgumentList getArguments() { none() }
}
class ScopeResolutionMethodCall extends RubyCall, @ruby_call {
ScopeResolutionMethodCall() { ruby_call_def(this, any(@ruby_scope_resolution s)) }
override RubyArgumentList getArguments() { ruby_call_arguments(this, result) }
}
from RubyCall ruby_call
select ruby_call, ruby_call.getArguments()

View File

@@ -0,0 +1,27 @@
class RubyCallMethodType = @ruby_token_operator or @ruby_underscore_variable;
abstract class RubyCall extends @ruby_ast_node {
string toString() { none() }
}
class NormalRubyCall extends RubyCall, @ruby_call {
NormalRubyCall() { ruby_call_def(this, any(RubyCallMethodType m)) }
}
class ImplicitRubyCall extends RubyCall, @ruby_call {
ImplicitRubyCall() { ruby_call_def(this, any(@ruby_argument_list a)) }
}
class ScopeResolutionCall extends RubyCall, @ruby_scope_resolution {
ScopeResolutionCall() {
ruby_scope_resolution_def(this, any(@ruby_token_identifier m)) and
not ruby_call_def(_, this)
}
}
class ScopeResolutionMethodCall extends RubyCall, @ruby_call {
ScopeResolutionMethodCall() { ruby_call_def(this, any(@ruby_scope_resolution s)) }
}
from RubyCall ruby_call
select ruby_call

View File

@@ -0,0 +1,52 @@
class RubyCallMethodType = @ruby_token_operator or @ruby_underscore_variable;
class RubyMethod extends RubyCallMethodType {
string toString() { none() }
}
abstract class RubyCall extends @ruby_ast_node {
string toString() { none() }
abstract RubyMethod getMethod();
}
class NormalRubyCall extends RubyCall, @ruby_call {
private RubyMethod method;
NormalRubyCall() { ruby_call_def(this, method) }
override RubyMethod getMethod() { result = method }
}
class ImplicitRubyCall extends RubyCall, @ruby_call {
ImplicitRubyCall() { ruby_call_def(this, any(@ruby_argument_list a)) }
override RubyMethod getMethod() { none() }
}
class ScopeResolutionCall extends RubyCall, @ruby_scope_resolution {
private @ruby_token_identifier method;
ScopeResolutionCall() {
ruby_scope_resolution_def(this, method) and
not ruby_call_def(_, this)
}
override RubyMethod getMethod() { result = method }
}
class ScopeResolutionMethodCall extends RubyCall, @ruby_call {
private RubyMethod method;
ScopeResolutionMethodCall() {
exists(@ruby_scope_resolution scope |
ruby_call_def(this, scope) and
ruby_scope_resolution_def(scope, method)
)
}
override RubyMethod getMethod() { result = method }
}
from RubyCall ruby_call
select ruby_call, ruby_call.getMethod()

View File

@@ -0,0 +1,45 @@
class RubyCallOperator extends @ruby_reserved_word {
RubyCallOperator() { ruby_tokeninfo(this, _, [".", "::", "&."]) }
string toString() { none() }
}
class RubyCallMethodType = @ruby_token_operator or @ruby_underscore_variable;
abstract class RubyCall extends @ruby_ast_node {
string toString() { none() }
abstract RubyCallOperator getOperator();
}
class NormalRubyCall extends RubyCall, @ruby_call {
NormalRubyCall() { ruby_call_def(this, any(RubyCallMethodType m)) }
override RubyCallOperator getOperator() { ruby_ast_node_info(result, this, _, _) }
}
class ImplicitRubyCall extends RubyCall, @ruby_call {
ImplicitRubyCall() { ruby_call_def(this, any(@ruby_argument_list a)) }
override RubyCallOperator getOperator() { ruby_ast_node_info(result, this, _, _) }
}
class ScopeResolutionCall extends RubyCall, @ruby_scope_resolution {
ScopeResolutionCall() {
ruby_scope_resolution_def(this, any(@ruby_token_identifier m)) and
not ruby_call_def(_, this)
}
override RubyCallOperator getOperator() { ruby_ast_node_info(result, this, _, _) }
}
class ScopeResolutionMethodCall extends RubyCall, @ruby_call {
private @ruby_scope_resolution scope;
ScopeResolutionMethodCall() { ruby_call_def(this, scope) }
override RubyCallOperator getOperator() { ruby_ast_node_info(result, scope, _, _) }
}
from RubyCall ruby_call
select ruby_call, ruby_call.getOperator()

View File

@@ -0,0 +1,43 @@
class RubyCallMethodType = @ruby_token_operator or @ruby_underscore_variable;
class RubyPrimary extends @ruby_underscore_primary {
string toString() { none() }
}
abstract class RubyCall extends @ruby_ast_node {
string toString() { none() }
abstract RubyPrimary getReceiver();
}
class NormalRubyCall extends RubyCall, @ruby_call {
NormalRubyCall() { ruby_call_def(this, any(RubyCallMethodType m)) }
override RubyPrimary getReceiver() { ruby_call_receiver(this, result) }
}
class ImplicitRubyCall extends RubyCall, @ruby_call {
ImplicitRubyCall() { ruby_call_def(this, any(@ruby_argument_list a)) }
override RubyPrimary getReceiver() { ruby_call_receiver(this, result) }
}
class ScopeResolutionCall extends RubyCall, @ruby_scope_resolution {
ScopeResolutionCall() {
ruby_scope_resolution_def(this, any(@ruby_token_identifier m)) and
not ruby_call_def(_, this)
}
override RubyPrimary getReceiver() { ruby_scope_resolution_scope(this, result) }
}
class ScopeResolutionMethodCall extends RubyCall, @ruby_call {
private @ruby_scope_resolution scope;
ScopeResolutionMethodCall() { ruby_call_def(this, scope) }
override RubyPrimary getReceiver() { ruby_scope_resolution_scope(scope, result) }
}
from RubyCall ruby_call
select ruby_call, ruby_call.getReceiver()

View File

@@ -0,0 +1,16 @@
class RubyScopeResolution extends @ruby_scope_resolution {
RubyScopeResolution() {
exists(RubyConstant name | ruby_scope_resolution_def(this, name)) and
not ruby_call_def(_, this)
}
string toString() { none() }
}
class RubyConstant extends @ruby_token_constant {
string toString() { none() }
}
from RubyScopeResolution scope, RubyConstant name
where ruby_scope_resolution_def(scope, name)
select scope, name

View File

@@ -0,0 +1,20 @@
private class RubyToken extends @ruby_token {
string toString() { none() }
}
bindingset[old]
private int newKind(int old) {
// @ruby_token_complex was removed, for lack of a better solution
// it gets translated to @ruby_token_float
// 4 = @ruby_token_complex
// 10 = @ruby_token_float
old = 4 and result = 10
or
old <= 3 and result = old
or
old >= 5 and result = old - 1
}
from RubyToken id, int kind, string value
where ruby_tokeninfo(id, kind, value)
select id, newKind(kind), value

View File

@@ -0,0 +1,12 @@
description: tree-sitter-ruby update
compatibility: backwards
ruby_block_parameters_child.rel: run ruby_block_parameters_child.qlo
ruby_block_parameters_locals.rel: run ruby_block_parameters_locals.qlo
ruby_call_def.rel: run ruby_call_def.qlo
ruby_call_arguments.rel: run ruby_call_arguments.qlo
ruby_call_method.rel: run ruby_call_method.qlo
ruby_call_operator.rel: run ruby_call_operator.qlo
ruby_call_receiver.rel: run ruby_call_receiver.qlo
ruby_scope_resolution_def.rel: run ruby_scope_resolution_def.qlo
ruby_ast_node_info.rel: run ruby_ast_node_info.qlo
ruby_tokeninfo.rel: run ruby_tokeninfo.qlo