querly 0.2.1 → 0.3.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bd9629e495b71aa9395ad56acba1b0a90438f8a
4
- data.tar.gz: 988988c9c767178f711ea944a1955807675ad08a
3
+ metadata.gz: 278d6249e0070a8df23463f5a87e192723582d9b
4
+ data.tar.gz: 7f25f0bec22cc8fa8dc715aaa1c151f917ddbe1a
5
5
  SHA512:
6
- metadata.gz: 14691228c8cc50ce2219558080b9ff0d814f1e2c98421c9d4967c1aeaf54a00261f8e883da6c00095545a4d92173fa4136004ed8768ca2e95ba7174bbdcc9dcc
7
- data.tar.gz: 4cda473f15bc4fb71ea036b6914b6222766a3b6c088bd5c31ffb111aeaa6f5e57a75e30cfb8f640d917dc9f9313a7b77d5410cf8c991f3e68ad00deb8dd6001f
6
+ metadata.gz: 3fce9e93f1b3656ab76379d105eb5812694ebd21d812d3db673bc7d62c8ca8b1ddb57adc4500cf111c9c9bd29aafd37d7cb48b827806fb4cb130bd0ca8470893
7
+ data.tar.gz: 406d47ca60ac29da0d1adae7c239e327fa71640bc713fc4cbc2fd2ef1488ba6a0154cc3619ab7c45ac1aa2b67cc75cc786efdfcd38cb056c999e73f3f44c3e2d
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.3.0
6
+
7
+ * Add `version` command
8
+ * Fix *with block* and *without block* pattern parsing
9
+ * Prettier backtrace printing
10
+ * Prettier pattern syntax error message
11
+
5
12
  ## 0.2.1 (2016-11-24)
6
13
 
7
14
  * Fix `self` pattern matching
@@ -12,7 +19,7 @@
12
19
  * Add `check` section to select rules to check
13
20
  * Add `import` section to load rules from other file
14
21
  * Add `querly rules` sub command to print loaded rules
15
- * Add *with block* and *without block* pattern (`foo {}` / `foo !{}`)
22
+ * Add *with block* and *without block* pattern (`foo() {}` / `foo() !{}`)
16
23
  * Add *some of receiver chain* pattern (`...`)
17
24
  * Fix keyword args pattern matching bug
18
25
 
@@ -3,6 +3,8 @@ require 'readline'
3
3
  module Querly
4
4
  class CLI
5
5
  class Console
6
+ include Concerns::BacktraceFormatter
7
+
6
8
  attr_reader :paths
7
9
 
8
10
  def initialize(paths:)
@@ -87,8 +89,9 @@ Querly #{VERSION}, interactive console
87
89
 
88
90
  puts "#{count} results"
89
91
  rescue => exn
90
- STDOUT.puts exn.inspect
91
- STDOUT.puts exn.backtrace
92
+ STDOUT.puts Rainbow("Error: #{exn}").red
93
+ STDOUT.puts "Backtrace:"
94
+ STDOUT.puts format_backtrace(exn.backtrace)
92
95
  end
93
96
  else
94
97
  puts_commands
@@ -2,6 +2,8 @@ module Querly
2
2
  class CLI
3
3
  module Formatter
4
4
  class Base
5
+ include Concerns::BacktraceFormatter
6
+
5
7
  # Called when analyzer started
6
8
  def start; end
7
9
 
@@ -26,7 +28,8 @@ module Querly
26
28
  # Abort(status != 0) after the call
27
29
  def fatal_error(error)
28
30
  STDERR.puts Rainbow("Fatal error: #{error}").red
29
- STDERR.puts error.backtrace.inspect
31
+ STDERR.puts "Backtrace:"
32
+ STDERR.puts format_backtrace(error.backtrace)
30
33
  end
31
34
 
32
35
  # Called on exit/abort
@@ -37,7 +40,8 @@ module Querly
37
40
  def config_error(path, error)
38
41
  STDERR.puts Rainbow("Failed to load configuration: #{path}").red
39
42
  STDERR.puts error
40
- STDERR.puts error.backtrace.inspect
43
+ STDERR.puts "Backtrace:"
44
+ STDERR.puts format_backtrace(error.backtrace)
41
45
  end
42
46
 
43
47
  def script_error(path, error)
data/lib/querly/cli.rb CHANGED
@@ -81,6 +81,11 @@ Specify configuration file by --config option.
81
81
  Rules.new(config_path: config_path, ids: ids).run
82
82
  end
83
83
 
84
+ desc "version", "Print version"
85
+ def version
86
+ puts "Querly #{VERSION}"
87
+ end
88
+
84
89
  private
85
90
 
86
91
  def config_path
@@ -0,0 +1,7 @@
1
+ module Concerns
2
+ module BacktraceFormatter
3
+ def format_backtrace(backtrace, indent: 2)
4
+ backtrace.map {|x| " "*indent + x }.join("\n")
5
+ end
6
+ end
7
+ end
@@ -9,7 +9,7 @@ module Querly
9
9
  module Pattern
10
10
  class Parser < Racc::Parser
11
11
 
12
- module_eval(<<'...end parser.y/module_eval...', 'parser.y', 101)
12
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 102)
13
13
 
14
14
  require "strscan"
15
15
 
@@ -113,116 +113,120 @@ end
113
113
  ##### State transition tables begin ###
114
114
 
115
115
  racc_action_table = [
116
- 55, -38, 29, 62, 71, 72, 73, 56, 57, 26,
117
- 71, -39, 56, 57, -37, -38, 41, 34, 40, 30,
118
- 30, -40, 42, 69, 70, 56, 57, 72, 73, 69,
119
- 70, 7, 18, 72, 73, 33, 6, 8, 9, 10,
120
- 11, 12, 13, 14, 15, 16, 17, 33, 19, 29,
121
- 61, 44, 18, 20, 22, 23, 6, 8, 9, 10,
122
- 11, 12, 13, 14, 15, 16, 17, 30, 19, 63,
123
- 46, 48, 64, 20, 51, 52, 7, 18, 66, 77,
124
- nil, 6, 8, 9, 10, 11, 12, 13, 14, 15,
125
- 16, 17, nil, 19, 29, nil, 7, 18, 20, 22,
116
+ -39, 29, -38, 29, 64, -39, 26, 59, -37, -38,
117
+ 34, 35, 34, 35, 74, 75, 39, 61, 38, 30,
118
+ -41, 30, -40, 44, 36, 34, 35, 34, 35, 36,
119
+ 34, 35, 34, 35, 34, 35, 7, 18, 20, 41,
120
+ 42, 6, 8, 9, 10, 11, 12, 13, 14, 15,
121
+ 16, 17, 30, 19, 46, 36, 48, 18, 20, 22,
126
122
  23, 6, 8, 9, 10, 11, 12, 13, 14, 15,
127
- 16, 17, 30, 19, 29, nil, 44, 18, 20, 22,
128
- 23, 6, 8, 9, 10, 11, 12, 13, 14, 15,
129
- 16, 17, 30, 19, nil, 46, 48, nil, 20, 51,
130
- 52, 7, 18, nil, 29, nil, 6, 8, 9, 10,
131
- 11, 12, 13, 14, 15, 16, 17, nil, 19, nil,
132
- 59, 7, 30, 20, 22, 23, 6, 8, 9, 10,
133
- 11, 12, 13, 14, 15, 16, 17, 35, 19, 29,
134
- nil, 7, 18, 20, 51, 52, 6, 8, 9, 10,
135
- 11, 12, 13, 14, 15, 16, 17, 30, 19, 20,
136
- 37, 38, -39, 20, 22, 23, 7, 18, nil, nil,
137
- nil, 6, 8, 9, 10, 11, 12, 13, 14, 15,
138
- 16, 17, -41, 19, nil, nil, 33, 7, 20, 22,
139
- 23, nil, 6, 8, 9, 10, 11, 12, 13, 14,
140
- 15, 16, 17, nil, 19, nil, nil, 44, 18, 20,
141
- 22, 23, 6, 8, 9, 10, 11, 12, 13, 14,
142
- 15, 16, 17, nil, 19, nil, 46, 48, nil, 20,
143
- 51, 52, 29, 27, 28, nil, nil, nil, nil, nil,
144
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
145
- 30 ]
123
+ 16, 17, 73, 19, 73, 50, 52, 63, 20, 55,
124
+ 56, 65, 66, 29, 29, 29, 68, 79, nil, nil,
125
+ nil, 71, 72, 71, 72, 74, 75, 74, 75, 7,
126
+ 18, 30, 30, 30, 6, 8, 9, 10, 11, 12,
127
+ 13, 14, 15, 16, 17, nil, 19, nil, nil, 7,
128
+ 18, 20, 22, 23, 6, 8, 9, 10, 11, 12,
129
+ 13, 14, 15, 16, 17, nil, 19, nil, nil, 48,
130
+ 18, 20, 22, 23, 6, 8, 9, 10, 11, 12,
131
+ 13, 14, 15, 16, 17, nil, 19, nil, 50, 52,
132
+ 7, 20, 55, 56, nil, 6, 8, 9, 10, 11,
133
+ 12, 13, 14, 15, 16, 17, nil, 19, nil, nil,
134
+ 7, 18, 20, 55, 56, 6, 8, 9, 10, 11,
135
+ 12, 13, 14, 15, 16, 17, nil, 19, nil, nil,
136
+ 7, nil, 20, 22, 23, 6, 8, 9, 10, 11,
137
+ 12, 13, 14, 15, 16, 17, nil, 19, nil, nil,
138
+ 7, 18, 20, 22, 23, 6, 8, 9, 10, 11,
139
+ 12, 13, 14, 15, 16, 17, nil, 19, nil, nil,
140
+ 7, 18, 20, 22, 23, 6, 8, 9, 10, 11,
141
+ 12, 13, 14, 15, 16, 17, nil, 19, nil, nil,
142
+ 48, 18, 20, 22, 23, 6, 8, 9, 10, 11,
143
+ 12, 13, 14, 15, 16, 17, 29, 19, nil, 50,
144
+ 52, nil, 20, 55, 56, 29, 27, 28, nil, nil,
145
+ 45, nil, nil, nil, 30, nil, nil, nil, nil, nil,
146
+ nil, nil, nil, 30 ]
146
147
 
