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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/querly/cli/console.rb +1 -1
- data/lib/querly/pattern/parser.y +8 -9
- data/lib/querly/pp/cli.rb +19 -1
- data/lib/querly/script.rb +20 -0
- data/lib/querly/script_enumerator.rb +1 -20
- data/lib/querly/version.rb +1 -1
- data/manual/patterns.md +14 -2
- data/querly.gemspec +4 -1
- data/sample.yaml +2 -0
- data/template.yml +3 -1
- metadata +46 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c34b195fa9bb5ccf96c35fe740b783b3567c137a664949e65c84b6d7980f1270
|
4
|
+
data.tar.gz: 47a16a78713ababe10ae4ec8f51aed46b5b750288cff22ffbf7114ba980a8d6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d612449bfd38faca312aaec2cd6e8e420ff3ac5ee41fa8d1d84c94b5413e5121b4ff49f559b193c4a23f54e1d70c95f4e36d665c31515093acb297c18cd7eed0
|
7
|
+
data.tar.gz: c61989656fb5d91872f4a684339aa5d3f6b83af89b39d73c8cf0b1422d7f2c1833bb788f0c27bb5f78d5f76eeabd3e455ebcbdd6dcd5339066b0ccb03a844691
|
data/CHANGELOG.md
CHANGED
@@ -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
|
data/lib/querly/cli/console.rb
CHANGED
data/lib/querly/pattern/parser.y
CHANGED
@@ -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],
|
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:/)
|
data/lib/querly/pp/cli.rb
CHANGED
@@ -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
|
data/lib/querly/script.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/querly/version.rb
CHANGED
data/manual/patterns.md
CHANGED
@@ -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
|
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
|
-
```
|
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*)
|
data/querly.gemspec
CHANGED
@@ -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", "
|
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"
|
data/sample.yaml
CHANGED
data/template.yml
CHANGED
@@ -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.
|
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-
|
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
|