
###################################################################################
#
#   Embperl - Copyright (c) 1997-2000 Gerald Richter / ECOS
#
#   You may distribute under the terms of either the GNU General Public
#   License or the Artistic License, as specified in the Perl README file.
#
#   THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
#   IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
#   WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
#   $Id$
#
###################################################################################
 


package HTML::Embperl::Syntax ;

use constant  ntypTag           => 1 ;
use constant  ntypStartTag      => 1 + 0x20 ;
use constant  ntypEndTag        => 1 + 0x40 ;
use constant  ntypEndStartTag   => 1 + 0x60 ;
use constant  ntypAttr	        => 2 ;
use constant  ntypAttrValue     => 2 + 0x20 ;
use constant  ntypText	        => 3 ;
use constant  ntypCDATA	        => 4 ;
use constant  ntypEntityRef       => 5 ;
use constant  ntypEntity          => 6 ;
use constant  ntypProcessingInstr => 7 ;
use constant  ntypComment         => 8 ;
use constant  ntypDocument        => 9 ;
use constant  ntypDocumentType    => 10 ;
use constant  ntypDocumentFraq    => 11 ;
use constant  ntypNotation        => 12 ;


sub clonehash
    {
    my ($old, $new, $replace) = @_ ;


    $replace ||= {} ;    
    my ($v, $k) ;

    while (($k, $v) = each (%$old))
        {
        if ($replace -> {$k})
            {
            $new -> {$k} = $replace -> {$k} ;
            }
        else
            {
            if (ref ($v) eq 'HASH')
                {
                $new -> {$k} = clonehash ($v, {}, $replace) ;
                }
            elsif (ref ($v) eq 'ARRAY')
                {
                $new -> {$k} = [$v] ;
                }
            else
                {
                $new -> {$k} = $v ;
                }
            }
        }

    return $new ;
    }


###################################################################################
#
#   Default Syntax
#
###################################################################################




%Attr = (
    '-lsearch' => 1,
    'Attribut ""' => 
        {
        'text'   => '"',
        'end'    => '"',
        'inside' => \%Cmds,
        'nodetype'   => ntypAttr,
        'cdatatype'  => ntypAttrValue,
        },
    'Attribut \'\'' => 
        {
        'text'   => '\'',
        'end'    => '\'',
        'inside' => \%Cmds,
        'nodetype'   => ntypAttr,
        'cdatatype'  => ntypAttrValue,
        },
    'Attribut alphanum' => 
        {
        'contains'   => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789',
        'inside' => \%Cmds,
        'nodetype'   => ntypAttr,
        'cdatatype'  => ntypAttrValue,
        }
    ) ;


%AssignAttr = (
    'Assign' => 
        {
        'text' => '=',
        'follow' => \%Attr,
        }
    ) ;


%AssignAttrLink = (
    'Assign' => 
        {
        'text' => '=',
        'follow' => \%AttrLink,
        }
    ) ;


%Cmds = (
    '-lsearch' => 1,
    'Embperl command escape' => {
        'text' => '[[',
        'nodename' => '[',
        'nodetype' => ntypCDATA,
        },
    'Embperl meta command' => {
        'text' => '[$',
        'end'  => '$]',
        'follow' => \%MetaCmds,
        'unescape' => 1,
        },
     'Embperl output code' => {
        'text' => '[+',
        'end'  => '+]',
        'unescape' => 1,
        'procinfo' => {
            embperl => { 
                    perlcode => 
                        [
                        'if (!defined (_ep_rp(%$n%,scalar(do{%#~0:$col%})))) %#~-0:$row% { if ($col == 0) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; } else { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }}',
                        'if (!defined (_ep_rp(%$n%,scalar(do{%#~0:$col%})))) { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }',
                        'if (!defined (_ep_rp(%$n%,scalar(do{%#~0:$row%})))) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; }',
                        '_ep_rp(%$n%,scalar(do{%#0%}));', 
                        ],
                    removenode  => 4,
                    mayjump => '%#~0:$col|$row|$cnt% %?*htmlrow% %?*htmltable%',
                    compilechilds => 0,
                    }
            },
        },
     'Embperl code' => {
        'text' => '[-',
        'end'  => '-]',
        'unescape' => 1,
        'procinfo' => {
            embperl => { 
                        perlcode    => [
                                '$_ep_node=%$l%;if (!defined (scalar(do{%#~0:$col%}))) %#~-0:$row% { if ($col == 0) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; } else { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }}',
                                '$_ep_node=%$l%;if (!defined (scalar(do{%#~0:$col%}))) { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }',
                                '$_ep_node=%$l%;if (!defined (scalar(do{%#~0:$row%}))) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; }',
                                '$_ep_node=%$l%;{%#0%;}',
                                ],
                        removenode  => 3,
                        mayjump     => 1,
                        compilechilds => 0,
                        },
            },
        },
     'Embperl global code' => {
        'text' => '[*',
        'end'  => '*]',
        'unescape' => 1,
        'procinfo' => {
            embperl => { 
                        perlcode    => '$_ep_node=%$l%;%#0%',
                        removenode  => 3,
                        mayjump     => 1,
                        compilechilds => 0,
                        },
            },
        },
     'Embperl startup code' => {
        'text' => '[!',
        'end'  => '!]',
        'unescape' => 1,
        'procinfo' => {
            embperl =>  { 
                        compiletimeperlcode => '%#0%;',
                        removenode  => 3,
                        compilechilds => 0,
                        }
            },
        },
     'Embperl comment' => {
        'text' => '[#',
        'end'  => '#]',
#        'inside' => \%MetaComment,
        'procinfo' => {
            embperl => { 
                compilechilds => 0,
                removenode  => 3, 
                },
            },
        },
      ) ;  
   
