#=========================================================================
#
# Template::Grammar
#
# DESCRIPTION
# Perl 5 module defining the default grammar for Template::Parser.
#
# AUTHOR
# Andy Wardley <abw@cre.canon.co.uk>
#
# COPYRIGHT
# Copyright (C) 1996-1999 Andy Wardley. All Rights Reserved.
# Copyright (C) 1998-1999 Canon Research Centre Europe Ltd.
#
# This module is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
#------------------------------------------------------------------------
#
# NOTE: this module is constructed from the parser/Grammar.pm.skel
# file by running the parser/yc script. You only need to do this if
# you have modified the grammar in the parser/Parser.yp file and need
# to-recompile it. See the README in the 'parser' directory for more
# information (sub-directory of the Template distribution).
#
#------------------------------------------------------------------------
#
# $Id: Grammar.pm.skel,v 1.18 2000/05/19 09:38:26 abw Exp $
#
#========================================================================
package Template::Grammar;
require 5.004;
use strict;
use vars qw( $VERSION );
use Template::Constants qw( :ops :status );
$VERSION = sprintf("%d.%02d", q$Revision: 1.18 $ =~ /(\d+)\.(\d+)/);
my (@RESERVED, $LEXTABLE, $RULES, $STATES);
my $factory;
sub new {
my $class = shift;
bless {
LEXTABLE => $LEXTABLE,
STATES => $STATES,
RULES => $RULES,
};
}
# update method to set package-scoped $factory lexical
sub install_factory {
my ($self, $new_factory) = @_;
$factory = $new_factory;
}
#========================================================================
# Reserved Words
#========================================================================
@RESERVED = qw(
GET CALL SET DEFAULT INCLUDE PROCESS
IF UNLESS ELSE ELSIF FOR WHILE USE FILTER
THROW CATCH ERROR RETURN STOP BREAK MACRO
PERL BLOCK END TO STEP AND OR NOT
);
#========================================================================
# Lexer Token Table
#========================================================================
# lookup table used by lexer is initialised with special-cases
$LEXTABLE = {
'FOREACH' => 'FOR',
'&&' => 'AND',
'||' => 'OR',
'!' => 'NOT',
'|' => 'FILTER',
'.' => 'DOT',
'..' => 'TO',
'=' => 'ASSIGN',
'=>' => 'ASSIGN',
',' => 'COMMA',
'\\' => 'REF',
'and' => 'AND', # explicitly specified so that qw( and or
'or' => 'OR', # not ) can always be used in lower case,
'not' => 'NOT' # regardless of CASE sensitivity flag
};
# localise the temporary variables needed to complete lexer table
{
my @tokens = qw< ( ) [ ] { } ${ $ / ; >;
my @compop = qw( == != < <= >= > );
my @binop = qw( + - * DIV MOD );
# fill lexer table, slice by slice, with reserved words and operators
@$LEXTABLE{ @RESERVED, @compop, @binop, @tokens }
= ( @RESERVED, ('COMPOP') x @compop, ('BINOP') x @binop, @tokens );
}
#========================================================================
# States
#========================================================================
$STATES = <<$states>>;
#========================================================================
# Rules
#========================================================================
$RULES = <<$rules>>;
1;