tsql_parser 0.0.1 → 0.0.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/lib/parsing/formatter.rb +3 -3
- data/lib/parsing/keyword.rb +2 -2
- data/lib/parsing/text_formatter.rb +14 -8
- 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: 261c5aa051e63968deb877640c812121e3898cccdd71a60aebed350f7cbc2cd2
|
4
|
+
data.tar.gz: e15cae8c9e0616deafc9d0ccefd5e4414c2653e673722d1995d7b27c24ad114c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 508119aff4af84168665d355bbc154232a4a98d713728adcd18495435fdc39fdb8868cde5cbccb2e570fc7c587f92e295d137f04b3c765aa99945974723c516f
|
7
|
+
data.tar.gz: 3888919f8554c94e596f567ac085ecde9316b32244781b30600a1c6d1a4d0bd47cc6e824bbbf110b084fe4ed392fdf552d2f587f9075938a1881bc2ea623a049
|
data/lib/parsing/formatter.rb
CHANGED
@@ -48,7 +48,7 @@ module TSqlParser::Parsing
|
|
48
48
|
new_lines << ""
|
49
49
|
next
|
50
50
|
end
|
51
|
-
if
|
51
|
+
if Parser.is_newline_required? first or first.start_with? "/*"
|
52
52
|
new_lines << ""
|
53
53
|
end
|
54
54
|
new_lines << line
|
@@ -64,7 +64,7 @@ module TSqlParser::Parsing
|
|
64
64
|
end
|
65
65
|
sub_one = false
|
66
66
|
work_lines = work_lines.flatten
|
67
|
-
last =
|
67
|
+
last = ""
|
68
68
|
work_lines.each_with_index do |line, index|
|
69
69
|
first = line.strip.split(" ").first
|
70
70
|
|
@@ -74,7 +74,7 @@ module TSqlParser::Parsing
|
|
74
74
|
elsif %w[END GO FROM].include? first and last != "DELETE"
|
75
75
|
tab_count -= 1 if tab_count > 0
|
76
76
|
indented_lines << "#{tab * tab_count}#{line}"
|
77
|
-
elsif %w[IF].include? first
|
77
|
+
elsif %w[IF].include? first
|
78
78
|
indented_lines << "#{tab * tab_count}#{line}"
|
79
79
|
next_line = work_lines[index + 1] unless index + 1 > work_lines.size
|
80
80
|
sub_one = true unless next_line.start_with? "BEGIN"
|
data/lib/parsing/keyword.rb
CHANGED
@@ -25,7 +25,7 @@ module TSqlParser::Parsing
|
|
25
25
|
|
26
26
|
def self.get_new_node_keywords
|
27
27
|
%w[CREATE ALTER DROP RENAME SELECT INSERT UPDATE DELETE WHILE IF ELSE DECLARE SET WITH BEGIN FROM WHERE INNER LEFT JOIN END GO GROUP ORDER CASE PRINT RETURN] \
|
28
|
-
- %w[WHERE SET]
|
28
|
+
- %w[WHERE SET WITH]
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.get_begin_keyword
|
@@ -45,7 +45,7 @@ module TSqlParser::Parsing
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def self.get_newline_keywords
|
48
|
-
%w[INSERT UPDATE DELETE SELECT
|
48
|
+
%w[INSERT UPDATE DELETE SELECT CREATE IF RETURN PRINT WHILE]
|
49
49
|
end
|
50
50
|
|
51
51
|
def self.get_reserved_keywords
|
@@ -34,7 +34,7 @@ module TSqlParser::Parsing
|
|
34
34
|
parts = line.strip.split(" SET ")
|
35
35
|
tab_count = self.get_tab_count(line, tab)
|
36
36
|
formatted << "#{tab * tab_count}#{parts[0]}\n"
|
37
|
-
parts[1..].each {|p| formatted << "#{tab * tab_count}SET #{p}" }
|
37
|
+
parts[1..].each { |p| formatted << "#{tab * tab_count}SET #{p}" }
|
38
38
|
else
|
39
39
|
formatted << line
|
40
40
|
end
|
@@ -157,28 +157,30 @@ module TSqlParser::Parsing
|
|
157
157
|
private
|
158
158
|
|
159
159
|
def self.format_set(s, tab_count = 0, tab = " ")
|
160
|
+
return s if s.nil?
|
160
161
|
parts = []
|
161
|
-
builder =
|
162
|
+
builder = ""
|
162
163
|
parenthesis = 0
|
163
|
-
s.split(
|
164
|
-
parenthesis += 1 if c ==
|
165
|
-
parenthesis -= 1 if c ==
|
166
|
-
if c ==
|
164
|
+
s.split("").each do |c|
|
165
|
+
parenthesis += 1 if c == "("
|
166
|
+
parenthesis -= 1 if c == ")"
|
167
|
+
if c == ","
|
167
168
|
if parenthesis > 0
|
168
169
|
builder << c
|
169
170
|
else
|
170
171
|
parts << builder
|
171
|
-
builder =
|
172
|
+
builder = ""
|
172
173
|
end
|
173
174
|
else
|
174
175
|
builder << c
|
175
176
|
end
|
176
177
|
end
|
177
178
|
parts << builder unless builder.empty?
|
178
|
-
"\n#{parts.map {|p| "#{tab * (tab_count + 1)}#{p.strip}"}.join(",\n")}"
|
179
|
+
"\n#{parts.map { |p| "#{tab * (tab_count + 1)}#{p.strip}" }.join(",\n")}"
|
179
180
|
end
|
180
181
|
|
181
182
|
def self.format_update(s, tab_count = 0, tab = " ")
|
183
|
+
return s if s.nil?
|
182
184
|
formatted = []
|
183
185
|
parts = s.split(" SET ")
|
184
186
|
table = parts[0]
|
@@ -190,6 +192,7 @@ module TSqlParser::Parsing
|
|
190
192
|
end
|
191
193
|
|
192
194
|
def self.format_insert(s, tab_count = 0, tab = " ")
|
195
|
+
return s if s.nil?
|
193
196
|
formatted = []
|
194
197
|
if s.include? ") VALUES ("
|
195
198
|
tokens = s.split(") VALUES (")
|
@@ -205,11 +208,14 @@ module TSqlParser::Parsing
|
|
205
208
|
end
|
206
209
|
|
207
210
|
def self.format_select(s, tab_count = 0, tab = " ")
|
211
|
+
return s if s.nil?
|
212
|
+
|
208
213
|
tokens = s.split(", ")
|
209
214
|
"\n#{tokens.map { |t| "#{tab * (tab_count + 1)}#{t}" }.join(",\n")}"
|
210
215
|
end
|
211
216
|
|
212
217
|
def self.format_predicate(s, tab_count = 0, tab = " ")
|
218
|
+
return s if s.nil?
|
213
219
|
indented = []
|
214
220
|
formatted = []
|
215
221
|
builder = []
|