Skip to content

Commit

Permalink
simplified tree building process, more tolerant of missing closers now.
Browse files Browse the repository at this point in the history
  • Loading branch information
roojs committed Nov 16, 2004
1 parent c528d2b commit 16d78fe
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Flexy/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,51 @@ function buildTokens($tokenizer)
//
//




for($i=1;$i<$total;$i++) {
//echo "Checking TAG $i\n";
if (empty($res[$i]->tag)) {
continue;
}
if ($res[$i]->tag{0} == '/') { // it's a close tag..
//echo "GOT END TAG: {$res[$i]->tag}\n";
$tag = strtoupper(substr($res[$i]->tag,1));
if (!count($stack)) {
continue;
}
$ssc = count($stack) - 1;
for($s = $ssc; $s > -1; $s--) {
if (!isset($stack[$s])) {
echo "MISSED STACK? $s<BR><PRE>";print_r($stack);exit;
}
if (!isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$stack[$s]])) {
echo "STACKED BAD OFFSET : {$stack[$s]}<BR><PRE>";print_r($stack);exit;
}
$tok = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$stack[$s]];
if (strtoupper($tok->tag) == $tag) {
// got the matching closer..
//echo "MATCH: {$i}:{$tok->tag} to {$stack[$s]}:$tag<BR>";
$tok->close = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i];
$sc = count($stack);
for ($ss = $ssc;$ss!=$s;$ss--) {
array_pop($stack);

}

continue 2;
}
}
continue;
}
$stack[] = $i;
// tag with no closer (or unmatched in stack..)
}
//print_R($stack);
//exit;
/*
for($i=1;$i<$total;$i++) {
//echo "Checking TAG $i\n";
Expand Down Expand Up @@ -340,6 +385,7 @@ function buildTokens($tokenizer)
// too many closes - just ignore it..
$stack[$tag]['pos'] = 0;
}
continue;
}
// new entry on stack..
Expand All @@ -352,7 +398,10 @@ function buildTokens($tokenizer)
}
$stack[$tag][$npos] = $i;
}
*/

// create a dummy close for the end
$i = $total;
Expand Down

0 comments on commit 16d78fe

Please sign in to comment.