vorax 0.1.0pre

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.
Files changed (57) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +1 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +45 -0
  5. data/Rakefile +30 -0
  6. data/lib/vorax/base_funnel.rb +30 -0
  7. data/lib/vorax/output/html_convertor.rb +120 -0
  8. data/lib/vorax/output/html_funnel.rb +79 -0
  9. data/lib/vorax/output/pagezip_convertor.rb +20 -0
  10. data/lib/vorax/output/tablezip_convertor.rb +22 -0
  11. data/lib/vorax/output/vertical_convertor.rb +53 -0
  12. data/lib/vorax/output/zip_convertor.rb +117 -0
  13. data/lib/vorax/parser/argument.rb~ +125 -0
  14. data/lib/vorax/parser/body_split.rb +168 -0
  15. data/lib/vorax/parser/conn_string.rb +104 -0
  16. data/lib/vorax/parser/grammars/alias.rb +912 -0
  17. data/lib/vorax/parser/grammars/alias.rl +146 -0
  18. data/lib/vorax/parser/grammars/column.rb +454 -0
  19. data/lib/vorax/parser/grammars/column.rl +64 -0
  20. data/lib/vorax/parser/grammars/common.rl +98 -0
  21. data/lib/vorax/parser/grammars/package_spec.rb +1186 -0
  22. data/lib/vorax/parser/grammars/package_spec.rl +78 -0
  23. data/lib/vorax/parser/grammars/plsql_def.rb +469 -0
  24. data/lib/vorax/parser/grammars/plsql_def.rl +59 -0
  25. data/lib/vorax/parser/grammars/statement.rb +925 -0
  26. data/lib/vorax/parser/grammars/statement.rl +83 -0
  27. data/lib/vorax/parser/parser.rb +320 -0
  28. data/lib/vorax/parser/plsql_structure.rb +158 -0
  29. data/lib/vorax/parser/plsql_walker.rb +143 -0
  30. data/lib/vorax/parser/statement_inspector.rb~ +52 -0
  31. data/lib/vorax/parser/stmt_inspector.rb +78 -0
  32. data/lib/vorax/parser/target_ref.rb +110 -0
  33. data/lib/vorax/sqlplus.rb +281 -0
  34. data/lib/vorax/version.rb +7 -0
  35. data/lib/vorax/vorax_io.rb +70 -0
  36. data/lib/vorax.rb +60 -0
  37. data/spec/column_spec.rb +40 -0
  38. data/spec/conn_string_spec.rb +53 -0
  39. data/spec/package_spec_spec.rb +48 -0
  40. data/spec/pagezip_spec.rb +153 -0
  41. data/spec/parser_spec.rb +299 -0
  42. data/spec/plsql_structure_spec.rb +44 -0
  43. data/spec/spec_helper.rb +13 -0
  44. data/spec/sql/create_objects.sql +69 -0
  45. data/spec/sql/dbms_crypto.spc +339 -0
  46. data/spec/sql/dbms_crypto.~spc +339 -0
  47. data/spec/sql/dbms_stats.spc +4097 -0
  48. data/spec/sql/drop_user.sql +10 -0
  49. data/spec/sql/muci.spc +24 -0
  50. data/spec/sql/setup_user.sql +22 -0
  51. data/spec/sql/test.pkg +67 -0
  52. data/spec/sqlplus_spec.rb +52 -0
  53. data/spec/stmt_inspector_spec.rb +84 -0
  54. data/spec/tablezip_spec.rb +111 -0
  55. data/spec/vertical_spec.rb +150 -0
  56. data/vorax.gemspec +21 -0
  57. metadata +139 -0
