Comments (5)
actually... .soft.surroundedBy(a)
seems like a good idea to have, which would be a.soft *> p.soft <* a
What do you think of that API?
from cats-parse.
See this comment:
surroundedBy with whitespace does not work great. The problem is lack of backtracking. Your design is assuming backtracking. As soon as you see whitespace, the first item will start to parse, if you don't hit the surrounded thing, you will get an error (again, an intentional goal is opt-in backtracking).
So, I think instead you want something like: whitespaces0.soft *> comma *> whitespaces0
The reason your final example fails is because with you hit y )
the space starts looking like a listSeparator, but then you don't see a ,
but the parser expects that.
Altenatively, you could make listSeparator
backtrack by doing:
val listSeparator = comma.surroundedBy(whitespaces0).backtrack
from cats-parse.
Thanks for the explanation. It pointed me to a reasonable solution.
Rather than introducing backtracking just to eliminate whitespace, I'm removing whitespace after each token, rather than both before and after. I created a ".strip" method to skip over trailing whitespace.
extension[T](self:Parser[T]) def strip = self <* (whitespace.rep0.void)
I fell into my way of errors by following the README example. Given the pitfalls, it probably isn't good practice to use surroundedBy to remove whitespace.
from cats-parse.
you are right. We need to improve the readme... it compiles, but it actually isn't great for the same reason.
from cats-parse.
from cats-parse.
Related Issues (20)
- Recursive parser creates infinite loop. HOT 1
- A parser string interpolator
- Backtracking with context HOT 1
- Rep same char as surrounded by HOT 5
- idea for safe repetition on Parser0
- RadixNode and stringIn are a bit slow
- Is it possible to support Scala Native? HOT 6
- alternate design for voiding
- use java.util.BitSet on scalajs
- `p1.? ~ p2` != `(p1 ~ p2) | p2` for error reporting purposes HOT 9
- Remove isScalaJs/isScalaJvm on minor version update
- identifier parser HOT 2
- flakey test: X cats.parse.ParserTest.a.flatMap(b) composes as expected parser00
- add json string parsing
- add a withString combinator
- Should `Parser` have a typeclass? HOT 2
- set up github CI to run benchmarks on release
- investigate scalacheck failure 20230625T112756
- Link errors when crossbuilding for scalaJS or scalaNative HOT 3
- Recursion with `Parser0` HOT 2
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 cats-parse.