147
148
  racc_action_check = [
148
- 39, 51, 32, 49, 61, 71, 71, 64, 64, 1,
149
- 62, 23, 77, 77, 21, 22, 32, 24, 26, 31,
150
- 32, 51, 33, 61, 61, 39, 39, 61, 61, 62,
151
- 62, 63, 63, 62, 62, 23, 63, 63, 63, 63,
152
- 63, 63, 63, 63, 63, 63, 63, 42, 63, 60,
153
- 48, 59, 59, 63, 63, 63, 59, 59, 59, 59,
154
- 59, 59, 59, 59, 59, 59, 59, 60, 59, 50,
155
- 59, 59, 53, 59, 59, 59, 66, 66, 58, 65,
156
- nil, 66, 66, 66, 66, 66, 66, 66, 66, 66,
157
- 66, 66, nil, 66, 78, nil, 69, 69, 66, 66,
158
- 66, 69, 69, 69, 69, 69, 69, 69, 69, 69,
159
- 69, 69, 78, 69, 79, nil, 34, 34, 69, 69,
160
- 69, 34, 34, 34, 34, 34, 34, 34, 34, 34,
161
- 34, 34, 79, 34, nil, 34, 34, nil, 34, 34,
162
- 34, 18, 18, nil, 45, nil, 18, 18, 18, 18,
163
- 18, 18, 18, 18, 18, 18, 18, nil, 18, nil,
164
- 45, 44, 45, 18, 18, 18, 44, 44, 44, 44,
165
- 44, 44, 44, 44, 44, 44, 44, 25, 44, 75,
166
- nil, 46, 46, 44, 44, 44, 46, 46, 46, 46,
167
- 46, 46, 46, 46, 46, 46, 46, 75, 46, 25,
168
- 25, 25, 52, 46, 46, 46, 0, 0, nil, nil,
169
- nil, 0, 0, 0, 0, 0, 0, 0, 0, 0,
170
- 0, 0, 52, 0, nil, nil, 52, 7, 0, 0,
171
- 0, nil, 7, 7, 7, 7, 7, 7, 7, 7,
172
- 7, 7, 7, nil, 7, nil, nil, 55, 55, 7,
173
- 7, 7, 55, 55, 55, 55, 55, 55, 55, 55,
174
- 55, 55, 55, nil, 55, nil, 55, 55, nil, 55,
175
- 55, 55, 3, 3, 3, nil, nil, nil, nil, nil,
176
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
177
- 3 ]
149
+ 56, 49, 55, 77, 53, 23, 1, 43, 21, 22,
150
+ 66, 66, 79, 79, 73, 73, 25, 49, 24, 49,
151
+ 56, 77, 55, 26, 56, 56, 56, 55, 55, 23,
152
+ 23, 23, 43, 43, 22, 22, 71, 71, 25, 25,
153
+ 25, 71, 71, 71, 71, 71, 71, 71, 71, 71,
154
+ 71, 71, 31, 71, 36, 46, 61, 61, 71, 71,
155
+ 71, 61, 61, 61, 61, 61, 61, 61, 61, 61,
156
+ 61, 61, 63, 61, 64, 61, 61, 52, 61, 61,
157
+ 61, 54, 57, 62, 80, 81, 60, 67, nil, nil,
158
+ nil, 63, 63, 64, 64, 63, 63, 64, 64, 65,
159
+ 65, 62, 80, 81, 65, 65, 65, 65, 65, 65,
160
+ 65, 65, 65, 65, 65, nil, 65, nil, nil, 68,
161
+ 68, 65, 65, 65, 68, 68, 68, 68, 68, 68,
162
+ 68, 68, 68, 68, 68, nil, 68, nil, nil, 38,
163
+ 38, 68, 68, 68, 38, 38, 38, 38, 38, 38,
164
+ 38, 38, 38, 38, 38, nil, 38, nil, 38, 38,
165
+ 48, 38, 38, 38, nil, 48, 48, 48, 48, 48,
166
+ 48, 48, 48, 48, 48, 48, nil, 48, nil, nil,
167
+ 50, 50, 48, 48, 48, 50, 50, 50, 50, 50,
168
+ 50, 50, 50, 50, 50, 50, nil, 50, nil, nil,
169
+ 7, nil, 50, 50, 50, 7, 7, 7, 7, 7,
170
+ 7, 7, 7, 7, 7, 7, nil, 7, nil, nil,
171
+ 0, 0, 7, 7, 7, 0, 0, 0, 0, 0,
172
+ 0, 0, 0, 0, 0, 0, nil, 0, nil, nil,
173
+ 18, 18, 0, 0, 0, 18, 18, 18, 18, 18,
174
+ 18, 18, 18, 18, 18, 18, nil, 18, nil, nil,
175
+ 59, 59, 18, 18, 18, 59, 59, 59, 59, 59,
176
+ 59, 59, 59, 59, 59, 59, 32, 59, nil, 59,
177
+ 59, nil, 59, 59, 59, 3, 3, 3, nil, nil,
178
+ 32, nil, nil, nil, 32, nil, nil, nil, nil, nil,
179
+ nil, nil, nil, 3 ]
178
180
 
