anbt-sql-formatter 0.1.1 → 0.1.2
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/CHANGELOG.md +24 -0
- data/anbt-sql-formatter.gemspec +0 -1
- data/bin/anbt-sql-formatter +0 -1
- data/lib/anbt-sql-formatter/coarse-tokenizer.rb +0 -2
- data/lib/anbt-sql-formatter/constants.rb +2 -3
- data/lib/anbt-sql-formatter/exception.rb +0 -2
- data/lib/anbt-sql-formatter/formatter.rb +10 -21
- data/lib/anbt-sql-formatter/parser.rb +2 -4
- data/lib/anbt-sql-formatter/rule.rb +0 -2
- data/lib/anbt-sql-formatter/token.rb +0 -2
- data/lib/anbt-sql-formatter/version.rb +1 -1
- data/misc/anbt-sql-formatter-customize-example +2 -3
- data/test/helper.rb +2 -2
- data/test/test_coarse-tokenizer.rb +0 -2
- data/test/test_formatter.rb +0 -2
- data/test/test_helper.rb +0 -2
- data/test/test_in_values.rb +0 -2
- data/test/test_parser.rb +0 -2
- data/test/test_rule.rb +0 -2
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84e2831d39ea0a114b7dd67a1ad69be88df0a575f017c6e9ec16ed87cdc8597b
|
4
|
+
data.tar.gz: b7f86dd15c4c5b421035f39b4f7bff403305e1f2f0ebd84eed5644b5be57e7a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b928f9e74ae4139c3f1408c6727832e352b2f78ad5479f38eb5959817c405f936faab338620536ac7c2a94dc931e839e3e58e2b460922e64fbb8da805d74aff
|
7
|
+
data.tar.gz: b978f80c52d14d067c150e48992dc81eaafc948d1103ff12fade72bb3d1f6835af86532393e658b5856dd75ee3d3dc03cf9498a01b66379011a09ffb9adc87cc
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
# 0.1.2 (2025-01-xx)
|
2
|
+
|
3
|
+
## Breaking changes
|
4
|
+
|
5
|
+
- Changed to exclusive branching to reduce complexity (`Formatter#format_list_main_loop`).
|
6
|
+
- If you have not customized the rules, there will be no change in behavior.
|
7
|
+
- This likely applies to most users.
|
8
|
+
- If you have customized the rules such that keywords overlap between conditions of the branches,
|
9
|
+
this update may change the behavior.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# Example of customization that may change behavior:
|
13
|
+
|
14
|
+
custom_rule = AnbtSql::Rule.new
|
15
|
+
custom_rule.kw_nl_x << "SOME_CUSTOM_KEYWORD"
|
16
|
+
custom_rule.kw_nl_x_plus1_indent << "SOME_CUSTOM_KEYWORD"
|
17
|
+
```
|
18
|
+
|
19
|
+
## Improvements
|
20
|
+
|
21
|
+
- Some cleanups, formatting improvements
|
22
|
+
- cleanup: Remove encoding magic comments
|
23
|
+
|
24
|
+
|
1
25
|
# 0.1.1 (2025-01-12)
|
2
26
|
|
3
27
|
No breaking changes.
|
data/anbt-sql-formatter.gemspec
CHANGED
data/bin/anbt-sql-formatter
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
=begin rdoc
|
4
2
|
AnbtSqlFormatter: SQL整形ツール. SQL文を決められたルールに従い整形します。
|
5
3
|
|
@@ -76,6 +74,7 @@ class AnbtSql
|
|
76
74
|
"ORDINALITY", "OUT", "PARAMETER", "PARAMETERS", "PATH", "POSTFIX",
|
77
75
|
"PREFIX", "PREORDER", "RAW", "READS", "RECURSIVE", "REDO",
|
78
76
|
# ANSI SQLではないのだが とても良く使われる構文
|
79
|
-
"TRUNCATE"
|
77
|
+
"TRUNCATE"
|
78
|
+
]
|
80
79
|
end
|
81
80
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
require "anbt-sql-formatter/rule"
|
4
2
|
require "anbt-sql-formatter/parser"
|
5
3
|
require "anbt-sql-formatter/exception"
|
@@ -222,56 +220,47 @@ class AnbtSql
|
|
222
220
|
equals_ignore_case(token.string, "UPDATE") )
|
223
221
|
indent += 2
|
224
222
|
index += insert_return_and_indent(tokens, index + 1, indent, "+2")
|
225
|
-
end
|
226
223
|
|
227
224
|
# indentを1つ増やし、キーワードの後ろで改行
|
228
|
-
|
225
|
+
elsif @rule.kw_plus1_indent_x_nl.any?{ |kw| equals_ignore_case(token.string, kw) }
|
229
226
|
indent += 1
|
230
227
|
index += insert_return_and_indent(tokens, index + 1, indent)
|
231
|
-
end
|
232
228
|
|
233
229
|
# キーワードの前でindentを1つ減らして改行、キーワードの後ろでindentを戻して改行。
|
234
|
-
|
230
|
+
elsif @rule.kw_minus1_indent_nl_x_plus1_indent.any?{ |kw| equals_ignore_case(token.string, kw) }
|
235
231
|
index += insert_return_and_indent(tokens, index , indent - 1)
|
236
232
|
index += insert_return_and_indent(tokens, index + 1, indent )
|
237
|
-
end
|
238
233
|
|
239
234
|
# キーワードの前でindentを1つ減らして改行、キーワードの後ろでindentを戻して改行。
|
240
|
-
|
235
|
+
elsif (equals_ignore_case(token.string, "VALUES"))
|
241
236
|
indent -= 1
|
242
237
|
index += insert_return_and_indent(tokens, index, indent)
|
243
|
-
end
|
244
238
|
|
245
239
|
# キーワードの前でindentを1つ減らして改行
|
246
|
-
|
240
|
+
elsif (equals_ignore_case(token.string, "END"))
|
247
241
|
indent -= 1
|
248
242
|
index += insert_return_and_indent(tokens, index, indent)
|
249
|
-
end
|
250
243
|
|
251
244
|
# キーワードの前で改行
|
252
|
-
|
245
|
+
elsif @rule.kw_nl_x.any?{ |kw| equals_ignore_case(token.string, kw) }
|
253
246
|
index += insert_return_and_indent(tokens, index, indent)
|
254
|
-
end
|
255
247
|
|
256
248
|
# キーワードの前で改行, インデント+1
|
257
|
-
|
249
|
+
elsif @rule.kw_nl_x_plus1_indent.any?{ |kw| equals_ignore_case(token.string, kw) }
|
258
250
|
index += insert_return_and_indent(tokens, index, indent + 1)
|
259
|
-
end
|
260
251
|
|
261
252
|
# キーワードの前で改行。indentを強制的に0にする。
|
262
|
-
|
253
|
+
elsif (equals_ignore_case(token.string, "UNION" ) ||
|
263
254
|
equals_ignore_case(token.string, "INTERSECT") ||
|
264
255
|
equals_ignore_case(token.string, "EXCEPT" ) )
|
265
256
|
indent -= 2
|
266
257
|
index += insert_return_and_indent(tokens, index , indent)
|
267
258
|
index += insert_return_and_indent(tokens, index + 1, indent)
|
268
|
-
end
|
269
259
|
|
270
|
-
|
260
|
+
elsif equals_ignore_case(token.string, "BETWEEN")
|
271
261
|
encounter_between = true
|
272
|
-
end
|
273
262
|
|
274
|
-
|
263
|
+
elsif equals_ignore_case(token.string, "AND")
|
275
264
|
# BETWEEN のあとのANDは改行しない。
|
276
265
|
if not encounter_between
|
277
266
|
index += insert_return_and_indent(tokens, index, indent)
|
@@ -395,7 +384,7 @@ class AnbtSql
|
|
395
384
|
if $DEBUG
|
396
385
|
$stderr.puts e.message, e.backtrace
|
397
386
|
$stderr.puts "tokens: "
|
398
|
-
tokens.each_with_index{|t,i|
|
387
|
+
tokens.each_with_index{|t, i|
|
399
388
|
$stderr.puts "index=%d: %s" % [i, t.inspect]
|
400
389
|
}
|
401
390
|
$stderr.puts "index/size: %d/%d / indent: %d / opt: %s" % [index, tokens.size, indent, opt]
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
1
|
require "pp"
|
4
2
|
|
5
3
|
require "anbt-sql-formatter/token"
|
@@ -67,7 +65,7 @@ class AnbtSql
|
|
67
65
|
# これ以降の文字の扱いは保留
|
68
66
|
def symbol?(c)
|
69
67
|
%w(" ? % & ' \( \) | * + , - . / : ; < = > !).include? c
|
70
|
-
#"
|
68
|
+
# "
|
71
69
|
end
|
72
70
|
|
73
71
|
|
@@ -160,7 +158,7 @@ class AnbtSql
|
|
160
158
|
|
161
159
|
# 2文字の記号かどうか調べる
|
162
160
|
ch2 = char_at(@before, @pos)
|
163
|
-
#for (int i = 0; i < two_character_symbol.length; i++) {
|
161
|
+
# for (int i = 0; i < two_character_symbol.length; i++) {
|
164
162
|
for i in 0...@two_character_symbol.length
|
165
163
|
if (char_at(@two_character_symbol[i], 0) == @char &&
|
166
164
|
char_at(@two_character_symbol[i], 1) == ch2)
|
@@ -1,5 +1,4 @@
|
|
1
1
|
#! /usr/bin/ruby
|
2
|
-
# -*- coding: utf-8 -*-
|
3
2
|
|
4
3
|
require "pp"
|
5
4
|
|
@@ -55,8 +54,8 @@ if $0 == __FILE__
|
|
55
54
|
rule.function_names << func_name.upcase
|
56
55
|
}
|
57
56
|
|
58
|
-
#rule.indent_string = " "
|
59
|
-
#rule.indent_string = "('-')"
|
57
|
+
# rule.indent_string = " "
|
58
|
+
# rule.indent_string = "('-')"
|
60
59
|
rule.indent_string = "| "
|
61
60
|
|
62
61
|
formatter = AnbtSql::Formatter.new(rule)
|
data/test/helper.rb
CHANGED
data/test/test_formatter.rb
CHANGED
data/test/test_helper.rb
CHANGED
data/test/test_in_values.rb
CHANGED
data/test/test_parser.rb
CHANGED
data/test/test_rule.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anbt-sql-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sonota88
|
8
|
+
autorequire:
|
8
9
|
bindir: bin
|
9
10
|
cert_chain: []
|
10
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-26 00:00:00.000000000 Z
|
11
12
|
dependencies:
|
12
13
|
- !ruby/object:Gem::Dependency
|
13
14
|
name: test-unit
|
@@ -66,6 +67,7 @@ files:
|
|
66
67
|
homepage: https://github.com/sonota88/anbt-sql-formatter
|
67
68
|
licenses: []
|
68
69
|
metadata: {}
|
70
|
+
post_install_message:
|
69
71
|
rdoc_options: []
|
70
72
|
require_paths:
|
71
73
|
- lib
|
@@ -80,7 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
82
|
- !ruby/object:Gem::Version
|
81
83
|
version: '0'
|
82
84
|
requirements: []
|
83
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.4.19
|
86
|
+
signing_key:
|
84
87
|
specification_version: 4
|
85
88
|
summary: A tool for SQL formatting written in Ruby.
|
86
89
|
test_files: []
|