@@ -43,6 +43,7 @@ $lines = get-content $args[0]
43
43
$inComment = $false
44
44
$inCreateTable = $false
45
45
$inCreateFunction = $false
46
+ $inCreateProcedure = $false
46
47
47
48
# For all lines...
48
49
foreach ($line in $lines )
@@ -52,7 +53,7 @@ foreach ($line in $lines)
52
53
{
53
54
write-output $line
54
55
}
55
- # If currently parsing a comment, continue until end of comment found.
56
+ # If currently parsing a comment, continue until end found.
56
57
elseif ($inComment -eq $true )
57
58
{
58
59
write-output $line
@@ -69,49 +70,49 @@ foreach ($line in $lines)
69
70
70
71
if ($line -notmatch ' \*/' )
71
72
{
72
- $inComment = $true
73
- }
73
+ $inComment = $true
74
+ }
74
75
}
75
- # Part of sql-style comment?
76
+ # Part of sql-style comment?
76
77
elseif ($line -match ' ^--' )
77
- {
78
- if ($line -match ' ^----+' )
79
- {
80
- $line = $line -replace ' -' , ' /'
81
- }
82
-
78
+ {
79
+ if ($line -match ' ^----+' )
80
+ {
81
+ $line = $line -replace ' -' , ' /'
82
+ }
83
+
83
84
$line = $line -replace ' --!' , ' //!'
84
85
$line = $line -replace ' ---' , ' ///'
85
86
$line = $line -replace ' --' , ' //'
86
87
87
88
write-output $line
88
- }
89
- # If currently parsing a table, continue until end of table found.
89
+ }
90
+ # If currently parsing a table, continue until end found.
90
91
elseif ($inCreateTable -eq $true )
91
92
{
92
- $line = $line -replace ' ^\(' , ' {'
93
- $line = $line -replace ' ^\);?' , ' };'
94
-
95
- $line = $line -replace ' --!' , ' //!'
96
- $line = $line -replace ' ---' , ' ///'
97
- $line = $line -replace ' --' , ' //'
98
-
99
93
if ($line -match ' ^(?<indent>\s+)(?<column>\w+)\s+(?<fulltype>[\w.]+)' )
100
94
{
101
95
$type = $matches.fulltype -replace ' ^\w+\.' , ' '
102
- $indent = $matches.indent
103
- $column = $matches.column
96
+ $indent = $matches.indent
97
+ $column = $matches.column
104
98
105
- $comment = ' '
99
+ $comment = ' '
106
100
107
- if ($line -match ' (?<comment>/\*.+\*/$)' )
108
- {
109
- $comment = $matches.comment
110
- }
101
+ if ($line -match ' (?<comment>( /\*.+\*/|-.+) $)' )
102
+ {
103
+ $comment = $matches.comment
104
+ }
111
105
112
106
$line = $indent + $type + ' ' + $column + ' ; ' + $comment
113
107
}
114
108
109
+ $line = $line -replace ' ^\(' , ' {'
110
+ $line = $line -replace ' ^\);?' , ' };'
111
+
112
+ $line = $line -replace ' --!' , ' //!'
113
+ $line = $line -replace ' ---' , ' ///'
114
+ $line = $line -replace ' --' , ' //'
115
+
115
116
write-output $line
116
117
117
118
if ($line -match ' };' )
@@ -130,7 +131,7 @@ foreach ($line in $lines)
130
131
131
132
$inCreateTable = $true
132
133
}
133
- # If currently parsing a function, continue until end of function found.
134
+ # If currently parsing a function, continue until end found.
134
135
elseif ($inCreateFunction -eq $true )
135
136
{
136
137
$line = $line -replace ' ^begin' , ' {'
@@ -141,7 +142,7 @@ foreach ($line in $lines)
141
142
if ($line -match ' ^\($' )
142
143
{
143
144
$inArgsList = $true
144
- $argsList = @ ()
145
+ $argsList = @ ()
145
146
}
146
147
147
148
if ($line -match ' ^\)$' )
@@ -155,45 +156,49 @@ foreach ($line in $lines)
155
156
$returnType = $returnType -replace ' \(' , ' ['
156
157
$returnType = $returnType -replace ' \)' , ' ]'
157
158
158
- write-output ($returnType + ' ' + $name )
159
- write-output ' ('
159
+ write-output ($returnType + ' ' + $name )
160
+ write-output ' ('
161
+
162
+ $firstArg = $true
160
163
161
- $firstArg = $true
162
-
163
- foreach ($arg in $argsList )
164
- {
165
- if ($firstArg -ne $true )
166
- {
167
- $arg = ' , ' + $arg
168
- }
169
-
170
- write-output $arg
164
+ foreach ($arg in $argsList )
165
+ {
166
+ if ($firstArg -ne $true )
167
+ {
168
+ $arg = ' , ' + $arg
169
+ }
171
170
172
- $firstArg = $false
173
- }
171
+ write-output $arg
174
172
175
- write-output ' )'
173
+ $firstArg = $false
174
+ }
175
+
176
+ write-output ' )'
176
177
}
177
- elseif ( ($inArgsList -eq $true ) -and ($line -match ' ^(?<indent>\s+)(?<param>@\w+)\s+(?<fulltype>[\w.]+)' ) )
178
+ elseif ( ($inArgsList -eq $true ) -and ($line -match ' ^(?<indent>\s+)(?<param>@\w+)\s+(?<fulltype>[\w.]+)' ) )
178
179
{
179
180
$type = $matches.fulltype -replace ' ^\w+\.' , ' '
180
- $indent = $matches.indent
181
- $param = $matches.param
181
+ $indent = $matches.indent
182
+ $param = $matches.param
183
+
184
+ $comment = ' '
182
185
183
- $comment = ' '
186
+ if ($line -match ' (?<comment>(/\*.+\*/|--.+)$)' )
187
+ {
188
+ $comment = $matches.comment
184
189
185
- if ( $line -match ' (?<comment>/\*.+\*/$) ' )
186
- {
187
- $comment = $matches . comment
188
- }
190
+ $comment = $comment -replace ' --! ' , ' //! '
191
+ $comment = $comment -replace ' --- ' , ' /// '
192
+ $comment = $comment -replace ' -- ' , ' // '
193
+ }
189
194
190
195
$argsList += $indent + $type + ' ' + $param + ' ' + $comment
191
196
}
192
- elseif ($returnType -ne $null )
193
- {
194
- write-output $line
195
- }
196
-
197
+ elseif ($returnType -ne $null )
198
+ {
199
+ write-output $line
200
+ }
201
+
197
202
if ($line -match ' }' )
198
203
{
199
204
$inCreateFunction = $false
@@ -220,11 +225,88 @@ foreach ($line in $lines)
220
225
$parens = $matches.parens
221
226
}
222
227
223
- if ($returnType -ne $null )
224
- {
225
- write-output ($returnType + ' ' + $name + $parens )
226
- }
227
-
228
+ if ($returnType -ne $null )
229
+ {
230
+ write-output ($returnType + ' ' + $name + $parens )
231
+ }
232
+
228
233
$inCreateFunction = $true
229
234
}
235
+ # If currently parsing a procedure, continue until end found.
236
+ elseif ($inCreateProcedure -eq $true )
237
+ {
238
+ $line = $line -replace ' ^as' , ' {'
239
+ $line = $line -replace ' ^go' , ' }'
240
+
241
+ if ( ($line -match ' ^{$' ) -and ($name -ne $null ) )
242
+ {
243
+ write-output (' void' + ' ' + $name + ' ()' )
244
+ write-output ' {'
245
+ }
246
+ elseif ($line -match ' ^\($' )
247
+ {
248
+ $inArgsList = $true
249
+ $argsList = @ ()
250
+
251
+ write-output (' void' + ' ' + $name )
252
+ write-output ' ('
253
+
254
+ $name = $null
255
+ }
256
+ elseif ($line -match ' ^\)$' )
257
+ {
258
+ $inArgsList = $false
259
+
260
+ $firstArg = $true
261
+
262
+ foreach ($arg in $argsList )
263
+ {
264
+ if ($firstArg -ne $true )
265
+ {
266
+ $arg = ' , ' + $arg
267
+ }
268
+
269
+ write-output $arg
270
+
271
+ $firstArg = $false
272
+ }
273
+
274
+ write-output ' )'
275
+ }
276
+ elseif ( ($inArgsList -eq $true ) -and ($line -match ' ^(?<indent>\s+)(?<param>@\w+)\s+(?<fulltype>[\w.]+)' ) )
277
+ {
278
+ $type = $matches.fulltype -replace ' ^\w+\.' , ' '
279
+ $indent = $matches.indent
280
+ $param = $matches.param
281
+
282
+ $comment = ' '
283
+
284
+ if ($line -match ' (?<comment>(/\*.+\*/|--.+)$)' )
285
+ {
286
+ $comment = $matches.comment
287
+
288
+ $comment = $comment -replace ' --!' , ' //!'
289
+ $comment = $comment -replace ' ---' , ' ///'
290
+ $comment = $comment -replace ' --' , ' //'
291
+ }
292
+
293
+ $argsList += $indent + $type + ' ' + $param + ' ' + $comment
294
+ }
295
+ else
296
+ {
297
+ write-output $line
298
+ }
299
+
300
+ if ($line -match ' }' )
301
+ {
302
+ $inCreateProcedure = $false
303
+ }
304
+ }
305
+ # Start of procedure definition?
306
+ elseif ($line -match ' ^\s*create\s+procedure\s+(?<fullname>[\w.]+)' )
307
+ {
308
+ $name = $matches.fullname -replace ' ^\w+\.' , ' '
309
+
310
+ $inCreateProcedure = $true
311
+ }
230
312
}
0 commit comments