1 #============================================================= -*-Perl-*-
6 # Grammar file for the Template Toolkit language containing token
7 # definitions and parser state/rules tables generated by Parse::Yapp.
10 # Andy Wardley <abw@wardley.org>
13 # Copyright (C) 1996-2006 Andy Wardley. All Rights Reserved.
14 # Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
16 # This module is free software; you can redistribute it and/or
17 # modify it under the same terms as Perl itself.
20 # $Id: Grammar.pm 1243 2009-07-04 15:32:19Z abw $
23 # This module is constructed from the parser/Grammar.pm.skel file by
24 # running the parser/yc script. You only need to do this if # you
25 # have modified the grammar in the parser/Parser.yp file and need #
26 # to-recompile it. See the README in the 'parser' directory for
27 # more information (sub-directory of the Template distribution).
29 #========================================================================
31 package Template::Grammar;
38 my (@RESERVED, %CMPOP, $LEXTABLE, $RULES, $STATES);
39 my ($factory, $rawstart);
42 #========================================================================
44 # Reserved words, comparison and binary operators
45 #========================================================================
48 GET CALL SET DEFAULT INSERT INCLUDE PROCESS WRAPPER BLOCK END
49 USE PLUGIN FILTER MACRO PERL RAWPERL TO STEP AND OR NOT DIV MOD
50 IF UNLESS ELSE ELSIF FOR NEXT WHILE SWITCH CASE META IN
51 TRY THROW CATCH FINAL LAST RETURN STOP CLEAR VIEW DEBUG
54 # for historical reasons, != and == are converted to ne and eq to perform
55 # stringwise comparison (mainly because it doesn't generate "non-numerical
56 # comparison" warnings which != and == can) but the others (e.g. < > <= >=)
57 # are not converted to their stringwise equivalents. I added 'gt' et al,
58 # briefly for v2.04d and then took them out again in 2.04e.
70 # eq eq # add these lines to the above to
71 # lt lt # enable the eq, lt and gt operators
74 #========================================================================
76 #========================================================================
78 # lookup table used by lexer is initialised with special-cases
95 'and' => 'AND', # explicitly specified so that qw( and or
96 'or' => 'OR', # not ) can always be used in lower case,
97 'not' => 'NOT', # regardless of ANYCASE flag
102 # localise the temporary variables needed to complete lexer table
104 # my @tokens = qw< ( ) [ ] { } ${ $ / ; : ? >;
105 my @tokens = qw< ( ) [ ] { } ${ $ + / ; : ? >;
106 my @cmpop = keys %CMPOP;
107 # my @binop = qw( + - * % ); # '/' above, in @tokens
108 my @binop = qw( - * % ); # '+' and '/' above, in @tokens
110 # fill lexer table, slice by slice, with reserved words and operators
111 @$LEXTABLE{ @RESERVED, @cmpop, @binop, @tokens }
112 = ( @RESERVED, ('CMPOP') x @cmpop, ('BINOP') x @binop, @tokens );
116 #========================================================================
118 #========================================================================
123 LEXTABLE => $LEXTABLE,
129 # update method to set package-scoped $factory lexical
130 sub install_factory {
131 my ($self, $new_factory) = @_;
132 $factory = $new_factory;
136 #========================================================================
138 #========================================================================
199 'defblockname' => 14,
584 'defblockname' => 14,
1223 'defblockname' => 14,
2223 'defblockname' => 14,
2436 'defblockname' => 14,
2703 'defblockname' => 14,
2799 'defblockname' => 14,
2972 'defblockname' => 14,
3052 'defblockname' => 14,
3192 'defblockname' => 14,
3272 'defblockname' => 14,
3660 'defblockname' => 14,
3767 'defblockname' => 14,
3896 'defblockname' => 14,
4032 'defblockname' => 14,
4173 'defblockname' => 14,
4262 'defblockname' => 14,
4559 'defblockname' => 14,
4675 'defblockname' => 14,
4765 'defblockname' => 14,
4863 'defblockname' => 14,
4962 'defblockname' => 14,
5068 'defblockname' => 14,
5148 'defblockname' => 14,
5201 #========================================================================
5203 #========================================================================
5212 #line 64 "Parser.yp"
5213 { $factory->template($_[1]) }
5218 #line 67 "Parser.yp"
5219 { $factory->block($_[1]) }
5224 #line 68 "Parser.yp"
5225 { $factory->block() }
5230 #line 71 "Parser.yp"
5231 { push(@{$_[1]}, $_[2])
5232 if defined $_[2]; $_[1] }
5237 #line 73 "Parser.yp"
5238 { defined $_[1] ? [ $_[1] ] : [ ] }
5243 #line 76 "Parser.yp"
5244 { $factory->textblock($_[1]) }
5249 #line 77 "Parser.yp"
5250 { return '' unless $_[1];
5251 $_[0]->location() . $_[1];
5255 'statement', 1, undef
5258 'statement', 1, undef
5261 'statement', 1, undef
5264 'statement', 1, undef
5267 'statement', 1, undef
5270 'statement', 1, undef
5273 'statement', 1, undef
5276 'statement', 1, undef
5281 #line 90 "Parser.yp"
5282 { $factory->get($_[1]) }
5287 #line 91 "Parser.yp"
5288 { $_[0]->add_metadata($_[2]); }
5291 'statement', 0, undef
5296 #line 95 "Parser.yp"
5297 { $factory->set($_[1]) }
5300 'directive', 1, undef
5303 'directive', 1, undef
5306 'directive', 1, undef
5309 'directive', 1, undef
5312 'directive', 1, undef
5315 'directive', 1, undef
5320 #line 109 "Parser.yp"
5321 { $factory->get($_[1]) }
5324 'atomexpr', 1, undef
5329 #line 113 "Parser.yp"
5330 { $factory->get($_[2]) }
5335 #line 114 "Parser.yp"
5336 { $factory->call($_[2]) }
5341 #line 115 "Parser.yp"
5342 { $factory->set($_[2]) }
5347 #line 116 "Parser.yp"
5348 { $factory->default($_[2]) }
5353 #line 117 "Parser.yp"
5354 { $factory->insert($_[2]) }
5359 #line 118 "Parser.yp"
5360 { $factory->include($_[2]) }
5365 #line 119 "Parser.yp"
5366 { $factory->process($_[2]) }
5371 #line 120 "Parser.yp"
5372 { $factory->throw($_[2]) }
5377 #line 121 "Parser.yp"
5378 { $factory->return() }
5383 #line 122 "Parser.yp"
5384 { $factory->stop() }
5389 #line 123 "Parser.yp"
5390 { "\$output = '';"; }
5395 #line 124 "Parser.yp"
5396 { $_[0]->block_label('last ', ';') }
5401 #line 125 "Parser.yp"
5402 { $_[0]->in_block('FOR')
5403 ? $factory->next($_[0]->block_label)
5404 : $_[0]->block_label('next ', ';') }
5409 #line 128 "Parser.yp"
5410 { if ($_[2]->[0]->[0] =~ /^'(on|off)'$/) {
5411 $_[0]->{ DEBUG_DIRS } = ($1 eq 'on');
5412 $factory->debug($_[2]);
5415 $_[0]->{ DEBUG_DIRS } ? $factory->debug($_[2]) : '';
5428 #line 141 "Parser.yp"
5429 { $factory->if(@_[2, 4, 5]) }
5434 #line 142 "Parser.yp"
5435 { $factory->if(@_[3, 1]) }
5440 #line 144 "Parser.yp"
5441 { $factory->if("!($_[2])", @_[4, 5]) }
5446 #line 145 "Parser.yp"
5447 { $factory->if("!($_[3])", $_[1]) }
5452 #line 149 "Parser.yp"
5453 { unshift(@{$_[5]}, [ @_[2, 4] ]);
5459 #line 151 "Parser.yp"
5465 #line 152 "Parser.yp"
5471 #line 156 "Parser.yp"
5472 { $factory->switch(@_[2, 5]) }
5477 #line 160 "Parser.yp"
5478 { unshift(@{$_[5]}, [ @_[2, 4] ]);
5484 #line 162 "Parser.yp"
5490 #line 163 "Parser.yp"
5496 #line 164 "Parser.yp"
5502 #line 167 "Parser.yp"
5503 { $_[0]->enter_block('FOR') }
5508 #line 168 "Parser.yp"
5509 { $factory->foreach(@{$_[2]}, $_[5], $_[0]->leave_block) }
5514 #line 169 "Parser.yp"
5515 { $factory->foreach(@{$_[3]}, $_[1]) }
5520 #line 170 "Parser.yp"
5521 { $_[0]->enter_block('WHILE') }
5526 #line 171 "Parser.yp"
5527 { $factory->while(@_[2, 5], $_[0]->leave_block) }
5532 #line 172 "Parser.yp"
5533 { $factory->while(@_[3, 1]) }
5538 #line 175 "Parser.yp"
5544 #line 176 "Parser.yp"
5550 #line 177 "Parser.yp"
5556 #line 181 "Parser.yp"
5557 { $factory->wrapper(@_[2, 4]) }
5562 #line 183 "Parser.yp"
5563 { $factory->wrapper(@_[3, 1]) }
5568 #line 187 "Parser.yp"
5569 { $factory->try(@_[3, 4]) }
5574 #line 191 "Parser.yp"
5575 { unshift(@{$_[5]}, [ @_[2,4] ]);
5581 #line 194 "Parser.yp"
5582 { unshift(@{$_[5]}, [ undef, $_[4] ]);
5588 #line 197 "Parser.yp"
5589 { unshift(@{$_[4]}, [ undef, $_[3] ]);
5595 #line 199 "Parser.yp"
5601 #line 200 "Parser.yp"
5607 #line 203 "Parser.yp"
5608 { $factory->use($_[2]) }
5613 #line 206 "Parser.yp"
5614 { $_[0]->push_defblock(); }
5619 #line 207 "Parser.yp"
5620 { $factory->view(@_[2,5],
5621 $_[0]->pop_defblock) }
5626 #line 211 "Parser.yp"
5627 { ${$_[0]->{ INPERL }}++; }
5632 #line 212 "Parser.yp"
5633 { ${$_[0]->{ INPERL }}--;
5634 $_[0]->{ EVAL_PERL }
5635 ? $factory->perl($_[4])
5636 : $factory->no_perl(); }
5641 #line 218 "Parser.yp"
5642 { ${$_[0]->{ INPERL }}++;
5643 $rawstart = ${$_[0]->{'LINE'}}; }
5648 #line 220 "Parser.yp"
5649 { ${$_[0]->{ INPERL }}--;
5650 $_[0]->{ EVAL_PERL }
5651 ? $factory->rawperl($_[4], $rawstart)
5652 : $factory->no_perl(); }
5657 #line 227 "Parser.yp"
5658 { $factory->filter(@_[2,4]) }
5663 #line 229 "Parser.yp"
5664 { $factory->filter(@_[3,1]) }
5669 #line 234 "Parser.yp"
5670 { my $name = join('/', @{ $_[0]->{ DEFBLOCKS } });
5671 pop(@{ $_[0]->{ DEFBLOCKS } });
5672 $_[0]->define_block($name, $_[4]);
5679 #line 241 "Parser.yp"
5680 { push(@{ $_[0]->{ DEFBLOCKS } }, $_[2]);
5685 'blockname', 1, undef
5690 #line 247 "Parser.yp"
5691 { $_[1] =~ s/^'(.*)'$/$1/; $_[1] }
5694 'blockargs', 1, undef
5697 'blockargs', 0, undef
5702 #line 255 "Parser.yp"
5704 print STDERR "experimental block args: [@{ $_[2] }]\n"
5706 $factory->anon_block($_[4]) }
5711 #line 261 "Parser.yp"
5712 { $factory->capture(@_[1, 3]) }
5717 #line 265 "Parser.yp"
5718 { $factory->macro(@_[2, 6, 4]) }
5723 #line 266 "Parser.yp"
5724 { $factory->macro(@_[2, 3]) }
5732 #line 270 "Parser.yp"
5738 #line 273 "Parser.yp"
5739 { push(@{$_[1]}, $_[2]); $_[1] }
5744 #line 274 "Parser.yp"
5750 #line 275 "Parser.yp"
5756 #line 278 "Parser.yp"
5757 { push(@{$_[1]}, @{$_[2]}); $_[1] }
5760 'metadata', 2, undef
5763 'metadata', 1, undef
5768 #line 283 "Parser.yp"
5769 { for ($_[3]) { s/^'//; s/'$//;
5776 #line 286 "Parser.yp"
5782 #line 287 "Parser.yp"
5794 #line 299 "Parser.yp"
5800 #line 300 "Parser.yp"
5806 #line 301 "Parser.yp"
5812 #line 302 "Parser.yp"
5818 #line 305 "Parser.yp"
5819 { $factory->ident($_[1]) }
5824 #line 306 "Parser.yp"
5825 { $factory->identref($_[2]) }
5830 #line 307 "Parser.yp"
5831 { $factory->quoted($_[2]) }
5842 #line 312 "Parser.yp"
5854 #line 317 "Parser.yp"
5855 { $_[1] . '..' . $_[3] }
5863 #line 322 "Parser.yp"
5869 #line 325 "Parser.yp"
5881 #line 330 "Parser.yp"
5882 { "$_[1] => $_[3]" }
5887 #line 331 "Parser.yp"
5888 { "$_[1] => $_[3]" }
5893 #line 334 "Parser.yp"
5894 { push(@{$_[1]}, @{$_[3]}); $_[1] }
5899 #line 335 "Parser.yp"
5901 map {($_, 0)} split(/\./, $_[3]));
5910 #line 341 "Parser.yp"
5916 #line 342 "Parser.yp"
5917 { [ $_[1], $factory->args($_[3]) ] }
5922 #line 345 "Parser.yp"
5928 #line 346 "Parser.yp"
5934 #line 347 "Parser.yp"
5935 { $_[0]->{ V1DOLLAR }
5937 : $factory->ident(["'$_[2]'", 0]) }
5942 #line 352 "Parser.yp"
5943 { "$_[1] $_[2] $_[3]" }
5948 #line 353 "Parser.yp"
5949 { "$_[1] $_[2] $_[3]" }
5954 #line 354 "Parser.yp"
5955 { "$_[1] $_[2] $_[3]" }
5960 #line 355 "Parser.yp"
5961 { "int($_[1] / $_[3])" }
5966 #line 356 "Parser.yp"
5972 #line 357 "Parser.yp"
5973 { "$_[1] $CMPOP{ $_[2] } $_[3]" }
5978 #line 358 "Parser.yp"
5984 #line 359 "Parser.yp"
5985 { "$_[1] && $_[3]" }
5990 #line 360 "Parser.yp"
5991 { "$_[1] || $_[3]" }
5996 #line 361 "Parser.yp"
6002 #line 362 "Parser.yp"
6003 { "$_[1] ? $_[3] : $_[5]" }
6008 #line 363 "Parser.yp"
6009 { $factory->assign(@{$_[2]}) }
6014 #line 364 "Parser.yp"
6023 #line 368 "Parser.yp"
6024 { push(@{$_[1]}, @{$_[2]}); $_[1] }
6035 #line 374 "Parser.yp"
6036 { [ $_[1], $_[3] ] }
6041 #line 375 "Parser.yp"
6047 #line 382 "Parser.yp"
6048 { push(@{$_[1]}, $_[2]); $_[1] }
6053 #line 383 "Parser.yp"
6054 { push(@{$_[1]->[0]}, $_[2]); $_[1] }
6059 #line 384 "Parser.yp"
6060 { push(@{$_[1]->[0]}, "'', " .
6061 $factory->assign(@_[2,4])); $_[1] }
6066 #line 386 "Parser.yp"
6072 #line 387 "Parser.yp"
6078 #line 397 "Parser.yp"
6079 { push(@{$_[3]}, $_[1]); $_[3] }
6082 'lnameargs', 1, undef
6090 #line 402 "Parser.yp"
6091 { $factory->quoted($_[2]) }
6099 #line 406 "Parser.yp"
6100 { [ [$factory->ident($_[2])], $_[3] ] }
6105 #line 407 "Parser.yp"
6111 #line 408 "Parser.yp"
6117 #line 411 "Parser.yp"
6118 { push(@{$_[1]}, $_[3]); $_[1] }
6123 #line 412 "Parser.yp"
6129 #line 415 "Parser.yp"
6130 { $factory->quoted($_[2]) }
6135 #line 416 "Parser.yp"
6144 #line 420 "Parser.yp"
6148 'filename', 1, undef
6151 'filepart', 1, undef
6154 'filepart', 1, undef
6157 'filepart', 1, undef
6162 #line 434 "Parser.yp"
6163 { push(@{$_[1]}, $_[2])
6164 if defined $_[2]; $_[1] }
6169 #line 436 "Parser.yp"
6175 #line 439 "Parser.yp"
6176 { $factory->ident($_[1]) }
6181 #line 440 "Parser.yp"
6182 { $factory->text($_[1]) }
6187 #line 441 "Parser.yp"
6200 Template::Grammar - Parser state/rule tables for the TT grammar
6204 # no user serviceable parts inside
6208 This module defines the state and rule tables that the L<Template::Parser>
6209 module uses to parse templates. It is generated from a YACC-like grammar
6210 using the C<Parse::Yapp> module. The F<parser> sub-directory of the
6211 Template Toolkit source distribution contains the grammar and other
6212 files required to generate this module.
6214 But you don't need to worry about any of that unless you're planning to
6215 modify the Template Toolkit language.
6219 Andy Wardley E<lt>abw@wardley.orgE<gt>
6221 L<http://wardley.org/>
6225 Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved.
6227 This module is free software; you can redistribute it and/or
6228 modify it under the same terms as Perl itself.
6238 # perl-indent-level: 4
6239 # indent-tabs-mode: nil
6242 # vim: expandtab shiftwidth=4: