1 ###############################################################################
3 # Class: NaturalDocs::Languages::Pascal
5 ###############################################################################
7 # A subclass to handle the language variations of Pascal and Delphi.
9 ###############################################################################
11 # This file is part of Natural Docs, which is Copyright © 2003-2010 Greg Valure
12 # Natural Docs is licensed under version 3 of the GNU Affero General Public License (AGPL)
13 # Refer to License.txt for the complete details
18 package NaturalDocs::Languages::Pascal;
20 use base 'NaturalDocs::Languages::Simple';
24 # hash: prototypeDirectives
26 # An existence hash of all the directives that can appear after a function prototype and will be included. The keys are the all
29 my %prototypeDirectives = ( 'overload' => 1,
47 # hash: longPrototypeDirectives
49 # An existence hash of all the directives with parameters that can appear after a function prototype and will be included. The
50 # keys are the all lowercase keywords.
52 my %longPrototypeDirectives = ( 'alias' => 1,
56 # bool: checkingForDirectives
58 # Set after the first function semicolon, which means we're in directives mode.
60 my $checkingForDirectives;
66 # Just overridden to reset <checkingForDirectives>.
70 my ($self, @parameters) = @_;
72 $checkingForDirectives = 0;
74 return $self->SUPER::OnCode(@parameters);
79 # Function: OnPrototypeEnd
81 # Pascal's syntax has directives after the prototype that should be included.
83 # > function MyFunction ( param1: type ); virtual; abstract;
87 # type - The <TopicType> of the prototype.
88 # prototypeRef - A reference to the prototype so far, minus the ender in dispute.
89 # ender - The ender symbol.
93 # ENDER_ACCEPT - The ender is accepted and the prototype is finished.
94 # ENDER_IGNORE - The ender is rejected and parsing should continue. Note that the prototype will be rejected as a whole
95 # if all enders are ignored before reaching the end of the code.
96 # ENDER_ACCEPT_AND_CONTINUE - The ender is accepted so the prototype may stand as is. However, the prototype might
97 # also continue on so continue parsing. If there is no accepted ender between here and
98 # the end of the code this version will be accepted instead.
99 # ENDER_REVERT_TO_ACCEPTED - The expedition from ENDER_ACCEPT_AND_CONTINUE failed. Use the last accepted
100 # version and end parsing.
102 sub OnPrototypeEnd #(type, prototypeRef, ender)
104 my ($self, $type, $prototypeRef, $ender) = @_;
106 if ($type eq ::TOPIC_FUNCTION() && $ender eq ';')
108 if (!$checkingForDirectives)
110 $checkingForDirectives = 1;
111 return ::ENDER_ACCEPT_AND_CONTINUE();
113 elsif ($$prototypeRef =~ /;[ \t]*([a-z]+)([^;]*)$/i)
115 my ($lastDirective, $extra) = (lc($1), $2);
117 if (exists $prototypeDirectives{$lastDirective} && $extra =~ /^[ \t]*$/)
118 { return ::ENDER_ACCEPT_AND_CONTINUE(); }
119 elsif (exists $longPrototypeDirectives{$lastDirective})
120 { return ::ENDER_ACCEPT_AND_CONTINUE(); }
122 { return ::ENDER_REVERT_TO_ACCEPTED(); };
125 { return ::ENDER_REVERT_TO_ACCEPTED(); };
128 { return ::ENDER_ACCEPT(); };
132 sub ParseParameterLine #(...)
134 my ($self, @params) = @_;
135 return $self->SUPER::ParsePascalParameterLine(@params);
138 sub TypeBeforeParameter