@@ -8,7 +8,7 @@ module Prism
8
8
# of cases, this is a one-to-one mapping of the token type. Everything else
9
9
# generally lines up. However, there are a few cases that require special
10
10
# handling.
11
- class LexCompat
11
+ class LexCompat # :nodoc:
12
12
# This is a mapping of prism token types to Ripper token types. This is a
13
13
# many-to-one mapping because we split up our token types, whereas Ripper
14
14
# tends to group them.
@@ -184,18 +184,22 @@ class LexCompat
184
184
# However, we add a couple of convenience methods onto them to make them a
185
185
# little easier to work with. We delegate all other methods to the array.
186
186
class Token < SimpleDelegator
187
+ # The location of the token in the source.
187
188
def location
188
189
self [ 0 ]
189
190
end
190
191
192
+ # The type of the token.
191
193
def event
192
194
self [ 1 ]
193
195
end
194
196
197
+ # The slice of the source that this token represents.
195
198
def value
196
199
self [ 2 ]
197
200
end
198
201
202
+ # The state of the lexer when this token was produced.
199
203
def state
200
204
self [ 3 ]
201
205
end
@@ -204,15 +208,15 @@ def state
204
208
# Ripper doesn't include the rest of the token in the event, so we need to
205
209
# trim it down to just the content on the first line when comparing.
206
210
class EndContentToken < Token
207
- def ==( other )
211
+ def ==( other ) # :nodoc:
208
212
[ self [ 0 ] , self [ 1 ] , self [ 2 ] [ 0 ..self [ 2 ] . index ( "\n " ) ] , self [ 3 ] ] == other
209
213
end
210
214
end
211
215
212
216
# Tokens where state should be ignored
213
217
# used for :on_comment, :on_heredoc_end, :on_embexpr_end
214
218
class IgnoreStateToken < Token
215
- def ==( other )
219
+ def ==( other ) # :nodoc:
216
220
self [ 0 ...-1 ] == other [ 0 ...-1 ]
217
221
end
218
222
end
@@ -222,7 +226,7 @@ def ==(other)
222
226
# through named captures in regular expressions). In that case we don't
223
227
# compare the state.
224
228
class IdentToken < Token
225
- def ==( other )
229
+ def ==( other ) # :nodoc:
226
230
( self [ 0 ...-1 ] == other [ 0 ...-1 ] ) && (
227
231
( other [ 3 ] == Ripper ::EXPR_LABEL | Ripper ::EXPR_END ) ||
228
232
( other [ 3 ] & Ripper ::EXPR_ARG_ANY != 0 )
@@ -233,7 +237,7 @@ def ==(other)
233
237
# Ignored newlines can occasionally have a LABEL state attached to them, so
234
238
# we compare the state differently here.
235
239
class IgnoredNewlineToken < Token
236
- def ==( other )
240
+ def ==( other ) # :nodoc:
237
241
return false unless self [ 0 ...-1 ] == other [ 0 ...-1 ]
238
242
239
243
if self [ 4 ] == Ripper ::EXPR_ARG | Ripper ::EXPR_LABELED
@@ -253,7 +257,7 @@ def ==(other)
253
257
# more accurately, so we need to allow comparing against both END and
254
258
# END|LABEL.
255
259
class ParamToken < Token
256
- def ==( other )
260
+ def ==( other ) # :nodoc:
257
261
( self [ 0 ...-1 ] == other [ 0 ...-1 ] ) && (
258
262
( other [ 3 ] == Ripper ::EXPR_END ) ||
259
263
( other [ 3 ] == Ripper ::EXPR_END | Ripper ::EXPR_LABEL )
@@ -264,12 +268,12 @@ def ==(other)
264
268
# A heredoc in this case is a list of tokens that belong to the body of the
265
269
# heredoc that should be appended onto the list of tokens when the heredoc
266
270
# closes.
267
- module Heredoc
271
+ module Heredoc # :nodoc:
268
272
# Heredocs that are no dash or tilde heredocs are just a list of tokens.
269
273
# We need to keep them around so that we can insert them in the correct
270
274
# order back into the token stream and set the state of the last token to
271
275
# the state that the heredoc was opened in.
272
- class PlainHeredoc
276
+ class PlainHeredoc # :nodoc:
273
277
attr_reader :tokens
274
278
275
279
def initialize
@@ -288,7 +292,7 @@ def to_a
288
292
# Dash heredocs are a little more complicated. They are a list of tokens
289
293
# that need to be split on "\\\n" to mimic Ripper's behavior. We also need
290
294
# to keep track of the state that the heredoc was opened in.
291
- class DashHeredoc
295
+ class DashHeredoc # :nodoc:
292
296
attr_reader :split , :tokens
293
297
294
298
def initialize ( split )
@@ -347,7 +351,7 @@ def to_a
347
351
# insert them into the stream in the correct order. As such, we can do
348
352
# some extra manipulation on the tokens to make them match Ripper's
349
353
# output by mirroring the dedent logic that Ripper uses.
350
- class DedentingHeredoc
354
+ class DedentingHeredoc # :nodoc:
351
355
TAB_WIDTH = 8
352
356
353
357
attr_reader :tokens , :dedent_next , :dedent , :embexpr_balance
@@ -588,6 +592,8 @@ def self.build(opening)
588
592
end
589
593
end
590
594
595
+ private_constant :Heredoc
596
+
591
597
attr_reader :source , :filepath
592
598
593
599
def initialize ( source , filepath = "" )
@@ -829,9 +835,11 @@ def result
829
835
end
830
836
end
831
837
838
+ private_constant :LexCompat
839
+
832
840
# This is a class that wraps the Ripper lexer to produce almost exactly the
833
841
# same tokens.
834
- class LexRipper
842
+ class LexRipper # :nodoc:
835
843
attr_reader :source
836
844
837
845
def initialize ( source )
@@ -869,4 +877,6 @@ def result
869
877
results
870
878
end
871
879
end
880
+
881
+ private_constant :LexRipper
872
882
end
0 commit comments