cvs: php-gtk /docs/scripts TemplateParser.class

From: Date: Thu, 29 Mar 2001 17:15:31 +0000
Subject: cvs: php-gtk /docs/scripts TemplateParser.class
Groups: php.gtk 
Request: Send a blank email to php-gtk+get-1195@lists.php.net to get a copy of this message
jmoore Thu Mar 29 09:15:31 2001 EDT Modified files: /php-gtk/docs/scripts TemplateParser.class Log: Updating TemplateParser due to a few small bug fixes

Index: php-gtk/docs/scripts/TemplateParser.class diff -u php-gtk/docs/scripts/TemplateParser.class:1.1 php-gtk/docs/scripts/TemplateParser.class:1.2 --- php-gtk/docs/scripts/TemplateParser.class:1.1 Mon Mar 26 11:15:49 2001 +++ php-gtk/docs/scripts/TemplateParser.class Thu Mar 29 09:15:30 2001 @@ -1,9 +1,8 @@ <?php - /* +------------------------------------------------------------------------+ - | Logic Template Engine (V2.01) | + | Logic Template Engine (V2.02) | +------------------------------------------------------------------------+ | Filename: TemplateParser.class | Copyright ©2000-2001 Servability Ltd. | +--------------------------------+---------------------------------------+ @@ -67,17 +66,16 @@ CVS Info: * - * $Id: TemplateParser.class,v 1.1 2001/03/26 19:15:49 jmoore Exp $ + * $Id: TemplateParser.class,v 1.2 2001/03/29 17:15:30 jmoore Exp $ * TODO: * * - Separate out the parser and the template handler to * use callbacks. - * - Sort out whitespace handling within the template commands. * - add foreach functionality. * - enable escaping of [% to use \[\% which will be changed to - * - [% and left in the text by the parser itself. + * [% and left in the text by the parser itself. * - Add support for ! * - Allow variables both sides of the operator. * - Remove parsing inside of html comments <!-- --> if practical. @@ -156,7 +154,6 @@ echo "<!-- " . strlen($output) . " chars -->"; // output it's length as an html comment */ - /* -- Class Entry Point -- */ class TemplateParser { @@ -432,8 +429,9 @@ { $this->get_char(); /* -- Loop until we get a non whitespace char -- */ - while(ereg("\s",$this->last_char)) + while(preg_match("/\s/i",$this->last_char)) { $this->get_char(); + } /* -- Rewind the pointers -- */ $this->rewind(); return; @@ -441,6 +439,29 @@ /* }}} */ + /* {{{ void jump_past_end_tags() + Jumps past the end tags */ + function jump_past_end_tags() + { + $this->get_char(); + while(1) { + while($this->last_char != $this->closing_tag[0]) + $this->get_char(); + + $this->get_char(); + + if($this->last_char == $this->closing_tag[1]) + break; + + } + + + return; + + } + + /* }}} */ + /* {{{ char get_token() Returns the next token in the file */ @@ -451,7 +472,7 @@ /* -- Get Charaters -- */ while($this->get_char()) { - if(($this->last_char == $this->tok_sep_char) || (ereg("\s",$this->last_char)) + if((!(ereg("[A-Za-z0-9_!=><]",$this->last_char))) || (($this->last_char == $this->closing_tag[0]) && ($this->template_buff[$this->line][$this->line_offset] == $this->closing_tag[1]))) { @@ -552,6 +573,7 @@ $this->parseflag[$this->level] = PARSER_OFF; /* -- Turn parser off -- */ $this->flagset[$this->level] = PARSER_ON; /* -- Ignore and other logic statements at this level of nesting -- */ + $this->jump_past_end_tags(); /* -- Jump past end tags -- */ break; /* -- Jump out of switch -- */ } else { @@ -564,25 +586,7 @@ $this->skip_blanks(); /* -- Skip blanks before next token -- */ $this->get_token(); /* -- Get token -- */ $operand = $this->last_token; /* -- Assign Token -- */ - $this->skip_blanks(); /* -- Jump to what should be the closing tags -- */ - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } + $this->jump_past_end_tags(); /* -- Jump past end tags -- */ if ($operator && $operand) { @@ -626,25 +630,7 @@ $this->skip_blanks(); /* -- Skip blanks before next token -- */ $this->get_token(); /* -- Get token -- */ $operand = $this->last_token; /* -- Assign Token -- */ - $this->skip_blanks(); /* -- Jump to what should be the closing tags -- */ - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } + $this->jump_past_end_tags(); /* -- Jump past end tags -- */ if($this->flagset[$this->level] == PARSER_ON) { @@ -692,51 +678,13 @@ } else { $this->parseflag[$this->level] = PARSER_OFF; } - $this->skip_blanks(); - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) - { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } + $this->jump_past_end_tags(); /* -- Jump past end tags -- */ break; /* -- End of Else -- */ case "ENDIF": $this->level--; - $this->skip_blanks(); - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) - { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } - break; + $this->jump_past_end_tags(); /* -- Jump past end tags -- */ + break; default: @@ -744,27 +692,8 @@ { $this->output_buff .= $this->defined[strtolower($this->last_token)]; } - $this->skip_blanks(); - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) - { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } - $this->get_char(); /* -- Jump past first end tag -- */ - if($this->debug) { - if($this->last_char != $this->closing_tag[0]) - { - prinf("Error: CLosing tag expected at line: %d in Template: %s <br>",$this->line, $this->template_name); - printf("Cannot recover exiting... <br>"); - exit(); - } - } - break; /* -- End of default handler -- */ + $this->jump_past_end_tags(); /* -- Jump past end tags -- */ + break; /* -- End of default handler -- */ } /* -- End of switch -- */ $this->handle_text(); return; @@ -772,7 +701,5 @@ /* }}} */ -} /* -- End of class -- */ - - -?> +}/* -- End of class -- */ +?> \ No newline at end of file
« previous php.gtk (#1195) next »