179
181
  racc_action_pointer = [
180
- 204, 9, nil, 268, nil, nil, nil, 225, nil, nil,
181
- nil, nil, nil, nil, nil, nil, nil, nil, 139, nil,
182
- nil, 11, 12, 8, 14, 175, 18, nil, nil, nil,
183
- nil, -3, -2, -4, 114, nil, nil, nil, nil, -3,
184
- nil, nil, 20, nil, 159, 140, 179, nil, 30, -17,
185
- 46, -2, 199, 54, nil, 245, nil, nil, 55, 49,
186
- 45, 2, 8, 29, -21, 61, 74, nil, nil, 94,
187
- nil, -20, nil, nil, nil, 175, nil, -16, 90, 110,
188
- nil ]
182
+ 218, 6, nil, 281, nil, nil, nil, 198, nil, nil,
183
+ nil, nil, nil, nil, nil, nil, nil, nil, 238, nil,
184
+ nil, 5, 6, 2, 15, 14, 23, nil, nil, nil,
185
+ nil, 30, 272, nil, nil, nil, 28, nil, 137, nil,
186
+ nil, nil, nil, 4, nil, nil, 28, nil, 158, -3,
187
+ 178, nil, 57, -16, 58, -1, -3, 64, nil, 258,
188
+ 63, 54, 79, 70, 72, 97, -18, 69, 117, nil,
189
+ nil, 34, nil, -11, nil, nil, nil, -1, nil, -16,
190
+ 80, 81, nil ]
189
191
 
