There are multiple things described in this issue, but I think it's better to keep them close.
I'm doing some free text parsing migrating from the regular expressions based solution. I faced an issue that I couldn't fully specify the surrounding context. when is the only parser that could work with context but documentation doesn't say anything whether it consumes input or not (I assume it does which raises a question how it is different from sequence). Also when allows to specify preceding context only and I'm not sure what should I use to specify the context after the target parser.
It would be nice to have non-consuming parser (context) and negation parser (not) so it would be possible to specify surrounding context e.g.
// context(before, target, optional after)
const helloWorld = string('hello world');
const strictHelloWorld = context(
not(letter()),
helloWorld,
not(whole())
);
const parser1 = sequence(any(), strictHelloWorld, any());
const parser2 = sequence(any(), helloWorld, any());
run(parser1).with('1hello worldA'); // result.isOk = true, value = ['1', 'hello world', 'A'];
run(parser1).with('Ahello world1'); // result.isOk = false
run(parser2).with('1hello worldA'); // result.isOk = true, value = ['1', 'hello world', 'A'];
run(parser2).with('Ahello world1'); // result.isOk = true, value = ['A', 'hello world', '1'];
Also it would be nice to have some default non-consuming parsers such as wordBoundary. What is more this will require polyfilling JS \b since it's not unicode friendly.
More examples can be found in the codesandbox.
There are multiple things described in this issue, but I think it's better to keep them close.
I'm doing some free text parsing migrating from the regular expressions based solution. I faced an issue that I couldn't fully specify the surrounding context.
whenis the only parser that could work with context but documentation doesn't say anything whether it consumes input or not (I assume it does which raises a question how it is different fromsequence). Alsowhenallows to specify preceding context only and I'm not sure what should I use to specify the context after the target parser.It would be nice to have non-consuming parser (
context) and negation parser (not) so it would be possible to specify surrounding context e.g.Also it would be nice to have some default non-consuming parsers such as
wordBoundary. What is more this will require polyfilling JS\bsince it's not unicode friendly.More examples can be found in the codesandbox.