ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Extensions_SimpleTokenParser Class Reference
+ Inheritance diagram for Twig_Extensions_SimpleTokenParser:
+ Collaboration diagram for Twig_Extensions_SimpleTokenParser:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
- Public Member Functions inherited from Twig_TokenParser
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
- Public Member Functions inherited from Twig_TokenParserInterface
 getTag ()
 Gets the tag name associated with this token parser. More...
 

Static Public Member Functions

static parseGrammar ($str, $main=true)
 

Protected Member Functions

 getGrammar ()
 Gets the grammar as an object or as a string. More...
 
 getNode (array $values, $line)
 Gets the nodes based on the parsed values. More...
 
 getAttribute ($node, $attribute, $arguments=array(), $type=Twig_Node_Expression_GetAttr::TYPE_ANY, $line=-1)
 
 call ($node, $attribute, $arguments=array(), $line=-1)
 
 markAsSafe (Twig_Node $node, $line=-1)
 
 output (Twig_Node $node, $line=-1)
 
 getNodeValues (array $values)
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

Deprecated:
since version 1.5

Definition at line 17 of file SimpleTokenParser.php.

Member Function Documentation

◆ call()

Twig_Extensions_SimpleTokenParser::call (   $node,
  $attribute,
  $arguments = array(),
  $line = -1 
)
protected

Definition at line 65 of file SimpleTokenParser.php.

References getAttribute().

66  {
67  return $this->getAttribute($node, $attribute, $arguments, Twig_Node_Expression_GetAttr::TYPE_METHOD, $line);
68  }
getAttribute($node, $attribute, $arguments=array(), $type=Twig_Node_Expression_GetAttr::TYPE_ANY, $line=-1)
+ Here is the call graph for this function:

◆ getAttribute()

Twig_Extensions_SimpleTokenParser::getAttribute (   $node,
  $attribute,
  $arguments = array(),
  $type = Twig_Node_Expression_GetAttr::TYPE_ANY,
  $line = -1 
)
protected

Definition at line 54 of file SimpleTokenParser.php.

References $type.

Referenced by call().

55  {
57  $node instanceof Twig_Node ? $node : new Twig_Node_Expression_Name($node, $line),
58  $attribute instanceof Twig_Node ? $attribute : new Twig_Node_Expression_Constant($attribute, $line),
59  $arguments instanceof Twig_Node ? $arguments : new Twig_Node($arguments),
60  $type,
61  $line
62  );
63  }
Represents a node in the AST.
Definition: Node.php:18
$type
+ Here is the caller graph for this function:

◆ getGrammar()

Twig_Extensions_SimpleTokenParser::getGrammar ( )
abstractprotected

Gets the grammar as an object or as a string.

Returns
string|Twig_Extensions_Grammar A Twig_Extensions_Grammar instance or a string

Referenced by parse().

+ Here is the caller graph for this function:

◆ getNode()

Twig_Extensions_SimpleTokenParser::getNode ( array  $values,
  $line 
)
abstractprotected

Gets the nodes based on the parsed values.

Parameters
array$valuesAn array of values
int$lineThe parser line

Referenced by parse().

+ Here is the caller graph for this function:

◆ getNodeValues()

Twig_Extensions_SimpleTokenParser::getNodeValues ( array  $values)
protected

Definition at line 85 of file SimpleTokenParser.php.

References array.

86  {
87  $nodes = array();
88  foreach ($values as $value) {
89  if ($value instanceof Twig_Node) {
90  $nodes[] = $value;
91  }
92  }
93 
94  return $nodes;
95  }
Represents a node in the AST.
Definition: Node.php:18
Create styles array
The data for the language used.

◆ markAsSafe()

Twig_Extensions_SimpleTokenParser::markAsSafe ( Twig_Node  $node,
  $line = -1 
)
protected

Definition at line 70 of file SimpleTokenParser.php.

71  {
72  return new Twig_Node_Expression_Filter(
73  $node,
74  new Twig_Node_Expression_Constant('raw', $line),
75  new Twig_Node(),
76  $line
77  );
78  }
Represents a node in the AST.
Definition: Node.php:18

◆ output()

Twig_Extensions_SimpleTokenParser::output ( Twig_Node  $node,
  $line = -1 
)
protected

Definition at line 80 of file SimpleTokenParser.php.

81  {
82  return new Twig_Node_Print($node, $line);
83  }
Represents a node that outputs an expression.
Definition: Print.php:18

◆ parse()

Twig_Extensions_SimpleTokenParser::parse ( Twig_Token  $token)

Parses a token and returns a node.

Parameters
Twig_Token$tokenA Twig_Token instance
Returns
Twig_Node A Twig_Node instance

Implements Twig_TokenParserInterface.

Definition at line 26 of file SimpleTokenParser.php.

References array, getGrammar(), Twig_Token\getLine(), and getNode().

27  {
28  $grammar = $this->getGrammar();
29  if (!is_object($grammar)) {
30  $grammar = self::parseGrammar($grammar);
31  }
32 
33  $grammar->setParser($this->parser);
34  $values = $grammar->parse($token);
35 
36  return $this->getNode($values, $token->getLine());
37  }
getGrammar()
Gets the grammar as an object or as a string.
getNode(array $values, $line)
Gets the nodes based on the parsed values.
getLine()
Definition: Token.php:87
+ Here is the call graph for this function:

◆ parseGrammar()

static Twig_Extensions_SimpleTokenParser::parseGrammar (   $str,
  $main = true 
)
static

Definition at line 97 of file SimpleTokenParser.php.

References Twig_Token\PUNCTUATION_TYPE.

Referenced by Twig_Tests_SimpleTokenParserTest\testParseGrammar(), and Twig_Tests_SimpleTokenParserTest\testParseGrammarExceptions().

98  {
99  static $cursor;
100 
101  if (true === $main) {
102  $cursor = 0;
103  $grammar = new Twig_Extensions_Grammar_Tag();
104  } else {
105  $grammar = new Twig_Extensions_Grammar_Optional();
106  }
107 
108  while ($cursor < strlen($str)) {
109  if (preg_match('/\s+/A', $str, $match, null, $cursor)) {
110  $cursor += strlen($match[0]);
111  } elseif (preg_match('/<(\w+)(?:\:(\w+))?>/A', $str, $match, null, $cursor)) {
112  $class = sprintf('Twig_Extensions_Grammar_%s', ucfirst(isset($match[2]) ? $match[2] : 'Expression'));
113  if (!class_exists($class)) {
114  throw new Twig_Error_Runtime(sprintf('Unable to understand "%s" in grammar (%s class does not exist)', $match[0], $class));
115  }
116  $grammar->addGrammar(new $class($match[1]));
117  $cursor += strlen($match[0]);
118  } elseif (preg_match('/\w+/A', $str, $match, null, $cursor)) {
119  $grammar->addGrammar(new Twig_Extensions_Grammar_Constant($match[0]));
120  $cursor += strlen($match[0]);
121  } elseif (preg_match('/,/A', $str, $match, null, $cursor)) {
122  $grammar->addGrammar(new Twig_Extensions_Grammar_Constant($match[0], Twig_Token::PUNCTUATION_TYPE));
123  $cursor += strlen($match[0]);
124  } elseif (preg_match('/\[/A', $str, $match, null, $cursor)) {
125  $cursor += strlen($match[0]);
126  $grammar->addGrammar(self::parseGrammar($str, false));
127  } elseif (true !== $main && preg_match('/\]/A', $str, $match, null, $cursor)) {
128  $cursor += strlen($match[0]);
129 
130  return $grammar;
131  } else {
132  throw new Twig_Error_Runtime(sprintf('Unable to parse grammar "%s" near "...%s..."', $str, substr($str, $cursor, 10)));
133  }
134  }
135 
136  return $grammar;
137  }
const PUNCTUATION_TYPE
Definition: Token.php:36
Exception thrown when an error occurs at runtime.
Definition: Runtime.php:18
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: