@@ -108,17 +108,51 @@ def parse
108
108
109
109
# Visit a CallNode node.
110
110
def visit_call_node ( node )
111
- if !node . message . match? ( /^[[:alpha:]_]/ ) && node . opening_loc . nil? && node . arguments &.arguments &.length == 1
111
+ bounds ( node . location )
112
+
113
+ if node . message . match? ( /^[[:alpha:]_]/ )
114
+ val = on_ident ( node . message )
115
+
116
+ return on_vcall ( val )
117
+ end
118
+
119
+ if node . opening_loc . nil?
112
120
left = visit ( node . receiver )
113
- right = visit ( node . arguments . arguments . first )
121
+ if node . arguments &.arguments &.length == 1
122
+ right = visit ( node . arguments . arguments . first )
123
+
124
+ on_binary ( left , node . name , right )
125
+ elsif !node . arguments || node . arguments . empty?
126
+ on_unary ( node . name , left )
127
+ else
128
+ raise NotImplementedError , "More than two arguments for operator"
129
+ end
130
+ else
131
+ # This is a method call, not an operator
132
+ raise NotImplementedError , "Non-nil opening_loc"
133
+ end
134
+ end
114
135
115
- bounds ( node . location )
116
- on_binary ( left , node . name , right )
136
+ # Visit a RangeNode
137
+ def visit_range_node ( node )
138
+ bounds ( node . location )
139
+ left = visit ( node . left )
140
+ right = visit ( node . right )
141
+
142
+ if node . operator_loc . slice == "..."
143
+ on_dot3 ( left , right )
117
144
else
118
- raise NotImplementedError
145
+ on_dot2 ( left , right )
119
146
end
120
147
end
121
148
149
+ # Visit a ParenthesesNode
150
+ def visit_parentheses_node ( node )
151
+ bounds ( node . location )
152
+ val = visit ( node . body )
153
+ on_paren ( val )
154
+ end
155
+
122
156
# Visit a FloatNode node.
123
157
def visit_float_node ( node )
124
158
bounds ( node . location )
@@ -133,8 +167,22 @@ def visit_imaginary_node(node)
133
167
134
168
# Visit an IntegerNode node.
135
169
def visit_integer_node ( node )
136
- bounds ( node . location )
137
- on_int ( node . slice )
170
+ text = node . slice
171
+ loc = node . location
172
+ if text [ 0 ] == "-"
173
+ # TODO: This is ugly. We test that a newline between - and 7 doesn't give an error, but this could still be bad somehow.
174
+ bounds_line_col ( loc . start_line , loc . start_column + 1 )
175
+ on_int_val = on_int ( text [ 1 ..-1 ] )
176
+ bounds ( node . location )
177
+ if RUBY_ENGINE == "jruby"
178
+ on_unary ( :- , on_int_val )
179
+ else
180
+ on_unary ( :-@ , on_int_val )
181
+ end
182
+ else
183
+ bounds ( node . location )
184
+ on_int ( text )
185
+ end
138
186
end
139
187
140
188
# Visit a RationalNode node.
@@ -184,6 +232,13 @@ def bounds(location)
184
232
@column = location . start_column
185
233
end
186
234
235
+ # If we need to do something unusual, we can directly update the line number
236
+ # and column to reflect the current node.
237
+ def bounds_line_col ( lineno , column )
238
+ @lineno = lineno
239
+ @column = column
240
+ end
241
+
187
242
# Lazily initialize the parse result.
188
243
def result
189
244
@result ||= Prism . parse ( source )
0 commit comments