Debian Codegraph @

Embperl/Syntax/ASP.pm

raw
1
2 ###################################################################################
3 #
4 # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de
5 # Embperl - Copyright (c) 2008-2014 Gerald Richter
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the Perl README file.
9 #
10 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
11 # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
12 # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13 #
14 # $Id: ASP.pm 1578075 2014-03-16 14:01:14Z richter $
15 #
16 ###################################################################################
17
18 package Embperl::Syntax::ASP ;
19
20 use Embperl::Syntax qw{:types} ;
21 use Embperl::Syntax::HTML ;
22
23 use strict ;
24 use vars qw{@ISA %Cmds %CmdsOutput %CmdsOutputLink} ;
25
26 @ISA = qw(Embperl::Syntax::HTML) ;
27
28
29 ###################################################################################
30 #
31 # Methods
32 #
33 ###################################################################################
34
35 # ---------------------------------------------------------------------------------
36 #
37 # Create new Syntax Object
38 #
39 # ---------------------------------------------------------------------------------
40
41
42 sub new
43
44 {
45 my $class = shift ;
46
47 my $self = Embperl::Syntax::HTML::new ($class) ;
48
49 if (!$self -> {-aspInit})
50 {
51 $self -> {-aspInit} = 1 ;
52 Init ($self) ;
53 }
54
55 return $self ;
56 }
57
58
59
60 ###################################################################################
61 #
62 # Definitions for ASP HTML tags
63 #
64 ###################################################################################
65
66 sub Init
67
68 {
69 my ($self) = @_ ;
70
71
72 $self -> {-aspCmds} = $self -> CloneHash ({ %Cmds, %CmdsOutput }) ;
73 $self -> {-aspCmdsLink} = $self -> CloneHash ({ %Cmds, %CmdsOutputLink }, { 'unescape' => 2 }) ;
74
75 $self -> AddToRoot ($self -> {-aspCmds}) ;
76
77 $self -> AddToRoot ({
78 'ASP Syntax' => {
79 'text' => '<%?syntax',
80 'end' => '?%>',
81 'procinfo' => {
82 embperl => {
83 compiletimeperlcode => '$_[0] -> Syntax (Embperl::Syntax::GetSyntax(%#\'0%, $_[0] -> SyntaxName));',
84 parsetimeperlcode => '$_[0] -> Syntax (Embperl::Syntax::GetSyntax(\'%%\', $_[0] -> SyntaxName)) ;',
85 removenode => 3,
86 }
87 }
88 }
89 }) ;
90
91
92
93 }
94
95 # ---------------------------------------------------------------------------------
96 #
97 # Add new simple html tag (override to add asp commands inside html tags)
98 #
99 # ---------------------------------------------------------------------------------
100
101
102 sub AddTag
103
104 {
105 my $self = shift ;
106
107 my $tag = $self -> Embperl::Syntax::HTML::AddTag (@_) ;
108
109 #### add the ASP cmd inside the new HTML Tag ####
110
111 $tag -> {inside} ||= {} ;
112 my $inside = $tag -> {inside} ;
113
114 while (my ($k, $v) = each (%{$self -> {-aspCmds}}))
115 {
116 $inside -> {$k} = $v ;
117 }
118
119 if (!$self -> {-aspHTMLInit})
120 {
121 #### if not already done add the ASP cmds inside the HTML Attributes ####
122
123 $self -> {-aspHTMLInit} = 1 ;
124
125 my $unescape = 0 ;
126 foreach ('', 'Link')
127 {
128 my $attr = $self -> {"-htmlAssignAttr$_"} ;
129 my $blocks = $self -> {"-aspCmds$_"} ;
130 while (my ($k1, $v1) = each %$attr)
131 {
132 if (!($k1 =~ /^-/) && ref ($v1) eq 'HASH')
133 {
134 my $follow = $v1 -> {follow} ;
135 if (ref($follow) eq 'HASH')
136 {
137 while (my ($k2, $v2) = each %$follow)
138 {
139 if (ref($v2) eq 'HASH')
140 {
141 $v2 -> {inside} ||= {} ;
142 my $inside = $v2 -> {inside} ;
143
144 while (my ($k, $v) = each (%$blocks))
145 {
146 $inside -> {$k} = $v ;
147 }
148 }
149 }
150 }
151 }
152 }
153 }
154
155 my $quotes = $self -> {"-htmlQuotes"} ;
156 my $blocks = $self -> {"-aspCmds"} ;
157 while (my ($k2, $v2) = each %$quotes)
158 {
159 if (ref($v2) eq 'HASH')
160 {
161 $v2 -> {inside} ||= {} ;
162 my $inside = $v2 -> {inside} ;
163
164 while (my ($k, $v) = each (%$blocks))
165 {
166 $inside -> {$k} = $v ;
167 }
168 }
169 }
170 }
171 return $tag ;
172 }
173
174 ###################################################################################
175 #
176 # ASP Implementation
177 #
178 ###################################################################################
179
180
181
182
183 %Cmds = (
184 '-lsearch' => 1,
185 'ASP Code' => {
186 'text' => '<%',
187 'end' => '%>',
188 'procinfo' =>
189 {
190 embperl =>
191 {
192 perlcode => '%$c%%#0%',
193 removenode => 3,
194 mayjump => 1,
195 compilechilds => 0,
196 },
197 },
198 }
199 ) ;
200
201 %CmdsOutput = (
202 'ASP Output' => {
203 'text' => '<%=',
204 'end' => '%>',
205 'procinfo' => {
206 embperl => {
207 perlcode =>
208 [
209 'if (!defined (_ep_rp(%$x%,scalar(%#~0:$col%)))) %#~-0:$row% { if ($col == 0) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; } else { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }}',
210 'if (!defined (_ep_rp(%$x%,scalar(%#~0:$col%)))) { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }',
211 'if (!defined (_ep_rp(%$x%,scalar(%#~0:$row%)))) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; }',
212 '_ep_rp(%$x%,scalar(%#0%));',
213 ],
214 removenode => 4,
215 mayjump => '%#~0:$col|$row|$cnt% %?*htmlrow% %?*htmltable%',
216 compilechilds => 0,
217 }
218 }
219 }
220 ) ;
221
222 %CmdsOutputLink = (
223 'ASP Output Link' => {
224 'text' => '<%=',
225 'end' => '%>',
226 'nodename' => '<%=url',
227 'unescape' => 2,
228 'procinfo' => {
229 embperl => {
230 perlcode =>
231 [
232 'if (!defined (_ep_rpurl(%$x%,scalar(%#~0:$col%)))) %#~-0:$row% { if ($col == 0) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; } else { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }}',
233 'if (!defined (_ep_rpurl(%$x%,scalar(%#~0:$col%)))) { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }',
234 'if (!defined (_ep_rpurl(%$x%,scalar(%#~0:$row%)))) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; }',
235 '_ep_rpurl(%$x%,scalar(%#0%));',
236 ],
237 removenode => 4,
238 mayjump => '%#~0:$col|$row|$cnt% %?*htmlrow% %?*htmltable%',
239 compilechilds => 0,
240 }
241 }
242 }
243 ) ;
244
245
246 1;
247
248 __END__
249
250 =pod
251
252 =head1 NAME
253
254 Embperl::Syntax::ASP - ASP syntax module for Embperl
255
256 =head1 SYNOPSIS
257
258 [$syntax ASP $]
259
260 <% $a = 1 ; %>
261 <table>
262 <% foreach (1..5) { %>
263 <tr>
264 <td><%= $_ %></td>
265 <td><%= $a += 2 %></td>
266 </tr>
267 <% } %>
268 </table>
269
270
271
272
273 =head1 DESCRIPTION
274
275 The module add the ASP syntax to Embperl. That mean when you select ASP as
276 syntax, Embperl understand the two following tags:
277
278 =over 4
279
280 =item <% %>
281
282 Between <% and %> you can put any Perl code that should be executed.
283
284
285 =item <%= %>
286
287 Between <%= and %> you can place a valid Perl expression and the result of
288 the expression is inserted instead of the <%= %> block.
289
290
291 =back
292
293 =head1 Author
294
295 Gerald Richter <richter at embperl dot org>
296
297 =head1 See Also
298
299 Embperl::Syntax
300