%MetaComment = (
    '-lsearch' => 1,
     'Embperl comment' => {
        'text' => '[#',
        'end'  => '#]',
        'inside' => \%MetaComment
        },
) ;


%HtmlTagsStd = (
        'cdatatype'  => ntypAttrValue,
        'inside'    => \%Cmds,
        ) ;


%ProcInfoTable = (
            embperl => { 
                perlcode    => 'l%$l%: for (my $row = 0; $row < $maxrow; $row++) {' ,
                perlcodeend =>  '} %?*-htmltable%' ,
                perlcoderemove => 1,
                stackname   => 'htmltable',
                'push'        => '%$l%',
                mayjump     => 1,
                }                     
            ) ;



%HtmlTags = (
    'input' => {
        'text' => 'input',
        'cdatatype'  => ntypAttrValue,
        'inside' => 
            {
            'type'  => { 'text' => 'type',  'nodename' => 'type',  follow => \%AssignAttr },
            'name'  => { 'text' => 'name',  'nodename' => 'name',  follow => \%AssignAttr },
            'value' => { 'text' => 'value', 'nodename' => 'value', follow => \%AssignAttr },
            'checked' => { 'text' => 'checked', 'nodetype'   => ntypAttr, },
            %Cmds,
            },
        'procinfo' => {
            embperl => { 
                perlcode =>
                    [ 
                    'HTML::Embperl::Cmd::InputCheck (%$n%, %&*\'name%, %&*\'value%) ;  %&=-type:radio|checkbox% ',
                    '$idat{%&*\'name%}=$fdat{%&*\'name%} ; _ep_sa(%$n%, \'value\', $fdat{%&*\'name%} || \'\') ;   %&!-value%',
                    '$idat{%&*\'name%}=%&*\'value% ; ',
                    ]
                }                     
            },
         },
    'textarea' => {
        'text' => 'textarea',
        'nodetype'   => ntypStartTag, 
        'cdatatype'  => ntypAttrValue,
        'inside' => 
            {
            'name'  => { 'text' => 'name',  'nodename' => 'name',  follow => \%AssignAttr },
            %Cmds,
            },
        'procinfo' => {
            embperl => { 
                perlcode =>
                    [ 
                    '$idat{%&*\'name%}=$fdat{%&*\'name%};_ep_ac(%$n%, HTML::Embperl::Syntax::ntypText, $fdat{%&*\'name%}) ;   %#!-0%',
                    '$idat{%&*\'name%}=\'%#*0%\' ; ',
                    ]
                }                     
            },
         },
    '/textarea' => {
         'text' => '/textarea',
         'nodetype'   => ntypEndTag, 
         'cdatatype'  => 0,
         'starttag'   => 'textarea', 
         },
    'tr' => {
        'text' => 'tr',
        'nodetype'   => ntypStartTag, 
        %HtmlTagsStd,
        'procinfo' => {
            embperl => { 
                perlcode    => 'l%$l%: for (my $col = 0; $col < $maxcol; $col++) {' ,
                perlcodeend => '} %?*-htmlrow%' ,
                perlcoderemove => 1,
                stackname   => 'htmlrow',
                'push'        => '%$l%',
                mayjump     => 1,
                }                     
            },
        },
    '/tr' => {
        'text' => '/tr',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'tr', 
         },
    'table' => {
        'text' => 'table',
        'nodetype'   => ntypStartTag, 
        %HtmlTagsStd,
        'procinfo' => \%ProcInfoTable,
         },
    '/table' => {
        'text' => '/table',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'table', 
         },
    'ol' => {
        'text' => 'ol',
        'nodetype'   => ntypStartTag, 
        %HtmlTagsStd,
        'procinfo' => \%ProcInfoTable,
         },
    '/ol' => {
        'text' => '/ol',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'ol', 
         },
    'ul' => {
        'text' => 'ul',
        'nodetype'   => ntypStartTag, 
        %HtmlTagsStd,
        'procinfo' => \%ProcInfoTable,
         },
    '/ul' => {
        'text' => '/ul',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'ul', 
         },
    'dl' => {
        'text' => 'dl',
        'nodetype'   => ntypStartTag, 
        %HtmlTagsStd,
        'procinfo' => \%ProcInfoTable,
         },
    '/dl' => {
        'text' => '/dl',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'dl', 
         },
    'menu' => {
        'text' => 'menu',
        'nodetype'   => ntypStartTag, 
        %HtmlTagsStd,
        'procinfo' => \%ProcInfoTable,
         },
    '/menu' => {
        'text' => '/menu',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'menu', 
         },
    'dir' => {
        'text' => 'dir',
        'nodetype'   => ntypStartTag, 
        %HtmlTagsStd,
        'procinfo' => \%ProcInfoTable,
         },
    '/dir' => {
        'text' => '/dir',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'dir', 
         },
#    'th' => {
#        'text' => 'th',
#        'nodetype'   => ntypStartTag, 
#        %HtmlTagsStd,
#         },
#    '/th' => {
#        'text' => '/th',
#        'nodetype'   => ntypEndTag, 
#        'cdatatype'  => 0,
#         'starttag'   => 'th', 
#         },
    'select' => {
        'text' => 'select',
        'nodetype'   => ntypStartTag, 
        'inside' => 
            {
            'name'  => { 'text' => 'name',  'nodename' => 'name', follow => \%AssignAttr },
            %Cmds,
            },
        'procinfo' => {
            embperl => { 
                stackname2   => 'htmlselect',
                push2        => '%&*name%',

                perlcode    => 'l%$l%: for (my $row = 0; $row < $maxrow; $row++) {' ,
                perlcodeend =>  '} %?*-htmltable%' ,
                perlcoderemove => 1,
                stackname   => 'htmltable',
                'push'        => '%$l%',
                mayjump     => 1,
                }                     
            },
         },
    'option' => {
        'text' => 'option',
        'nodetype'   => ntypTag, 
        %HtmlTagsStd,
        'inside' => 
            {
            'value'  => { 'text' => 'value',  'nodename' => 'value',  follow => \%AssignAttr },
            'selected' => { 'text' => 'selected', 'nodetype'   => ntypAttr, },
            %Cmds,
            },
        'procinfo' => {
            embperl => { 
                perlcode =>
                    [ 
                    '_ep_opt (%$n%, %^*\'htmlselect%, %&*\'value%);',
                    '_ep_opt (%$n%, %^*\'htmlselect%, %>*\'0%);',
                    ]
                }                     
            },
         },
    '/option' => {
        'text' => '/option',
        'nodetype'   => ntypTag, 
        'cdatatype'  => 0,
         'starttag'   => 'option', 
         },
    '/select' => {
        'text' => '/select',
        'nodetype'   => ntypEndTag, 
        'cdatatype'  => 0,
         'starttag'   => 'select', 
         },
    'body' => {
        'text' => 'body',
        %HtmlTagsStd,
         },
    'a' => {
        'text' => 'a',
        'cdatatype'  => ntypAttrValue,
        'inside' => \%HrefLink,
         },
    'frame' => {
        'text' => 'frame',
        'inside' => \%SrcLink,
        'cdatatype'  => ntypAttrValue,
         },
    'iframe' => {
        'text' => 'iframe',
        'inside' => \%SrcLink,
        'cdatatype'  => ntypAttrValue,
         },
    'embed' => {
        'text' => 'embed',
        'cdatatype'  => ntypAttrValue,
        'inside' => \%SrcLink,
         },
    'layer' => {
        'text' => 'layer',
        'cdatatype'  => ntypAttrValue,
        'inside' => \%SrcLink,
         },
    'img' => {
        'text' => 'img',
        'cdatatype'  => ntypAttrValue,
        'inside' => \%SrcLink,
         },
    'form' => {
        'text' => 'form',
        'cdatatype'  => ntypAttrValue,
        'inside' => \%ActionLink,
         },

    ) ;


