Skip to content

Commit

Permalink
Grammar: Reduce and rename for clarity (WordPress#6127)
Browse files Browse the repository at this point in the history
* Rename Token to Block
* Rename Block_Void to Block_Empty
* Port WS+ to __
* Update PHP parser
  • Loading branch information
mcsf authored and nuzzio committed Apr 25, 2018
1 parent 55d83ec commit 5709cfe
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 201 deletions.
34 changes: 11 additions & 23 deletions blocks/api/post.pegjs
Expand Up @@ -161,19 +161,19 @@ function partition( predicate, list ) {
//////////////////////////////////////////////////////

Block_List
= pre:$(!Token .)*
ts:(t:Token html:$((!Token .)*) { /** <?php return array( $t, $html ); ?> **/ return [ t, html ] })*
= pre:$(!Block .)*
bs:(b:Block html:$((!Block .)*) { /** <?php return array( $b, $html ); ?> **/ return [ b, html ] })*
post:$(.*)
{ /** <?php return peg_join_blocks( $pre, $ts, $post ); ?> **/
return joinBlocks( pre, ts, post );
{ /** <?php return peg_join_blocks( $pre, $bs, $post ); ?> **/
return joinBlocks( pre, bs, post );
}

Token
Block
= Block_Void
/ Block_Balanced

Block_Void
= "<!--" WS+ "wp:" blockName:Block_Name WS+ attrs:(a:Block_Attributes WS+ {
= "<!--" __ "wp:" blockName:Block_Name __ attrs:(a:Block_Attributes __ {
/** <?php return $a; ?> **/
return a;
})? "/-->"
Expand All @@ -196,7 +196,7 @@ Block_Void
}

Block_Balanced
= s:Block_Start children:(Token / $(!Block_End .))* e:Block_End
= s:Block_Start children:(Block / $(!Block_End .))* e:Block_End
{
/** <?php
list( $innerHTML, $innerBlocks ) = peg_array_partition( $children, 'is_string' );
Expand All @@ -222,7 +222,7 @@ Block_Balanced
}

Block_Start
= "<!--" WS+ "wp:" blockName:Block_Name WS+ attrs:(a:Block_Attributes WS+ {
= "<!--" __ "wp:" blockName:Block_Name __ attrs:(a:Block_Attributes __ {
/** <?php return $a; ?> **/
return a;
})? "-->"
Expand All @@ -241,7 +241,7 @@ Block_Start
}

Block_End
= "<!--" WS+ "/wp:" blockName:Block_Name WS+ "-->"
= "<!--" __ "/wp:" blockName:Block_Name __ "-->"
{
/** <?php
return array(
Expand Down Expand Up @@ -272,23 +272,11 @@ Block_Name_Part
= $( [a-z][a-z0-9_-]* )

Block_Attributes
= attrs:$("{" (!("}" WS+ """/"? "-->") .)* "}")
= attrs:$("{" (!("}" __ """/"? "-->") .)* "}")
{
/** <?php return json_decode( $attrs, true ); ?> **/
return maybeJSON( attrs );
}

WS
= [ \t\r\n]

Newline
= [\r\n]

_
= [ \t]

__
= _+

Any
= .
= [ \t\r\n]+

0 comments on commit 5709cfe

Please sign in to comment.