-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathGenericToken.php
More file actions
41 lines (36 loc) · 1.22 KB
/
GenericToken.php
File metadata and controls
41 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace PHPCR\Util\CND\Scanner;
/**
* @license http://www.apache.org/licenses Apache License Version 2.0, January 2004
* @license http://opensource.org/licenses/MIT MIT License
* @author Daniel Barsotti <daniel.barsotti@liip.ch>
*/
class GenericToken extends Token implements \Stringable
{
public const TK_WHITESPACE = 0;
public const TK_NEWLINE = 1;
public const TK_STRING = 2;
public const TK_COMMENT = 3;
public const TK_IDENTIFIER = 4;
public const TK_KEYWORD = 5;
public const TK_SYMBOL = 6;
public const TK_UNKNOWN = 99;
public static function getTypeName(int $type): string
{
return match ($type) {
self::TK_WHITESPACE => 'Whitespace',
self::TK_NEWLINE => 'Newline',
self::TK_STRING => 'String',
self::TK_COMMENT => 'Comment',
self::TK_IDENTIFIER => 'Identifier',
self::TK_KEYWORD => 'Keyword',
self::TK_SYMBOL => 'Symbol',
default => 'Unknown',
};
}
public function __toString()
{
return sprintf("TOKEN(%s, '%s', %s, %s)", self::getTypeName($this->getType()), trim($this->getData()), $this->getLine(), $this->getRow());
}
}