%MetaCmds = (
    'if' => {
        'text' => 'if',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'cdatatype'  => ntypAttrValue,
        'unescape' => 1,
        'endtag'   => 'endif',
        'procinfo' => {
            embperl => { 
                perlcode => 'if (%&<noname>%) { ', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                'push'        => 'if',
                }
            },
         },
    'else' => {
        'text' => 'else',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'unescape' => 1,
        'endtag'   => 'endif',
        'procinfo' => {
            embperl => { 
                perlcode => '} else {',
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                stackmatch  => 'if',
                'push'      => 'if',
                }
            },
         },
    'endif' => {
        'text' => 'endif',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'cdatatype'  => 0,
        'procinfo' => {
            embperl => { 
                perlcode => '}', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                stackmatch  => 'if',
                }
            },
         },
    'elsif' => {
        'text' => 'elsif',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'cdatatype'  => ntypAttrValue,
        'unescape' => 1,
        'endtag'   => 'endif',
        'procinfo' => {
            embperl => { 
                perlcode => '} elsif (%&<noname>%) { ', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                stackmatch  => 'if',
                'push'      => 'if',
                }
            },
         },
    'while' => {
        'text' => 'while',
        'nodetype'   => ntypTag, 
        'cdatatype'  => ntypAttrValue,
        'forcetype'  => 1,
        'unescape' => 1,
        'endtag'   => 'endwhile',
        'procinfo' => {
            embperl => { 
                perlcode => 'while (%&<noname>%) { ', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                'push'      => 'while',
                }
            },
         },
    'endwhile' => {
        'text' => 'endwhile',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'cdatatype'  => 0,
        'procinfo' => {
            embperl => { 
                perlcode => '};', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                stackmatch  => 'while',
                }
            },
         },
    'foreach' => {
        'text' => 'foreach',
        'nodetype'   => ntypTag, 
        'cdatatype'  => ntypAttrValue,
        'forcetype'  => 1,
        'unescape' => 1,
        'endtag'   => 'endforeach',
        'procinfo' => {
            embperl => { 
                perlcode => 'foreach %&<noname>% { ', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                'push'      => 'foreach',
                }
            },
         },
    'endforeach' => {
        'text' => 'endforeach',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'cdatatype'  => 0,
        'procinfo' => {
            embperl => { 
                perlcode => '};', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                stackmatch  => 'foreach',
                }
            },
         },
    'do' => {
        'text' => 'do',
        'nodetype'   => ntypTag, 
        'cdatatype'  => 0,
        'forcetype'  => 1,
        'unescape' => 1,
        'endtag'   => 'until',
        'procinfo' => {
            embperl => { 
                perlcode => 'do { ', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                'push'      => 'do',
                }
            },
         },
    'until' => {
        'text' => 'until',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'cdatatype'  => ntypAttrValue,
        'unescape' => 1,
        'procinfo' => {
            embperl => { 
                perlcode => '} until (%&<noname>%) ; ',
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                stackmatch  => 'do',
                }
            },
         },
    'var' => {
        'text' => 'var',
        'cdatatype'  => ntypAttrValue,
        'unescape' => 1,
        'procinfo' => {
            embperl => { 
                perlcode => 'use strict ; use vars qw {%&<noname>%} ;', 
                removenode => 3,
                }
            },
         },
    'hidden' => {
        'text' => 'hidden',
        'cdatatype'  => ntypAttrValue,
        'unescape' => 1,
        'procinfo' => {
            embperl => { 
                perlcode => '_ep_hid(%$n%,%&\'<noname>%);', 
                removenode => 8,
                }
            },
         },
    'sub' => {
        'text' => 'sub',
        'nodetype'   => ntypTag, 
        'cdatatype'  => ntypAttrValue,
        'forcetype'  => 1,
        'unescape' => 1,
        'endtag'   => 'endsub',
        'procinfo' => {
            embperl => { 
                perlcode => 'sub %&<noname>% { ', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                'push'      => 'sub',
                switchcodetype => 2,
                }
            },
         },
    'endsub' => {
        'text' => 'endsub',
        'nodetype'   => ntypTag, 
        'forcetype'  => 1,
        'cdatatype'  => 0,
        'procinfo' => {
            embperl => { 
                perlcode => '};', 
                removenode => 10,
                mayjump     => 1,
                stackname   => 'metacmd',
                stackmatch  => 'sub',
                switchcodetype => 1,
                }
            },
         },
    ) ;


