diff --git a/Compiler.php b/Compiler.php index aee7494..31cf43d 100644 --- a/Compiler.php +++ b/Compiler.php @@ -672,7 +672,7 @@ function compile() { '$result = $this->construct( "'.$function_name.'" );', '$substack = array();', $this->parsed->compile()->replace(array( - 'MATCH' => 'return $result ;', + 'MATCH' => 'return $this->finalise( "'.$function_name.'", $result );', 'FAIL' => 'return FALSE;' )) ); diff --git a/Parser.php b/Parser.php index 7598deb..6b97343 100644 --- a/Parser.php +++ b/Parser.php @@ -173,6 +173,15 @@ function construct( $name ) { return $result ; } + function finalise( $name, &$result ) { + $callback = array( $this, "{$name}__finalise" ) ; + if ( is_callable( $callback ) ) { + call_user_func_array( $callback, array( &$result ) ) ; + } + + return $result ; + } + function store ( &$result, $subres, $storetag = NULL ) { $result['text'] .= $subres['text'] ;