~ubuntu-branches/ubuntu/trusty/teeworlds/trusty-updates

« back to all changes in this revision

Viewing changes to docs/tool/Modules/NaturalDocs/Languages/PLSQL.pm

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-08-05 15:02:49 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20110805150249-1kai5j7v29m13dl3
Tags: 0.6.1+dfsg-1
* New upstream release.
* Repackage upstream tarball to remove pre-compiled libraries.
* Update watch file.
* Refresh patches.
* Drop patches that have been applied upstream: fix-ftbfs-hurd.patch,
  fix-ftbfs-kfreebsd.patch and gcc-endianness.patch.
* Use dh_link to create the DejaVuSans.ttf symlink.
* Query dpkg-buildflags instead of relying on dpkg-buildpackage to set the
  environment variables.

Show diffs side-by-side

added added

removed removed

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