4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\ExpressionLanguage;
17 * @author Fabien Potencier <fabien@symfony.com>
25 const EOF_TYPE = 'end of expression';
26 const NAME_TYPE = 'name';
27 const NUMBER_TYPE = 'number';
28 const STRING_TYPE = 'string';
29 const OPERATOR_TYPE = 'operator';
30 const PUNCTUATION_TYPE = 'punctuation';
35 * @param int $type The type of the token
36 * @param string $value The token value
37 * @param int $cursor The cursor position in the source
39 public function __construct($type, $value, $cursor)
42 $this->value = $value;
43 $this->cursor = $cursor;
47 * Returns a string representation of the token.
49 * @return string A string representation of the token
51 public function __toString()
53 return sprintf('%3d %-11s %s', $this->cursor, strtoupper($this->type), $this->value);
57 * Tests the current token for a type and/or a value.
59 * @param array|int $type The type to test
60 * @param string|null $value The token value
64 public function test($type, $value = null)
66 return $this->type === $type && (null === $value || $this->value == $value);