%MetaCmdsDropTag = (
    'br' => {
        'text' => '<br>',
        'follow' => \%MetaCmds,
        },
    'p' => {
        'text' => '<p>',
        'follow' => \%MetaCmds,
        },
    %MetaCmds,
    ) ;





clonehash (\%Cmds, \%CmdsLink, { 'unescape' => 2 }) ;

$CmdsLink{'Embperl output code'}{'nodename'} = '[+url' ;
$CmdsLink{'Embperl output code'}{'procinfo'}{'embperl'}{'perlcode'} = 
                        [
                        'if (!defined (_ep_rpurl(%$n%,scalar(do{%#~0:$col%})))) %#~-0:$row% { if ($col == 0) { _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; } else { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }}',
                        'if (!defined (_ep_rpurl(%$n%,scalar(do{%#~0:$col%})))) { _ep_dcp (%$t%,%^*htmlrow%) ; last l%^*htmlrow% ; }',
                        'if (!defined (_ep_rpurl(%$n%,scalar($val3=do{%#~0:$row%;})))) {  _ep_dcp (%$t%,%^*htmltable%) ; last l%^*htmltable% ; }',
                        '_ep_rpurl(%$n%,scalar(do{%#0%}));', 
                        ] ;



clonehash (\%Attr, \%AttrLink, { inside => \%CmdsLink }) ;


