dispersion 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dispersion/annotator.rb +321 -327
- data/lib/dispersion/tokens.rb +18 -0
- data/lib/dispersion/version.rb +1 -1
- data/lib/dispersion.rb +39 -5
- metadata +10 -24
- data/CHANGELOG.md +0 -5
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -34
- data/Rakefile +0 -12
- data/dispersion.gemspec +0 -29
- data/lib/dispersion/annotation.rb +0 -29
- data/lib/dispersion/formatters/ansi.rb +0 -89
- data/lib/dispersion/formatters/html.rb +0 -51
- data/lib/dispersion/formatters.rb +0 -8
- data/lib/dispersion/highlighter.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6d839f727b08a163dc893736afaed93d3563f26c5bc500b7ade8fa3b06803f4
|
4
|
+
data.tar.gz: 6065a58ba57342d09f600831d521cdce62db0effc33491944075e9c87b79128e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41dc3511ba6378dca079e6984c2a19ba3013894ae654d7e31483a2d0385939d553c430574b9123fbf277c73f3b8aa5e2389fc60691e6de80e4ae7f5a3b306b51
|
7
|
+
data.tar.gz: d7ce2287bc8fe50d0cf03ea5c47ca6e6defd09fa37e7929040c777539431ef955d5fe1b728f9e933b8160968c297fad11f2b6124300556dfe27ced241a102bd4
|
data/lib/dispersion/annotator.rb
CHANGED
@@ -3,331 +3,325 @@
|
|
3
3
|
require "prism"
|
4
4
|
|
5
5
|
module Dispersion
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
def visit_capture_pattern_node(node)
|
329
|
-
highlight :operator, node.operator_loc
|
330
|
-
super
|
331
|
-
end
|
332
|
-
end
|
6
|
+
class Annotator < Prism::Visitor
|
7
|
+
def self.call(code)
|
8
|
+
new(code).call
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(code)
|
12
|
+
@code = code
|
13
|
+
@annotations = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
@prev_end = 0
|
18
|
+
parsed = Prism.parse(@code)
|
19
|
+
parsed.comments.each { |c| visit_comment(c) }
|
20
|
+
visit(parsed.value)
|
21
|
+
|
22
|
+
@annotations.sort_by(&:first)
|
23
|
+
end
|
24
|
+
|
25
|
+
def highlight(token, loc)
|
26
|
+
return unless loc
|
27
|
+
return if loc.start_line == loc.end_line && loc.start_column == loc.end_column
|
28
|
+
|
29
|
+
@annotations << [loc.start_offset, loc.end_offset, token].freeze
|
30
|
+
end
|
31
|
+
|
32
|
+
def visit_comment(node)
|
33
|
+
highlight Tokens::COMMENT, node.location
|
34
|
+
end
|
35
|
+
|
36
|
+
def visit_def_node(node)
|
37
|
+
highlight Tokens::KEYWORD, node.def_keyword_loc
|
38
|
+
highlight Tokens::FUNCTION, node.name_loc
|
39
|
+
highlight Tokens::PUNCTUATION, node.lparen_loc
|
40
|
+
highlight Tokens::PUNCTUATION, node.rparen_loc
|
41
|
+
highlight Tokens::KEYWORD, node.end_keyword_loc
|
42
|
+
super
|
43
|
+
end
|
44
|
+
|
45
|
+
def visit_local_variable_write_node(node)
|
46
|
+
highlight Tokens::LOCAL_VARIABLE, node.name_loc
|
47
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
48
|
+
super
|
49
|
+
end
|
50
|
+
|
51
|
+
def visit_local_variable_read_node(node)
|
52
|
+
highlight Tokens::LOCAL_VARIABLE, node.location
|
53
|
+
super
|
54
|
+
end
|
55
|
+
|
56
|
+
def visit_instance_variable_write_node(node)
|
57
|
+
highlight Tokens::INSTANCE_VARIABLE, node.name_loc
|
58
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
59
|
+
super
|
60
|
+
end
|
61
|
+
|
62
|
+
def visit_instance_variable_and_write_node(node)
|
63
|
+
highlight Tokens::INSTANCE_VARIABLE, node.name_loc
|
64
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
65
|
+
super
|
66
|
+
end
|
67
|
+
|
68
|
+
def visit_instance_variable_or_write_node(node)
|
69
|
+
highlight Tokens::INSTANCE_VARIABLE, node.name_loc
|
70
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
71
|
+
super
|
72
|
+
end
|
73
|
+
|
74
|
+
def visit_instance_variable_read_node(node)
|
75
|
+
highlight Tokens::INSTANCE_VARIABLE, node.location
|
76
|
+
super
|
77
|
+
end
|
78
|
+
|
79
|
+
def visit_constant_read_node(node)
|
80
|
+
highlight Tokens::CONSTANT, node.location
|
81
|
+
super
|
82
|
+
end
|
83
|
+
|
84
|
+
def visit_class_node(node)
|
85
|
+
highlight Tokens::KEYWORD, node.class_keyword_loc
|
86
|
+
highlight Tokens::KEYWORD, node.end_keyword_loc
|
87
|
+
super
|
88
|
+
end
|
89
|
+
|
90
|
+
def visit_call_node(node)
|
91
|
+
unless node.name in :[] | :[]=
|
92
|
+
highlight Tokens::FUNCTION, node.message_loc
|
93
|
+
end
|
94
|
+
|
95
|
+
super
|
96
|
+
end
|
97
|
+
|
98
|
+
def visit_string_node(node)
|
99
|
+
highlight Tokens::STRING, node.location
|
100
|
+
super
|
101
|
+
end
|
102
|
+
|
103
|
+
def visit_interpolated_string_node(node)
|
104
|
+
highlight Tokens::PUNCTUATION, node.opening_loc
|
105
|
+
highlight Tokens::PUNCTUATION, node.closing_loc
|
106
|
+
super
|
107
|
+
end
|
108
|
+
|
109
|
+
def visit_symbol_node(node)
|
110
|
+
highlight Tokens::SYMBOL, node.location
|
111
|
+
super
|
112
|
+
end
|
113
|
+
|
114
|
+
def visit_block_node(node)
|
115
|
+
if node.opening_loc.length == 1
|
116
|
+
highlight Tokens::PUNCTUATION, node.opening_loc
|
117
|
+
else
|
118
|
+
highlight Tokens::KEYWORD, node.opening_loc
|
119
|
+
end
|
120
|
+
|
121
|
+
if node.closing_loc.length == 1
|
122
|
+
highlight Tokens::PUNCTUATION, node.closing_loc
|
123
|
+
else
|
124
|
+
highlight Tokens::KEYWORD, node.closing_loc
|
125
|
+
end
|
126
|
+
|
127
|
+
super
|
128
|
+
end
|
129
|
+
|
130
|
+
def visit_case_node(node)
|
131
|
+
highlight Tokens::KEYWORD, node.case_keyword_loc
|
132
|
+
highlight Tokens::KEYWORD, node.end_keyword_loc
|
133
|
+
super
|
134
|
+
end
|
135
|
+
|
136
|
+
def visit_case_match_node(node)
|
137
|
+
highlight Tokens::KEYWORD, node.case_keyword_loc
|
138
|
+
highlight Tokens::KEYWORD, node.end_keyword_loc
|
139
|
+
super
|
140
|
+
end
|
141
|
+
|
142
|
+
def visit_module_node(node)
|
143
|
+
highlight Tokens::KEYWORD, node.module_keyword_loc
|
144
|
+
highlight Tokens::KEYWORD, node.end_keyword_loc
|
145
|
+
super
|
146
|
+
end
|
147
|
+
|
148
|
+
def visit_if_node(node)
|
149
|
+
highlight Tokens::KEYWORD, node.if_keyword_loc
|
150
|
+
highlight Tokens::KEYWORD, node.end_keyword_loc
|
151
|
+
|
152
|
+
if node.then_keyword&.length == 1
|
153
|
+
highlight Tokens::OPERATOR, node.then_keyword_loc
|
154
|
+
else
|
155
|
+
highlight Tokens::KEYWORD, node.then_keyword_loc
|
156
|
+
end
|
157
|
+
|
158
|
+
super
|
159
|
+
end
|
160
|
+
|
161
|
+
def visit_when_node(node)
|
162
|
+
highlight Tokens::KEYWORD, node.keyword_loc
|
163
|
+
super
|
164
|
+
end
|
165
|
+
|
166
|
+
def visit_else_node(node)
|
167
|
+
if node.else_keyword.length == 1
|
168
|
+
highlight Tokens::OPERATOR, node.else_keyword_loc
|
169
|
+
else
|
170
|
+
highlight Tokens::KEYWORD, node.else_keyword_loc
|
171
|
+
end
|
172
|
+
|
173
|
+
super
|
174
|
+
end
|
175
|
+
|
176
|
+
def visit_block_argument_node(node)
|
177
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
178
|
+
super
|
179
|
+
end
|
180
|
+
|
181
|
+
def visit_and_node(node)
|
182
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
183
|
+
super
|
184
|
+
end
|
185
|
+
|
186
|
+
def visit_or_node(node)
|
187
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
188
|
+
super
|
189
|
+
end
|
190
|
+
|
191
|
+
def visit_local_variable_or_write_node(node)
|
192
|
+
highlight Tokens::LOCAL_VARIABLE, node.name_loc
|
193
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
194
|
+
super
|
195
|
+
end
|
196
|
+
|
197
|
+
def visit_local_variable_and_write_node(node)
|
198
|
+
highlight Tokens::LOCAL_VARIABLE, node.name_loc
|
199
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
200
|
+
super
|
201
|
+
end
|
202
|
+
|
203
|
+
def visit_rescue_node(node)
|
204
|
+
highlight Tokens::KEYWORD, node.keyword_loc
|
205
|
+
highlight Tokens::KEYWORD, node.operator_loc
|
206
|
+
super
|
207
|
+
end
|
208
|
+
|
209
|
+
def visit_rest_parameter_node(node)
|
210
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
211
|
+
super
|
212
|
+
end
|
213
|
+
|
214
|
+
def visit_keyword_rest_parameter_node(node)
|
215
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
216
|
+
super
|
217
|
+
end
|
218
|
+
|
219
|
+
def visit_block_parameter_node(node)
|
220
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
221
|
+
super
|
222
|
+
end
|
223
|
+
|
224
|
+
def visit_while_node(node)
|
225
|
+
highlight Tokens::KEYWORD, node.keyword_loc
|
226
|
+
highlight Tokens::KEYWORD, node.closing_loc
|
227
|
+
super
|
228
|
+
end
|
229
|
+
|
230
|
+
def visit_until_node(node)
|
231
|
+
highlight Tokens::KEYWORD, node.keyword_loc
|
232
|
+
highlight Tokens::KEYWORD, node.closing_loc
|
233
|
+
super
|
234
|
+
end
|
235
|
+
|
236
|
+
def visit_next_node(node)
|
237
|
+
highlight Tokens::KEYWORD, node.keyword_loc
|
238
|
+
super
|
239
|
+
end
|
240
|
+
|
241
|
+
def visit_integer_node(node)
|
242
|
+
highlight Tokens::INTEGER, node.location
|
243
|
+
super
|
244
|
+
end
|
245
|
+
|
246
|
+
def visit_float_node(node)
|
247
|
+
highlight Tokens::FLOAT, node.location
|
248
|
+
super
|
249
|
+
end
|
250
|
+
|
251
|
+
def visit_hash_node(node)
|
252
|
+
highlight Tokens::PUNCTUATION, node.opening_loc
|
253
|
+
highlight Tokens::PUNCTUATION, node.closing_loc
|
254
|
+
super
|
255
|
+
end
|
256
|
+
|
257
|
+
def visit_array_node(node)
|
258
|
+
highlight Tokens::PUNCTUATION, node.opening_loc
|
259
|
+
highlight Tokens::PUNCTUATION, node.closing_loc
|
260
|
+
super
|
261
|
+
end
|
262
|
+
|
263
|
+
def visit_assoc_node(node)
|
264
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
265
|
+
super
|
266
|
+
end
|
267
|
+
|
268
|
+
def visit_forwarding_parameter_node(node)
|
269
|
+
highlight Tokens::OPERATOR, node.location
|
270
|
+
super
|
271
|
+
end
|
272
|
+
|
273
|
+
def visit_forwarding_super_node(node)
|
274
|
+
highlight Tokens::KEYWORD, node.location
|
275
|
+
end
|
276
|
+
|
277
|
+
def visit_embedded_statements_node(node)
|
278
|
+
highlight Tokens::PUNCTUATION, node.opening_loc
|
279
|
+
highlight Tokens::PUNCTUATION, node.closing_loc
|
280
|
+
super
|
281
|
+
end
|
282
|
+
|
283
|
+
def visit_parentheses_node(node)
|
284
|
+
highlight Tokens::PUNCTUATION, node.opening_loc
|
285
|
+
highlight Tokens::PUNCTUATION, node.closing_loc
|
286
|
+
super
|
287
|
+
end
|
288
|
+
|
289
|
+
def visit_range_node(node)
|
290
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
291
|
+
super
|
292
|
+
end
|
293
|
+
|
294
|
+
def visit_in_node(node)
|
295
|
+
highlight Tokens::KEYWORD, node.in_loc
|
296
|
+
highlight Tokens::KEYWORD, node.then_loc
|
297
|
+
super
|
298
|
+
end
|
299
|
+
|
300
|
+
def visit_array_pattern_node(node)
|
301
|
+
highlight Tokens::PUNCTUATION, node.opening_loc
|
302
|
+
highlight Tokens::PUNCTUATION, node.closing_loc
|
303
|
+
super
|
304
|
+
end
|
305
|
+
|
306
|
+
def visit_alternation_pattern_node(node)
|
307
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
308
|
+
super
|
309
|
+
end
|
310
|
+
|
311
|
+
def visit_required_parameter_node(node)
|
312
|
+
highlight Tokens::LOCAL_VARIABLE, node.location
|
313
|
+
super
|
314
|
+
end
|
315
|
+
|
316
|
+
def visit_optional_parameter_node(node)
|
317
|
+
highlight Tokens::LOCAL_VARIABLE, node.name_loc
|
318
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
319
|
+
super
|
320
|
+
end
|
321
|
+
|
322
|
+
def visit_capture_pattern_node(node)
|
323
|
+
highlight Tokens::OPERATOR, node.operator_loc
|
324
|
+
super
|
325
|
+
end
|
326
|
+
end
|
333
327
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dispersion
|
4
|
+
module Tokens
|
5
|
+
COMMENT = :COMMENT
|
6
|
+
KEYWORD = :KEYWORD
|
7
|
+
CONSTANT = :CONSTANT
|
8
|
+
FUNCTION = :FUNCTION
|
9
|
+
PUNCTUATION = :PUNCTUATION
|
10
|
+
LOCAL_VARIABLE = :LOCAL_VARIABLE
|
11
|
+
INSTANCE_VARIABLE = :INSTANCE_VARIABLE
|
12
|
+
OPERATOR = :OPERATOR
|
13
|
+
STRING = :STRING
|
14
|
+
SYMBOL = :SYMBOL
|
15
|
+
INTEGER = :INTEGER
|
16
|
+
FLOAT = :FLOAT
|
17
|
+
end
|
18
|
+
end
|
data/lib/dispersion/version.rb
CHANGED
data/lib/dispersion.rb
CHANGED
@@ -1,9 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "prism"
|
4
|
+
|
3
5
|
module Dispersion
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
autoload :Annotator, "dispersion/annotator"
|
7
|
+
autoload :Tokens, "dispersion/tokens"
|
8
|
+
|
9
|
+
THEME = {
|
10
|
+
Tokens::COMMENT => "\e[90m",
|
11
|
+
Tokens::KEYWORD => "\e[31m",
|
12
|
+
Tokens::CONSTANT => "\e[34m",
|
13
|
+
Tokens::FUNCTION => "\e[33m",
|
14
|
+
Tokens::PUNCTUATION => "\e[37m",
|
15
|
+
Tokens::LOCAL_VARIABLE => "\e[32m",
|
16
|
+
Tokens::INSTANCE_VARIABLE => "\e[35m",
|
17
|
+
Tokens::OPERATOR => "\e[33m",
|
18
|
+
Tokens::STRING => "\e[32m",
|
19
|
+
Tokens::SYMBOL => "\e[36m",
|
20
|
+
Tokens::INTEGER => "\e[33m",
|
21
|
+
Tokens::FLOAT => "\e[33m",
|
22
|
+
}.freeze
|
23
|
+
|
24
|
+
def self.annotate(code)
|
25
|
+
Annotator.call(code)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.ansi(code)
|
29
|
+
code.dup.tap do |buffer|
|
30
|
+
offset = 0
|
31
|
+
|
32
|
+
for start_offset, end_offset, token in annotate(code)
|
33
|
+
start = THEME.fetch(token)
|
34
|
+
|
35
|
+
buffer.bytesplice(start_offset + offset, 0, start)
|
36
|
+
offset += start.bytesize
|
37
|
+
|
38
|
+
buffer.bytesplice(end_offset + offset, 0, "\e[0m")
|
39
|
+
offset += 4
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
9
43
|
end
|
metadata
CHANGED
@@ -1,51 +1,39 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dispersion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Drapper
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-31 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: prism
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
18
|
+
version: '0'
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
27
|
-
description:
|
25
|
+
version: '0'
|
28
26
|
email:
|
29
27
|
- joel@drapper.me
|
30
28
|
executables: []
|
31
29
|
extensions: []
|
32
30
|
extra_rdoc_files: []
|
33
31
|
files:
|
34
|
-
- CHANGELOG.md
|
35
|
-
- CODE_OF_CONDUCT.md
|
36
|
-
- Gemfile
|
37
|
-
- Gemfile.lock
|
38
32
|
- LICENSE.txt
|
39
33
|
- README.md
|
40
|
-
- Rakefile
|
41
|
-
- dispersion.gemspec
|
42
34
|
- lib/dispersion.rb
|
43
|
-
- lib/dispersion/annotation.rb
|
44
35
|
- lib/dispersion/annotator.rb
|
45
|
-
- lib/dispersion/
|
46
|
-
- lib/dispersion/formatters/ansi.rb
|
47
|
-
- lib/dispersion/formatters/html.rb
|
48
|
-
- lib/dispersion/highlighter.rb
|
36
|
+
- lib/dispersion/tokens.rb
|
49
37
|
- lib/dispersion/version.rb
|
50
38
|
homepage: https://github.com/joeldrapper/dispersion
|
51
39
|
licenses:
|
@@ -53,9 +41,8 @@ licenses:
|
|
53
41
|
metadata:
|
54
42
|
homepage_uri: https://github.com/joeldrapper/dispersion
|
55
43
|
source_code_uri: https://github.com/joeldrapper/dispersion
|
56
|
-
changelog_uri: https://github.com/joeldrapper/dispersion
|
44
|
+
changelog_uri: https://github.com/joeldrapper/dispersion
|
57
45
|
funding_uri: https://github.com/sponsors/joeldrapper
|
58
|
-
post_install_message:
|
59
46
|
rdoc_options: []
|
60
47
|
require_paths:
|
61
48
|
- lib
|
@@ -70,8 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
57
|
- !ruby/object:Gem::Version
|
71
58
|
version: '0'
|
72
59
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
74
|
-
signing_key:
|
60
|
+
rubygems_version: 3.6.2
|
75
61
|
specification_version: 4
|
76
|
-
summary:
|
62
|
+
summary: Syntac Highlighter for Ruby
|
77
63
|
test_files: []
|
data/CHANGELOG.md
DELETED
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
# Contributor Covenant Code of Conduct
|
2
|
-
|
3
|
-
## Our Pledge
|
4
|
-
|
5
|
-
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
-
|
7
|
-
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
-
|
9
|
-
## Our Standards
|
10
|
-
|
11
|
-
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
-
|
13
|
-
* Demonstrating empathy and kindness toward other people
|
14
|
-
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
-
* Giving and gracefully accepting constructive feedback
|
16
|
-
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
-
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
-
|
19
|
-
Examples of unacceptable behavior include:
|
20
|
-
|
21
|
-
* The use of sexualized language or imagery, and sexual attention or
|
22
|
-
advances of any kind
|
23
|
-
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
-
* Public or private harassment
|
25
|
-
* Publishing others' private information, such as a physical or email
|
26
|
-
address, without their explicit permission
|
27
|
-
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
-
professional setting
|
29
|
-
|
30
|
-
## Enforcement Responsibilities
|
31
|
-
|
32
|
-
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
-
|
34
|
-
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
-
|
36
|
-
## Scope
|
37
|
-
|
38
|
-
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
-
|
40
|
-
## Enforcement
|
41
|
-
|
42
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at joel@drapper.me. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
-
|
44
|
-
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
-
|
46
|
-
## Enforcement Guidelines
|
47
|
-
|
48
|
-
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
-
|
50
|
-
### 1. Correction
|
51
|
-
|
52
|
-
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
-
|
54
|
-
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
-
|
56
|
-
### 2. Warning
|
57
|
-
|
58
|
-
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
-
|
60
|
-
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
-
|
62
|
-
### 3. Temporary Ban
|
63
|
-
|
64
|
-
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
-
|
66
|
-
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
-
|
68
|
-
### 4. Permanent Ban
|
69
|
-
|
70
|
-
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
-
|
72
|
-
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
-
|
74
|
-
## Attribution
|
75
|
-
|
76
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
-
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
-
|
79
|
-
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
-
|
81
|
-
[homepage]: https://www.contributor-covenant.org
|
82
|
-
|
83
|
-
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
-
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../green_dots
|
3
|
-
specs:
|
4
|
-
green_dots (0.1.0)
|
5
|
-
concurrent-ruby
|
6
|
-
prism
|
7
|
-
rouge
|
8
|
-
tty-tree
|
9
|
-
zeitwerk
|
10
|
-
|
11
|
-
PATH
|
12
|
-
remote: .
|
13
|
-
specs:
|
14
|
-
dispersion (0.1.0)
|
15
|
-
prism (~> 0.18)
|
16
|
-
|
17
|
-
GEM
|
18
|
-
remote: https://rubygems.org/
|
19
|
-
specs:
|
20
|
-
concurrent-ruby (1.2.2)
|
21
|
-
prism (0.18.0)
|
22
|
-
rouge (4.1.3)
|
23
|
-
tty-tree (0.4.0)
|
24
|
-
zeitwerk (2.6.12)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
arm64-darwin-22
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
dispersion!
|
31
|
-
green_dots!
|
32
|
-
|
33
|
-
BUNDLED WITH
|
34
|
-
2.4.12
|
data/Rakefile
DELETED
data/dispersion.gemspec
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/dispersion/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "dispersion"
|
7
|
-
spec.version = Dispersion::VERSION
|
8
|
-
spec.authors = ["Joel Drapper"]
|
9
|
-
spec.email = ["joel@drapper.me"]
|
10
|
-
|
11
|
-
spec.summary = "Prism-powered syntax highlighter for Ruby"
|
12
|
-
spec.homepage = "https://github.com/joeldrapper/dispersion"
|
13
|
-
spec.license = "MIT"
|
14
|
-
spec.required_ruby_version = ">= 3.0.0"
|
15
|
-
|
16
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
18
|
-
spec.metadata["changelog_uri"] = "https://github.com/joeldrapper/dispersion/blob/main/CHANGELOG.md"
|
19
|
-
spec.metadata["funding_uri"] = "https://github.com/sponsors/joeldrapper"
|
20
|
-
|
21
|
-
spec.files = Dir.chdir(__dir__) do
|
22
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
-
(File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
spec.require_paths = ["lib"]
|
28
|
-
spec.add_dependency "prism", "~> 0.18"
|
29
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dispersion
|
4
|
-
class Annotation
|
5
|
-
include Comparable
|
6
|
-
|
7
|
-
def initialize(type, location)
|
8
|
-
@type = type
|
9
|
-
@location = location
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :type, :location
|
13
|
-
|
14
|
-
def <=>(other)
|
15
|
-
comparison_value <=> other.comparison_value
|
16
|
-
end
|
17
|
-
|
18
|
-
def comparison_value
|
19
|
-
[
|
20
|
-
location,
|
21
|
-
(type == :reset ? 0 : 1)
|
22
|
-
]
|
23
|
-
end
|
24
|
-
|
25
|
-
def to_ary
|
26
|
-
[type, location]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dispersion
|
4
|
-
module Formatters
|
5
|
-
class ANSI
|
6
|
-
Regular = "\e[22m"
|
7
|
-
Bold = "\e[1m"
|
8
|
-
Faint = "\e[2m"
|
9
|
-
Reset = "\e[0m"
|
10
|
-
Italic = "\e[3m"
|
11
|
-
Underline = "\e[4m"
|
12
|
-
|
13
|
-
# Basic Colors
|
14
|
-
Black = "\e[30m"
|
15
|
-
Red = "\e[31m"
|
16
|
-
Green = "\e[32m"
|
17
|
-
Yellow = "\e[33m"
|
18
|
-
Blue = "\e[34m"
|
19
|
-
Magenta = "\e[35m"
|
20
|
-
Cyan = "\e[36m"
|
21
|
-
White = "\e[37m"
|
22
|
-
|
23
|
-
# Bright Colors
|
24
|
-
BrightBlack = "\e[90m"
|
25
|
-
BrightRed = "\e[91m"
|
26
|
-
BrightGreen = "\e[92m"
|
27
|
-
BrightYellow = "\e[93m"
|
28
|
-
BrightBlue = "\e[94m"
|
29
|
-
BrightMagenta = "\e[95m"
|
30
|
-
BrightCyan = "\e[96m"
|
31
|
-
BrightWhite = "\e[97m"
|
32
|
-
|
33
|
-
DEFAULT_ANSI = {
|
34
|
-
call: Red,
|
35
|
-
string: Yellow,
|
36
|
-
keyword: Cyan,
|
37
|
-
comment: Italic + Magenta,
|
38
|
-
var: "",
|
39
|
-
constant: Blue,
|
40
|
-
ivar: Blue,
|
41
|
-
symbol: Green,
|
42
|
-
numeric: Green,
|
43
|
-
bracket: "",
|
44
|
-
operator: "\e[36m",
|
45
|
-
}
|
46
|
-
|
47
|
-
def initialize(code, annotations:, theme:)
|
48
|
-
@code = code
|
49
|
-
@annotations = annotations
|
50
|
-
@marks = DEFAULT_ANSI
|
51
|
-
end
|
52
|
-
|
53
|
-
def call
|
54
|
-
lines = @code.lines
|
55
|
-
current_symbol = nil
|
56
|
-
buffer = +""
|
57
|
-
|
58
|
-
lines.each_with_index do |line, line_number|
|
59
|
-
cursor = 0
|
60
|
-
|
61
|
-
@annotations[line_number].each do |(symbol, column)|
|
62
|
-
buffer << line[cursor...column]
|
63
|
-
cursor = column
|
64
|
-
|
65
|
-
# Always reset the current symbol
|
66
|
-
if current_symbol
|
67
|
-
buffer << Reset
|
68
|
-
current_symbol = nil
|
69
|
-
end
|
70
|
-
|
71
|
-
unless symbol == :reset
|
72
|
-
buffer << @marks.fetch(symbol)
|
73
|
-
current_symbol = symbol
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
buffer << line[cursor..]
|
78
|
-
end
|
79
|
-
|
80
|
-
if current_symbol
|
81
|
-
buffer << Reset
|
82
|
-
current_symbol = nil
|
83
|
-
end
|
84
|
-
|
85
|
-
buffer.gsub(/\t/, " ")
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "erb"
|
4
|
-
|
5
|
-
module Dispersion
|
6
|
-
module Formatters
|
7
|
-
class HTML
|
8
|
-
def initialize(code, annotations:)
|
9
|
-
@code = code
|
10
|
-
@annotations = annotations
|
11
|
-
end
|
12
|
-
|
13
|
-
def call
|
14
|
-
lines = @code.lines
|
15
|
-
current_symbol = nil
|
16
|
-
buffer = +""
|
17
|
-
|
18
|
-
lines.each_with_index do |line, line_number|
|
19
|
-
cursor = 0
|
20
|
-
|
21
|
-
@annotations[line_number].each do |(symbol, column)|
|
22
|
-
buffer << ERB::Escape.html_escape(line[cursor...column])
|
23
|
-
cursor = column
|
24
|
-
|
25
|
-
# Always reset the current symbol
|
26
|
-
if current_symbol
|
27
|
-
buffer << "</span>"
|
28
|
-
current_symbol = nil
|
29
|
-
end
|
30
|
-
|
31
|
-
unless symbol == :reset
|
32
|
-
buffer << %(<span data-dispersion-symbol="#{symbol.name}">)
|
33
|
-
current_symbol = symbol
|
34
|
-
end
|
35
|
-
|
36
|
-
# binding.irb
|
37
|
-
end
|
38
|
-
|
39
|
-
buffer << ERB::Escape.html_escape(line[cursor..])
|
40
|
-
end
|
41
|
-
|
42
|
-
if current_symbol
|
43
|
-
buffer << "</span>"
|
44
|
-
current_symbol = nil
|
45
|
-
end
|
46
|
-
|
47
|
-
buffer.gsub(/\t/, " ")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Dispersion
|
4
|
-
class Highlighter
|
5
|
-
def initialize(code)
|
6
|
-
@code = code
|
7
|
-
@annotations = Dispersion::Annotator.call(code)
|
8
|
-
freeze
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_ansi(theme: nil)
|
12
|
-
Dispersion::Formatters::ANSI.new(@code, annotations: @annotations, theme:).call
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_html
|
16
|
-
Dispersion::Formatters::HTML.new(@code, annotations: @annotations).call
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|