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

@final

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.

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

References $lineno, $type, and $value.

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 }
sprintf('%.4f', $callTime)

References sprintf.

◆ getLine()

◆ getType()

Twig_Token::getType ( )
Returns
int

Definition at line 95 of file Token.php.

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

References $type.

◆ getValue()

Twig_Token::getValue ( )
Returns
string

Definition at line 103 of file Token.php.

104 {
105 return $this->value;
106 }

References $value.

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

+ 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.

71 {
72 if (null === $values && !is_int($type)) {
73 $values = $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 }
const NAME_TYPE
Definition: Token.php:32

References $type, and NAME_TYPE.

Referenced by Twig_Extensions_Grammar_Body\decideBlockEnd(), Twig_TokenParser_AutoEscape\decideBlockEnd(), Twig_TokenParser_Block\decideBlockEnd(), Twig_TokenParser_Embed\decideBlockEnd(), Twig_TokenParser_Filter\decideBlockEnd(), Twig_TokenParser_Macro\decideBlockEnd(), Twig_TokenParser_Sandbox\decideBlockEnd(), Twig_TokenParser_Set\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().

+ 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.

173 {
174 switch ($type) {
175 case self::EOF_TYPE:
176 return 'end of template';
177 case self::TEXT_TYPE:
178 return 'text';
180 return 'begin of statement block';
182 return 'begin of print statement';
184 return 'end of statement block';
186 return 'end of print statement';
187 case self::NAME_TYPE:
188 return 'name';
190 return 'number';
192 return 'string';
194 return 'operator';
196 return 'punctuation';
198 return 'begin of string interpolation';
200 return 'end of string interpolation';
201 default:
202 throw new LogicException(sprintf('Token of type "%s" does not exist.', $type));
203 }
204 }
const INTERPOLATION_START_TYPE
Definition: Token.php:37
const BLOCK_END_TYPE
Definition: Token.php:30
const EOF_TYPE
Definition: Token.php:26
const VAR_START_TYPE
Definition: Token.php:29
const INTERPOLATION_END_TYPE
Definition: Token.php:38
const TEXT_TYPE
Definition: Token.php:27
const NUMBER_TYPE
Definition: Token.php:33
const BLOCK_START_TYPE
Definition: Token.php:28
const VAR_END_TYPE
Definition: Token.php:31
const STRING_TYPE
Definition: Token.php:34
const PUNCTUATION_TYPE
Definition: Token.php:36
const OPERATOR_TYPE
Definition: Token.php:35

References $type, BLOCK_END_TYPE, BLOCK_START_TYPE, EOF_TYPE, INTERPOLATION_END_TYPE, INTERPOLATION_START_TYPE, NAME_TYPE, NUMBER_TYPE, OPERATOR_TYPE, PUNCTUATION_TYPE, sprintf, STRING_TYPE, TEXT_TYPE, VAR_END_TYPE, and VAR_START_TYPE.

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

+ 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.

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;
126 $name = 'BLOCK_START_TYPE';
127 break;
129 $name = 'VAR_START_TYPE';
130 break;
132 $name = 'BLOCK_END_TYPE';
133 break;
135 $name = 'VAR_END_TYPE';
136 break;
137 case self::NAME_TYPE:
138 $name = 'NAME_TYPE';
139 break;
141 $name = 'NUMBER_TYPE';
142 break;
144 $name = 'STRING_TYPE';
145 break;
147 $name = 'OPERATOR_TYPE';
148 break;
150 $name = 'PUNCTUATION_TYPE';
151 break;
153 $name = 'INTERPOLATION_START_TYPE';
154 break;
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

References $name, $type, BLOCK_END_TYPE, BLOCK_START_TYPE, EOF_TYPE, INTERPOLATION_END_TYPE, INTERPOLATION_START_TYPE, NAME_TYPE, NUMBER_TYPE, OPERATOR_TYPE, PUNCTUATION_TYPE, sprintf, STRING_TYPE, TEXT_TYPE, VAR_END_TYPE, and VAR_START_TYPE.

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

const Twig_Token::NAME_TYPE = 5

Definition at line 32 of file Token.php.

Referenced by Twig_Extensions_Grammar_Constant\__construct(), Twig_ExpressionParser\getTest(), Twig_Lexer\lexExpression(), Twig_Extensions_Grammar_Boolean\parse(), Twig_Extensions_Grammar_Optional\parse(), Twig_Extensions_Grammar_Switch\parse(), Twig_TokenParser_AutoEscape\parse(), Twig_TokenParser_Block\parse(), Twig_TokenParser_Embed\parse(), Twig_TokenParser_For\parse(), Twig_TokenParser_From\parse(), Twig_TokenParser_Import\parse(), Twig_TokenParser_Macro\parse(), Twig_TokenParser_Use\parse(), Twig_TokenParser_With\parse(), TestTokenParser\parse(), Twig_ExpressionParser\parseArguments(), Twig_TokenParser_Include\parseArguments(), Twig_ExpressionParser\parseAssignmentExpression(), Twig_ExpressionParser\parseFilterExpressionRaw(), Twig_ExpressionParser\parseHashExpression(), Twig_ExpressionParser\parsePrimaryExpression(), Twig_ExpressionParser\parseSubscriptExpression(), Twig_Parser\subparse(), test(), Twig_Tests_LexerTest\testLineDirective(), Twig_Tests_LexerTest\testLineDirectiveInline(), Twig_Tests_LexerTest\testNameLabelForFunction(), Twig_Tests_LexerTest\testNameLabelForTag(), Twig_Tests_ParserTest\testParseIsReentrant(), Twig_Tests_LexerTest\testStringWithInterpolation(), Twig_Tests_LexerTest\testStringWithNestedInterpolations(), Twig_Tests_LexerTest\testStringWithNestedInterpolationsInBlock(), Twig_Tests_ParserTest\testUnknownTag(), Twig_Tests_ParserTest\testUnknownTagWithoutSuggestions(), typeToEnglish(), and typeToString().

◆ 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: