-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokens.php
More file actions
126 lines (108 loc) · 2.68 KB
/
Tokens.php
File metadata and controls
126 lines (108 loc) · 2.68 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
declare(strict_types=1);
namespace JustHTML;
final class Tag
{
public const START = 0;
public const END = 1;
public int $kind;
public string $name;
/** @var array<string, string|null> */
public array $attrs;
public bool $selfClosing;
/** @param array<string, string|null>|null $attrs */
public function __construct(int $kind, string $name, ?array $attrs = null, bool $selfClosing = false)
{
$this->kind = $kind;
$this->name = $name;
$this->attrs = $attrs ?? [];
$this->selfClosing = $selfClosing;
}
}
final class CharacterTokens
{
public string $data;
public function __construct(string $data)
{
$this->data = $data;
}
}
final class CommentToken
{
public string $data;
public function __construct(string $data)
{
$this->data = $data;
}
}
final class Doctype
{
public ?string $name;
public ?string $publicId;
public ?string $systemId;
public bool $forceQuirks;
public function __construct(
?string $name = null,
?string $publicId = null,
?string $systemId = null,
bool $forceQuirks = false
) {
$this->name = $name;
$this->publicId = $publicId;
$this->systemId = $systemId;
$this->forceQuirks = $forceQuirks;
}
}
final class DoctypeToken
{
public Doctype $doctype;
public function __construct(Doctype $doctype)
{
$this->doctype = $doctype;
}
}
final class EOFToken
{
}
final class TokenSinkResult
{
public const Continue = 0;
public const Plaintext = 1;
}
final class ParseError
{
public string $code;
public ?int $line;
public ?int $column;
public string $message;
public ?string $sourceHtml;
public ?int $endColumn;
public function __construct(
string $code,
?int $line = null,
?int $column = null,
?string $message = null,
?string $sourceHtml = null,
?int $endColumn = null
) {
$this->code = $code;
$this->line = $line;
$this->column = $column;
$this->message = $message ?? $code;
$this->sourceHtml = $sourceHtml;
$this->endColumn = $endColumn;
}
public function __toString(): string
{
if ($this->line !== null && $this->column !== null) {
if ($this->message !== $this->code) {
return "({$this->line},{$this->column}): {$this->code} - {$this->message}";
}
return "({$this->line},{$this->column}): {$this->code}";
}
if ($this->message !== $this->code) {
return "{$this->code} - {$this->message}";
}
return $this->code;
}
}