Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(parser) Compiler extensions (for grammars + plugins) #2834

Merged
merged 28 commits into from
Dec 23, 2020

Conversation

joshgoebel
Copy link
Member

@joshgoebel joshgoebel commented Nov 5, 2020

Closes #2794. Works towards #2520. Closes #2833.

Changes

Implements #2833 with the key compilerExtensions on a grammar which is an
array of extensions that takes the mode (and it's parent) as input.

Inside the compiler (for all grammars):

  • More modular pipeline that users the new extensions internally also
  • Adds support for illegal being an array of illegal expressions seamlessly compiled into a single regex

R grammar:

  • Testing out the beforeMatch (alternative to look-behind) as a candidate for future inclusion in the compiler.

It also adds two plugin hooks that take the same input:

  • before:compileEarly
  • before:compileLate

The plugin hooks were removed for now.

Overall this allows grammars (and plugins) to add syntactic sugar to their own definitions.

Checklist

  • Added markup tests, or they don't apply here
  • Added tests to guarantee plugin extensions are called properly by compiler
  • Updated the changelog at CHANGES.md
  • Added myself to AUTHORS.txt, under Contributors
  • Document the new plugin options

@joshgoebel joshgoebel force-pushed the grammar_extensions branch 2 times, most recently from 8150e7f to 3aa5ab4 Compare November 10, 2020 21:17
@joshgoebel joshgoebel changed the title wip: grammar extensions enh(parser) Compiler extensions (for grammars + plugins) Nov 10, 2020
@joshgoebel joshgoebel added enhancement An enhancement or new feature parser labels Nov 10, 2020
@joshgoebel joshgoebel self-assigned this Nov 15, 2020
@joshgoebel joshgoebel added this to the 10.5 milestone Nov 20, 2020
@joshgoebel
Copy link
Member Author

Ping.

Copy link
Member

@allejo allejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Some comments have become dated though and should be updated for accuracy

src/lib/mode_compiler.js Outdated Show resolved Hide resolved
src/lib/mode_compiler.js Outdated Show resolved Hide resolved
src/lib/mode_compiler.js Outdated Show resolved Hide resolved
src/languages/r.js Show resolved Hide resolved
Copy link
Collaborator

@egor-rogov egor-rogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really cool. The feature can be easily abused, but it's a powerful tool.
I mentioned some points regarding the documentation.

@@ -130,3 +130,41 @@ language
The language determined from the class attribute (or undefined).

It returns nothing.


before:compile(mode, parent)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actially before:compileEarly and before:compileLate, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to rework all the docs (which is why this isn't merged). No one has asked for this as a plugin so I'm probably going to rip that out completely (plus I'm not sure a world where to install grammar xyz you also need plugin 123 and 234 is a great place to end up, so we can push off that decision into the future)... so the new capability is just that languages can define their own sugar (and of course the more modular compiler setup)... and then inside the library we can "test" new extensions in a single language first... and if that goes well they can be promoted to the compiler.

So these docs are probably moving into compilerExtensions inside the mode docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved docs into the mode reference.

src/lib/compiler_extensions.js Show resolved Hide resolved
src/lib/compiler_extensions.js Show resolved Hide resolved
Copy link
Collaborator

@egor-rogov egor-rogov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like it.
The feature is great, the added docs are clear.

docs/mode-reference.rst Outdated Show resolved Hide resolved
@joshgoebel joshgoebel merged commit 0de0fca into highlightjs:master Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature parser
Projects
None yet
3 participants