Skip to content

Commit d5a5053

Browse files
Earlopainkddnewton
authored andcommitted
Rename some keyword locations for consistency
Prism is generally good about their naming but these had some inconsistencies compared to others: * `InNode` was missing the `keyword` in the name * `MatchPredicateNode` `in` was named `operator` instead * `UnlessNode`/`UntilNode`/`WhenNode`/`WhileNode` has more than one keyword, with one generic `keyword_loc` * `UntilNode`/`WhileNode` named their `end` keyword `closing_loc` The old names are still around, but you have to require prism/deprecated
1 parent 70519ed commit d5a5053

117 files changed

Lines changed: 1194 additions & 948 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

config.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,9 +3018,9 @@ nodes:
30183018
- name: statements
30193019
type: node?
30203020
kind: StatementsNode
3021-
- name: in_loc
3021+
- name: in_keyword_loc
30223022
type: location
3023-
- name: then_loc
3023+
- name: then_keyword_loc
30243024
type: location?
30253025
comment: |
30263026
Represents the use of the `in` keyword in a case statement.
@@ -3605,7 +3605,7 @@ nodes:
36053605
- name: pattern
36063606
type: node
36073607
kind: pattern expression
3608-
- name: operator_loc
3608+
- name: keyword_loc
36093609
type: location
36103610
comment: |
36113611
Represents the use of the modifier `in` operator.
@@ -4578,7 +4578,7 @@ nodes:
45784578
^^^^^^^^^^^^^^^^^^^^^^
45794579
- name: UnlessNode
45804580
fields:
4581-
- name: keyword_loc
4581+
- name: unless_keyword_loc
45824582
type: location
45834583
comment: |
45844584
The Location of the `unless` keyword.
@@ -4642,11 +4642,11 @@ nodes:
46424642
- name: UntilNode
46434643
flags: LoopFlags
46444644
fields:
4645-
- name: keyword_loc
4645+
- name: until_keyword_loc
46464646
type: location
46474647
- name: do_keyword_loc
46484648
type: location?
4649-
- name: closing_loc
4649+
- name: end_keyword_loc
46504650
type: location?
46514651
- name: predicate
46524652
type: node
@@ -4665,7 +4665,7 @@ nodes:
46654665
^^^^^^^^^^^^^^^^^^^^
46664666
- name: WhenNode
46674667
fields:
4668-
- name: keyword_loc
4668+
- name: when_keyword_loc
46694669
type: location
46704670
- name: conditions
46714671
type: node[]
@@ -4685,11 +4685,11 @@ nodes:
46854685
- name: WhileNode
46864686
flags: LoopFlags
46874687
fields:
4688-
- name: keyword_loc
4688+
- name: while_keyword_loc
46894689
type: location
46904690
- name: do_keyword_loc
46914691
type: location?
4692-
- name: closing_loc
4692+
- name: end_keyword_loc
46934693
type: location?
46944694
- name: predicate
46954695
type: node

lib/prism/deprecated.rb

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# frozen_string_literal: true
2+
# :markup: markdown
3+
#--
4+
# rbs_inline: enabled
5+
6+
module Prism
7+
class InNode < Node
8+
#: () -> String
9+
def in # :nodoc
10+
in_keyword
11+
end
12+
13+
#: () -> Location
14+
def in_loc # :nodoc
15+
in_keyword_loc
16+
end
17+
18+
#: () -> String?
19+
def then # :nodoc
20+
then_keyword
21+
end
22+
23+
#: () -> Location?
24+
def then_loc # :nodoc
25+
then_keyword_loc
26+
end
27+
end
28+
29+
class MatchPredicateNode < Node
30+
#: () -> String
31+
def operator # :nodoc
32+
keyword
33+
end
34+
35+
#: () -> Location
36+
def operator_loc # :nodoc
37+
keyword_loc
38+
end
39+
end
40+
41+
class UnlessNode < Node
42+
#: () -> String
43+
def keyword # :nodoc
44+
unless_keyword
45+
end
46+
47+
#: () -> Location
48+
def keyword_loc # :nodoc
49+
unless_keyword_loc
50+
end
51+
end
52+
53+
class UntilNode < Node
54+
#: () -> String
55+
def keyword # :nodoc
56+
until_keyword
57+
end
58+
59+
#: () -> Location
60+
def keyword_loc # :nodoc
61+
until_keyword_loc
62+
end
63+
64+
#: () -> String?
65+
def closing # :nodoc
66+
end_keyword
67+
end
68+
69+
#: () -> Location?
70+
def closing_loc # :nodoc
71+
end_keyword_loc
72+
end
73+
end
74+
75+
class WhenNode < Node
76+
#: () -> String
77+
def keyword # :nodoc
78+
when_keyword
79+
end
80+
81+
#: () -> Location
82+
def keyword_loc # :nodoc
83+
when_keyword_loc
84+
end
85+
end
86+
87+
class WhileNode < Node
88+
#: () -> String
89+
def keyword # :nodoc
90+
while_keyword
91+
end
92+
93+
#: () -> Location
94+
def keyword_loc # :nodoc
95+
while_keyword_loc
96+
end
97+
98+
#: () -> String?
99+
def closing # :nodoc
100+
end_keyword
101+
end
102+
103+
#: () -> Location?
104+
def closing_loc # :nodoc
105+
end_keyword_loc
106+
end
107+
end
108+
end

