Skip to content

Commit

Permalink
Shuffle the parser changes around a little bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
pento committed Oct 11, 2017
1 parent 374605a commit b925d43
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 69 deletions.
20 changes: 13 additions & 7 deletions blocks/api/post.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,27 @@ WP_Block_End
}

WP_Block_Name
= blockName:$(ASCII_Letter (ASCII_AlphaNumeric / "/" ASCII_AlphaNumeric)*)
= namespace:$(WP_Block_Namespace "/")? name:WP_Namespaced_Block_Name
{
/** <?php
if ( false === strpos( $blockName, '/' ) ) {
$blockName = "core/$blockName";
if ( ! $namespace ) {
$namespace = 'core/';
}
return $blockName;
return $namespace . $name;
?> **/

if ( ! blockName.includes( '/' ) ) {
blockName = 'core/' + blockName;
if ( ! namespace ) {
namespace = 'core/';
}
return blockName;
return namespace + name;
}

WP_Block_Namespace
= $(ASCII_Letter ASCII_AlphaNumeric*)

WP_Namespaced_Block_Name
= $(ASCII_Letter ASCII_AlphaNumeric*)

WP_Block_Attributes
= attrs:$("{" (!("}" WS+ """/"? "-->") .)* "}")
{
Expand Down
153 changes: 91 additions & 62 deletions lib/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ private function peg_f10($blockName) {
'blockName' => $blockName,
);
}
private function peg_f11($blockName) {
if ( false === strpos( $blockName, '/' ) ) {
$blockName = "core/$blockName";
private function peg_f11($namespace, $name) {
if ( ! $namespace ) {
$namespace = 'core/';
}
return $blockName;
return $namespace . $name;
}
private function peg_f12($attrs) { return json_decode( $attrs, true ); }

Expand Down Expand Up @@ -1185,62 +1185,15 @@ private function peg_parseWP_Block_Name() {
$s0 = $this->peg_currPos;
$s1 = $this->peg_currPos;
$s2 = $this->peg_currPos;
$s3 = $this->peg_parseASCII_Letter();
$s3 = $this->peg_parseWP_Block_Namespace();
if ($s3 !== $this->peg_FAILED) {
$s4 = array();
$s5 = $this->peg_parseASCII_AlphaNumeric();
if ($s5 === $this->peg_FAILED) {
$s5 = $this->peg_currPos;
if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c15) {
$s6 = $this->peg_c15;
$this->peg_currPos++;
} else {
$s6 = $this->peg_FAILED;
if ($this->peg_silentFails === 0) {
$this->peg_fail($this->peg_c16);
}
}
if ($s6 !== $this->peg_FAILED) {
$s7 = $this->peg_parseASCII_AlphaNumeric();
if ($s7 !== $this->peg_FAILED) {
$s6 = array($s6, $s7);
$s5 = $s6;
} else {
$this->peg_currPos = $s5;
$s5 = $this->peg_FAILED;
}
} else {
$this->peg_currPos = $s5;
$s5 = $this->peg_FAILED;
}
}
while ($s5 !== $this->peg_FAILED) {
$s4[] = $s5;
$s5 = $this->peg_parseASCII_AlphaNumeric();
if ($s5 === $this->peg_FAILED) {
$s5 = $this->peg_currPos;
if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c15) {
$s6 = $this->peg_c15;
$this->peg_currPos++;
} else {
$s6 = $this->peg_FAILED;
if ($this->peg_silentFails === 0) {
$this->peg_fail($this->peg_c16);
}
}
if ($s6 !== $this->peg_FAILED) {
$s7 = $this->peg_parseASCII_AlphaNumeric();
if ($s7 !== $this->peg_FAILED) {
$s6 = array($s6, $s7);
$s5 = $s6;
} else {
$this->peg_currPos = $s5;
$s5 = $this->peg_FAILED;
}
} else {
$this->peg_currPos = $s5;
$s5 = $this->peg_FAILED;
}
if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c15) {
$s4 = $this->peg_c15;
$this->peg_currPos++;
} else {
$s4 = $this->peg_FAILED;
if ($this->peg_silentFails === 0) {
$this->peg_fail($this->peg_c16);
}
}
if ($s4 !== $this->peg_FAILED) {
Expand All @@ -1254,16 +1207,92 @@ private function peg_parseWP_Block_Name() {
$this->peg_currPos = $s2;
$s2 = $this->peg_FAILED;
}
if ($s2 === $this->peg_FAILED) {
$s2 = null;
}
if ($s2 !== $this->peg_FAILED) {
$s1 = $this->input_substr($s1, $this->peg_currPos - $s1);
} else {
$s1 = $s2;
}
if ($s1 !== $this->peg_FAILED) {
$this->peg_reportedPos = $s0;
$s1 = $this->peg_f11($s1);
$s2 = $this->peg_parseWP_Namespaced_Block_Name();
if ($s2 !== $this->peg_FAILED) {
$this->peg_reportedPos = $s0;
$s1 = $this->peg_f11($s1, $s2);
$s0 = $s1;
} else {
$this->peg_currPos = $s0;
$s0 = $this->peg_FAILED;
}
} else {
$this->peg_currPos = $s0;
$s0 = $this->peg_FAILED;
}

return $s0;
}

private function peg_parseWP_Block_Namespace() {

$s0 = $this->peg_currPos;
$s1 = $this->peg_currPos;
$s2 = $this->peg_parseASCII_Letter();
if ($s2 !== $this->peg_FAILED) {
$s3 = array();
$s4 = $this->peg_parseASCII_AlphaNumeric();
while ($s4 !== $this->peg_FAILED) {
$s3[] = $s4;
$s4 = $this->peg_parseASCII_AlphaNumeric();
}
if ($s3 !== $this->peg_FAILED) {
$s2 = array($s2, $s3);
$s1 = $s2;
} else {
$this->peg_currPos = $s1;
$s1 = $this->peg_FAILED;
}
} else {
$this->peg_currPos = $s1;
$s1 = $this->peg_FAILED;
}
if ($s1 !== $this->peg_FAILED) {
$s0 = $this->input_substr($s0, $this->peg_currPos - $s0);
} else {
$s0 = $s1;
}

return $s0;
}

private function peg_parseWP_Namespaced_Block_Name() {

$s0 = $this->peg_currPos;
$s1 = $this->peg_currPos;
$s2 = $this->peg_parseASCII_Letter();
if ($s2 !== $this->peg_FAILED) {
$s3 = array();
$s4 = $this->peg_parseASCII_AlphaNumeric();
while ($s4 !== $this->peg_FAILED) {
$s3[] = $s4;
$s4 = $this->peg_parseASCII_AlphaNumeric();
}
if ($s3 !== $this->peg_FAILED) {
$s2 = array($s2, $s3);
$s1 = $s2;
} else {
$this->peg_currPos = $s1;
$s1 = $this->peg_FAILED;
}
} else {
$this->peg_currPos = $s1;
$s1 = $this->peg_FAILED;
}
if ($s1 !== $this->peg_FAILED) {
$s0 = $this->input_substr($s0, $this->peg_currPos - $s0);
} else {
$s0 = $s1;
}
$s0 = $s1;

return $s0;
}
Expand Down

0 comments on commit b925d43

Please sign in to comment.