Embperl base class for defining custom syntaxes
Embperl::Syntax provides a base class from which all custom syntaxes should be derived. Currently Embperl comes with the following derived syntaxes:
all the HTML tag that Embperl recognizes by default
all the [ ] blocks that Embperl supports
The default syntax; is derived from EmbperlHtml and EmbperlBlocks
EmbperlHtml
EmbperlBlocks
<% %> and <%= %>, see perldoc Embperl::Syntax::ASP
Server Side Includes, see perldoc Embperl::Syntax::SSI
File contains pure Perl (similar to Apache::Registry), but can be used inside EmbperlObject
File contains only Text, no actions is taken on the Text
Defines the <mail:send> tag, for sending mail. This is an example for a taglib, which could be a base for writing your own taglib to extent the number of available tags
Parses POD out of any file and creates a XML tree similar to pod2xml, which can be formatted by XSLT afterwards.
You can choose which syntax is used inside your page, either by the EMBPERL_SYNTAX configuration directive, the syntax, parameter to Execute or the [$ syntax $] metacommand.
EMBPERL_SYNTAX
syntax
Execute
[$ syntax $]
You can also specify multiple syntaxes e.g.
PerlSetEnv EMBPERL_SYNTAX "Embperl SSI" Execute ({inputfile => '*', syntax => 'Embperl ASP'}) ;
The syntax metacommand allows to switch the syntax or to add or subtract syntaxes e.g.
[$ syntax + Mail $]
will add the Mail taglib so the <mail:send> tag is available after this line.
[$ syntax - Mail $]
now the <mail:send> tag is unknown again
[$ syntax SSI $]
now you can only use SSI commands inside your page.
If you want to define your own syntax, you have to derive a new class from one of the existing ones and extent it with new tags/functionality. The best thing is to take a look at the syntax classes that comes with Embperl. (inside the directory Embperl/Syntax/).
For example if you want to add new html tags, derive from Embperl::Syntax::HTML, if you want to add new metacommands derive from Embperl::Syntax::EmbperlBlocks.
Some of the classes define addtionaly methods to easily add new tags. See the respective pod file, which methods are available for a certain class.
Embperl::Syntax defines the basic methods to create a syntax:
Create a new syntax class. This method should only be called inside a constructor of a derived class.
This adds a new element to the root of the parser tree. $elements must be a hashref. See Embperl::Syntax::ASP for an example.
$elements
This gives you the possibility to add some Perl code, that is always executed at the beginning of a document ($initcode), at the end of the document ($termcode) or at compile time ($compiletimecode). The three strings must be valid Perl code. See Embperl::Syntax::SSI for an example. $procinfo is a hashref that can consits of addtional processor infos (see below) for the document.
$initcode
$termcode
$compiletimecode
$procinfo
Returns the root of the parser tree.
Returns a syntax object which is build form the syntaxes named in $name. If $oldname is given, $name can start with a + or - to add or subtract a syntax. This is normaly only needed by Embperl itself or to implement a syntax switch statement (see Embperl::Syntax::SSI for an example.)
$name
$oldname
+
-
Clones a hash which is given as hashref in $old, optional replace the tags given in the hashref $replace and return a hashref to the new hash.
$old
$replace
Internaly the syntax object builds a data structure which serve as base for the parser. This structure consists of a list of tokens and options, which starts with a dash:
Do an linear serach instead of a binary search. This is necessary if the tokens can't clearly separated.
Defines the default type for text nodes. Without any specification the type is CDATA, which mean no escaping takes places. With ntypText all special characters are escaped.
ntypText
Name for a root node to insert always.
All items which does not start with a slash are treated as names. The name of a token is only descriptive and is used in error messages. The item must contain a hashref which describes the token.
Each token can have the following members:
Start text
End text
when set to 1 new token starts at next character, when set to -1 new token starts at next character, but only if it is the first token inside another one.
Text that should be outputed when node is stringifyed. Defaults to text. If the first character is a ':' you can specify the sourounding delimiters for this tag with :<start>:<end>:<text>:<endtag>. Example: ':{:}:NAME' . If the nodename starts with a '!' a unique internal id is generated, so two or more nodename of the same text, can have different meaning in different contexts.
Token consists of the following characters. Either start and end or contains could be specified.
start
end
contains
NOTE: If a item that only specfifies contains but no text should be compiled, you must specfify a nodname.
If optRawInput isn't set unescape the data of the inside the node
optRawInput
Type of the node
Type of nodes for data (which is not matched by 'inside' definitions) inside this node. Set to zero to not generate any nodes for text inside of this node, other then these that are matched by a 'inside' definition.
Name of the tag that marks the end of a block. This is used by the parser to track correct nesting.
Hashref that specifices one or more tokens that must follow this token.
Hashref that specifices one or more tokens that could occur inside a node that is started with this token.
when the token found, the parser stop searching in the current level and continues with the tokens that are defined in the hash from there the current one was "called" via inside
set to 1 to don't eat the start text, so it will be matched again, by any tokens set under inside. Set 2 to don't the end text. Set to 3 for both.
inside
Processor info. Hashref with informations how to process this token.
The processor info gives information how to compile this token to valid code that can be executed later on by the processor. There could be informations for multiple processors. At the moment only the embperl processor is defined. Normaly you must not worry about different processor, because the syntax object knows inside that all procinfo is for the embperl processor. procinfo is a parameter to many methods, it is a hashref and can take the following items:
Code to generate. You can also specify a arrayref of strings. The first string which contains matching attributes are used. The following special strings are replaced:
Text of childnode number <N> (starting with zero)
Text of sibling node number <N> . 0 gives the current node, > 0 gives the Nth next node, < 0 gives the Nth previous node.
Value of attribute <attr>.
Stringvalue of given stack
Set if stackvalue was used
Source Dom Tree, Index of current node.
Source Dom Tree
Index of current node
Index of last node
Sets the current node Index, if not already done
Index of source Dom Tree
Number of current checkpoint
Gives a single %
All of the above special values (expect those start with $) allows the following modifiers:
Attribute/Child etc. must exist.
Attribute/Child etc. must not exist.
Attribute/Child etc. must have the value = <value1> or <value2> etc.
Attribute/Child etc. must contain the substring <value1> or <value2> etc. and a non alphanum character must follow the substring.
writing a minus sign (-) after * ! = or ~ will cause the child/attribute not to be included, but the condition is evaluated. Writing an ' will cause the value to be quoted.
Code to generate at the end of the block.
Code that is executed at compile time. You can also specify a arrayref of string. The first string which contains matching attributes are used. The same special strings are replaced as in perlcode.
perlcode
$_[0] contains the Embperl request object. The method Code can be used to get or set the perl code that should be generated by this node.
$_[0]
Code
If the code begins with #!- all newlines are removed in the code. This is basicly usefull to keep all code on the same line, so the linenumber in error reporting matches the line in the source.
Code that is executed at compile time, but at the end of the tag. The same special strings are replaced as in perlcode.
Remove perlcode if perlcodeend condition is not met.
Remove node after compiling. <removelevel> could be one of the following, values could be added:
Remove this node only
Remove next node if it consists of only white spaces and optKeepSpaces isn't set.
Replace next node with one space if next node consists only of white spaces and optKeepSpaces isn't set.
Set this node to ignore for output.
Remove all child nodes
Set all child nodes to ignore for output.
Calculate Attributes values of this node also for nodes that are set to ignore for output (makes only sense if 8 is also set).
Remove spaces before or after tag.
Remove all white spaces before tag
Remove all white spaces after tag
Remove spaces and tabs before tag
Remove spaces and tabs after tag
Remove all spaces and tabs but one before tag
Remove all whihe space after text inside of tag
Remove spaces and tabs after text inside of tag
If set, tells the compiler that this code may jump to another programm location. (e.g. if, while, goto etc.). Could also be a condition as described under perlcode.
Compile child nodes. Default: 1
Name of stack for push, stackmatch
push
stackmatch
Name of stack for push2
push2
Push value on stack which name is given with stackname. Value could include the same specical values as perlcode
stackname
Push value on stack which name is given with stackname2. Value could include the same specical values as perlcode
stackname2
Check if value on stack which name is given with stackname is the same as the given value. If not give a error message about tag mismatch. Value could include the same specical values as perlcode
1 means put the following code into normal code which is executed everytime the page is requested
2 means put the following code put into code which is executed direct after compilation. This is mainly for defining subs, or using modules etc.
10 POD Errors
The following errors were encountered while parsing the POD:
You have '=item 4' instead of the expected '=item 3'
You have '=item 8' instead of the expected '=item 4'
You have '=item 16' instead of the expected '=item 5'
You have '=item 32' instead of the expected '=item 6'
You have '=item 64' instead of the expected '=item 7'
To install Embperl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Embperl
CPAN shell
perl -MCPAN -e shell install Embperl
For more information on module installation, please visit the detailed CPAN module installation guide.