Skip to content

Commit

Permalink
added some helper method to build common nodes more easily (experimen…
Browse files Browse the repository at this point in the history
…tal)
  • Loading branch information
fabpot committed Jun 10, 2010
1 parent 7e926fc commit 1aa60bf
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/Twig/SimpleTokenParser.php
Expand Up @@ -45,6 +45,43 @@ abstract protected function getGrammar();
*/
abstract protected function getNode(array $values, $line);

protected function getAttribute($node, $attribute, $arguments = array(), $line = -1)
{
return new \Twig_Node_Expression_GetAttr(
$node instanceof Twig_NodeInterface ? $node : new \Twig_Node_Expression_Name($node, $line),
$attribute instanceof Twig_NodeInterface ? $attribute : new \Twig_Node_Expression_Constant($attribute, $line),
$arguments instanceof Twig_NodeInterface ? $arguments : new \Twig_Node($arguments),
\Twig_Node_Expression_GetAttr::TYPE_ANY,
$line
);
}

protected function markAsSafe(Twig_NodeInterface $node, $line = -1)
{
return new \Twig_Node_Expression_Filter(
$node,
new \Twig_Node(array(new \Twig_Node_Expression_Constant('safe', $line), new \Twig_Node())),
$line
);
}

protected function output(Twig_NodeInterface $node, $line = -1)
{
return new \Twig_Node_Print($node, $line);
}

protected function getNodeValues(array $values)
{
$nodes = array();
foreach ($values as $value) {
if ($value instanceof \Twig_NodeInterface) {
$nodes[] = $value;
}
}

return $nodes;
}

static public function parseGrammar($str, $main = true)
{
static $cursor;
Expand Down

0 comments on commit 1aa60bf

Please sign in to comment.