Git Product home page Git Product logo

Comments (7)

deliciouslytyped avatar deliciouslytyped commented on August 17, 2024

Related: I seem to have to define wrap something like the following to get backtracking to work?

def wrap(fn):
  def thing(res):
    try:
      result = fn.parse(res)
      return success(result)
    except:
      return fail("idk")
  return thing

What's the correct way to do this?

from parsy.

spookylukey avatar spookylukey commented on August 17, 2024

@jneen do you have any input on this? I've never actually used bind directly, perhaps you could answer this question more easily than me?

from parsy.

deliciouslytyped avatar deliciouslytyped commented on August 17, 2024

Ok, this makes more sense when used like in #36 (comment) , I need to revisit this later.

from parsy.

jneen avatar jneen commented on August 17, 2024

I'm not sure what you're trying to do, could you explain in a little more detail? The "pseudocode" example you gave passes a Parser instance to .bind - but .bind takes a function that returns a parser. It's a little hard to follow because your variable named fn is not actually a function, but a parser.

from parsy.

jneen avatar jneen commented on August 17, 2024

Oh, I think I see what's happening. You are mixing strings and tokens, and want to "re-parse" the parse result when it's not a token. I... would suggest just tokenizing your entire input before passing it to parsy if that's the direction you want to go.

from parsy.

jneen avatar jneen commented on August 17, 2024

If you are really dedicated to this approach you might want to define something like:

def reparse(parser):
    return test_item(lambda x: isinstance(x, unicode), 'not a string').map(parser.parse)

from parsy.

jneen avatar jneen commented on August 17, 2024

@spookylukey for reference, bind is just a way to dynamically determine the next parser, which you can naturally do with @generate functions. These are equivalent:

parser = first.bind(second)

@generate
def parser():
    res = yield first
    return (yield second(res))

from parsy.

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.