Git Product home page Git Product logo

Comments (5)

johnynek avatar johnynek commented on June 15, 2024 1

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.

johnynek avatar johnynek commented on June 15, 2024

See this comment:

#188 (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.

precision-software avatar precision-software commented on June 15, 2024

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.

johnynek avatar johnynek commented on June 15, 2024

you are right. We need to improve the readme... it compiles, but it actually isn't great for the same reason.

from cats-parse.

johnynek avatar johnynek commented on June 15, 2024

done in #289 #290

from cats-parse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.