190
192
  racc_action_default = [
191
- -56, -56, -1, -2, -5, -6, -7, -36, -9, -10,
192
- -11, -12, -13, -14, -15, -16, -17, -18, -56, -20,
193
- -35, -45, -44, -42, -56, -56, -56, -3, -4, -51,
194
- -52, -8, -56, -56, -21, -36, -37, -38, -39, -53,
195
- 81, -19, -42, -43, -36, -22, -56, -25, -26, -31,
196
- -56, -44, -42, -56, -47, -21, -54, -55, -56, -21,
197
- -24, -28, -28, -56, -53, -56, -56, -23, -27, -56,
198
- -30, -56, -40, -41, -32, -33, -46, -53, -34, -29,
199
- -49 ]
193
+ -57, -57, -1, -2, -5, -6, -7, -36, -9, -10,
194
+ -11, -12, -13, -14, -15, -16, -17, -18, -57, -20,
195
+ -35, -46, -54, -42, -57, -57, -57, -3, -4, -52,
196
+ -53, -8, -57, -44, -55, -56, -57, -45, -21, -36,
197
+ -37, -38, -39, -54, 83, -19, -42, -43, -36, -22,
198
+ -57, -25, -26, -31, -57, -54, -42, -57, -48, -21,
199
+ -57, -21, -24, -28, -28, -57, -54, -57, -57, -23,
200
+ -27, -57, -30, -57, -40, -41, -32, -33, -47, -54,
201
+ -34, -29, -50 ]
200
202
 
201
203
  racc_goto_table = [
202
- 3, 54, 58, 53, 68, 74, 1, 31, 43, 36,
203
- 39, 2, nil, nil, nil, nil, nil, nil, 32, nil,
204
- nil, nil, nil, nil, 65, nil, 76, nil, 67, 58,
205
- nil, nil, nil, nil, nil, nil, nil, nil, nil, 80,
206
- nil, nil, nil, nil, 31, nil, 60, nil, nil, nil,
207
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
208
- nil, nil, nil, 75, nil, nil, 78, nil, nil, 79 ]
204
+ 3, 37, 60, 57, 70, 76, 1, 31, 47, 40,
205
+ 43, 2, nil, nil, nil, nil, nil, nil, 32, nil,
206
+ nil, 58, nil, nil, 67, nil, 69, 60, nil, nil,
207
+ nil, nil, nil, nil, 37, nil, nil, nil, nil, nil,
208
+ nil, nil, nil, nil, 78, nil, nil, nil, 31, nil,
209
+ 62, nil, nil, nil, nil, nil, nil, 82, nil, nil,
210
+ nil, nil, nil, nil, nil, 77, nil, nil, 80, nil,
211
+ nil, 81 ]
209
212
 
210
213
  racc_goto_check = [
211
214
  3, 12, 9, 6, 7, 7, 1, 3, 4, 10,
212
215
  11, 2, nil, nil, nil, nil, nil, nil, 3, nil,
213
- nil, nil, nil, nil, 6, nil, 12, nil, 6, 9,
214
- nil, nil, nil, nil, nil, nil, nil, nil, nil, 12,
215
- nil, nil, nil, nil, 3, nil, 3, nil, nil, nil,
216
- nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
217
- nil, nil, nil, 3, nil, nil, 3, nil, nil, 3 ]
216
+ nil, 12, nil, nil, 6, nil, 6, 9, nil, nil,
217
+ nil, nil, nil, nil, 12, nil, nil, nil, nil, nil,
218
+ nil, nil, nil, nil, 12, nil, nil, nil, 3, nil,
219
+ 3, nil, nil, nil, nil, nil, nil, 12, nil, nil,
220
+ nil, nil, nil, nil, nil, 3, nil, nil, 3, nil,
221
+ nil, 3 ]
218
222
 
219
223
  racc_goto_pointer = [
220
- nil, 6, 11, 0, -25, nil, -31, -57, nil, -42,
221
- -16, -15, -38, nil ]
224
+ nil, 6, 11, 0, -28, nil, -35, -59, nil, -46,
225
+ -16, -15, -22, nil ]
222
226
 
223
227
  racc_goto_default = [
224
- nil, nil, nil, 45, 4, 5, nil, 47, 49, 50,
225
- 21, 24, nil, 25 ]
228
+ nil, nil, nil, 49, 4, 5, nil, 51, 53, 54,
229
+ 21, 24, 33, 25 ]
226
230
 
227
231
  racc_reduce_table = [
228
232
  0, 0, :racc_error,
@@ -269,22 +273,23 @@ racc_reduce_table = [
269
273
  1, 39, :_reduce_none,
270
274
  1, 34, :_reduce_42,
271
275
  3, 34, :_reduce_43,
272
- 1, 35, :_reduce_44,
273
- 1, 35, :_reduce_45,
274
- 5, 35, :_reduce_46,
275
- 3, 35, :_reduce_47,
276
+ 2, 35, :_reduce_44,
277
+ 2, 35, :_reduce_45,
278
+ 1, 35, :_reduce_46,
279
+ 5, 35, :_reduce_47,
276
280
  3, 35, :_reduce_48,
277
- 6, 35, :_reduce_49,
281
+ 3, 35, :_reduce_49,
278
282
  6, 35, :_reduce_50,
279
- 2, 43, :_reduce_51,
283
+ 6, 35, :_reduce_51,
280
284
  2, 43, :_reduce_52,
281
- 0, 42, :_reduce_53,
282
- 1, 42, :_reduce_54,
283
- 1, 42, :_reduce_55 ]
285
+ 2, 43, :_reduce_53,
286
+ 0, 42, :_reduce_54,
287
+ 1, 42, :_reduce_55,
288
+ 1, 42, :_reduce_56 ]
284
289
 
285
- racc_reduce_n = 56
290
+ racc_reduce_n = 57
286
291
 
287
- racc_shift_n = 81
292
+ racc_shift_n = 83
288
293
 
