diff options
-rw-r--r-- | php/luigi-template.php | 98 |
1 files changed, 0 insertions, 98 deletions
diff --git a/php/luigi-template.php b/php/luigi-template.php index cec1ff6..9cd2975 100644 --- a/php/luigi-template.php +++ b/php/luigi-template.php @@ -88,104 +88,6 @@ final class Filters { } }; -final class LegacyParser { - private static $RES = array( - 'action' => '/ - # match opening brace - %\{\s* - - # match key - ([\w_-]+) - - # match filter(s) - ((\s*\|\s*\w+\s*(\([\w\s,-]+\))?)*) - - # match closing brace - \} - - # or match up all non-% chars or a single % char - | ([^%]* | %) - /mx', - - 'filter' => '/ - # match filter name - ([\w_-]+) - - # optional trailing whitespace - \s* - - # optional filter arguments - (\(([\w\s_,-]+)\))? - /mx', - ); - - public static function parse_template($template) { - # build list of matches - $matches = array(); - $num_matches = preg_match_all( - self::$RES['action'], - $template, - $matches, - PREG_SET_ORDER - ); - - # check for error - if ($num_matches === false) - throw new Error('error matching template'); - - # walk over matches and build list of actions - $r = array_map(function($m) { - if ($m[1] !== '') { - # key and filters - return array( - 'type' => 'action', - 'key' => $m[1], - 'filters' => self::parse_filters($m[2]), - ); - } else { - # literal text - return array( - 'type' => 'text', - 'text' => $m[5], - ); - } - }, $matches); - - # return result - return $r; - } - - public static function parse_filters($filters) { - # split into individual filters - $r = array(); - foreach (preg_split('/\s*\|\s*/', $filters) as $f) { - # skip empty filters - if (!$f) - continue; - - # match filter - $md = array(); - if (!preg_match(self::$RES['filter'], $f, $md)) - throw new Error("invalid filter: $f"); - - # add filter to results - $r[] = array( - # filter name - 'name' => $md[1], - - # filter arguments - 'args' => (count($md) > 2) ? preg_split( - '/\s*,\s*/', - trim($md[3]) - ) : array(), - ); - } - - # return results - return $r; - } -}; - final class Parser { private static $RES = array( 'action' => '/ |