querly 0.15.1 → 0.16.0

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
  SHA256:
3
- metadata.gz: 667d28c47f1169482de3e65425249fd1e9ca2593876fe13c8661558b1a588151
4
- data.tar.gz: b0d6025b7fcb82b6933b020d080b28f8ef6e5637b9096fbd9d9e806cf5e1177f
3
+ metadata.gz: c34b195fa9bb5ccf96c35fe740b783b3567c137a664949e65c84b6d7980f1270
4
+ data.tar.gz: 47a16a78713ababe10ae4ec8f51aed46b5b750288cff22ffbf7114ba980a8d6e
5
5
  SHA512:
6
- metadata.gz: cf4b1ce23c783b45e54369cfe5372d4be44bf516db2a9938f898d376706b832d3618d7940ed0f78135a565bd853a8707068390df71a1a8c41fdbc8581fec3e49
7
- data.tar.gz: 66cdc533c9a98c0a9cd9139a1f015225bc1d33ecb44c066c65b46c2ca608c80a37d6b31aec3dd7e1837a7684f7307e93e7acfe0be2c378fd9d994ac7cb213489
6
+ metadata.gz: d612449bfd38faca312aaec2cd6e8e420ff3ac5ee41fa8d1d84c94b5413e5121b4ff49f559b193c4a23f54e1d70c95f4e36d665c31515093acb297c18cd7eed0
7
+ data.tar.gz: c61989656fb5d91872f4a684339aa5d3f6b83af89b39d73c8cf0b1422d7f2c1833bb788f0c27bb5f78d5f76eeabd3e455ebcbdd6dcd5339066b0ccb03a844691
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.16.0 (2019-04-23)
6
+
7
+ * Support string literal pattern (@pocke) [#64](https://github.com/soutaro/querly/pull/64)
8
+ * Allow underscore method name pattern (@pocke) [#63](https://github.com/soutaro/querly/pull/63)
9
+ * Add erb support (@hanachin) [#61](https://github.com/soutaro/querly/pull/61)
10
+ * Add `exit` command on console (@wata727) [#59](https://github.com/soutaro/querly/pull/59)
11
+
5
12
  ## 0.15.1 (2019-03-12)
6
13
 
7
14
  * Relax parser version requirement
@@ -60,7 +60,7 @@ Querly #{VERSION}, interactive console
60
60
  def start_loop
61
61
  while line = Readline.readline("> ", true)
62
62
  case line
63
- when "quit"
63
+ when "quit", "exit"
64
64
  exit
65
65
  when "reload!"
66
66
  STDOUT.print "reloading..."
@@ -72,7 +72,7 @@ keyword: LIDENT | UIDENT
72
72
  constant: UIDENT { result = [val[0]] }
73
73
  | UIDENT COLONCOLON constant { result = [val[0]] + val[2] }
74
74
 
75
- send: LIDENT block { result = val[1] != nil ? Expr::Send.new(receiver: nil, name: val[0], args: Argument::AnySeq.new, block: val[1]) : Expr::Vcall.new(name: val[0]) }
75
+ send: LIDENT block { result = val[1] != nil ? Expr::Send.new(receiver: nil, name: val[0], block: val[1]) : Expr::Vcall.new(name: val[0]) }
76
76
  | UIDENT block { result = Expr::Send.new(receiver: nil, name: val[0], block: val[1]) }
77
77
  | method_name { result = Expr::Send.new(receiver: nil, name: val[0], block: nil) }
78
78
  | method_name_or_ident LPAREN args RPAREN block { result = Expr::Send.new(receiver: nil,
@@ -83,18 +83,15 @@ send: LIDENT block { result = val[1] != nil ? Expr::Send.new(receiver: nil, name
83
83
  name: val[1],
84
84
  args: Argument::AnySeq.new,
85
85
  block: val[2]) }
86
- | receiver method_name_or_ident block { result = Expr::Send.new(receiver: val[0],
87
- name: val[1],
88
- args: Argument::AnySeq.new,
89
- block: val[2]) }
90
- | receiver method_name_or_ident LPAREN args RPAREN block { result = Expr::Send.new(receiver: val[0],
91
- name: val[1],
92
- args: val[3],
93
- block: val[5]) }
94
86
  | receiver method_name_or_ident LPAREN args RPAREN block { result = Expr::Send.new(receiver: val[0],
95
87
  name: val[1],
96
88
  args: val[3],
97
89
  block: val[5]) }
90
+ | receiver UNDERBAR block { result = Expr::Send.new(receiver: val[0], name: /.+/, block: val[2]) }
91
+ | receiver UNDERBAR LPAREN args RPAREN block { result = Expr::Send.new(receiver: val[0],
92
+ name: /.+/,
93
+ args: val[3],
94
+ block: val[5]) }
98
95
 
99
96
  receiver: expr DOT { result = val[0] }
100
97
  | expr DOTDOTDOT { result = Expr::ReceiverContext.new(receiver: val[0]) }
@@ -136,6 +133,8 @@ def next_token
136
133
  [:NIL, false]
137
134
  when input.scan(/:string:/)
138
135
  [:STRING, nil]
136
+ when input.scan(/"([^"]+)"/)
137
+ [:STRING, input[1]]
139
138
  when input.scan(/:dstr:/)
140
139
  [:DSTR, nil]
141
140
  when input.scan(/:int:/)
@@ -42,7 +42,7 @@ module Querly
42
42
  end
43
43
 
44
44
  def run
45
- available_commands = [:haml]
45
+ available_commands = [:haml, :erb]
46
46
 
47
47
  if available_commands.include?(command)
48
48
  send :"run_#{command}"
@@ -70,6 +70,24 @@ module Querly
70
70
  stdout.print compiler.precompiled
71
71
  end
72
72
  end
73
+
74
+ def run_erb
75
+ require 'better_html'
76
+ require 'better_html/parser'
77
+ load_libs
78
+ source = stdin.read
79
+ source_buffer = Parser::Source::Buffer.new('(erb)')
80
+ source_buffer.source = source
81
+ parser = BetterHtml::Parser.new(source_buffer, template_language: :html)
82
+
83
+ new_source = source.gsub(/./, ' ')
84
+ parser.ast.descendants(:erb).each do |erb_node|
85
+ _, _, code_node, = *erb_node
86
+ new_source[code_node.loc.range] = code_node.loc.source
87
+ new_source[code_node.loc.range.end] = ';'
88
+ end
89
+ stdout.puts new_source
90
+ end
73
91
  end
74
92
  end
75
93
  end
@@ -3,6 +3,16 @@ module Querly
3
3
  attr_reader :path
4
4
  attr_reader :node
5
5
 
6
+ def self.load(path:, source:)
7
+ parser = Parser::Ruby25.new(Builder.new).tap do |parser|
8
+ parser.diagnostics.all_errors_are_fatal = true
9
+ parser.diagnostics.ignore_warnings = true
10
+ end
11
+ buffer = Parser::Source::Buffer.new(path.to_s, 1)
12
+ buffer.source = source
13
+ self.new(path: path, node: parser.parse(buffer))
14
+ end
15
+
6
16
  def initialize(path:, node:)
7
17
  @path = path
8
18
  @node = node
@@ -11,5 +21,15 @@ module Querly
11
21
  def root_pair
12
22
  NodePair.new(node: node)
13
23
  end
24
+
25
+ class Builder < Parser::Builders::Default
26
+ def string_value(token)
27
+ value(token)
28
+ end
29
+
30
+ def emit_lambda
31
+ true
32
+ end
33
+ end
14
34
  end
15
35
  end
@@ -45,9 +45,7 @@ module Querly
45
45
  path.read
46
46
  end
47
47
 
48
- buffer = Parser::Source::Buffer.new(path.to_s, 1)
49
- buffer.source = source
50
- script = Script.new(path: path, node: parser.parse(buffer))
48
+ script = Script.load(path: path, source: source)
51
49
  rescue StandardError, LoadError, Preprocessor::Error => exn
52
50
  script = exn
53
51
  end
@@ -55,13 +53,6 @@ module Querly
55
53
  yield(path, script)
56
54
  end
57
55
 
58
- def parser
59
- Parser::Ruby25.new(Builder.new).tap do |parser|
60
- parser.diagnostics.all_errors_are_fatal = true
61
- parser.diagnostics.ignore_warnings = true
62
- end
63
- end
64
-
65
56
  def preprocessors
66
57
  config&.preprocessors || {}
67
58
  end
@@ -101,15 +92,5 @@ module Querly
101
92
  load_script_from_path(path, &block) if should_load_file
102
93
  end
103
94
  end
104
-
105
- class Builder < Parser::Builders::Default
106
- def string_value(token)
107
- value(token)
108
- end
109
-
110
- def emit_lambda
111
- true
112
- end
113
- end
114
95
  end
115
96
  end
@@ -1,3 +1,3 @@
1
1
  module Querly
2
- VERSION = "0.15.1"
2
+ VERSION = "0.16.0"
3
3
  end
@@ -71,6 +71,8 @@ bar.foo.baz # foo...bar...baz does not match
71
71
  * `1.23` (float)
72
72
  * `:foobar` (symbol)
73
73
  * `:symbol:` (any symbol literal)
74
+ * `"foobar"` (string)
75
+ * NOTE: It only supports double quotation.
74
76
  * `:string:` (any string literal)
75
77
  * `:dstr:` (any dstr `"hi #{name}"`)
76
78
  * `true`, `false` (true and false)
@@ -145,9 +147,9 @@ end
145
147
 
146
148
  # Interpolation Syntax
147
149
 
148
- If you want to describe a pattern that can not be described with adove syntax, you can use interpolation as follows:
150
+ If you want to describe a pattern that can not be described with above syntax, you can use interpolation as follows:
149
151
 
150
- ```rb
152
+ ```yaml
151
153
  id: find_by_abc_and_def
152
154
  pattern:
153
155
  subject: "'finder(...)"
@@ -164,6 +166,16 @@ It matches with `find_by_email_and_name(...)`.
164
166
  - If value of meta var is a string `foo`, it matches send nodes with exactly same method name
165
167
  - If value of meta var is a regexp `/foo/`, it matches send nodes with method name which `=~` the regexp
166
168
 
169
+ You can also use `as` syntax with `:symbol:` and so on.
170
+
171
+ ```yaml
172
+ id: migration_references
173
+ pattern:
174
+ subject: "t.integer(:symbol: as 'column, ...)"
175
+ where:
176
+ column: '/.+_id/'
177
+ ```
178
+
167
179
  # Difference from Ruby
168
180
 
169
181
  * Method call parenthesis cannot be omitted (if omitted, it means *any arguments*)
@@ -25,8 +25,11 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", ">= 1.12"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "minitest", "~> 5.0"
28
- spec.add_development_dependency "racc", "= 1.4.14"
28
+ spec.add_development_dependency "racc", ">= 1.4.14"
29
29
  spec.add_development_dependency "unification_assertion", "0.0.1"
30
+ spec.add_development_dependency "better_html", "~> 1.0.13"
31
+ spec.add_development_dependency "slim", "~> 4.0.1"
32
+ spec.add_development_dependency "haml", "~> 5.0.4"
30
33
 
31
34
  spec.add_dependency 'thor', ">= 0.19.0", "< 0.21.0"
32
35
  spec.add_dependency "parser", ">= 2.5.0"
@@ -146,6 +146,8 @@ rules:
146
146
 
147
147
  preprocessor:
148
148
  .slim: slimrb --compile
149
+ .haml: querly-pp haml
150
+ .erb: querly-pp erb
149
151
 
150
152
  import:
151
153
  - load: querly/rules/*.yml
@@ -58,7 +58,9 @@ rules:
58
58
  assert_empty some.count
59
59
 
60
60
  preprocessor:
61
- .slim: slimrb --compile
61
+ # .slim: slimrb --compile # Install `slim` gem for slim support
62
+ # .erb: querly-pp erb # Install `better_erb` gem for erb support
63
+ # .haml: querly-pp haml # Install `haml` gem for haml support
62
64
 
63
65
  check:
64
66
  - path: /
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.15.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-12 00:00:00.000000000 Z
11
+ date: 2019-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,14 +56,14 @@ dependencies:
56
56
  name: racc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.4.14
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.4.14
69
69
  - !ruby/object:Gem::Dependency
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: better_html
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.13
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.13
97
+ - !ruby/object:Gem::Dependency
98
+ name: slim
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.0.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.0.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: haml
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 5.0.4
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 5.0.4
83
125
  - !ruby/object:Gem::Dependency
84
126
  name: thor
85
127
  requirement: !ruby/object:Gem::Requirement