question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: include support for plugins

See original GitHub issue

It would be nice to support user-definable plugins, i.e. “Phone Number”

Something like:

const myRegex = SuperExpressive({ plugins: [ phoneNumber ] })
  .startOfInput
  .optional.string('0x')
  .capture
    .exactly(4).group
      .plugin.phoneNumber()
      .newline
    .end()
  .end()
  .endOfInput
  .toRegex();

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
francisrstokescommented, Jul 19, 2020

@jcao219 @floriancargoet @puf17640 I’ve added support for subexpression based modularity in PR #17. It was kind of tricky, but I think I managed to get something that behaves sensibly in a flexible way, and hopefully still quite easy to use.

I’ve written a set of tests which outline the edge cases I could think of. If you notice more, or have an other kinds of feedback, please let me know. I’ll keep the PR open for a little while.

1reaction
francisrstokescommented, Jul 18, 2020

Interesting idea! I’ve been thinking a bit about how this could work, and there would be some challenges

In merging two SuperExpressive instances, as @floriancargoet mentioned, you would have to address some sticking points.

  • How do you deal with flags? Are sub expressions able to assert that the entire expression should become global, case insensitive, etc?
  • How do you deal with capture groups and back references?
    • Avoiding naming collisions
    • Avoiding indexing collisions, where the primary expression uses capture groups and indexed backreferencing, but the plugin/module does too
// a modular SuperExpressive...
const modularExpression = SuperExpressive()
  .exactly(3).digit
  .capture
    .zeroOrMore.anyChar
    .string('!')
  .end()
  .backreference(1);

// using the module
const mainExpression = SuperExpressive()
  .startOfInput
  .capture
    .range('a', 'z')
  .end()
  .subexpression(modularExpression)
  .backreference(1);

// The module expression creates and backreferences to index 1, but it would actually be index 2 in the main expression

With a plugin based architecture, there would be similar kinds of concerns I imagine that the plugin would be an extension of another class like SuperExpressivePlugin, which would provide a (perhaps more limited) interface. That limited interface might even allow the plugin author to describe that they’d like to modify a flag, or create an explicit capture group namespace, etc.

Personally I’m more inclined to go with merging SuperExpressive instances, because that would allow people to very easily organise their own code in a modular way, and one interface to maintain is always better than 2!

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 WordPress Proposal Plugins and Tools Designed to Help ...
Fortunately, there are several available worth considering, including some WordPress proposal plugins. We've explored five of them below.
Read more >
Add support for global plugins/universal addons #831 - GitHub
Add support for global plugins/universal addons #831 ... Describe how your proposal will work, with code, pseudocode, mockups, ...
Read more >
WP Proposals – WordPress plugin
Beautiful, simple free WordPress proposal software. ... you create stunning professional proposals that will help you and your sales team land dream deals....
Read more >
How to Write Proposals for WordPress Projects - WPMU Dev
#1. Proposify. Proposify has 50+ proposal templates including the ones for WordPress development and support projects. Because Proposify offers ...
Read more >
babel/plugin-proposal-class-properties not being picked up ...
I am trying to incorporate React Native Calendars into my React webapp. I have run npm install --save react-native-calendars.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found