1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
###############################################################################
#
# Class: NaturalDocs::Languages::PLSQL
#
###############################################################################
#
# A subclass to handle the language variations of PL/SQL.
#
###############################################################################
# This file is part of Natural Docs, which is Copyright (C) 2003-2008 Greg Valure
# Natural Docs is licensed under the GPL
use strict;
use integer;
package NaturalDocs::Languages::PLSQL;
use base 'NaturalDocs::Languages::Simple';
#
# Function: OnPrototypeEnd
#
# Microsoft's SQL specifies parameters as shown below.
#
# > CREATE PROCEDURE Test @as int, @foo int AS ...
#
# Having a parameter @is or @as is perfectly valid even though those words are also used to end the prototype. We need to
# ignore text-based enders preceded by an at sign. Also note that it does not have parenthesis for parameter lists. We need to
# skip all commas if the prototype doesn't have parenthesis but does have @ characters.
#
# Identifiers such as function names may contain the characters $, #, and _, so if "as" or "is" appears directly after one of them
# we need to ignore the ender there as well.
#
# > FUNCTION Something_is_something ...
#
# Parameters:
#
# type - The <TopicType> of the prototype.
# prototypeRef - A reference to the prototype so far, minus the ender in dispute.
# ender - The ender symbol.
#
# Returns:
#
# ENDER_ACCEPT - The ender is accepted and the prototype is finished.
# ENDER_IGNORE - The ender is rejected and parsing should continue. Note that the prototype will be rejected as a whole
# if all enders are ignored before reaching the end of the code.
# ENDER_ACCEPT_AND_CONTINUE - The ender is accepted so the prototype may stand as is. However, the prototype might
# also continue on so continue parsing. If there is no accepted ender between here and
# the end of the code this version will be accepted instead.
# ENDER_REVERT_TO_ACCEPTED - The expedition from ENDER_ACCEPT_AND_CONTINUE failed. Use the last accepted
# version and end parsing.
#
sub OnPrototypeEnd #(type, prototypeRef, ender)
{
my ($self, $type, $prototypeRef, $ender) = @_;
# _ should be handled already.
if ($ender =~ /^[a-z]+$/i && substr($$prototypeRef, -1) =~ /^[\@\$\#]$/)
{ return ::ENDER_IGNORE(); }
elsif ($type eq ::TOPIC_FUNCTION() && $ender eq ',')
{
if ($$prototypeRef =~ /^[^\(]*\@/)
{ return ::ENDER_IGNORE(); }
else
{ return ::ENDER_ACCEPT(); };
}
else
{ return ::ENDER_ACCEPT(); };
};
#
# Function: ParsePrototype
#
# Overridden to handle Microsoft's parenthesisless version. Otherwise just throws to the parent.
#
# Parameters:
#
# type - The <TopicType>.
# prototype - The text prototype.
#
# Returns:
#
# A <NaturalDocs::Languages::Prototype> object.
#
sub ParsePrototype #(type, prototype)
{
my ($self, $type, $prototype) = @_;
my $noParenthesisParameters = ($type eq ::TOPIC_FUNCTION() && $prototype =~ /^[^\(]*\@/);
if ($prototype !~ /\(.*[^ ].*\)/ && !$noParenthesisParameters)
{ return $self->SUPER::ParsePrototype($type, $prototype); };
my ($beforeParameters, $afterParameters, $isAfterParameters);
if ($noParenthesisParameters)
{
($beforeParameters, $prototype) = split(/\@/, $prototype, 2);
$prototype = '@' . $prototype;
};
my @tokens = $prototype =~ /([^\(\)\[\]\{\}\<\>\'\"\,]+|.)/g;
my $parameter;
my @parameterLines;
my @symbolStack;
foreach my $token (@tokens)
{
if ($isAfterParameters)
{ $afterParameters .= $token; }
elsif ($symbolStack[-1] eq '\'' || $symbolStack[-1] eq '"')
{
if ($noParenthesisParameters || $symbolStack[0] eq '(')
{ $parameter .= $token; }
else
{ $beforeParameters .= $token; };
if ($token eq $symbolStack[-1])
{ pop @symbolStack; };
}
elsif ($token =~ /^[\(\[\{\<\'\"]$/)
{
if ($noParenthesisParameters || $symbolStack[0] eq '(')
{ $parameter .= $token; }
else
{ $beforeParameters .= $token; };
push @symbolStack, $token;
}
elsif ( ($token eq ')' && $symbolStack[-1] eq '(') ||
($token eq ']' && $symbolStack[-1] eq '[') ||
($token eq '}' && $symbolStack[-1] eq '{') ||
($token eq '>' && $symbolStack[-1] eq '<') )
{
if (!$noParenthesisParameters && $token eq ')' && scalar @symbolStack == 1 && $symbolStack[0] eq '(')
{
$afterParameters .= $token;
$isAfterParameters = 1;
}
else
{ $parameter .= $token; };
pop @symbolStack;
}
elsif ($token eq ',')
{
if (!scalar @symbolStack)
{
if ($noParenthesisParameters)
{
push @parameterLines, $parameter . $token;
$parameter = undef;
}
else
{
$beforeParameters .= $token;
};
}
else
{
if (scalar @symbolStack == 1 && $symbolStack[0] eq '(' && !$noParenthesisParameters)
{
push @parameterLines, $parameter . $token;
$parameter = undef;
}
else
{
$parameter .= $token;
};
};
}
else
{
if ($noParenthesisParameters || $symbolStack[0] eq '(')
{ $parameter .= $token; }
else
{ $beforeParameters .= $token; };
};
};
push @parameterLines, $parameter;
foreach my $item (\$beforeParameters, \$afterParameters)
{
$$item =~ s/^ //;
$$item =~ s/ $//;
}
my $prototypeObject = NaturalDocs::Languages::Prototype->New($beforeParameters, $afterParameters);
# Parse the actual parameters.
foreach my $parameterLine (@parameterLines)
{
$prototypeObject->AddParameter( $self->ParseParameterLine($parameterLine) );
};
return $prototypeObject;
};
#
# Function: ParseParameterLine
#
# Parses a prototype parameter line and returns it as a <NaturalDocs::Languages::Prototype::Parameter> object.
#
sub ParseParameterLine #(line)
{
my ($self, $line) = @_;
$line =~ s/^ //;
$line =~ s/ $//;
my @tokens = $line =~ /([^\(\)\[\]\{\}\<\>\'\"\:\=\ ]+|\:\=|.)/g;
my ($name, $type, $defaultValue, $defaultValuePrefix, $inType, $inDefaultValue);
my @symbolStack;
foreach my $token (@tokens)
{
if ($inDefaultValue)
{ $defaultValue .= $token; }
elsif ($symbolStack[-1] eq '\'' || $symbolStack[-1] eq '"')
{
if ($inType)
{ $type .= $token; }
else
{ $name .= $token; };
if ($token eq $symbolStack[-1])
{ pop @symbolStack; };
}
elsif ($token =~ /^[\(\[\{\<\'\"]$/)
{
if ($inType)
{ $type .= $token; }
else
{ $name .= $token; };
push @symbolStack, $token;
}
elsif ( ($token eq ')' && $symbolStack[-1] eq '(') ||
($token eq ']' && $symbolStack[-1] eq '[') ||
($token eq '}' && $symbolStack[-1] eq '{') ||
($token eq '>' && $symbolStack[-1] eq '<') )
{
if ($inType)
{ $type .= $token; }
else
{ $name .= $token; };
pop @symbolStack;
}
elsif ($token eq ' ')
{
if ($inType)
{ $type .= $token; }
elsif (!scalar @symbolStack)
{ $inType = 1; }
else
{ $name .= $token; };
}
elsif ($token eq ':=' || $token eq '=')
{
if (!scalar @symbolStack)
{
$defaultValuePrefix = $token;
$inDefaultValue = 1;
}
elsif ($inType)
{ $type .= $token; }
else
{ $name .= $token; };
}
else
{
if ($inType)
{ $type .= $token; }
else
{ $name .= $token; };
};
};
foreach my $part (\$type, \$defaultValue)
{
$$part =~ s/ $//;
};
return NaturalDocs::Languages::Prototype::Parameter->New($type, undef, $name, undef, $defaultValue, $defaultValuePrefix);
};
sub TypeBeforeParameter
{ return 0; };
1;
|