Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Packages: Create new `spec-parser` package #7664
This PR follows the setup for Simplenote app: https://github.com/Automattic/simplenote-grammar-pegjs where grammar is published to npm together with a generated JS source file.
This change allows to use Gutenberg grammar without Webpack config and simplifies setup we have. It makes it also much easier to use gramma parser outside of Gutenberg.
Downside of this approach is that we won't be able to iterate as easily as now on the parser's content. What we had so far allows to use Webpack to dynamically update code using
How has this been tested?
Gave the PR a try on the native mobile app @gziolo .
Had to install
pegjs globally first and also manually tweak the
element package entrypoint (removing the .js extension as we discuss elsewhere).
The results are mixed I'd say:
- The parser is generated and loaded just fine
- The (RN) parser tests fail for the
moreblock though. Here's the result:
console.error gutenberg/blocks/api/validation.js:147 Block validation failed for `core/more` (0). Expected: <!--more--> Actual: <!--more-->
That's an error I remember seeing in the past when I was first trying to port the parser to mobile. If I recall correctly, I resolved it by finding a different way to get a hold to the generated parser.
Here's a branch on the RN repo in case you want to have a look.
We need to replicate what you did in the past because we need to be able to update parser without doing manual steps. In addition, it should work for all platforms with one JS codebase if possible.
OK, I think I found what I did in the past: I tapped into the
The particular use of the pegjs options might be a key here. Though, I tried passing those same options to the
I personally like this change, while the
postinstall trick is not perfect to build the grammar. We probably need support to custom build tools in our packages build script and also probably a bit harder support watching changes to the pegjs file as well. But I'm fine landing this as is because I think we'll be in a better position to make other packages generic (blocks, editor) which is far more important IMO