lib-ruby-parser 4.0.3.0-x64-mingw32 → 4.0.3.1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +122 -122
- data/lib/lib-ruby-parser/messages.rb +468 -468
- data/lib/lib-ruby-parser/native/x86_64-pc-windows-gnu/3.0/lib_ruby_parser.so +0 -0
- data/lib/lib-ruby-parser/native/x86_64-pc-windows-gnu/3.1/lib_ruby_parser.so +0 -0
- data/lib/lib-ruby-parser/native/x86_64-pc-windows-gnu/3.2/lib_ruby_parser.so +0 -0
- data/lib/lib-ruby-parser/nodes.rb +2456 -2456
- data/lib/lib-ruby-parser/version.rb +4 -4
- data/lib/lib-ruby-parser.rb +323 -314
- data/lib-ruby-parser.gemspec +36 -36
- metadata +9 -9
- data/lib/lib-ruby-parser/native/2.7/lib_ruby_parser.so +0 -0
- data/lib/lib-ruby-parser/native/3.0/lib_ruby_parser.so +0 -0
- data/lib/lib-ruby-parser/native/3.1/lib_ruby_parser.so +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
module LibRubyParser
|
2
|
-
# Version of the lib-ruby-parser
|
3
|
-
VERSION = '4.0.3.
|
4
|
-
end
|
1
|
+
module LibRubyParser
|
2
|
+
# Version of the lib-ruby-parser
|
3
|
+
VERSION = '4.0.3.1'
|
4
|
+
end
|
data/lib/lib-ruby-parser.rb
CHANGED
@@ -1,314 +1,323 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LibRubyParser
|
4
|
-
# Representation of any location in the given input
|
5
|
-
class Loc
|
6
|
-
# Begin of the `Loc` range
|
7
|
-
#
|
8
|
-
# @return [Integer]
|
9
|
-
attr_accessor :begin
|
10
|
-
|
11
|
-
# End of the `Loc` range
|
12
|
-
#
|
13
|
-
# @return [Integer]
|
14
|
-
attr_accessor :end
|
15
|
-
|
16
|
-
# @param [Hash] options
|
17
|
-
# @option options [Integer] :begin
|
18
|
-
# @option options [Integer] :end
|
19
|
-
def initialize(**options)
|
20
|
-
@begin = options[:begin] || 0
|
21
|
-
@end = options[:end] || 0
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# A token that is emitted by a lexer and consumed by a parser
|
26
|
-
class Token
|
27
|
-
# Numeric representation of the token type, e.g. +132+ (for example) for +tINTEGER+
|
28
|
-
#
|
29
|
-
# @return [Integer]
|
30
|
-
attr_accessor :token_type
|
31
|
-
|
32
|
-
# String type of the token
|
33
|
-
#
|
34
|
-
# @return [String]
|
35
|
-
attr_accessor :token_name
|
36
|
-
|
37
|
-
# Value of the token, e.g +“42”+ for +42+
|
38
|
-
#
|
39
|
-
# @return [String]
|
40
|
-
attr_accessor :token_value
|
41
|
-
|
42
|
-
# Lex state before token was read
|
43
|
-
#
|
44
|
-
# @return [Integer]
|
45
|
-
attr_accessor :lex_state_before
|
46
|
-
|
47
|
-
# Lex state after token was read
|
48
|
-
#
|
49
|
-
# @return [Integer]
|
50
|
-
attr_accessor :lex_state_after
|
51
|
-
|
52
|
-
# Location of the token
|
53
|
-
#
|
54
|
-
# @return [Loc]
|
55
|
-
attr_accessor :loc
|
56
|
-
|
57
|
-
# @param token_type [Integer]
|
58
|
-
# @param token_name [String]
|
59
|
-
# @param token_value [String]
|
60
|
-
# @param loc [Loc]
|
61
|
-
def initialize(token_type:, token_name:, token_value:, loc:)
|
62
|
-
@token_type = token_type
|
63
|
-
@token_name = token_name
|
64
|
-
@token_value = token_value
|
65
|
-
@lex_state_before = 0
|
66
|
-
@lex_state_after = 0
|
67
|
-
@loc = loc
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
# Diagnostic message that comes from the parser when there’s an error or warning
|
72
|
-
class Diagnostic
|
73
|
-
# Level of the diagnostic (+:error+ or +:warning+)
|
74
|
-
#
|
75
|
-
# @return [Symbol] +:error+ or +:warning+
|
76
|
-
attr_accessor :level
|
77
|
-
|
78
|
-
# Message of the diagnostic
|
79
|
-
#
|
80
|
-
# @return [DiagnosticMessage]
|
81
|
-
attr_accessor :message
|
82
|
-
|
83
|
-
# Location of the diagnostic
|
84
|
-
#
|
85
|
-
# @return [Loc]
|
86
|
-
attr_accessor :loc
|
87
|
-
|
88
|
-
# @param level [Symbol]
|
89
|
-
# @param message [DiagnosticMessage]
|
90
|
-
# @param loc [Loc]
|
91
|
-
def initialize(level:, message:, loc:)
|
92
|
-
@level = level
|
93
|
-
@message = message
|
94
|
-
@loc = loc
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
# A class that represents a comment in Ruby
|
99
|
-
class Comment
|
100
|
-
# Location of the comment (starts with # and ends with the last char)
|
101
|
-
#
|
102
|
-
# @return [Loc]
|
103
|
-
attr_accessor :location
|
104
|
-
|
105
|
-
# Kind of the comment (+:inline+ or +:document+ or +:unknown+)
|
106
|
-
#
|
107
|
-
# @return [Symbol] +:inline+ or +:document+ or +:unknown+
|
108
|
-
attr_accessor :kind
|
109
|
-
|
110
|
-
# @param location [Loc]
|
111
|
-
# @param kind [Symbol]
|
112
|
-
def initialize(location:, kind:)
|
113
|
-
@location = location
|
114
|
-
@kind = kind
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
# Representation of a magic comment in Ruby
|
119
|
-
class MagicComment
|
120
|
-
# Kind of a magic comment, can be
|
121
|
-
#
|
122
|
-
# 1. +encoding+
|
123
|
-
# 2. +frozen_string_literal+
|
124
|
-
# 3. +warn_indent+
|
125
|
-
# 4. +shareable_constant_value+
|
126
|
-
#
|
127
|
-
# @return [Symbol]
|
128
|
-
attr_accessor :kind
|
129
|
-
|
130
|
-
# Location of the “key”
|
131
|
-
#
|
132
|
-
# @example
|
133
|
-
# # encoding: utf-8
|
134
|
-
# ~~~~~~~~
|
135
|
-
#
|
136
|
-
# @return [Loc]
|
137
|
-
attr_accessor :key_l
|
138
|
-
|
139
|
-
# Location of the “value”
|
140
|
-
#
|
141
|
-
# @example
|
142
|
-
# # encoding: utf-8
|
143
|
-
# ~~~~~
|
144
|
-
#
|
145
|
-
# @return [Loc]
|
146
|
-
attr_accessor :value_l
|
147
|
-
|
148
|
-
# @param kind [Symbol]
|
149
|
-
# @param key_l [Loc]
|
150
|
-
# @param value_l [Loc]
|
151
|
-
def initialize(kind:, key_l:, value_l:)
|
152
|
-
@kind = kind
|
153
|
-
@key_l = key_l
|
154
|
-
@value_l = value_l
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
# Base class for all AST nodes
|
159
|
-
class Node
|
160
|
-
end
|
161
|
-
|
162
|
-
# Base class for all diagnostic messages
|
163
|
-
class DiagnosticMessage
|
164
|
-
end
|
165
|
-
|
166
|
-
# Input decoded by parser.
|
167
|
-
#
|
168
|
-
# If your code has magic encoding comment LibRubyParser
|
169
|
-
# re-encodes given input and (potentially) operates
|
170
|
-
# on a different byte sequence.
|
171
|
-
#
|
172
|
-
# This is why this input should be used to get source
|
173
|
-
# of all locations.
|
174
|
-
#
|
175
|
-
# Using initial input is wrong as you may get a different
|
176
|
-
# source range in a different byte representation.
|
177
|
-
class DecodedInput
|
178
|
-
# Name of the initial input
|
179
|
-
#
|
180
|
-
# @return [String]
|
181
|
-
attr_accessor :name
|
182
|
-
|
183
|
-
# Array of source lines
|
184
|
-
#
|
185
|
-
# @return [Array<SourceLine>]
|
186
|
-
attr_accessor :lines
|
187
|
-
|
188
|
-
# Re-encoded input string
|
189
|
-
#
|
190
|
-
# @return [String]
|
191
|
-
attr_accessor :bytes
|
192
|
-
end
|
193
|
-
|
194
|
-
# Representation of a source line in a source file
|
195
|
-
class SourceLine
|
196
|
-
# Start of the line (in bytes)
|
197
|
-
#
|
198
|
-
# @return [Integer]
|
199
|
-
attr_accessor :start
|
200
|
-
|
201
|
-
# End of the line (in bytes)
|
202
|
-
#
|
203
|
-
# @return [Integer]
|
204
|
-
attr_accessor :end
|
205
|
-
|
206
|
-
# +true+ if line ends with EOF char (which is true for the last line in the file)
|
207
|
-
#
|
208
|
-
# @return [true, false]
|
209
|
-
attr_accessor :ends_with_eof
|
210
|
-
|
211
|
-
# @param options [Hash]
|
212
|
-
# @option options [Integer] :start
|
213
|
-
# @option options [Integer] :end
|
214
|
-
# @option options [true, false] :ends_with_eof
|
215
|
-
def initialize(**options)
|
216
|
-
@start = options[:start]
|
217
|
-
@end = options[:end]
|
218
|
-
@ends_with_eof = options[:ends_with_eof]
|
219
|
-
end
|
220
|
-
|
221
|
-
# Default +==+ comparison
|
222
|
-
def ==(other)
|
223
|
-
start == other.start &&
|
224
|
-
self.end == other.end &&
|
225
|
-
ends_with_eof == other.ends_with_eof
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
# Combination of all data that +LibRubyParser+ can give you
|
230
|
-
class ParserResult
|
231
|
-
# Abstract Syntax Tree that was constructed from you code.
|
232
|
-
# +nil+ if the code gives no AST nodes
|
233
|
-
#
|
234
|
-
# @return [Node, nil]
|
235
|
-
attr_accessor :ast
|
236
|
-
|
237
|
-
# List of tokens returned by a Lexer and consumed by a Parser.
|
238
|
-
# Empty unless +:record_tokens+ is set to true.
|
239
|
-
#
|
240
|
-
# @return [Array<Token>]
|
241
|
-
attr_accessor :tokens
|
242
|
-
|
243
|
-
# List of all diagnostics (errors and warings) that
|
244
|
-
# have been recorded during lexing and parsing
|
245
|
-
#
|
246
|
-
# @return [Array<Diagnostic>]
|
247
|
-
attr_accessor :diagnostics
|
248
|
-
|
249
|
-
# List of comments extracted from the source code.
|
250
|
-
#
|
251
|
-
# @return [Array<Comment>]
|
252
|
-
attr_accessor :comments
|
253
|
-
|
254
|
-
# List of magic comments extracted from the source code.
|
255
|
-
#
|
256
|
-
# @return [Array<MagicComment>]
|
257
|
-
attr_accessor :magic_comments
|
258
|
-
|
259
|
-
# Input that was used for parsing.
|
260
|
-
#
|
261
|
-
# Note: this input is not necessary the same byte array that you passed to Parser::parse.
|
262
|
-
# If encoding of the input is not +UTF-8+ or +ASCII-8BIT/BINARY+ Parser invokes decoder
|
263
|
-
# that usually produces a different sequence of bytes.
|
264
|
-
#
|
265
|
-
# Pass this data to +Loc#source+, otherwise you’ll get incorrect source ranges.
|
266
|
-
#
|
267
|
-
# @return [DecodedInput]
|
268
|
-
attr_accessor :input
|
269
|
-
end
|
270
|
-
|
271
|
-
# Default decoder that is used to re-encode input
|
272
|
-
# from non-utf-8 encoding to utf-8
|
273
|
-
DEFAULT_DECODER = proc do |encoding, input|
|
274
|
-
encoding = Encoding.find(encoding)
|
275
|
-
input.force_encoding(encoding).encode('utf-8')
|
276
|
-
end
|
277
|
-
|
278
|
-
# Parses given input according to given options
|
279
|
-
#
|
280
|
-
# @param [String] input
|
281
|
-
# @param [Hash] options
|
282
|
-
# @option options [String] :buffer_name name of the input file
|
283
|
-
# @option options [#call] :decoder (DEFAULT_DECODER) decoder, called with +encoding+ (String) and +input+ (String)
|
284
|
-
# @option options [true, false] :record_tokens When set to true Parser records tokens. When set to false ParserResult::tokens is guaranteed to be empty. If you don’t need tokens better set it to false to speed up parsing.
|
285
|
-
#
|
286
|
-
# @return [ParserResult]
|
287
|
-
def self.parse(input, options)
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
require_relative './lib-ruby-parser/nodes'
|
292
|
-
require_relative './lib-ruby-parser/messages'
|
293
|
-
|
294
|
-
require 'rbconfig'
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LibRubyParser
|
4
|
+
# Representation of any location in the given input
|
5
|
+
class Loc
|
6
|
+
# Begin of the `Loc` range
|
7
|
+
#
|
8
|
+
# @return [Integer]
|
9
|
+
attr_accessor :begin
|
10
|
+
|
11
|
+
# End of the `Loc` range
|
12
|
+
#
|
13
|
+
# @return [Integer]
|
14
|
+
attr_accessor :end
|
15
|
+
|
16
|
+
# @param [Hash] options
|
17
|
+
# @option options [Integer] :begin
|
18
|
+
# @option options [Integer] :end
|
19
|
+
def initialize(**options)
|
20
|
+
@begin = options[:begin] || 0
|
21
|
+
@end = options[:end] || 0
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# A token that is emitted by a lexer and consumed by a parser
|
26
|
+
class Token
|
27
|
+
# Numeric representation of the token type, e.g. +132+ (for example) for +tINTEGER+
|
28
|
+
#
|
29
|
+
# @return [Integer]
|
30
|
+
attr_accessor :token_type
|
31
|
+
|
32
|
+
# String type of the token
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
attr_accessor :token_name
|
36
|
+
|
37
|
+
# Value of the token, e.g +“42”+ for +42+
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
attr_accessor :token_value
|
41
|
+
|
42
|
+
# Lex state before token was read
|
43
|
+
#
|
44
|
+
# @return [Integer]
|
45
|
+
attr_accessor :lex_state_before
|
46
|
+
|
47
|
+
# Lex state after token was read
|
48
|
+
#
|
49
|
+
# @return [Integer]
|
50
|
+
attr_accessor :lex_state_after
|
51
|
+
|
52
|
+
# Location of the token
|
53
|
+
#
|
54
|
+
# @return [Loc]
|
55
|
+
attr_accessor :loc
|
56
|
+
|
57
|
+
# @param token_type [Integer]
|
58
|
+
# @param token_name [String]
|
59
|
+
# @param token_value [String]
|
60
|
+
# @param loc [Loc]
|
61
|
+
def initialize(token_type:, token_name:, token_value:, loc:)
|
62
|
+
@token_type = token_type
|
63
|
+
@token_name = token_name
|
64
|
+
@token_value = token_value
|
65
|
+
@lex_state_before = 0
|
66
|
+
@lex_state_after = 0
|
67
|
+
@loc = loc
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Diagnostic message that comes from the parser when there’s an error or warning
|
72
|
+
class Diagnostic
|
73
|
+
# Level of the diagnostic (+:error+ or +:warning+)
|
74
|
+
#
|
75
|
+
# @return [Symbol] +:error+ or +:warning+
|
76
|
+
attr_accessor :level
|
77
|
+
|
78
|
+
# Message of the diagnostic
|
79
|
+
#
|
80
|
+
# @return [DiagnosticMessage]
|
81
|
+
attr_accessor :message
|
82
|
+
|
83
|
+
# Location of the diagnostic
|
84
|
+
#
|
85
|
+
# @return [Loc]
|
86
|
+
attr_accessor :loc
|
87
|
+
|
88
|
+
# @param level [Symbol]
|
89
|
+
# @param message [DiagnosticMessage]
|
90
|
+
# @param loc [Loc]
|
91
|
+
def initialize(level:, message:, loc:)
|
92
|
+
@level = level
|
93
|
+
@message = message
|
94
|
+
@loc = loc
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# A class that represents a comment in Ruby
|
99
|
+
class Comment
|
100
|
+
# Location of the comment (starts with # and ends with the last char)
|
101
|
+
#
|
102
|
+
# @return [Loc]
|
103
|
+
attr_accessor :location
|
104
|
+
|
105
|
+
# Kind of the comment (+:inline+ or +:document+ or +:unknown+)
|
106
|
+
#
|
107
|
+
# @return [Symbol] +:inline+ or +:document+ or +:unknown+
|
108
|
+
attr_accessor :kind
|
109
|
+
|
110
|
+
# @param location [Loc]
|
111
|
+
# @param kind [Symbol]
|
112
|
+
def initialize(location:, kind:)
|
113
|
+
@location = location
|
114
|
+
@kind = kind
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# Representation of a magic comment in Ruby
|
119
|
+
class MagicComment
|
120
|
+
# Kind of a magic comment, can be
|
121
|
+
#
|
122
|
+
# 1. +encoding+
|
123
|
+
# 2. +frozen_string_literal+
|
124
|
+
# 3. +warn_indent+
|
125
|
+
# 4. +shareable_constant_value+
|
126
|
+
#
|
127
|
+
# @return [Symbol]
|
128
|
+
attr_accessor :kind
|
129
|
+
|
130
|
+
# Location of the “key”
|
131
|
+
#
|
132
|
+
# @example
|
133
|
+
# # encoding: utf-8
|
134
|
+
# ~~~~~~~~
|
135
|
+
#
|
136
|
+
# @return [Loc]
|
137
|
+
attr_accessor :key_l
|
138
|
+
|
139
|
+
# Location of the “value”
|
140
|
+
#
|
141
|
+
# @example
|
142
|
+
# # encoding: utf-8
|
143
|
+
# ~~~~~
|
144
|
+
#
|
145
|
+
# @return [Loc]
|
146
|
+
attr_accessor :value_l
|
147
|
+
|
148
|
+
# @param kind [Symbol]
|
149
|
+
# @param key_l [Loc]
|
150
|
+
# @param value_l [Loc]
|
151
|
+
def initialize(kind:, key_l:, value_l:)
|
152
|
+
@kind = kind
|
153
|
+
@key_l = key_l
|
154
|
+
@value_l = value_l
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Base class for all AST nodes
|
159
|
+
class Node
|
160
|
+
end
|
161
|
+
|
162
|
+
# Base class for all diagnostic messages
|
163
|
+
class DiagnosticMessage
|
164
|
+
end
|
165
|
+
|
166
|
+
# Input decoded by parser.
|
167
|
+
#
|
168
|
+
# If your code has magic encoding comment LibRubyParser
|
169
|
+
# re-encodes given input and (potentially) operates
|
170
|
+
# on a different byte sequence.
|
171
|
+
#
|
172
|
+
# This is why this input should be used to get source
|
173
|
+
# of all locations.
|
174
|
+
#
|
175
|
+
# Using initial input is wrong as you may get a different
|
176
|
+
# source range in a different byte representation.
|
177
|
+
class DecodedInput
|
178
|
+
# Name of the initial input
|
179
|
+
#
|
180
|
+
# @return [String]
|
181
|
+
attr_accessor :name
|
182
|
+
|
183
|
+
# Array of source lines
|
184
|
+
#
|
185
|
+
# @return [Array<SourceLine>]
|
186
|
+
attr_accessor :lines
|
187
|
+
|
188
|
+
# Re-encoded input string
|
189
|
+
#
|
190
|
+
# @return [String]
|
191
|
+
attr_accessor :bytes
|
192
|
+
end
|
193
|
+
|
194
|
+
# Representation of a source line in a source file
|
195
|
+
class SourceLine
|
196
|
+
# Start of the line (in bytes)
|
197
|
+
#
|
198
|
+
# @return [Integer]
|
199
|
+
attr_accessor :start
|
200
|
+
|
201
|
+
# End of the line (in bytes)
|
202
|
+
#
|
203
|
+
# @return [Integer]
|
204
|
+
attr_accessor :end
|
205
|
+
|
206
|
+
# +true+ if line ends with EOF char (which is true for the last line in the file)
|
207
|
+
#
|
208
|
+
# @return [true, false]
|
209
|
+
attr_accessor :ends_with_eof
|
210
|
+
|
211
|
+
# @param options [Hash]
|
212
|
+
# @option options [Integer] :start
|
213
|
+
# @option options [Integer] :end
|
214
|
+
# @option options [true, false] :ends_with_eof
|
215
|
+
def initialize(**options)
|
216
|
+
@start = options[:start]
|
217
|
+
@end = options[:end]
|
218
|
+
@ends_with_eof = options[:ends_with_eof]
|
219
|
+
end
|
220
|
+
|
221
|
+
# Default +==+ comparison
|
222
|
+
def ==(other)
|
223
|
+
start == other.start &&
|
224
|
+
self.end == other.end &&
|
225
|
+
ends_with_eof == other.ends_with_eof
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
# Combination of all data that +LibRubyParser+ can give you
|
230
|
+
class ParserResult
|
231
|
+
# Abstract Syntax Tree that was constructed from you code.
|
232
|
+
# +nil+ if the code gives no AST nodes
|
233
|
+
#
|
234
|
+
# @return [Node, nil]
|
235
|
+
attr_accessor :ast
|
236
|
+
|
237
|
+
# List of tokens returned by a Lexer and consumed by a Parser.
|
238
|
+
# Empty unless +:record_tokens+ is set to true.
|
239
|
+
#
|
240
|
+
# @return [Array<Token>]
|
241
|
+
attr_accessor :tokens
|
242
|
+
|
243
|
+
# List of all diagnostics (errors and warings) that
|
244
|
+
# have been recorded during lexing and parsing
|
245
|
+
#
|
246
|
+
# @return [Array<Diagnostic>]
|
247
|
+
attr_accessor :diagnostics
|
248
|
+
|
249
|
+
# List of comments extracted from the source code.
|
250
|
+
#
|
251
|
+
# @return [Array<Comment>]
|
252
|
+
attr_accessor :comments
|
253
|
+
|
254
|
+
# List of magic comments extracted from the source code.
|
255
|
+
#
|
256
|
+
# @return [Array<MagicComment>]
|
257
|
+
attr_accessor :magic_comments
|
258
|
+
|
259
|
+
# Input that was used for parsing.
|
260
|
+
#
|
261
|
+
# Note: this input is not necessary the same byte array that you passed to Parser::parse.
|
262
|
+
# If encoding of the input is not +UTF-8+ or +ASCII-8BIT/BINARY+ Parser invokes decoder
|
263
|
+
# that usually produces a different sequence of bytes.
|
264
|
+
#
|
265
|
+
# Pass this data to +Loc#source+, otherwise you’ll get incorrect source ranges.
|
266
|
+
#
|
267
|
+
# @return [DecodedInput]
|
268
|
+
attr_accessor :input
|
269
|
+
end
|
270
|
+
|
271
|
+
# Default decoder that is used to re-encode input
|
272
|
+
# from non-utf-8 encoding to utf-8
|
273
|
+
DEFAULT_DECODER = proc do |encoding, input|
|
274
|
+
encoding = Encoding.find(encoding)
|
275
|
+
input.force_encoding(encoding).encode('utf-8')
|
276
|
+
end
|
277
|
+
|
278
|
+
# Parses given input according to given options
|
279
|
+
#
|
280
|
+
# @param [String] input
|
281
|
+
# @param [Hash] options
|
282
|
+
# @option options [String] :buffer_name name of the input file
|
283
|
+
# @option options [#call] :decoder (DEFAULT_DECODER) decoder, called with +encoding+ (String) and +input+ (String)
|
284
|
+
# @option options [true, false] :record_tokens When set to true Parser records tokens. When set to false ParserResult::tokens is guaranteed to be empty. If you don’t need tokens better set it to false to speed up parsing.
|
285
|
+
#
|
286
|
+
# @return [ParserResult]
|
287
|
+
def self.parse(input, options)
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
require_relative './lib-ruby-parser/nodes'
|
292
|
+
require_relative './lib-ruby-parser/messages'
|
293
|
+
|
294
|
+
require 'rbconfig'
|
295
|
+
|
296
|
+
ruby_version = Gem::Version.new(RUBY_VERSION).segments.first(2).join('.')
|
297
|
+
unless ['3.2', '3.1', '3.0'].include?(ruby_version)
|
298
|
+
raise "[lib-ruby-parser] Unsupported ruby-version #{ruby_version}"
|
299
|
+
end
|
300
|
+
|
301
|
+
os = RbConfig::CONFIG['host_os']
|
302
|
+
is_windows = !!(os =~ /mingw/)
|
303
|
+
is_darwin = !!(os =~ /darwin/)
|
304
|
+
is_linux = !!(os =~ /linux/)
|
305
|
+
|
306
|
+
cpu = RbConfig::CONFIG['host_cpu']
|
307
|
+
is_x86_64 = cpu == 'x86_64' || cpu == 'x64'
|
308
|
+
is_arm64 = ['arm64', 'aarch64'].include?(cpu)
|
309
|
+
|
310
|
+
triplet =
|
311
|
+
if is_darwin && is_x86_64
|
312
|
+
'x86_64-apple-darwin'
|
313
|
+
elsif is_darwin && is_arm64
|
314
|
+
'aarch64-apple-darwin'
|
315
|
+
elsif is_linux && is_x86_64
|
316
|
+
'x86_64-unknown-linux-gnu'
|
317
|
+
elsif is_windows && is_x86_64
|
318
|
+
'x86_64-pc-windows-gnu'
|
319
|
+
else
|
320
|
+
raise "[lib-ruby-parser] Unsupported os/cpu combination '#{os}'/'#{cpu}'"
|
321
|
+
end
|
322
|
+
|
323
|
+
require_relative "./lib-ruby-parser/native/#{triplet}/#{ruby_version}/lib_ruby_parser"
|