tsql_parser 0.0.5 → 0.0.6

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: 47f15eed54caa7c7f4c7525b27d302577ed8a07c3fce61b6af631ccc4bfbb3cc
4
- data.tar.gz: 06ad8019af83fbb0679692eb0ef91b6ee0258cca4e1c79c924d034d0e537c7f7
3
+ metadata.gz: ee8b4d7afa83f298c53d2f34be1012948466a1dc17dfb022bc59a723e7558c84
4
+ data.tar.gz: 29154ff1736be248f22c84a3e985699b1b3c1eadca44295634a9c27dba4cd848
5
5
  SHA512:
6
- metadata.gz: 56978f16697970a06636ccb533f50bf0528199622724568eea071647dcba591c14baa6e05564846f876fc01d413a64f2fdcb2e3f3e2f5b81cdd7a6a2f5c11d76
7
- data.tar.gz: 8c874fde5552f5e331d618b5e8ed427e8442cfbe513d3f43e59330c04298022637be9b821f7c6dce621368c9f2449b9ad878d28fc96f84ae17676a834cd3343a
6
+ metadata.gz: 01de8daed01b64881f3f112dc2233ea2a3fe27ffddd3e95940ed353425b36a2b2ae5631661cd81faab998494992149be1bc20d1adbd6939305350e2e8e9ab03e
7
+ data.tar.gz: f3212645945c40035938a96664e3f6df3044716750e12874f0cf4d40424729cea5054d42bbeb3335be7b914b7a5fbd14fb29c158163a39344b0f956dfd09c6b4
@@ -48,9 +48,16 @@ module TSqlParser::Parsing
48
48
  new_lines << ""
49
49
  next
50
50
  end
51
+
51
52
  if Parser.is_newline_required? first or first.start_with? "/*"
52
53
  new_lines << ""
53
54
  end
55
+
56
+ if Parser.is_label? first
57
+ #tab_count = self.get_tab_count(line)
58
+ # TODO: tab it out
59
+ end
60
+
54
61
  new_lines << line
55
62
  end
56
63
  new_lines
@@ -71,10 +78,13 @@ module TSqlParser::Parsing
71
78
  next_line = work_lines[index + 1] unless index + 1 > work_lines.size
72
79
  next_line_first = next_line.strip.split(" ").first unless next_line.nil?
73
80
 
74
- if %w[CASE BEGIN SELECT].include? first or line.strip.start_with? "CREATE PROCEDURE"
81
+ if Parser.is_label? first
75
82
  indented_lines << "#{tab * tab_count}#{line}"
76
83
  tab_count += 1
77
- elsif %w[FROM END GO].include? first and not %w[DELETE UPDATE INSERT].include? last
84
+ elsif %w[CASE BEGIN SELECT].include? first or line.strip.start_with? "CREATE PROCEDURE"
85
+ indented_lines << "#{tab * tab_count}#{line}"
86
+ tab_count += 1
87
+ elsif %w[FROM END GO].include? first and not %w[DELETE UPDATE INSERT SET].include? last
78
88
  tab_count -= 1 if tab_count > 0
79
89
  indented_lines << "#{tab * tab_count}#{line}"
80
90
  else
@@ -128,8 +138,26 @@ module TSqlParser::Parsing
128
138
  def self.as_containers(tokens)
129
139
  containers = []
130
140
  container = nil
131
- tokens.each do |t|
141
+ skip_count = 0
142
+ tokens.each_with_index do |t, index|
143
+ if skip_count > 0
144
+ skip_count -= 1
145
+ next
146
+ end
147
+
148
+ next_token = tokens[index + 1]
132
149
  if Parser.is_new_node_keyword? t[:value]
150
+ if not next_token.nil? and Parser.is_new_node_keyword? next_token[:value]
151
+ if Parser.is_new_node_composite?(t[:value], next_token[:value])
152
+ containers << container unless container.nil?
153
+ container = SqlContainer.combine(t, next_token)
154
+ skip_count = 1
155
+ next
156
+ end
157
+ end
158
+ containers << container unless container.nil?
159
+ container = SqlContainer.new(t)
160
+ elsif t[:label]
133
161
  containers << container unless container.nil?
134
162
  container = SqlContainer.new(t)
135
163
  else
@@ -24,8 +24,8 @@ module TSqlParser::Parsing
24
24
  end
25
25
 
26
26
  def self.get_new_node_keywords
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 WITH]
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 GOTO OPEN CLOSE DEALLOCATE FETCH] \
28
+ - %w[WITH LEFT RIGHT]
29
29
  end
30
30
 
31
31
  def self.get_begin_keyword
@@ -21,6 +21,17 @@ module TSqlParser::Parsing
21
21
  @nodes = []
22
22
  end
23
23
 
24
+ def self.combine(first, second)
25
+ token = {}
26
+ token[:value] = "#{first[:value]} #{second[:value]}"
27
+ [first, second].each do |t|
28
+ t.each do |k, v|
29
+ token[k] = v unless token.has_key? k
30
+ end
31
+ end
32
+ SqlContainer.new(token)
33
+ end
34
+
24
35
  def set_token(token)
25
36
  @token = token
26
37
  end
@@ -138,8 +138,16 @@ module TSqlParser::Parsing
138
138
  Keyword.get_new_node_keywords.include? s.upcase
139
139
  end
140
140
 
141
+ def self.is_new_node_composite?(s, next_s)
142
+ ["INNER JOIN", "LEFT JOIN", "RIGHT JOIN", "ELSE IF"].include? "#{s} #{next_s}"
143
+ end
144
+
141
145
  def self.is_terminator?(s)
142
146
  s == ";"
143
147
  end
148
+
149
+ def self.is_label?(s)
150
+ s.end_with? ":"
151
+ end
144
152
  end
145
153
  end
@@ -181,12 +181,7 @@ module TSqlParser::Parsing
181
181
 
182
182
  def self.format_update(s, tab_count = 0, tab = " ")
183
183
  return s if s.nil?
184
- formatted = []
185
- parts = s.split(" SET ")
186
- table = parts[0]
187
- formatted << "\n#{tab * (tab_count + 1)}#{table}"
188
- formatted << "#{tab * tab_count}SET #{parts[1]}"
189
- formatted.join("\n")
184
+ "\n#{tab * (tab_count + 1)}#{s}"
190
185
  end
191
186
 
192
187
  def self.format_insert(s, tab_count = 0, tab = " ")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsql_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Stauffer