mirror of
https://github.com/ruby/ruby.git
synced 2026-01-26 20:19:19 +00:00
Implement UNDEF NODE keyword locations
This commit is contained in:
parent
b7fa2dd0d0
commit
af143d8a74
Notes:
git
2024-09-03 12:15:34 +00:00
4
ast.c
4
ast.c
@ -775,6 +775,10 @@ node_locations(VALUE ast_value, const NODE *node)
|
||||
{
|
||||
enum node_type type = nd_type(node);
|
||||
switch (type) {
|
||||
case NODE_UNDEF:
|
||||
return rb_ary_new_from_args(2,
|
||||
location_new(nd_code_loc(node)),
|
||||
location_new(&RNODE_UNDEF(node)->keyword_loc));
|
||||
case NODE_UNLESS:
|
||||
return rb_ary_new_from_args(4,
|
||||
location_new(nd_code_loc(node)),
|
||||
|
||||
@ -940,6 +940,7 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
|
||||
ANN("example: undef foo");
|
||||
LAST_NODE;
|
||||
F_ARRAY(nd_undefs, RNODE_UNDEF, "nd_undefs");
|
||||
F_LOC(keyword_loc, RNODE_UNDEF);
|
||||
return;
|
||||
|
||||
case NODE_CLASS:
|
||||
|
||||
2
parse.y
2
parse.y
@ -3156,6 +3156,7 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
|
||||
| keyword_undef undef_list
|
||||
{
|
||||
nd_set_first_loc($2, @1.beg_pos);
|
||||
RNODE_UNDEF($2)->keyword_loc = @1;
|
||||
$$ = $2;
|
||||
/*% ripper: undef!($:2) %*/
|
||||
}
|
||||
@ -12320,6 +12321,7 @@ rb_node_undef_new(struct parser_params *p, NODE *nd_undef, const YYLTYPE *loc)
|
||||
{
|
||||
rb_node_undef_t *n = NODE_NEWNODE(NODE_UNDEF, rb_node_undef_t, loc);
|
||||
n->nd_undefs = rb_parser_ary_new_capa_for_node(p, 1);
|
||||
n->keyword_loc = NULL_LOC;
|
||||
rb_parser_ary_push_node(p, n->nd_undefs, nd_undef);
|
||||
|
||||
return n;
|
||||
|
||||
@ -833,6 +833,7 @@ typedef struct RNode_UNDEF {
|
||||
NODE node;
|
||||
|
||||
rb_parser_ary_t *nd_undefs;
|
||||
rb_code_location_t keyword_loc;
|
||||
} rb_node_undef_t;
|
||||
|
||||
typedef struct RNode_CLASS {
|
||||
|
||||
@ -1338,6 +1338,14 @@ dummy
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 10], [1, 2, 1, 8], nil, nil])
|
||||
end
|
||||
|
||||
def test_undef_locations
|
||||
node = RubyVM::AbstractSyntaxTree.parse("undef foo")
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 9], [1, 0, 1, 5]])
|
||||
|
||||
node = RubyVM::AbstractSyntaxTree.parse("undef foo, bar")
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 14], [1, 0, 1, 5]])
|
||||
end
|
||||
|
||||
private
|
||||
def assert_locations(locations, expected)
|
||||
ary = locations.map {|loc| loc && [loc.first_lineno, loc.first_column, loc.last_lineno, loc.last_column] }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user