Comments (6)
Can you explain how these differ from method chaining?
How does wrapTimes
compare to the following?
parser.times(n).wrap(before, after)
parser.times(min, max).wrap(before, after)
// --- or ---
parser.wrap(before, after).times(n)
parser.wrap(before, after).times(min, max)
Same sort of question for wrapAtLeast
, wrapAtMost
, wrapMany
.
from parsimmon.
This parser will only succeed when the input is "(abra-abra-abra-)"
string("abra-").times(3).wrap(string("("), string(")"))
```
This parser will only succeed when the input is "(abra)(abra)(abra)"
```js
string("abra").wrap(string("("), string(")")).times(3)
```
```
```
from parsimmon.
Times followed with wrap will only succeed when the input is "(abra-abra-abra-)"
string("abra-").times(3).wrap(string("("), string(")"))
Wrap followed with times will only succeed when the input is "(abra)(abra)(abra)"
string("abra").wrap(string("("), string(")")).times(3)
WrapTimes will only succeed when the input is "(((abra)))"
string("abra").wrapTimes(string("("), string(")"), 3);
// wrapTimes is same as this below
string("abra")
.wrap(string("("), string(")"))
.wrap(string("("), string(")"))
.wrap(string("("), string(")"))
WrapAtLeast will succeed if you have wrapped it at least n times. In this case "abra" must be wrapped at least in 2 parentheses or more, for example it would succeed if the input is "((abra))" or "(((((abra)))))"
string("abra").wrapAtLeast(string("("), string(")"), 2)
WrapAtMost will succeed if you have wrapped it at most n times. In this case "abra" must be wrapped at most 2 times or less, for example it would succeed if the input is "abra" or "(abra)" or "((abra))".
string("abra").wrapAtMost(string("("), string(")"), 2)
WrapMany will succeed if you have wrapped n times or not at all. In this case "abra" can be wrapped n times or not at all, for example it would succeed if the input is "abra" or "(((((((((((((abra)))))))))))))" or "(((((abra)))))"
from parsimmon.
Parsimmon already has a lot of methods, and I've never wanted this one personally. You can write this in terms of other combinators without a ton of fuss, so I don't want to add 4 new methods.
const P = require('parsimmon');
const x = P.string('x');
const xp = P.string('(').atLeast(1).chain((lp) => {
return x.skip(P.string(')').times(lp.length));
});
xp.parse('(((x)))');
from parsimmon.
To be honest with you I thought I would need it, but I realized now I don't actually need and it is nisch feature. By the way thanks for the answer.
from parsimmon.
Ah, good to know. I like hearing real-world use-cases for methods before adding them anyway.
from parsimmon.
Related Issues (20)
- Regex dotAll support (/s flag) HOT 2
- MS Edge 18 error HOT 9
- Question: What's wrong with my parser? HOT 3
- Question: How to parse html comment HOT 4
- Ignoring XML like tags when encountered inside XML like tags HOT 2
- The library doesn't include type definitions HOT 1
- Unneeded code dublication in formatGot HOT 4
- How do I properly nest then/or/atLeast parsers? HOT 3
- How can I parse the inside and outside of the parentheses? HOT 1
- Question HOT 9
- Question about parsing "define <name> [as <internalName>]" style grammar HOT 4
- Question: Is it possible to get consumed part of string from the parser result? HOT 1
- Import Parsimmon HOT 7
- Question: how to do an intersection of optional parsers? HOT 4
- Parsimmon.index yields incorrect position for tokens right before a newline ('\n') HOT 10
- Incorrect error formatting HOT 5
- Is there a way to do something like "everything up until SomeParser" HOT 4
- Use all the groups from regex HOT 3
- Slow parsing performance HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parsimmon.