Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Remove PegJS since it is no longer used"
This reverts commit 9c5cc57.
  • Loading branch information
nylen committed Apr 18, 2017
commit dddf78d3bff6be5c78027adf317ec8a5d3a9ac48
1 change: 1 addition & 0 deletions blocks/api/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { escape, unescape } from 'lodash';
/**
* Internal dependencies
*/
import { parse as grammarParse } from './post.pegjs';
import { getBlockSettings, getUnknownTypeHandler } from './registration';
import { createBlock } from './factory';

Expand Down
95 changes: 95 additions & 0 deletions blocks/api/post.pegjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Document
= WP_Block_List

WP_Block_List
= WP_Block*

WP_Block
= WP_Block_Balanced
/ WP_Block_Html

WP_Block_Balanced
= s:WP_Block_Start ts:(!WP_Block_End c:Any { return c })+ e:WP_Block_End & { return s.blockType === e.blockType }
{ return {
blockType: s.blockType,
attrs: s.attrs,
rawContent: ts.join( '' ),
} }

WP_Block_Html
= ts:(!WP_Block_Balanced c:Any { return c })+
{
return {
attrs: {},
rawContent: ts.join( '' )
}
}

WP_Block_Start
= "<!--" __ "wp:" blockType:WP_Block_Type attrs:WP_Block_Attribute_List _? "-->"
{ return {
blockType: blockType,
attrs: attrs
} }

WP_Block_End
= "<!--" __ "/wp:" blockType:WP_Block_Type __ "-->"
{ return {
blockType: blockType
} }

WP_Block_Type
= head:ASCII_Letter tail:WP_Block_Type_Char*
{ return [ head ].concat( tail ).join( '' ) }

WP_Block_Attribute_List
= as:(_+ attr:WP_Block_Attribute { return attr })*
{ return as.reduce( function( attrs, pair ) {
attrs[ pair.name ] = [ pair.value ];
return attrs;
}, {} ) }

WP_Block_Attribute
= name:WP_Block_Attribute_Name ":" value:WP_Block_Attribute_Value
{ return [ name, value ] }

WP_Block_Attribute_Name
= head:ASCII_Letter tail:ASCII_AlphaNumeric*
{ return [ head ].concat( tail ).join( '' ) }

WP_Block_Attribute_Value
= head:ASCII_Letter tail:WP_Block_Attribute_Value_Char*
{ return [ head ].concat( tail ).join( '' ) }

WP_Block_Type_Char
= ASCII_AlphaNumeric
/ [\/]

ASCII_AlphaNumeric
= ASCII_Letter
/ ASCII_Digit
/ Special_Chars

WP_Block_Attribute_Value_Char
= [^ \t\r\n]

ASCII_Letter
= [a-zA-Z]

ASCII_Digit
= [0-9]

Special_Chars
= [\-\_]

Newline
= [\r\n]

_
= [ \t]

__
= _+

Any
= .
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"jsdom": "^9.12.0",
"mocha": "^3.2.0",
"node-sass": "^4.5.0",
"pegjs": "^0.10.0",
"pegjs-loader": "^0.5.1",
"postcss-loader": "^1.3.3",
"raw-loader": "^0.5.1",
"react": "^15.4.2",
Expand Down
4 changes: 4 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const config = {
},
module: {
rules: [
{
test: /\.pegjs/,
use: 'pegjs-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
Expand Down