Browse Source

Moved treebuilder to its own class

• Changed use of static:: with constants to self:: in TreeBuilder
split-manual
Dustin Wilson 6 years ago
parent
commit
106efd5a8a
  1. 2
      lib/ActiveFormattingElementsList.php
  2. 12
      lib/Exception.php
  3. 1296
      lib/Parser.php
  4. 24
      lib/Tokenizer.php
  5. 1310
      lib/TreeBuilder.php

2
lib/ActiveFormattingElementsList.php

@ -170,7 +170,7 @@ class ActiveFormattingElementsList implements \ArrayAccess {
# 8. Create: Insert an HTML element for the token for which the element entry
# was created, to obtain new element.
create:
$element = Parser::insertStartTagToken($entry['token']);
$element = TreeBuilder::insertStartTagToken($entry['token']);
# 9. Replace the entry for entry in the list with an entry for new element.
$this->_storage[key($this->_storage)]['element'] = $element;

12
lib/Exception.php

@ -24,6 +24,9 @@ class Exception extends \Exception {
const TOKENIZER_INVALID_STATE = 10601;
const TREEBUILDER_FORMELEMENT_EXPECTED = 10701;
const TREEBUILDER_FRAGMENT_CONTEXT_DOMELEMENT_DOMDOCUMENT_DOMDOCUMENTFRAG_EXPECTED = 10702;
protected static $messages = [10000 => 'Invalid error code',
10001 => 'Unknown error; escaping',
10002 => 'Incorrect number of parameters for Exception message; %s expected',
@ -43,11 +46,14 @@ class Exception extends \Exception {
10501 => 'The first argument must either be an instance of \DOMElement, a string, or a closure; found %s',
10601 => 'The Tokenizer has entered an invalid state'];
10601 => 'The Tokenizer has entered an invalid state',
10701 => 'Form element expected, found %s',
10702 => 'DOMElement, DOMDocument, or DOMDocumentFragment expected; found %s'];
public function __construct(int $code, ...$args) {
if (!isset(static::$messages[$code])) {
throw new Exception(static::INVALID_CODE);
throw new Exception(self::INVALID_CODE);
}
$message = static::$messages[$code];
@ -64,7 +70,7 @@ class Exception extends \Exception {
$count = substr_count($message, '%s');
// If the number of replacements don't match the arguments then oops.
if (count($args) !== $count) {
throw new Exception(static::INCORRECT_PARAMETERS_FOR_MESSAGE, $count);
throw new Exception(self::INCORRECT_PARAMETERS_FOR_MESSAGE, $count);
}
if ($count > 0) {

1296
lib/Parser.php

File diff suppressed because it is too large

24
lib/Tokenizer.php

@ -636,7 +636,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# before attribute name state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::BEFORE_ATTRIBUTE_NAME_STATE;
} else {
$this->state = self::RCDATA_STATE;
@ -649,7 +649,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# self-closing start tag state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::SELF_CLOSING_START_TAG_STATE;
} else {
$this->state = self::RCDATA_STATE;
@ -662,7 +662,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# data state and emit the current tag token. Otherwise, treat it as per the
# "anything else" entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::DATA_STATE;
return $token;
} else {
@ -778,7 +778,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# before attribute name state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::BEFORE_ATTRIBUTE_NAME_STATE;
} else {
$this->state = self::RAWTEXT_STATE;
@ -793,7 +793,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# self-closing start tag state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::SELF_CLOSING_START_TAG_STATE;
} else {
$this->state = self::RAWTEXT_STATE;
@ -808,7 +808,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# data state and emit the current tag token. Otherwise, treat it as per the
# "anything else" entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::DATA_STATE;
return $token;
} else {
@ -935,7 +935,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# before attribute name state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::BEFORE_ATTRIBUTE_NAME_STATE;
} else {
$this->state = self::SCRIPT_DATA_STATE;
@ -948,7 +948,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# self-closing start tag state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::SELF_CLOSING_START_TAG_STATE;
} else {
$this->state = self::SCRIPT_DATA_STATE;
@ -961,7 +961,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# data state and emit the current tag token. Otherwise, treat it as per the
# "anything else" entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::DATA_STATE;
return $token;
} else {
@ -1255,7 +1255,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# before attribute name state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::BEFORE_ATTRIBUTE_NAME_STATE;
} else {
$this->state = self::SCRIPT_DATA_ESCAPED_STATE;
@ -1268,7 +1268,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# self-closing start tag state. Otherwise, treat it as per the "anything else"
# entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::SELF_CLOSING_START_TAG_STATE;
} else {
$this->state = self::SCRIPT_DATA_ESCAPED_STATE;
@ -1281,7 +1281,7 @@ class Tokenizer {
# If the current end tag token is an appropriate end tag token, then switch to the
# data state and emit the current tag token. Otherwise, treat it as per the
# "anything else" entry below.
if ($token->name === $this->stack->currentNode()->name) {
if ($token->name === $this->stack->currentNodeName) {
$this->state = self::DATA_STATE;
return $token;
} else {

1310
lib/TreeBuilder.php

File diff suppressed because it is too large
Loading…
Cancel
Save