lib/prism/translation/parser/compiler.rb

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -970,17 +970,17 @@ def visit_in_node(node)
970970
guard = builder.if_guard(token(node.pattern.if_keyword_loc), visit(node.pattern.predicate))
971971
when UnlessNode
972972
pattern = within_pattern { |compiler| node.pattern.statements.accept(compiler) }
973-
guard = builder.unless_guard(token(node.pattern.keyword_loc), visit(node.pattern.predicate))
973+
guard = builder.unless_guard(token(node.pattern.unless_keyword_loc), visit(node.pattern.predicate))
974974
else
975975
pattern = within_pattern { |compiler| node.pattern.accept(compiler) }
976976
end
977977

978978
builder.in_pattern(
979-
token(node.in_loc),
979+
token(node.in_keyword_loc),
980980
pattern,
981981
guard,
982-
if (then_loc = node.then_loc)
983-
token(then_loc)
982+
if (then_keyword_loc = node.then_keyword_loc)
983+
token(then_keyword_loc)
984984
else
985985
srange_semicolon(node.pattern.location.end_offset, node.statements&.location&.start_offset)
986986
end,
@@ -1291,7 +1291,7 @@ def visit_local_variable_target_node(node)
12911291
def visit_match_predicate_node(node)
12921292
builder.match_pattern_p(
12931293
visit(node.value),
1294-
token(node.operator_loc),
1294+
token(node.keyword_loc),
12951295
within_pattern { |compiler| node.pattern.accept(compiler) }
12961296
)
12971297
end
@@ -1802,9 +1802,9 @@ def visit_undef_node(node)
18021802
# bar unless foo
18031803
# ^^^^^^^^^^^^^^
18041804
def visit_unless_node(node)
1805-
if node.keyword_loc.start_offset == node.location.start_offset
1805+
if node.unless_keyword_loc.start_offset == node.location.start_offset
18061806
builder.condition(
1807-
token(node.keyword_loc),
1807+
token(node.unless_keyword_loc),
18081808
visit(node.predicate),
18091809
if (then_keyword_loc = node.then_keyword_loc)
18101810
token(then_keyword_loc)
@@ -1820,7 +1820,7 @@ def visit_unless_node(node)
18201820
builder.condition_mod(
18211821
visit(node.else_clause),
18221822
visit(node.statements),
1823-
token(node.keyword_loc),
1823+
token(node.unless_keyword_loc),
18241824
visit(node.predicate)
18251825
)
18261826
end
@@ -1832,24 +1832,24 @@ def visit_unless_node(node)
18321832
# bar until foo
18331833
# ^^^^^^^^^^^^^
18341834
def visit_until_node(node)
1835-
if node.location.start_offset == node.keyword_loc.start_offset
1835+
if node.location.start_offset == node.until_keyword_loc.start_offset
18361836
builder.loop(
18371837
:until,
1838-
token(node.keyword_loc),
1838+
token(node.until_keyword_loc),
18391839
visit(node.predicate),
18401840
if (do_keyword_loc = node.do_keyword_loc)
18411841
token(do_keyword_loc)
18421842
else
1843-
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset)
1843+
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.end_keyword_loc).start_offset)
18441844
end,
18451845
visit(node.statements),
1846-
token(node.closing_loc)
1846+
token(node.end_keyword_loc)
18471847
)
18481848
else
18491849
builder.loop_mod(
18501850
:until,
18511851
visit(node.statements),
1852-
token(node.keyword_loc),
1852+
token(node.until_keyword_loc),
18531853
visit(node.predicate)
18541854
)
18551855
end
@@ -1859,7 +1859,7 @@ def visit_until_node(node)
18591859
# ^^^^^^^^^^^^^
18601860
def visit_when_node(node)
18611861
builder.when(
1862-
token(node.keyword_loc),
1862+
token(node.when_keyword_loc),
18631863
visit_all(node.conditions),
18641864
if (then_keyword_loc = node.then_keyword_loc)
18651865
token(then_keyword_loc)
@@ -1876,24 +1876,24 @@ def visit_when_node(node)
18761876
# bar while foo
18771877
# ^^^^^^^^^^^^^
18781878
def visit_while_node(node)
1879-
if node.location.start_offset == node.keyword_loc.start_offset
1879+
if node.location.start_offset == node.while_keyword_loc.start_offset
18801880
builder.loop(
18811881
:while,
1882-
token(node.keyword_loc),
1882+
token(node.while_keyword_loc),
18831883
visit(node.predicate),
18841884
if (do_keyword_loc = node.do_keyword_loc)
18851885
token(do_keyword_loc)
18861886
else
1887-
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.closing_loc).start_offset)
1887+
srange_semicolon(node.predicate.location.end_offset, (node.statements&.location || node.end_keyword_loc).start_offset)
18881888
end,
18891889
visit(node.statements),
1890-
token(node.closing_loc)
1890+
token(node.end_keyword_loc)
18911891
)
18921892
else
18931893
builder.loop_mod(
18941894
:while,
18951895
visit(node.statements),
1896-
token(node.keyword_loc),
1896+
token(node.while_keyword_loc),
18971897
visit(node.predicate)
18981898
)
18991899
end

