Implement CASE3 NODE keyword locations
This commit is contained in:
parent
5334766beb
commit
b811a9a097
Notes:
git
2024-09-23 00:19:54 +00:00
5
ast.c
5
ast.c
@ -797,6 +797,11 @@ node_locations(VALUE ast_value, const NODE *node)
|
||||
location_new(nd_code_loc(node)),
|
||||
location_new(&RNODE_CASE2(node)->case_keyword_loc),
|
||||
location_new(&RNODE_CASE2(node)->end_keyword_loc));
|
||||
case NODE_CASE3:
|
||||
return rb_ary_new_from_args(3,
|
||||
location_new(nd_code_loc(node)),
|
||||
location_new(&RNODE_CASE3(node)->case_keyword_loc),
|
||||
location_new(&RNODE_CASE3(node)->end_keyword_loc));
|
||||
case NODE_NEXT:
|
||||
return rb_ary_new_from_args(2,
|
||||
location_new(nd_code_loc(node)),
|
||||
|
@ -281,8 +281,10 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node)
|
||||
ANN("format: case [nd_head]; [nd_body]; end");
|
||||
ANN("example: case x; in 1; foo; in 2; bar; else baz; end");
|
||||
F_NODE(nd_head, RNODE_CASE3, "case expr");
|
||||
LAST_NODE;
|
||||
F_NODE(nd_body, RNODE_CASE3, "in clauses");
|
||||
F_LOC(case_keyword_loc, RNODE_CASE3);
|
||||
LAST_NODE;
|
||||
F_LOC(end_keyword_loc, RNODE_CASE3);
|
||||
return;
|
||||
|
||||
case NODE_WHEN:
|
||||
|
14
parse.y
14
parse.y
@ -1065,7 +1065,7 @@ static rb_node_if_t *rb_node_if_new(struct parser_params *p, NODE *nd_cond, NODE
|
||||
static rb_node_unless_t *rb_node_unless_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, NODE *nd_else, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *then_keyword_loc, const YYLTYPE *end_keyword_loc);
|
||||
static rb_node_case_t *rb_node_case_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc);
|
||||
static rb_node_case2_t *rb_node_case2_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc);
|
||||
static rb_node_case3_t *rb_node_case3_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc);
|
||||
static rb_node_case3_t *rb_node_case3_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc);
|
||||
static rb_node_when_t *rb_node_when_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *then_keyword_loc);
|
||||
static rb_node_in_t *rb_node_in_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, NODE *nd_next, const YYLTYPE *loc);
|
||||
static rb_node_while_t *rb_node_while_new(struct parser_params *p, NODE *nd_cond, NODE *nd_body, long nd_state, const YYLTYPE *loc, const YYLTYPE *keyword_loc, const YYLTYPE *closing_loc);
|
||||
@ -1173,7 +1173,7 @@ static rb_node_error_t *rb_node_error_new(struct parser_params *p, const YYLTYPE
|
||||
#define NEW_UNLESS(c,t,e,loc,k_loc,t_loc,e_loc) (NODE *)rb_node_unless_new(p,c,t,e,loc,k_loc,t_loc,e_loc)
|
||||
#define NEW_CASE(h,b,loc,ck_loc,ek_loc) (NODE *)rb_node_case_new(p,h,b,loc,ck_loc,ek_loc)
|
||||
#define NEW_CASE2(b,loc,ck_loc,ek_loc) (NODE *)rb_node_case2_new(p,b,loc,ck_loc,ek_loc)
|
||||
#define NEW_CASE3(h,b,loc) (NODE *)rb_node_case3_new(p,h,b,loc)
|
||||
#define NEW_CASE3(h,b,loc,ck_loc,ek_loc) (NODE *)rb_node_case3_new(p,h,b,loc,ck_loc,ek_loc)
|
||||
#define NEW_WHEN(c,t,e,loc,k_loc,t_loc) (NODE *)rb_node_when_new(p,c,t,e,loc,k_loc,t_loc)
|
||||
#define NEW_IN(c,t,e,loc) (NODE *)rb_node_in_new(p,c,t,e,loc)
|
||||
#define NEW_WHILE(c,b,n,loc,k_loc,c_loc) (NODE *)rb_node_while_new(p,c,b,n,loc,k_loc,c_loc)
|
||||
@ -3375,7 +3375,7 @@ expr : command_call
|
||||
pop_pktbl(p, $p_pktbl);
|
||||
pop_pvtbl(p, $p_pvtbl);
|
||||
p->ctxt.in_kwarg = $ctxt.in_kwarg;
|
||||
$$ = NEW_CASE3($arg, NEW_IN($body, 0, 0, &@body), &@$);
|
||||
$$ = NEW_CASE3($arg, NEW_IN($body, 0, 0, &@body), &@$, &NULL_LOC, &NULL_LOC);
|
||||
/*% ripper: case!($:arg, in!($:body, Qnil, Qnil)) %*/
|
||||
}
|
||||
| arg keyword_in
|
||||
@ -3388,7 +3388,7 @@ expr : command_call
|
||||
pop_pktbl(p, $p_pktbl);
|
||||
pop_pvtbl(p, $p_pvtbl);
|
||||
p->ctxt.in_kwarg = $ctxt.in_kwarg;
|
||||
$$ = NEW_CASE3($arg, NEW_IN($body, NEW_TRUE(&@body), NEW_FALSE(&@body), &@body), &@$);
|
||||
$$ = NEW_CASE3($arg, NEW_IN($body, NEW_TRUE(&@body), NEW_FALSE(&@body), &@body), &@$, &NULL_LOC, &NULL_LOC);
|
||||
/*% ripper: case!($:arg, in!($:body, Qnil, Qnil)) %*/
|
||||
}
|
||||
| arg %prec tLBRACE_ARG
|
||||
@ -4571,7 +4571,7 @@ primary : literal
|
||||
p_case_body
|
||||
k_end
|
||||
{
|
||||
$$ = NEW_CASE3($2, $4, &@$);
|
||||
$$ = NEW_CASE3($2, $4, &@$, &@1, &@5);
|
||||
/*% ripper: case!($:2, $:4) %*/
|
||||
}
|
||||
| k_for for_var keyword_in expr_value_do
|
||||
@ -11637,11 +11637,13 @@ rb_node_case2_new(struct parser_params *p, NODE *nd_body, const YYLTYPE *loc, co
|
||||
}
|
||||
|
||||
static rb_node_case3_t *
|
||||
rb_node_case3_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc)
|
||||
rb_node_case3_new(struct parser_params *p, NODE *nd_head, NODE *nd_body, const YYLTYPE *loc, const YYLTYPE *case_keyword_loc, const YYLTYPE *end_keyword_loc)
|
||||
{
|
||||
rb_node_case3_t *n = NODE_NEWNODE(NODE_CASE3, rb_node_case3_t, loc);
|
||||
n->nd_head = nd_head;
|
||||
n->nd_body = nd_body;
|
||||
n->case_keyword_loc = *case_keyword_loc;
|
||||
n->end_keyword_loc = *end_keyword_loc;
|
||||
|
||||
return n;
|
||||
}
|
||||
|
@ -301,6 +301,8 @@ typedef struct RNode_CASE3 {
|
||||
|
||||
struct RNode *nd_head;
|
||||
struct RNode *nd_body;
|
||||
rb_code_location_t case_keyword_loc;
|
||||
rb_code_location_t end_keyword_loc;
|
||||
} rb_node_case3_t;
|
||||
|
||||
typedef struct RNode_WHEN {
|
||||
|
@ -1363,6 +1363,11 @@ dummy
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 17], [1, 0, 1, 4], [1, 14, 1, 17]])
|
||||
end
|
||||
|
||||
def test_case3_locations
|
||||
node = ast_parse("case a; in 1; end")
|
||||
assert_locations(node.children[-1].locations, [[1, 0, 1, 17], [1, 0, 1, 4], [1, 14, 1, 17]])
|
||||
end
|
||||
|
||||
def test_next_locations
|
||||
node = ast_parse("loop { next 1 }")
|
||||
assert_locations(node.children[-1].children[-1].children[-1].locations, [[1, 7, 1, 13], [1, 7, 1, 11]])
|
||||
|
Loading…
x
Reference in New Issue
Block a user