Scurvy.php
private function parseRecursive($start, $regex, $subName = 'template') {
		$re_beg = $regex[0];
		$re_end = $regex[1];

		$numLines = count($this->strings);
		$i = $start;
		$n = 0;
		$line = 0;
		
		for ($i; $i < $numLines; $i++) {
			$match = preg_match($re_beg, $this->strings[$i]);

			if ($match) $n += 1;
			$match = preg_match($re_end, $this->strings[$i]);
			if ($match) {
				$n -= 1;

				if ($n == 0) break;
			}
			$line++;
		}

		if ($n > 0) {
			echo "Opening brace on line $line of {$subName} has no closing brace\n<br />";
		}
		
		// Deal with edge-cases
		// 
		// - {block}TEXT{/block}
		// - {block}
		//   TEXT{/block}
		if ($start == $i) {
			$subTmpl = $this->strings[$start];
			$beg = strpos($subTmpl, '}') + 1;
			$subTmpl = array( substr($subTmpl, $beg, strrpos($subTmpl, '{') - $beg) );
		} else if ($i == ($start + 1)) {
			$subTmpl = $this->strings[$i];
			$subTmpl = array( substr($subTmpl, 0, strrpos($subTmpl, '{')));
		} else {
			$subTmpl = array_slice($this->strings, $start + 1, $i - ($start + 1));
		}

		for ($j = $start; $j <= $i; $j++) {
			//-- Just set the string to empty. Don't worry about removing it
			//-- from the array
			$this->strings[$j] = '';
		}
		
		if ($subName != 'comment')
			return new Scurvy($subTmpl, $this->template_dir, false, $subName);
	}
private function parseRecursive($start, $regex, $subName = 'template') {
		$re_beg = $regex[0];
		$re_end = $regex[1];

		$numLines = count($this->strings);
		$i = $start;
		$n = 0;
		$line = 0;
		
		for ($i; $i < $numLines; $i++) {
			$match = preg_match($re_beg, $this->strings[$i]);

			if ($match) $n += 1;
			$match = preg_match($re_end, $this->strings[$i]);
			if ($match) {
				$n -= 1;

				if ($n == 0) break;
			}
			$line++;
		}

		if ($n > 0) {
			echo "Opening brace on line $line of {$subName} has no closing brace\n<br />";
		}
		
		// Deal with edge-cases
		// 
		// - {block}TEXT{/block}
		// - {block}
		//   TEXT{/block}
		if ($start == $i) {
			$subTmpl = $this->strings[$start];
			$beg = strpos($subTmpl, '}') + 1;
			$subTmpl = array( substr($subTmpl, $beg, strrpos($subTmpl, '{') - $beg) );
		} else if ($i == ($start + 1)) {
			$subTmpl = $this->strings[$i];
			$subTmpl = array( substr($subTmpl, 0, strrpos($subTmpl, '{')));
		} else {
			$subTmpl = array_slice($this->strings, $start + 1, $i - ($start + 1));
		}

		for ($j = $start; $j <= $i; $j++) {
			//-- Just set the string to empty. Don't worry about removing it
			//-- from the array
			$this->strings[$j] = '';
		}
		
		if ($subName != 'comment')
			return new Scurvy($subTmpl, $this->template_dir, false, $subName);
	}
private function parseRecursive ( $ start , $ regex , $ subName = 'template' ) { $ re_beg = $ regex [ 0 ] ; $ re_end = $ regex [ 1 ] ; $ numLines = count ( $ this -> strings ) ; $ i = $ start ; $ n = 0 ; $ line = 0 ; for ( $ i ; $ i < $ numLines ; $ i ++ ) { $ match = preg_match ( $ re_beg , $ this -> strings [ $ i ] ) ; if ( $ match ) $ n += 1 ; $ match = preg_match ( $ re_end , $ this -> strings [ $ i ] ) ; if ( $ match ) { $ n -= 1 ; if ( $ n == 0 ) break ; } $ line ++ ; } if ( $ n > 0 ) { echo "Opening brace on line $line of {$subName} has no closing brace\n<br />" ; } // Deal with edge-cases //  // - {block}TEXT{/block} // - {block} //   TEXT{/block} if ( $ start == $ i ) { $ subTmpl = $ this -> strings [ $ start ] ; $ beg = strpos ( $ subTmpl , '}' ) + 1 ; $ subTmpl = array ( substr ( $ subTmpl , $ beg , strrpos ( $ subTmpl , '{' ) - $ beg ) ) ; } else if ( $ i == ( $ start + 1 ) ) { $ subTmpl = $ this -> strings [ $ i ] ; $ subTmpl = array ( substr ( $ subTmpl , 0 , strrpos ( $ subTmpl , '{' ) ) ) ; } else { $ subTmpl = array_slice ( $ this -> strings , $ start + 1 , $ i - ( $ start + 1 ) ) ; } for ( $ j = $ start ; $ j <= $ i ; $ j ++ ) { //-- Just set the string to empty. Don't worry about removing it //-- from the array $ this -> strings [ $ j ] = '' ; } if ( $ subName != 'comment' ) return new Scurvy ( $ subTmpl , $ this -> template_dir , false , $ subName ) ; }
This function is used by the parse function to grab the contents of
scurvy block statements.

@param start the start index into $this->strings
@param regex the regular expression for the block statement
@param subName the name of the subTemplate (for debugging purposes)
@return a new template with the contents of the block statement
This function is used by the parse function to grab the contents of scurvy block statements .