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

Add basic positive lookahead support #27

Closed
wants to merge 1 commit into from
Closed

Conversation

WesTyler
Copy link

Addresses basic implementation for #18 .

Basic cases not previously supported that now pass:

const justA = randexp('^(?=a).$');            // justA === 'a'

const positivePattern = '^hi(?= no one)';
const lookAhead = randexp(positivePattern);   // lookAhead === 'hi no one'
lookAhead.match(positivePattern);             // -->> [ 'hi', index: 0, input: 'hi no one' ]

const negativePattern = '^hi(?! no one)';
const noLookAhead = randexp(negativePattern); // noLookAhead === 'hi'
noLookAhead.match(negativePattern);           // -->> [ 'hi', index: 0, input: 'hi' ]
lookAhead.match(negativePattern);             // -->> null

@codecov-io
Copy link

codecov-io commented Oct 17, 2016

Current coverage is 100% (diff: 100%)

Merging #27 into master will not change coverage

@@           master   #27   diff @@
===================================
  Files           1     1          
  Lines         101   104     +3   
  Methods        12    12          
  Messages        0     0          
  Branches       32    33     +1   
===================================
+ Hits          101   104     +3   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update e5b28d6...e8db1a5

@fent
Copy link
Owner

fent commented Oct 18, 2016

This is what the library used to do a2b2ff5

But this only supports very basic lookaheads. I can't think of a use case where someone would prefer to use a basic lookahead to a regular group.

@WesTyler
Copy link
Author

WesTyler commented Oct 18, 2016

Not sure if this will influence whether you want to support very basic lookaheads or not, but here's some context on why I made the PR for such a simple implementation.

The company XO Group I work for is about to open-source a project we've been using internally since March for generating valid payloads from Joi schema. With this v1 release, we are implementing your (awesome!) utility for supporting Joi's regex schema options. We're hoping to cover as broad a base of support as possible with v1.

That being said, I totally understand if you don't think it's worth the very basic support :)

@fent
Copy link
Owner

fent commented Oct 18, 2016

It's good to hear the library is being used. Thanks for the PR but, supporting only a basic version of that feature would have people believe that your library fully supports lookaheads, when the basic version doesn't provide any added benefits compared to a regular group. And they might become frustrated when they find out lookaheads are not fully supported.

@WesTyler
Copy link
Author

Sure thing! Understood :)

I'll go ahead and close this for cleanliness. I may circle back around later to take a crack at a more complete support. Thanks for the feedback and the discussion!

@WesTyler WesTyler closed this Oct 18, 2016
@JonathanMontane
Copy link

@fent I've looked into how to support lookahead for generation, and short of transforming every part of the regex into DFAs and doing a cartesian product of those DFAs, it's not possible to support them properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants