ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
Twig_Token Class Reference

Represents a Token. More...

+ Collaboration diagram for Twig_Token:

Public Member Functions

 __construct ($type, $value, $lineno)
 
 __toString ()
 
 test ($type, $values=null)
 Tests the current token for a type and/or a value. More...
 
 getLine ()
 
 getType ()
 
 getValue ()
 

Static Public Member Functions

static typeToString ($type, $short=false)
 Returns the constant representation (internal) of a given type. More...
 
static typeToEnglish ($type)
 Returns the English representation of a given type. More...
 

Data Fields

const EOF_TYPE = -1
 
const TEXT_TYPE = 0
 
const BLOCK_START_TYPE = 1
 
const VAR_START_TYPE = 2
 
const BLOCK_END_TYPE = 3
 
const VAR_END_TYPE = 4
 
const NAME_TYPE = 5
 
const NUMBER_TYPE = 6
 
const STRING_TYPE = 7
 
const OPERATOR_TYPE = 8
 
const PUNCTUATION_TYPE = 9
 
const INTERPOLATION_START_TYPE = 10
 
const INTERPOLATION_END_TYPE = 11
 

Protected Attributes

 $value
 
 $type
 
 $lineno
 

Detailed Description

Represents a Token.

Author
Fabien Potencier fabie.nosp@m.n@sy.nosp@m.mfony.nosp@m..com

Definition at line 20 of file Token.php.

Constructor & Destructor Documentation

◆ __construct()

Twig_Token::__construct (   $type,
  $value,
  $lineno 
)
Parameters
int$typeThe type of the token
string$valueThe token value
int$linenoThe line position in the source

Definition at line 45 of file Token.php.

References $lineno, $type, and $value.

46  {
47  $this->type = $type;
48  $this->value = $value;
49  $this->lineno = $lineno;
50  }

Member Function Documentation

◆ __toString()

Twig_Token::__toString ( )

Definition at line 52 of file Token.php.

53  {
54  return sprintf('%s(%s)', self::typeToString($this->type, true), $this->value);
55  }

◆ getLine()

◆ getType()

Twig_Token::getType ( )
Returns
int

Definition at line 95 of file Token.php.

References $type.

96  {
97  return $this->type;
98  }

◆ getValue()

Twig_Token::getValue ( )
Returns
string

Definition at line 103 of file Token.php.

References $value.

Referenced by Twig_ExpressionParser\isBinary(), Twig_ExpressionParser\isUnary(), Twig_Extensions_Grammar_Boolean\parse(), Twig_Extensions_Grammar_Number\parse(), Twig_TokenParser_Macro\parse(), and Twig_TokenParser_Block\parse().

104  {
105  return $this->value;
106  }
+ Here is the caller graph for this function:

◆ test()

Twig_Token::test (   $type,
  $values = null 
)

Tests the current token for a type and/or a value.

Parameters may be:

  • just type
  • type and value (or array of possible values)
  • just value (or array of possible values) (NAME_TYPE is used as type)
Parameters
array | int$typeThe type to test
array | string | null$valuesThe token value
Returns
bool

Definition at line 70 of file Token.php.

References $type.

Referenced by Twig_Extensions_Grammar_Body\decideBlockEnd(), Twig_TokenParser_Filter\decideBlockEnd(), Twig_TokenParser_Macro\decideBlockEnd(), Twig_TokenParser_Sandbox\decideBlockEnd(), Twig_TokenParser_Embed\decideBlockEnd(), Twig_TokenParser_Block\decideBlockEnd(), Twig_TokenParser_Set\decideBlockEnd(), Twig_TokenParser_AutoEscape\decideBlockEnd(), Twig_Extensions_TokenParser_Trans\decideForEnd(), Twig_TokenParser_For\decideForEnd(), Twig_Extensions_TokenParser_Trans\decideForFork(), Twig_TokenParser_For\decideForFork(), Twig_TokenParser_If\decideIfEnd(), Twig_TokenParser_If\decideIfFork(), Twig_TokenParser_Spaceless\decideSpacelessEnd(), Twig_TokenParser_With\decideWithEnd(), Twig_ExpressionParser\isBinary(), and Twig_ExpressionParser\isUnary().

71  {
72  if (null === $values && !is_int($type)) {
73  $values = $type;
74  $type = self::NAME_TYPE;
75  }
76 
77  return ($this->type === $type) && (
78  null === $values ||
79  (is_array($values) && in_array($this->value, $values)) ||
80  $this->value == $values
81  );
82  }
+ Here is the caller graph for this function:

◆ typeToEnglish()

static Twig_Token::typeToEnglish (   $type)
static

Returns the English representation of a given type.

Parameters
int$typeThe type as an integer
Returns
string The string representation

Definition at line 172 of file Token.php.

References $type.

Referenced by Twig_TokenStream\expect(), Twig_ExpressionParser\parseHashExpression(), and Twig_ExpressionParser\parsePrimaryExpression().

173  {
174  switch ($type) {
175  case self::EOF_TYPE:
176  return 'end of template';
177  case self::TEXT_TYPE:
178  return 'text';
179  case self::BLOCK_START_TYPE:
180  return 'begin of statement block';
181  case self::VAR_START_TYPE:
182  return 'begin of print statement';
183  case self::BLOCK_END_TYPE:
184  return 'end of statement block';
185  case self::VAR_END_TYPE:
186  return 'end of print statement';
187  case self::NAME_TYPE:
188  return 'name';
189  case self::NUMBER_TYPE:
190  return 'number';
191  case self::STRING_TYPE:
192  return 'string';
193  case self::OPERATOR_TYPE:
194  return 'operator';
195  case self::PUNCTUATION_TYPE:
196  return 'punctuation';
197  case self::INTERPOLATION_START_TYPE:
198  return 'begin of string interpolation';
199  case self::INTERPOLATION_END_TYPE:
200  return 'end of string interpolation';
201  default:
202  throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
203  }
204  }
+ Here is the caller graph for this function:

◆ typeToString()

static Twig_Token::typeToString (   $type,
  $short = false 
)
static

Returns the constant representation (internal) of a given type.

Parameters
int$typeThe type as an integer
bool$shortWhether to return a short representation or not
Returns
string The string representation

Definition at line 116 of file Token.php.

References $name, and $type.

117  {
118  switch ($type) {
119  case self::EOF_TYPE:
120  $name = 'EOF_TYPE';
121  break;
122  case self::TEXT_TYPE:
123  $name = 'TEXT_TYPE';
124  break;
125  case self::BLOCK_START_TYPE:
126  $name = 'BLOCK_START_TYPE';
127  break;
128  case self::VAR_START_TYPE:
129  $name = 'VAR_START_TYPE';
130  break;
131  case self::BLOCK_END_TYPE:
132  $name = 'BLOCK_END_TYPE';
133  break;
134  case self::VAR_END_TYPE:
135  $name = 'VAR_END_TYPE';
136  break;
137  case self::NAME_TYPE:
138  $name = 'NAME_TYPE';
139  break;
140  case self::NUMBER_TYPE:
141  $name = 'NUMBER_TYPE';
142  break;
143  case self::STRING_TYPE:
144  $name = 'STRING_TYPE';
145  break;
146  case self::OPERATOR_TYPE:
147  $name = 'OPERATOR_TYPE';
148  break;
149  case self::PUNCTUATION_TYPE:
150  $name = 'PUNCTUATION_TYPE';
151  break;
152  case self::INTERPOLATION_START_TYPE:
153  $name = 'INTERPOLATION_START_TYPE';
154  break;
155  case self::INTERPOLATION_END_TYPE:
156  $name = 'INTERPOLATION_END_TYPE';
157  break;
158  default:
159  throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
160  }
161 
162  return $short ? $name : 'Twig_Token::'.$name;
163  }
if($format !==null) $name
Definition: metadata.php:146

Field Documentation

◆ $lineno

Twig_Token::$lineno
protected

Definition at line 24 of file Token.php.

Referenced by __construct(), and getLine().

◆ $type

Twig_Token::$type
protected

Definition at line 23 of file Token.php.

Referenced by __construct(), getType(), test(), typeToEnglish(), and typeToString().

◆ $value

Twig_Token::$value
protected

Definition at line 22 of file Token.php.

Referenced by __construct(), and getValue().

◆ BLOCK_END_TYPE

◆ BLOCK_START_TYPE

◆ EOF_TYPE

◆ INTERPOLATION_END_TYPE

◆ INTERPOLATION_START_TYPE

◆ NAME_TYPE

◆ NUMBER_TYPE

◆ OPERATOR_TYPE

◆ PUNCTUATION_TYPE

◆ STRING_TYPE

◆ TEXT_TYPE

◆ VAR_END_TYPE

◆ VAR_START_TYPE


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