Skip to content
Newer
Older
100644 88 lines (57 sloc) 3.25 KB
3ebfa07 @abw Initial revision
authored Jun 25, 2000
1 #========================================================================
2 # Template Toolkit - parser
3 #========================================================================
4
5 This directory contains the YAPP grammar for the Template processor. You
6 only need to worry about the files in this directory if you want to modify
7 the template parser grammar. If you're doing such a thing, then it is
8 assumed that you have some idea of what you're doing.
9
10
11 Files:
12
13 Parser.yp Yapp grammar file for the Template parser.
14 Grammar.pm.skel Skeleton file for ../lib/Template/Grammar.pm.
15 yc Simple shell cript to compile grammar and build new
16 ../lib/Template/Grammer.pm file from Grammar.pm.skel and
17 the output rules and states generated from the grammar.
18 Parser.output Output file generated by the yapp parser. This is
19 for information and debugging purposes only and can
20 otherwise be ignored.
21 README This file
22
23
24 If you don't know what you're doing and would like to, then I can
25 recommend "Lex and Yacc" by John R. Levine, Tony Mason & Doug Brown
26 (O'Reilly, ISBN: 1-56592-000-7) which gives a good introduction
27 to the principles of an LALR parser and how to define grammars in YACC.
28 YAPP is identical to YACC in all the important ways. See also the
29 Parse::Yapp documentation and the comments in Template::Parser for more
30 info. For an in-depth study of parser and compiler theory, consult
31 "Compiler Theory and Practice", a.k.a. "The Dragon Book", by Alfred
32 V. Aho, Ravi Sethi and Jeffrey D.Ullman (Addison-Wesley, ISBN:
33 0-201-10194-7)
34
35 The parser grammar is compiled by 'yapp', the front-end script to
36 Francois Desarmenien's Parse::Yapp module(s). You will need Parse::Yapp
37 version 0.32 or later, available from CPAN, to compile the grammar.
38
39 The grammar file that yapp produces (../Template/Grammar.pm) contains
40 the rule and state tables for the grammar. These are then loaded by
41 Template::Parser and used to run the DFA which is implemented by the
42 parse_directive() method. This has been derived from the standalone
43 parser created by Parse::Yapp.
44
45 Having modified the Parser.yp file to add your language changes, simply
46 run:
47
48 ./yc
49
50 to compile the grammar and install it in ../lib/Template/Grammar.pm.
51 You can then make, make test, make install, or whatever you normally
52 do, and the new grammar should be used by the template processor. To
53 revert to the original grammar, simply copy the original distribution
54 Parser.yp file back into this directory and repeat the above process.
55
56 To create a separate grammar, copy and modify the Parser.yp and
57 Grammar.pm.skel files as you wish and then run yapp to compile them:
58
59 yapp -v -s -o ../lib/Template/MyGrammar.pm \
60 -t MyGrammar.pm.skel MyParser.yp
61
62 You can then instantiate you own grammar and pass this to the
63 Template constructor.
64
65 my $template = Template->new({
66 GRAMMAR => Template::MyGrammar->new(),
67 });
68
69 Changing the grammar is a simple process, in theory at least, if you're
70 familiar with YAPP/YACC. In practice, it also requires some insight
71 into the inner working of the template toolkit which should probably
72 be better documented somewhere.
73
74
82cbea8 @abw version 2.00
authored Nov 1, 2000
75 Andy Wardley <abw@kfs.org>
3ebfa07 @abw Initial revision
authored Jun 25, 2000
76
77
78
79
80
81
82
83
84
85
86
87
Something went wrong with that request. Please try again.