Giter Site home page Giter Site logo

Comments (3)

evancz avatar evancz commented on June 26, 2024 2

I think you can write helpers for cases like this:

atMost : Int -> Parser () -> Parser ()
atMost n parser =
  if n <= 0 then
    succeed ()
  else
    oneOf
      [ map2 always parser (atMost (n - 1) parser)
      , succeed ()
      ]

It may be worth adding examples of a bunch of different things like this, but I hesitate to put them in the API directly. Maybe I can add things to examples/ and see how useful they are to folks.

from parser.

pablohirafuji avatar pablohirafuji commented on June 26, 2024

Couldn't you use getIndentLevel? I think that's also going to be useful when parsing lists inside lists inside lists...

from parser.

oldfartdeveloper avatar oldfartdeveloper commented on June 26, 2024

@BrianHicks I've been "stuck" on the same issue, and I woke up at 4:00 AM with this workaround:

oneOf [
    keep (Exactly 3) (\c -> c == ' ')
  , keep oneOrMore (\c -> c == ' ')
]

The first keep succeeds if it can grab the maximum number of spaces you are looking for.
Otherwise it will grab what it can in the 2nd keep.

An advantage is that this solution prevents the potential "buffer-busting" outcome of using just oneOrMore when a hacker might attempt to shove thousands of space characters.

I like your proposal, but until something like it is implemented, this might be suitable.

I have a similar situation in which I need to grab from 1 to 6 digits.

HTH

from parser.

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.