%HrefLink = (
            'link'  => { 'text' => 'href',  'nodename' => 'href', follow => \%AssignAttrLink },
            %Cmds,
) ;

%SrcLink = (
            'link'  => { 'text' => 'src',  'nodename' => 'src', follow => \%AssignAttrLink },
            %Cmds,
) ;

%ActionLink = (
            'link'  => { 'text' => 'action',  'nodename' => 'action', follow => \%AssignAttrLink },
            %Cmds,
) ;



%Default = (
    '-lsearch' => 1,

    # The document node is generated always and is not parserd, but can be used to include code
    'Document' => {
        'nodename'  => 'Document',
        'nodetype'  => ntypDocument, 
        'procinfo'  => {
            embperl => { 
                perlcode    => q{ 
my $_ep_DomTree = $_[1];
},
                compiletimeperlcode => q{
*_ep_rp=\\&XML::Embperl::DOM::Node_replaceChildWithCDATA;
*_ep_rpurl=\\&XML::Embperl::DOM::Node_replaceChildWithUrlDATA;
*_ep_cp=\\&XML::Embperl::DOM::DomTree_checkpoint;
*_ep_dcp=\\&XML::Embperl::DOM::DomTree_discardAfterCheckpoint;
*_ep_opt=\\&HTML::Embperl::Cmd::Option;
*_ep_hid=\\&HTML::Embperl::Cmd::Hidden;
*_ep_ac=\\&XML::Embperl::DOM::Node_appendChild;
*_ep_sa=\\&XML::Embperl::DOM::Element_setAttribut; 
},
                perlcodeend => '# Include here any cleanup code', 
                stackname   => 'metacmd',
                stackmatch  => 'Document',
                'push'      => 'Document',
                }
            },
        },
    # The document fraq node is generated always and is not parserd, but can be used to include code
    'DocumentFraq' => {
        'nodename'  => 'DocumentFraq',
        'nodetype'  => ntypDocumentFraq, 
        'procinfo'  => {
            embperl => { 
                perlcode    => q{ 
my $_ep_DomTree = $_[1];
},
                compiletimeperlcode => q{
*_ep_rp=\\&XML::Embperl::DOM::Node_replaceChildWithCDATA;
*_ep_rpurl=\\&XML::Embperl::DOM::Node_replaceChildWithUrlDATA;
*_ep_cp=\\&XML::Embperl::DOM::DomTree_checkpoint;
*_ep_dcp=\\&XML::Embperl::DOM::DomTree_discardAfterCheckpoint;
*_ep_opt=\\&HTML::Embperl::Cmd::Option;
*_ep_hid=\\&HTML::Embperl::Cmd::Hidden;
*_ep_ac=\\&XML::Embperl::DOM::Node_appendChild;
*_ep_sa=\\&XML::Embperl::DOM::Element_setAttribut; 
},
                perlcodeend => '# Include here any cleanup code', 
                stackname   => 'metacmd',
                stackmatch  => 'DocumentFraq',
                'push'      => 'DocumentFraq',
                }
            },
        },
    'HTML Tag' => {
        'text' => '<',
        'end'  => '>',
        'follow' => \%HtmlTags,
        },
    'HTML Comment' => {
        'text' => '<!--',
        'end'  => '-->',
        },
    %Cmds,

    ) ;