lib/prism/translation/ripper.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2472,12 +2472,12 @@ def visit_in_node(node)
24722472
# This is a special case where we're not going to call on_in directly
24732473
# because we don't have access to the subsequent. Instead, we'll return
24742474
# the component parts and let the parent node handle it.
2475-
bounds(node.in_loc)
2475+
bounds(node.in_keyword_loc)
24762476
on_kw("in")
24772477

24782478
pattern = visit_pattern_node(node.pattern)
2479-
if node.then_loc
2480-
bounds(node.then_loc)
2479+
if node.then_keyword_loc
2480+
bounds(node.then_keyword_loc)
24812481
on_kw("then")
24822482
end
24832483
statements =
@@ -2984,7 +2984,7 @@ def visit_match_last_line_node(node)
29842984
# ^^^^^^^^^^
29852985
def visit_match_predicate_node(node)
29862986
value = visit(node.value)
2987-
bounds(node.operator_loc)
2987+
bounds(node.keyword_loc)
29882988
on_kw("in")
29892989
pattern = on_in(visit_pattern_node(node.pattern), nil, nil)
29902990

@@ -3887,7 +3887,7 @@ def visit_undef_node(node)
38873887
# ^^^^^^^^^^^^^^
38883888
def visit_unless_node(node)
38893889
if node.statements.nil? || (node.predicate.location.start_offset < node.statements.location.start_offset)
3890-
bounds(node.keyword_loc)
3890+
bounds(node.unless_keyword_loc)
38913891
on_kw("unless")
38923892
predicate = visit(node.predicate)
38933893
if node.then_keyword_loc
@@ -3912,7 +3912,7 @@ def visit_unless_node(node)
39123912
on_unless(predicate, statements, else_clause)
39133913
else
39143914
statements = visit(node.statements.body.first)
3915-
bounds(node.keyword_loc)
3915+
bounds(node.unless_keyword_loc)
39163916
on_kw("unless")
39173917
predicate = visit(node.predicate)
39183918

@@ -3927,7 +3927,7 @@ def visit_unless_node(node)
39273927
# bar until foo
39283928
# ^^^^^^^^^^^^^
39293929
def visit_until_node(node)
3930-
bounds(node.keyword_loc)
3930+
bounds(node.until_keyword_loc)
39313931
on_kw("until")
39323932

39333933
if node.statements.nil? || (node.predicate.location.start_offset < node.statements.location.start_offset)
@@ -3944,8 +3944,8 @@ def visit_until_node(node)
39443944
visit(node.statements)
39453945
end
39463946

3947-
if node.closing_loc
3948-
bounds(node.closing_loc)
3947+
if node.end_keyword_loc
3948+
bounds(node.end_keyword_loc)
39493949
on_kw("end")
39503950
end
39513951

@@ -3966,7 +3966,7 @@ def visit_when_node(node)
39663966
# This is a special case where we're not going to call on_when directly
39673967
# because we don't have access to the subsequent. Instead, we'll return
39683968
# the component parts and let the parent node handle it.
3969-
bounds(node.keyword_loc)
3969+
bounds(node.when_keyword_loc)
39703970
on_kw("when")
39713971

39723972
conditions = visit_arguments(node.conditions)
@@ -3992,15 +3992,15 @@ def visit_when_node(node)
39923992
# ^^^^^^^^^^^^^
39933993
def visit_while_node(node)
39943994
if node.statements.nil? || (node.predicate.location.start_offset < node.statements.location.start_offset)
3995-
bounds(node.keyword_loc)
3995+
bounds(node.while_keyword_loc)
39963996
on_kw("while")
39973997
if node.do_keyword_loc
39983998
bounds(node.do_keyword_loc)
39993999
on_kw("do")
40004000
end
40014001
predicate = visit(node.predicate)
4002-
if node.closing_loc
4003-
bounds(node.closing_loc)
4002+
if node.end_keyword_loc
4003+
bounds(node.end_keyword_loc)
40044004
on_kw("end")
40054005
end
40064006
statements =
@@ -4015,7 +4015,7 @@ def visit_while_node(node)
40154015
on_while(predicate, statements)
40164016
else
40174017
statements = visit(node.statements.body.first)
4018-
bounds(node.keyword_loc)
4018+
bounds(node.while_keyword_loc)
40194019
on_kw("while")
40204020
predicate = visit(node.predicate)
40214021

0 commit comments

Comments
 (0)