289
294
  racc_token_table = {
290
295
  false => 0,
@@ -649,20 +654,27 @@ module_eval(<<'.,.,', 'parser.y', 65)
649
654
 
650
655
  module_eval(<<'.,.,', 'parser.y', 67)
651
656
  def _reduce_44(val, _values, result)
652
- result = Expr::Vcall.new(name: val[0])
657
+ result = val[1] != nil ? Expr::Send.new(receiver: Expr::Any.new, name: val[0], args: Argument::AnySeq.new, block: val[1]) : Expr::Vcall.new(name: val[0])
653
658
  result
654
659
  end
655
660
  .,.,
656
661
 
657
662
  module_eval(<<'.,.,', 'parser.y', 68)
658
663
  def _reduce_45(val, _values, result)
659
- result = Expr::Send.new(receiver: Expr::Any.new, name: val[0], block: nil)
664
+ result = Expr::Send.new(receiver: Expr::Any.new, name: val[0], block: val[1])
660
665
  result
661
666
  end
662
667
  .,.,
663
668
 
664
669
  module_eval(<<'.,.,', 'parser.y', 69)
665
670
  def _reduce_46(val, _values, result)
671
+ result = Expr::Send.new(receiver: Expr::Any.new, name: val[0], block: nil)
672
+ result
673
+ end
674
+ .,.,
675
+
676
+ module_eval(<<'.,.,', 'parser.y', 70)
677
+ def _reduce_47(val, _values, result)
666
678
  result = Expr::Send.new(receiver: Expr::Any.new,
667
679
  name: val[0],
668
680
  args: val[2],
@@ -671,8 +683,8 @@ module_eval(<<'.,.,', 'parser.y', 69)
671
683
  end
672
684
  .,.,
673
685
 
674
- module_eval(<<'.,.,', 'parser.y', 73)
675
- def _reduce_47(val, _values, result)
686
+ module_eval(<<'.,.,', 'parser.y', 74)
687
+ def _reduce_48(val, _values, result)
676
688
  result = Expr::Send.new(receiver: val[0],
677
689
  name: val[1],
678
690
  args: Argument::AnySeq.new,
@@ -681,8 +693,8 @@ module_eval(<<'.,.,', 'parser.y', 73)
681
693
  end
682
694
  .,.,
683
695
 
684
- module_eval(<<'.,.,', 'parser.y', 77)
685
- def _reduce_48(val, _values, result)
696
+ module_eval(<<'.,.,', 'parser.y', 78)
697
+ def _reduce_49(val, _values, result)
686
698
  result = Expr::Send.new(receiver: val[0],
687
699
  name: val[1],
688
700
  args: Argument::AnySeq.new,
@@ -691,8 +703,8 @@ module_eval(<<'.,.,', 'parser.y', 77)
691
703
  end
692
704
  .,.,
693
705
 
694
- module_eval(<<'.,.,', 'parser.y', 81)
695
- def _reduce_49(val, _values, result)
706
+ module_eval(<<'.,.,', 'parser.y', 82)
707
+ def _reduce_50(val, _values, result)
696
708
  result = Expr::Send.new(receiver: val[0],
697
709
  name: val[1],
698
710
  args: val[3],
@@ -701,8 +713,8 @@ module_eval(<<'.,.,', 'parser.y', 81)
701
713
  end
702
714
  .,.,
703
715
 
704
- module_eval(<<'.,.,', 'parser.y', 85)
705
- def _reduce_50(val, _values, result)
716
+ module_eval(<<'.,.,', 'parser.y', 86)
717
+ def _reduce_51(val, _values, result)
706
718
  result = Expr::Send.new(receiver: val[0],
707
719
  name: val[1],
708
720
  args: val[3],
@@ -711,36 +723,36 @@ module_eval(<<'.,.,', 'parser.y', 85)
711
723
  end
712
724
  .,.,
713
725
 
714
- module_eval(<<'.,.,', 'parser.y', 90)
715
- def _reduce_51(val, _values, result)
726
+ module_eval(<<'.,.,', 'parser.y', 91)
727
+ def _reduce_52(val, _values, result)
716
728
  result = val[0]
717
729
  result
718
730
  end
719
731
  .,.,
720
732
 
721
- module_eval(<<'.,.,', 'parser.y', 91)
722
- def _reduce_52(val, _values, result)
733
+ module_eval(<<'.,.,', 'parser.y', 92)
734
+ def _reduce_53(val, _values, result)
723
735
  result = Expr::ReceiverContext.new(receiver: val[0])
724
736
  result
725
737
  end
726
738
  .,.,
727
739
 
728
- module_eval(<<'.,.,', 'parser.y', 93)
729
- def _reduce_53(val, _values, result)
740
+ module_eval(<<'.,.,', 'parser.y', 94)
741
+ def _reduce_54(val, _values, result)
730
742
  result = nil
731
743
  result
732
744
  end
733
745
  .,.,
734
746
 
735
- module_eval(<<'.,.,', 'parser.y', 94)
736
- def _reduce_54(val, _values, result)
747
+ module_eval(<<'.,.,', 'parser.y', 95)
748
+ def _reduce_55(val, _values, result)
737
749
  result = true
738
750
  result
739
751
  end
740
752
  .,.,
741
753
 
742
- module_eval(<<'.,.,', 'parser.y', 95)
743
- def _reduce_55(val, _values, result)
754
+ module_eval(<<'.,.,', 'parser.y', 96)
755
+ def _reduce_56(val, _values, result)
744
756
  result = false
745
757
  result
746
758
  end
@@ -65,7 +65,8 @@ keyword: LIDENT | UIDENT
65
65
  constant: UIDENT { result = [val[0]] }
66
66
  | UIDENT COLONCOLON constant { result = [val[0]] + val[2] }
67
67
 
68
- send: LIDENT { result = Expr::Vcall.new(name: val[0]) }
68
+ send: LIDENT block { result = val[1] != nil ? Expr::Send.new(receiver: Expr::Any.new, name: val[0], args: Argument::AnySeq.new, block: val[1]) : Expr::Vcall.new(name: val[0]) }
69
+ | UIDENT block { result = Expr::Send.new(receiver: Expr::Any.new, name: val[0], block: val[1]) }
69
70
  | method_name { result = Expr::Send.new(receiver: Expr::Any.new, name: val[0], block: nil) }
70
71
  | method_name_or_ident LPAREN args RPAREN block { result = Expr::Send.new(receiver: Expr::Any.new,
71
72
  name: val[0],
data/lib/querly/rule.rb CHANGED
@@ -38,6 +38,7 @@ module Querly
38
38
  end
39
39
 
40
40
  class InvalidRuleHashError < StandardError; end
41
+ class PatternSyntaxError < StandardError; end
41
42
 
42
43
  def self.load(hash)
43
44
  id = hash["id"]
@@ -45,7 +46,13 @@ module Querly
45
46
 
46
47
  srcs = Array(hash["pattern"])
47
48
  raise InvalidRuleHashError, "pattern is missing" if srcs.empty?
48
- patterns = srcs.map {|src| Pattern::Parser.parse(src) }
49
+ patterns = srcs.map.with_index do |src, index|
50
+ begin
51
+ Pattern::Parser.parse(src)
52
+ rescue Racc::ParseError => exn
53
+ raise PatternSyntaxError, "Pattern syntax error: rule=#{hash["id"]}, index=#{index}, pattern=#{Rainbow(src.split("\n").first).blue}: #{exn}"
54
+ end
55
+ end
49
56
 
50
57
  messages = Array(hash["message"])
51
58
  raise InvalidRuleHashError, "message is missing" if messages.empty?
@@ -1,3 +1,3 @@
1
1
  module Querly
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0.beta.1"
3
3
  end
data/lib/querly.rb CHANGED
@@ -20,6 +20,7 @@ require 'querly/pattern/kind'
20
20
  require "querly/config"
21
21
  require "querly/preprocessor"
22
22
  require "querly/check"
23
+ require "querly/concerns/backtrace_formatter"
23
24
 
24
25
  module Querly
25
26
  # Your code goes here...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: querly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2017-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -151,6 +151,7 @@ files:
151
151
  - lib/querly/cli/formatter.rb
152
152
  - lib/querly/cli/rules.rb
153
153
  - lib/querly/cli/test.rb
154
+ - lib/querly/concerns/backtrace_formatter.rb
154
155
  - lib/querly/config.rb
155
156
  - lib/querly/node_pair.rb
156
157
  - lib/querly/pattern/argument.rb
@@ -180,12 +181,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
181
  version: '0'
181
182
  required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  requirements:
183
- - - ">="
184
+ - - ">"
184
185
  - !ruby/object:Gem::Version
185
- version: '0'
186
+ version: 1.3.1
186
187
  requirements: []
187
188
  rubyforge_project:
188
- rubygems_version: 2.5.1
189
+ rubygems_version: 2.6.8
189
190
  signing_key:
190
191
  specification_version: 4
191
192
  summary: Pattern Based Checking Tool for Ruby