@@ -0,0 +1,78 @@
1
+ %%{
2
+
3
+ machine package_spec;
4
+
5
+ include common "common.rl";
6
+
7
+ action start_identifier {
8
+ @start = p
9
+ }
10
+
11
+ action end_identifier {
12
+ @end = p - 1
13
+ }
14
+
15
+ terminator = (';' ws*) | (ws+ (K_AS | K_IS) ws+);
16
+ id = identifier >start_identifier %end_identifier;
17
+ variable_name = id - (K_CURSOR | K_TYPE | K_FUNCTION | K_PROCEDURE | K_END | K_PRAGMA);
18
+
19
+ constant = terminator id ws+ K_CONSTANT;
20
+ exception = terminator id ws+ K_EXCEPTION (ws+ | ';');
21
+ cursor = terminator K_CURSOR ws+ id ws+;
22
+ type = terminator K_TYPE ws+ id ws+;
23
+ global_variable = terminator variable_name ws+;
24
+ function = terminator K_FUNCTION ws+ id;
25
+ procedure = terminator K_PROCEDURE ws+ id;
26
+
27
+ main := |*
28
+ squoted_string;
29
+ dquoted_string;
30
+ comment;
31
+ constant => { @constants.add(data[(@start..@end)]) };
32
+ exception => { @exceptions.add(data[(@start..@end)]) };
33
+ cursor => { @cursors.add(data[(@start..@end)]) };
34
+ type => { @types.add(data[(@start..@end)]) };
35
+ global_variable => { @variables.add(data[(@start..@end)]) };
36
+ function => { @functions.add(data[(@start..@end)]) };
37
+ procedure => { @procedures.add(data[(@start..@end)]) };
38
+ any => {};
39
+ *|;
40
+
41
+ }%%
42
+
43
+ require 'set'
44
+
45
+ module Vorax
46
+
47
+ module Parser
48
+
49
+ # A class used to parse a PLSQL package spec.
50
+ class PackageSpec
51
+
52
+ attr_reader :constants, :types, :exceptions, :cursors, :variables, :functions, :procedures
53
+
54
+ # Walks the provided spec in order to compute the structure.
55
+ #
56
+ # param data [String] the package spec
57
+ def walk(data)
58
+ @constants = Set.new
59
+ @types = Set.new
60
+ @exceptions = Set.new
61
+ @cursors = Set.new
62
+ @variables = Set.new
63
+ @functions = Set.new
64
+ @procedures = Set.new
65
+ if data
66
+ eof = data.length
67
+ %% write data;
68
+ %% write init;
69
+ %% write exec;
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+
@@ -0,0 +1,469 @@
1
+
2
+ # line 1 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
3
+
4
+ # line 33 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
5
+
6
+
7
+ module Vorax
8
+
9
+ module Parser
10
+
11
+ # Check if the provided fragment could be a PLSQL spec or body (package or type).
12
+ #
13
+ # @param data [String] the PLSQL spec fragment (e.g. "PACKAGE muci as")
14
+ # @return [Hash] a hash with the following keys: :name => is the name
15
+ # of the PLSQL spec module, :end_def => the position where the spec
16
+ # fragment ends (immediatelly after "AS|IS"), :type => 'SPEC' or 'BODY'.
17
+ def self.plsql_def(data)
18
+ @end_pos = -1
19
+ if data
20
+ eof = data.length
21
+
22
+ # line 23 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rb"
23
+ class << self
24
+ attr_accessor :_plsql_def_actions
25
+ private :_plsql_def_actions, :_plsql_def_actions=
26
+ end
27
+ self._plsql_def_actions = [
28
+ 0, 1, 0, 1, 1, 1, 2, 1,
29
+ 3, 1, 4, 2, 3, 0
30
+ ]
31
+
32
+ class << self
33
+ attr_accessor :_plsql_def_key_offsets
34
+ private :_plsql_def_key_offsets, :_plsql_def_key_offsets=
35
+ end
36
+ self._plsql_def_key_offsets = [
37
+ 0, 0, 6, 8, 10, 16, 34, 35,
38
+ 41, 42, 43, 44, 45, 47, 62, 63,
39
+ 64, 65, 66, 68, 85, 94, 111, 128,
40
+ 145, 147, 149, 151, 153, 155, 157, 162,
41
+ 177, 178, 184, 193, 194, 195, 196, 197,
42
+ 199, 201, 206, 207, 208, 209, 210, 212,
43
+ 220, 221, 226, 240, 255, 256, 257, 258,
44
+ 259, 261, 278, 295, 312, 327, 344, 345,
45
+ 351, 360, 361, 362, 363, 364, 366, 368,
46
+ 373, 374, 375, 376, 377, 379, 387, 388,
47
+ 393, 407, 422, 423, 424, 425, 426, 428,
48
+ 445, 460, 461, 462, 463, 464, 466, 468,
49
+ 470, 470, 475, 480
50
+ ]
51
+
52
+ class << self
53
+ attr_accessor :_plsql_def_trans_keys
54
+ private :_plsql_def_trans_keys, :_plsql_def_trans_keys=
55
+ end
56
+ self._plsql_def_trans_keys = [
57
+ 69, 80, 84, 101, 112, 116, 78, 110,
58
+ 68, 100, 32, 45, 47, 59, 9, 13,
59
+ 32, 34, 45, 47, 59, 73, 76, 95,
60
+ 105, 108, 9, 13, 35, 36, 65, 90,
61
+ 97, 122, 34, 32, 45, 47, 59, 9,
62
+ 13, 45, 10, 42, 42, 42, 47, 32,
63
+ 45, 47, 59, 95, 9, 13, 35, 36,
64
+ 48, 57, 65, 90, 97, 122, 45, 10,
65
+ 42, 42, 42, 47, 32, 45, 47, 59,
66
+ 70, 95, 102, 9, 13, 35, 36, 48,
67
+ 57, 65, 90, 97, 122, 95, 35, 36,
68
+ 48, 57, 65, 90, 97, 122, 32, 45,
69
+ 47, 59, 79, 95, 111, 9, 13, 35,
70
+ 36, 48, 57, 65, 90, 97, 122, 32,
71
+ 45, 47, 59, 79, 95, 111, 9, 13,
72
+ 35, 36, 48, 57, 65, 90, 97, 122,
73
+ 32, 45, 47, 59, 80, 95, 112, 9,
74
+ 13, 35, 36, 48, 57, 65, 90, 97,
75
+ 122, 65, 97, 67, 99, 75, 107, 65,
76
+ 97, 71, 103, 69, 101, 32, 45, 47,
77
+ 9, 13, 32, 34, 45, 47, 66, 95,
78
+ 98, 9, 13, 35, 36, 65, 90, 97,
79
+ 122, 34, 32, 45, 46, 47, 9, 13,
80
+ 32, 45, 47, 65, 73, 97, 105, 9,
81
+ 13, 45, 10, 42, 42, 42, 47, 83,
82
+ 115, 32, 45, 47, 9, 13, 45, 10,
83
+ 42, 42, 42, 47, 34, 95, 35, 36,
84
+ 65, 90, 97, 122, 34, 32, 45, 47,
85
+ 9, 13, 32, 45, 47, 95, 9, 13,
86
+ 35, 36, 48, 57, 65, 90, 97, 122,
87
+ 32, 45, 46, 47, 95, 9, 13, 35,
88
+ 36, 48, 57, 65, 90, 97, 122, 45,
89
+ 10, 42, 42, 42, 47, 32, 45, 46,
90
+ 47, 79, 95, 111, 9, 13, 35, 36,
91
+ 48, 57, 65, 90, 97, 122, 32, 45,
92
+ 46, 47, 68, 95, 100, 9, 13, 35,
93
+ 36, 48, 57, 65, 90, 97, 122, 32,
94
+ 45, 46, 47, 89, 95, 121, 9, 13,
95
+ 35, 36, 48, 57, 65, 90, 97, 122,
96
+ 32, 45, 46, 47, 95, 9, 13, 35,
97
+ 36, 48, 57, 65, 90, 97, 122, 32,
98
+ 34, 45, 47, 65, 73, 95, 97, 105,
99
+ 9, 13, 35, 36, 66, 90, 98, 122,
100
+ 34, 32, 45, 46, 47, 9, 13, 32,
101
+ 45, 47, 65, 73, 97, 105, 9, 13,
102
+ 45, 10, 42, 42, 42, 47, 83, 115,
103
+ 32, 45, 47, 9, 13, 45, 10, 42,
104
+ 42, 42, 47, 34, 95, 35, 36, 65,
105
+ 90, 97, 122, 34, 32, 45, 47, 9,
106
+ 13, 32, 45, 47, 95, 9, 13, 35,
107
+ 36, 48, 57, 65, 90, 97, 122, 32,
108
+ 45, 46, 47, 95, 9, 13, 35, 36,
109
+ 48, 57, 65, 90, 97, 122, 45, 10,
110
+ 42, 42, 42, 47, 32, 45, 46, 47,
111
+ 83, 95, 115, 9, 13, 35, 36, 48,
112
+ 57, 65, 90, 97, 122, 32, 45, 46,
113
+ 47, 95, 9, 13, 35, 36, 48, 57,
114
+ 65, 90, 97, 122, 45, 10, 42, 42,
115
+ 42, 47, 89, 121, 80, 112, 32, 45,
116
+ 47, 9, 13, 32, 45, 47, 9, 13,
117
+ 32, 45, 47, 65, 73, 97, 105, 9,
118
+ 13, 0
119
+ ]
120
+
121
+ class << self
122
+ attr_accessor :_plsql_def_single_lengths
123
+ private :_plsql_def_single_lengths, :_plsql_def_single_lengths=
124
+ end
125
+ self._plsql_def_single_lengths = [
126
+ 0, 6, 2, 2, 4, 10, 1, 4,
127
+ 1, 1, 1, 1, 2, 5, 1, 1,
128
+ 1, 1, 2, 7, 1, 7, 7, 7,
129
+ 2, 2, 2, 2, 2, 2, 3, 7,
130
+ 1, 4, 7, 1, 1, 1, 1, 2,
131
+ 2, 3, 1, 1, 1, 1, 2, 2,
132
+ 1, 3, 4, 5, 1, 1, 1, 1,
133
+ 2, 7, 7, 7, 5, 9, 1, 4,
134
+ 7, 1, 1, 1, 1, 2, 2, 3,
135
+ 1, 1, 1, 1, 2, 2, 1, 3,
136
+ 4, 5, 1, 1, 1, 1, 2, 7,
137
+ 5, 1, 1, 1, 1, 2, 2, 2,
138
+ 0, 3, 3, 7
139
+ ]
140
+
141
+ class << self
142
+ attr_accessor :_plsql_def_range_lengths
143
+ private :_plsql_def_range_lengths, :_plsql_def_range_lengths=
144
+ end
145
+ self._plsql_def_range_lengths = [
146
+ 0, 0, 0, 0, 1, 4, 0, 1,
147
+ 0, 0, 0, 0, 0, 5, 0, 0,
148
+ 0, 0, 0, 5, 4, 5, 5, 5,
149
+ 0, 0, 0, 0, 0, 0, 1, 4,
150
+ 0, 1, 1, 0, 0, 0, 0, 0,
151
+ 0, 1, 0, 0, 0, 0, 0, 3,
152
+ 0, 1, 5, 5, 0, 0, 0, 0,
153
+ 0, 5, 5, 5, 5, 4, 0, 1,
154
+ 1, 0, 0, 0, 0, 0, 0, 1,
155
+ 0, 0, 0, 0, 0, 3, 0, 1,
156
+ 5, 5, 0, 0, 0, 0, 0, 5,
157
+ 5, 0, 0, 0, 0, 0, 0, 0,
158
+ 0, 1, 1, 1
159
+ ]
160
+
161
+ class << self
162
+ attr_accessor :_plsql_def_index_offsets
163
+ private :_plsql_def_index_offsets, :_plsql_def_index_offsets=
164
+ end
165
+ self._plsql_def_index_offsets = [
166
+ 0, 0, 7, 10, 13, 19, 34, 36,
167
+ 42, 44, 46, 48, 50, 53, 64, 66,
168
+ 68, 70, 72, 75, 88, 94, 107, 120,
169
+ 133, 136, 139, 142, 145, 148, 151, 156,
170
+ 168, 170, 176, 185, 187, 189, 191, 193,
171
+ 196, 199, 204, 206, 208, 210, 212, 215,
172
+ 221, 223, 228, 238, 249, 251, 253, 255,
173
+ 257, 260, 273, 286, 299, 310, 324, 326,
174
+ 332, 341, 343, 345, 347, 349, 352, 355,
175
+ 360, 362, 364, 366, 368, 371, 377, 379,
176
+ 384, 394, 405, 407, 409, 411, 413, 416,
177
+ 429, 440, 442, 444, 446, 448, 451, 454,
178
+ 457, 458, 463, 468
179
+ ]
180
+
181
+ class << self
182
+ attr_accessor :_plsql_def_indicies
183
+ private :_plsql_def_indicies, :_plsql_def_indicies=
184
+ end
185
+ self._plsql_def_indicies = [
186
+ 0, 2, 3, 0, 2, 3, 1, 4,
187
+ 4, 1, 5, 5, 1, 6, 7, 8,
188
+ 9, 6, 1, 6, 10, 7, 8, 9,
189
+ 12, 13, 11, 12, 13, 6, 11, 11,
190
+ 11, 1, 14, 10, 14, 15, 16, 9,
191
+ 14, 1, 17, 1, 14, 17, 18, 1,
192
+ 19, 18, 19, 14, 18, 14, 15, 16,
193
+ 9, 11, 14, 11, 11, 11, 11, 1,
194
+ 20, 1, 6, 20, 21, 1, 22, 21,
195
+ 22, 6, 21, 14, 15, 16, 9, 23,
196
+ 11, 23, 14, 11, 11, 11, 11, 1,
197
+ 11, 11, 11, 11, 11, 1, 14, 15,
198
+ 16, 9, 24, 11, 24, 14, 11, 11,
199
+ 11, 11, 1, 14, 15, 16, 9, 25,
200
+ 11, 25, 14, 11, 11, 11, 11, 1,
201
+ 14, 15, 16, 9, 23, 11, 23, 14,
202
+ 11, 11, 11, 11, 1, 26, 26, 1,
203
+ 27, 27, 1, 28, 28, 1, 29, 29,
204
+ 1, 30, 30, 1, 31, 31, 1, 32,
205
+ 33, 34, 32, 1, 32, 35, 33, 34,
206
+ 37, 36, 37, 32, 36, 36, 36, 1,
207
+ 39, 38, 40, 41, 42, 43, 40, 1,
208
+ 44, 45, 46, 47, 47, 47, 47, 44,
209
+ 1, 48, 1, 44, 48, 49, 1, 50,
210
+ 49, 50, 44, 49, 51, 51, 1, 52,
211
+ 53, 54, 52, 1, 55, 1, 52, 55,
212
+ 56, 1, 57, 56, 57, 52, 56, 58,
213
+ 59, 59, 59, 59, 1, 60, 58, 40,
214
+ 41, 43, 40, 1, 40, 41, 43, 59,
215
+ 40, 59, 59, 59, 59, 1, 40, 41,
216
+ 42, 43, 61, 40, 61, 61, 61, 61,
217
+ 1, 62, 1, 32, 62, 63, 1, 64,
218
+ 63, 64, 32, 63, 40, 41, 42, 43,
219
+ 65, 61, 65, 40, 61, 61, 61, 61,
220
+ 1, 40, 41, 42, 43, 66, 61, 66,
221
+ 40, 61, 61, 61, 61, 1, 40, 41,
222
+ 42, 43, 67, 61, 67, 40, 61, 61,
223
+ 61, 61, 1, 68, 69, 42, 70, 61,
224
+ 68, 61, 61, 61, 61, 1, 71, 72,
225
+ 74, 75, 76, 76, 73, 76, 76, 71,
226
+ 73, 73, 73, 1, 78, 77, 79, 80,
227
+ 81, 82, 79, 1, 83, 84, 85, 86,
228
+ 86, 86, 86, 83, 1, 87, 1, 83,
229
+ 87, 88, 1, 89, 88, 89, 83, 88,
230
+ 90, 90, 1, 91, 92, 93, 91, 1,
231
+ 94, 1, 91, 94, 95, 1, 96, 95,
232
+ 96, 91, 95, 97, 98, 98, 98, 98,
233
+ 1, 99, 97, 79, 80, 82, 79, 1,
234
+ 79, 80, 82, 98, 79, 98, 98, 98,
235
+ 98, 1, 79, 80, 81, 82, 100, 79,
236
+ 100, 100, 100, 100, 1, 101, 1, 71,
237
+ 101, 102, 1, 103, 102, 103, 71, 102,
238
+ 79, 80, 81, 82, 104, 100, 104, 79,
239
+ 100, 100, 100, 100, 1, 105, 106, 81,
240
+ 107, 100, 105, 100, 100, 100, 100, 1,
241
+ 108, 1, 109, 108, 110, 1, 111, 110,
242
+ 111, 109, 110, 112, 112, 1, 30, 30,
243
+ 1, 1, 52, 53, 54, 52, 1, 91,
244
+ 92, 93, 91, 1, 109, 113, 114, 86,
245
+ 86, 86, 86, 109, 1, 0
246
+ ]
247
+
248
+ class << self
249
+ attr_accessor :_plsql_def_trans_targs
250
+ private :_plsql_def_trans_targs, :_plsql_def_trans_targs=
251
+ end
252
+ self._plsql_def_trans_targs = [
253
+ 2, 0, 24, 94, 3, 4, 5, 14,
254
+ 16, 96, 6, 13, 19, 21, 7, 8,
255
+ 10, 9, 11, 12, 15, 17, 18, 20,
256
+ 22, 23, 25, 26, 27, 28, 29, 30,
257
+ 31, 52, 54, 32, 51, 57, 32, 33,
258
+ 34, 35, 47, 37, 34, 35, 37, 40,
259
+ 36, 38, 39, 41, 97, 42, 44, 43,
260
+ 45, 46, 48, 50, 49, 51, 53, 55,
261
+ 56, 58, 59, 60, 61, 82, 84, 61,
262
+ 62, 81, 82, 84, 87, 62, 63, 64,
263
+ 65, 77, 67, 64, 65, 67, 70, 66,
264
+ 68, 69, 71, 98, 72, 74, 73, 75,
265
+ 76, 78, 80, 79, 81, 83, 85, 86,
266
+ 88, 99, 89, 91, 90, 99, 92, 93,
267
+ 95, 89, 91
268
+ ]
269
+
270
+ class << self
271
+ attr_accessor :_plsql_def_trans_actions
272
+ private :_plsql_def_trans_actions, :_plsql_def_trans_actions=
273
+ end
274
+ self._plsql_def_trans_actions = [
275
+ 0, 0, 0, 0, 0, 0, 0, 0,
276
+ 0, 5, 0, 0, 0, 0, 0, 0,
277
+ 0, 0, 0, 0, 0, 0, 0, 0,
278
+ 0, 0, 0, 0, 0, 0, 0, 0,
279
+ 0, 0, 0, 9, 9, 9, 0, 0,
280
+ 7, 7, 0, 7, 0, 0, 0, 0,
281
+ 0, 0, 0, 0, 1, 0, 0, 0,
282
+ 0, 0, 0, 0, 0, 0, 0, 0,
283
+ 0, 0, 0, 0, 7, 7, 7, 0,
284
+ 9, 9, 0, 0, 9, 0, 0, 7,
285
+ 7, 0, 7, 0, 0, 0, 0, 0,
286
+ 0, 0, 0, 3, 0, 0, 0, 0,
287
+ 0, 0, 0, 0, 0, 0, 0, 0,
288
+ 0, 11, 7, 7, 0, 1, 0, 0,
289
+ 0, 0, 0
290
+ ]
291
+
292
+ class << self
293
+ attr_accessor :plsql_def_start
294
+ end
295
+ self.plsql_def_start = 1;
296
+ class << self
297
+ attr_accessor :plsql_def_first_final
298
+ end
299
+ self.plsql_def_first_final = 96;
300
+ class << self
301
+ attr_accessor :plsql_def_error
302
+ end
303
+ self.plsql_def_error = 0;
304
+
305
+ class << self
306
+ attr_accessor :plsql_def_en_main
307
+ end
308
+ self.plsql_def_en_main = 1;
309
+
310
+
311
+ # line 50 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
312
+
313
+ # line 314 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rb"
314
+ begin
315
+ p ||= 0
316
+ pe ||= data.length
317
+ cs = plsql_def_start
318
+ end
319
+
320
+ # line 51 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
321
+
322
+ # line 323 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rb"
323
+ begin
324
+ _klen, _trans, _keys, _acts, _nacts = nil
325
+ _goto_level = 0
326
+ _resume = 10
327
+ _eof_trans = 15
328
+ _again = 20
329
+ _test_eof = 30
330
+ _out = 40
331
+ while true
332
+ _trigger_goto = false
333
+ if _goto_level <= 0
334
+ if p == pe
335
+ _goto_level = _test_eof
336
+ next
337
+ end
338
+ if cs == 0
339
+ _goto_level = _out
340
+ next
341
+ end
342
+ end
343
+ if _goto_level <= _resume
344
+ _keys = _plsql_def_key_offsets[cs]
345
+ _trans = _plsql_def_index_offsets[cs]
346
+ _klen = _plsql_def_single_lengths[cs]
347
+ _break_match = false
348
+
349
+ begin
350
+ if _klen > 0
351
+ _lower = _keys
352
+ _upper = _keys + _klen - 1
353
+
354
+ loop do
355
+ break if _upper < _lower
356
+ _mid = _lower + ( (_upper - _lower) >> 1 )
357
+
358
+ if data[p].ord < _plsql_def_trans_keys[_mid]
359
+ _upper = _mid - 1
360
+ elsif data[p].ord > _plsql_def_trans_keys[_mid]
361
+ _lower = _mid + 1
362
+ else
363
+ _trans += (_mid - _keys)
364
+ _break_match = true
365
+ break
366
+ end
367
+ end # loop
368
+ break if _break_match
369
+ _keys += _klen
370
+ _trans += _klen
371
+ end
372
+ _klen = _plsql_def_range_lengths[cs]
373
+ if _klen > 0
374
+ _lower = _keys
375
+ _upper = _keys + (_klen << 1) - 2
376
+ loop do
377
+ break if _upper < _lower
378
+ _mid = _lower + (((_upper-_lower) >> 1) & ~1)
379
+ if data[p].ord < _plsql_def_trans_keys[_mid]
380
+ _upper = _mid - 2
381
+ elsif data[p].ord > _plsql_def_trans_keys[_mid+1]
382
+ _lower = _mid + 2
383
+ else
384
+ _trans += ((_mid - _keys) >> 1)
385
+ _break_match = true
386
+ break
387
+ end
388
+ end # loop
389
+ break if _break_match
390
+ _trans += _klen
391
+ end
392
+ end while false
393
+ _trans = _plsql_def_indicies[_trans]
394
+ cs = _plsql_def_trans_targs[_trans]
395
+ if _plsql_def_trans_actions[_trans] != 0
396
+ _acts = _plsql_def_trans_actions[_trans]
397
+ _nacts = _plsql_def_actions[_acts]
398
+ _acts += 1
399
+ while _nacts > 0
400
+ _nacts -= 1
401
+ _acts += 1
402
+ case _plsql_def_actions[_acts - 1]
403
+ when 0 then
404
+ # line 7 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
405
+ begin
406
+
407
+ @end_pos = p - 1;
408
+ @type = 'SPEC';
409
+ end
410
+ when 1 then
411
+ # line 12 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
412
+ begin
413
+
414
+ @end_pos = p - 1;
415
+ @type = 'BODY';
416
+ end
417
+ when 2 then
418
+ # line 17 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
419
+ begin
420
+
421
+ @end_pos = p - 1;
422
+ @type = 'END';
423
+ end
424
+ when 3 then
425
+ # line 22 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
426
+ begin
427
+
428
+ @name = data[(@start..p-1)]
429
+ end
430
+ when 4 then
431
+ # line 28 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
432
+ begin
433
+ @start = p end
434
+ # line 435 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rb"
435
+ end # action switch
436
+ end
437
+ end
438
+ if _trigger_goto
439
+ next
440
+ end
441
+ end
442
+ if _goto_level <= _again
443
+ if cs == 0
444
+ _goto_level = _out
445
+ next
446
+ end
447
+ p += 1
448
+ if p != pe
449
+ _goto_level = _resume
450
+ next
451
+ end
452
+ end
453
+ if _goto_level <= _test_eof
454
+ end
455
+ if _goto_level <= _out
456
+ break
457
+ end
458
+ end
459
+ end
460
+
461
+ # line 52 "/home/talek/Dropbox/ruby-vorax/lib/vorax/parser/grammars/plsql_def.rl"
462
+ end
463
+ return {:name => @name, :end_def => @end_pos, :type => @type}
464
+ end
465
+
466
+ end
467
+
468
+ end
469
+
@@ -0,0 +1,59 @@
1
+ %%{
2
+
3
+ machine plsql_def;
4
+
5
+ include common "common.rl";
6
+
7
+ action mark_spec_end {
8
+ @end_pos = p - 1;
9
+ @type = 'SPEC';
10
+ }
11
+
12
+ action mark_body_end {
13
+ @end_pos = p - 1;
14
+ @type = 'BODY';
15
+ }
16
+
17
+ action mark_end_def {
18
+ @end_pos = p - 1;
19
+ @type = 'END';
20
+ }
21
+
22
+ action plsql_name {
23
+ @name = data[(@start..p-1)]
24
+ }
25
+
26
+ subprog_name = identifier - (K_IF | K_LOOP);
27
+ end_def = (K_END ws* ';' | K_END ws+ subprog_name ws* ';') @mark_end_def;
28
+ name = ((identifier '.' identifier) | identifier) >{@start = p} %plsql_name;
29
+ spec = (K_PACKAGE | K_TYPE) ws+ name ws+ (K_AS | K_IS) ws+ @mark_spec_end;
30
+ body = (K_PACKAGE | K_TYPE) ws+ K_BODY ws+ name ws+ (K_AS | K_IS) ws+ @mark_body_end;
31
+ main := body | spec | end_def;
32
+
33
+ }%%
34
+
35
+ module Vorax
36
+
37
+ module Parser
38
+
39
+ # Check if the provided fragment could be a PLSQL spec or body (package or type).
40
+ #
41
+ # @param data [String] the PLSQL spec fragment (e.g. "PACKAGE muci as")
42
+ # @return [Hash] a hash with the following keys: :name => is the name
43
+ # of the PLSQL spec module, :end_def => the position where the spec
44
+ # fragment ends (immediatelly after "AS|IS"), :type => 'SPEC' or 'BODY'.
45
+ def self.plsql_def(data)
46
+ @end_pos = -1
47
+ if data
48
+ eof = data.length
49
+ %% write data;
50
+ %% write init;
51
+ %% write exec;
52
+ end
53
+ return {:name => @name, :end_def => @end_pos, :type => @type}
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+