__END__

=pod



=over 4

=item    '-lsearch' => 1

Do an linear serach instead of a binary search. This is necessary if the 
tokens can't clearly separated.

=item    <name> => \%token

All items which does not start with a slash are treated as names. The name
of a token is only descriptiv and is used in error messages. The item must
contain a hashref which describes the token.

=back

=head2 Tokendescription

=over 4

=item 'text' => '<'

Start text

=item 'end'  => '>'

End text

=item 'contains'   => 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789'

Token consists of the following characters. Either C<start> and C<end> B<or> C<contains>
could be specified.

=item 'unescape' => 1

If C<optRawInput> isn't set unescape the data of the inside the node

=item 'nodetype'   => ntypEndTag

Type of the node

=item 'cdatatype'  => ntypAttrValue

Type of nodes for data inside this node.

=item 'endtag'

Name of the tag that marks the end of a block.

=item 'follow' => \%HtmlTags

Hashref that specifices one or more tokens that must follow this token.

=item 'inside' => \%Cmds

Hashref that specifices one or moer tokens that could occur inside
a node that is started with this token.

=item 'procinfo' => 

Processor info. Hashref with informations how to process this token.

=back

=head2 Processor info for Embperl 

            embperl => { 
                        perlcode    => '%#0%;',
                        removenode  => 1,
                        },


=over 4

=item perlcode => <string> or <arrayref>

Code to generate. You can also specify a arrayref of string.
The first string which contains matching attributes are used.
The following special strings are replaced:

=over 4

=item %#<N>% 

Text of childnode number <N> (starting with zero)

=item %><N>% 

Text of sibling node number <N> (starting with zero)

=item %&<attr>%

Value of attribute <attr>.

=item %^<stackname>%

Stringvalue of given stack

=item %?<stackname>%

Set if stackvalue was used

=item %$n%

Node number.

=item %$l%

Unique label

=item %$l+%

Unique label and increment to next label

=back


All of the above special values (expect those start with $) allows the following
modifiers:

=over 4

=item %<X>B<*><N>%

Attribute/Child etc. must exist.

=item %<X>B<!><N>%

Attribute/Child etc. must not exist.

=item %<X>B<=><N>:<value1>|<value2>|<value3>%

Attribute/Child etc. must have the value = <value1> or <value2> etc.

=item %<X>B<~><N>:<value1>|<value2>|<value3>%

Attribute/Child etc. must contain the substring <value1> or <value2> etc.

=back

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.

=item perlcodeend => <string> 

Code to generate at the end of the block.

=item compiletimeperlcode => <string> or <arrayref>

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 C<perlcode>.

=item perlcoderemove => 0/1

Remove perlcode if perlcodeend condition is not met.


=item removenode => <removelevel>

Remove node after compiling. <removelevel> could be one of the following,
values could be added:

=over 4

=item 1

Remove this node only

=item 2

Remove next node if it consists of only white spaces and optKeepSpaces isn't set.

=item 4

Replace next node with one space if next node consists only of white spaces and
optKeepSpaces isn't set.

=item 8

Set this node to ignore for output.

=back

=item mayjump => 0/1

If set, tells the compiler that this code may jump to another programm location.
(e.g. if, while, goto etc.).

=item compilechilds => 0/1

Compile child nodes. Default: 1

=item stackname => <name>

Name of stack for C<push>, C<stackmatch>
 
=item stackname2 => <name>

Name of stack for C<push2>
 
=item push => <value> 

Push value on stack which name is given with C<stackname>. Value could
include the same specical values as C<perlcode>

=item push2 => <value> 

Push value on stack which name is given with C<stackname2>. Value could
include the same specical values as C<perlcode>

=item stackmatch => <value> 

Check if value on stack which name is given with C<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 C<perlcode>

=item switchcodetype => <1/2>

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.


=back

