1#============================================================= -*-Perl-*-
2#
3# Template::Grammar
4#
5# DESCRIPTION
6#   Grammar file for the Template Toolkit language containing token
7#   definitions and parser state/rules tables generated by Parse::Yapp.
8#
9# AUTHOR
10#   Andy Wardley   <abw@wardley.org>
11#
12# COPYRIGHT
13#   Copyright (C) 1996-2006 Andy Wardley.  All Rights Reserved.
14#   Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
15#
16#   This module is free software; you can redistribute it and/or
17#   modify it under the same terms as Perl itself.
18#
19# REVISION
20#   $Id$
21#
22# IMPORTANT NOTE
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).
28#
29#========================================================================
30
31package Template::Grammar;
32
33use strict;
34use warnings;
35
36our $VERSION  = 2.25;
37
38my (@RESERVED, %CMPOP, $LEXTABLE, $RULES, $STATES);
39my ($factory, $rawstart);
40
41
42#========================================================================
43
44# Reserved words, comparison and binary operators
45#========================================================================
46
47@RESERVED = qw( 
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
52    );
53
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.
59
60
61%CMPOP = qw( 
62    != ne
63    == eq
64    <  <
65    >  >
66    >= >=
67    <= <=
68);
69
70#    eq eq  # add these lines to the above to 
71#    lt lt  # enable the eq, lt and gt operators      
72#    gt gt
73
74#========================================================================
75# Lexer Token Table
76#========================================================================
77
78# lookup table used by lexer is initialised with special-cases
79$LEXTABLE = {
80    'FOREACH' => 'FOR',
81    'BREAK'   => 'LAST',
82    '&&'      => 'AND',
83    '||'      => 'OR',
84    '!'       => 'NOT',
85    '|'	      => 'FILTER',
86    '.'       => 'DOT',
87    '_'       => 'CAT',
88    '..'      => 'TO',
89#    ':'       => 'MACRO',
90    '='       => 'ASSIGN',
91    '=>'      => 'ASSIGN',
92#    '->'      => 'ARROW',
93    ','       => 'COMMA',
94    '\\'      => 'REF',
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
98    'mod'     => 'MOD',
99    'div'     => 'DIV',
100};
101
102# localise the temporary variables needed to complete lexer table
103{ 
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
109
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 );
113}
114
115
116#========================================================================
117# CLASS METHODS
118#========================================================================
119
120sub new {
121    my $class = shift;
122    bless {
123	LEXTABLE => $LEXTABLE,
124	STATES   => $STATES,
125	RULES    => $RULES,
126    }, $class;
127}
128
129# update method to set package-scoped $factory lexical 
130sub install_factory {
131    my ($self, $new_factory) = @_;
132    $factory = $new_factory;
133}
134
135
136#========================================================================
137# States
138#========================================================================
139
140$STATES = <<$states>>; 
141
142
143#========================================================================
144# Rules
145#========================================================================
146
147$RULES = <<$rules>>;
148
149
150
1511;
152
153__END__
154
155=head1 NAME
156
157Template::Grammar - Parser state/rule tables for the TT grammar
158
159=head1 SYNOPSIS
160
161    # no user serviceable parts inside
162
163=head1 DESCRIPTION
164
165This module defines the state and rule tables that the L<Template::Parser>
166module uses to parse templates.  It is generated from a YACC-like grammar
167using the C<Parse::Yapp> module.  The F<parser> sub-directory of the 
168Template Toolkit source distribution contains the grammar and other 
169files required to generate this module.
170
171But you don't need to worry about any of that unless you're planning to 
172modify the Template Toolkit language.
173
174=head1 AUTHOR
175
176Andy Wardley E<lt>abw@wardley.orgE<gt>
177
178L<http://wardley.org/>
179
180=head1 COPYRIGHT
181
182Copyright (C) 1996-2007 Andy Wardley.  All Rights Reserved.
183
184This module is free software; you can redistribute it and/or
185modify it under the same terms as Perl itself.
186
187=head1 SEE ALSO
188
189L<Template::Parser>
190
191=cut
192
193# Local Variables:
194# mode: perl
195# perl-indent-level: 4
196# indent-tabs-mode: nil
197# End:
198#
199# vim: expandtab shiftwidth=4:
200
201
202
203
204
205
206
207
208
209
210