ngworder 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/ngworder/version.rb +1 -1
- data/lib/ngworder.rb +28 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 58b3776df5c32d087309ec1988bc4fdb20627dc5140f66833ed2e6fed8d6e828
|
|
4
|
+
data.tar.gz: 5cc6fbd146932a83bef18dd91f3c939ca9d7f4bb99b7270ccd29ebb27664b630
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c628c99ca4def6086d7c1df8ccb927bcea84cb89901c967d3c1eb03a6c58b5dd0d107359118fd85e033cad7a2a0ada609b1e74d6d8d7f0a287e805c43e737ece
|
|
7
|
+
data.tar.gz: 755cb4ea9bc96a0bd62f5f40acba64d1d2c8b0fb838a8ea80eb00bb3d42753bb840ddb45e77be94cd6a5d04bbf8ca980a730a81b4cc971fe9e0dd17cf92fa850
|
data/README.md
CHANGED
data/lib/ngworder/version.rb
CHANGED
data/lib/ngworder.rb
CHANGED
|
@@ -5,17 +5,18 @@ require "tempfile"
|
|
|
5
5
|
require_relative "ngworder/version"
|
|
6
6
|
|
|
7
7
|
module Ngworder
|
|
8
|
-
Rule = Struct.new(:matcher, :label, :excludes)
|
|
8
|
+
Rule = Struct.new(:matcher, :label, :excludes, :comment)
|
|
9
9
|
Matcher = Struct.new(:type, :pattern, :label)
|
|
10
10
|
|
|
11
11
|
module Parser
|
|
12
12
|
module_function
|
|
13
13
|
|
|
14
|
-
def
|
|
14
|
+
def split_comment(line)
|
|
15
15
|
out = +""
|
|
16
16
|
escaped = false
|
|
17
|
+
comment = nil
|
|
17
18
|
|
|
18
|
-
line.each_char do |ch|
|
|
19
|
+
line.each_char.with_index do |ch, idx|
|
|
19
20
|
if escaped
|
|
20
21
|
out << ch
|
|
21
22
|
escaped = false
|
|
@@ -28,12 +29,15 @@ module Ngworder
|
|
|
28
29
|
next
|
|
29
30
|
end
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
if ch == "#"
|
|
33
|
+
comment = line[(idx + 1)..-1]
|
|
34
|
+
break
|
|
35
|
+
end
|
|
32
36
|
|
|
33
37
|
out << ch
|
|
34
38
|
end
|
|
35
39
|
|
|
36
|
-
out
|
|
40
|
+
[out, comment]
|
|
37
41
|
end
|
|
38
42
|
|
|
39
43
|
def split_unescaped_bang(line)
|
|
@@ -127,7 +131,7 @@ module Ngworder
|
|
|
127
131
|
rules = []
|
|
128
132
|
|
|
129
133
|
File.readlines(path, chomp: true).each do |line|
|
|
130
|
-
content =
|
|
134
|
+
content, comment = split_comment(line)
|
|
131
135
|
next if content.strip.empty?
|
|
132
136
|
|
|
133
137
|
parts = split_unescaped_bang(content)
|
|
@@ -135,7 +139,9 @@ module Ngworder
|
|
|
135
139
|
next unless base
|
|
136
140
|
|
|
137
141
|
excludes = parts.map { |part| parse_matcher(part, trim: :both) }.compact
|
|
138
|
-
|
|
142
|
+
comment = comment&.strip
|
|
143
|
+
comment = nil if comment.nil? || comment.empty?
|
|
144
|
+
rules << Rule.new(base, base.label, excludes, comment)
|
|
139
145
|
end
|
|
140
146
|
|
|
141
147
|
rules
|
|
@@ -272,6 +278,12 @@ module Ngworder
|
|
|
272
278
|
"\e[35m#{text}\e[0m"
|
|
273
279
|
end
|
|
274
280
|
|
|
281
|
+
colorize_path = lambda do |text|
|
|
282
|
+
return text unless color_enabled
|
|
283
|
+
|
|
284
|
+
"\e[36m#{text}\e[0m"
|
|
285
|
+
end
|
|
286
|
+
|
|
275
287
|
highlight_line = lambda do |line, span|
|
|
276
288
|
return line unless color_enabled
|
|
277
289
|
|
|
@@ -323,7 +335,9 @@ module Ngworder
|
|
|
323
335
|
found = true
|
|
324
336
|
col_no = span[0] + 1
|
|
325
337
|
match_text = colorize_match.call(span[2])
|
|
326
|
-
|
|
338
|
+
suffix = rule.comment ? " # #{rule.comment}" : ""
|
|
339
|
+
path_text = colorize_path.call(path)
|
|
340
|
+
puts "#{path_text}:#{line_no}:#{col_no} #{match_text}#{suffix}"
|
|
327
341
|
puts highlight_line.call(line, span) if line_enabled
|
|
328
342
|
end
|
|
329
343
|
end
|
|
@@ -353,7 +367,9 @@ module Ngworder
|
|
|
353
367
|
found = true
|
|
354
368
|
col_no = span[0] + 1
|
|
355
369
|
match_text = colorize_match.call(span[2])
|
|
356
|
-
|
|
370
|
+
suffix = rule.comment ? " # #{rule.comment}" : ""
|
|
371
|
+
path_text = colorize_path.call(path)
|
|
372
|
+
puts "#{path_text}:#{line_no}:#{col_no} #{match_text}#{suffix}"
|
|
357
373
|
puts highlight_line.call(line, span) if line_enabled
|
|
358
374
|
end
|
|
359
375
|
end
|
|
@@ -372,7 +388,9 @@ module Ngworder
|
|
|
372
388
|
found = true
|
|
373
389
|
col_no = span[0] + 1
|
|
374
390
|
match_text = colorize_match.call(span[2])
|
|
375
|
-
|
|
391
|
+
suffix = rule.comment ? " # #{rule.comment}" : ""
|
|
392
|
+
path_text = colorize_path.call(path)
|
|
393
|
+
puts "#{path_text}:#{line_no}:#{col_no} #{match_text}#{suffix}"
|
|
376
394
|
puts highlight_line.call(line, span) if line_enabled
|
|
377
395
|
end
|
|
378
396
|
end
|