Comments (7)
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.
@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.
Ok, this makes more sense when used like in #36 (comment) , I need to revisit this later.
from parsy.
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.
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.
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.
@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)
- >>= for bind HOT 14
- Missing documentation for eof parser? HOT 1
- Improve debugging: peek show next data in errors HOT 5
- Recompute line number for ParseError passed up from .bind
- Improve debugging ergonomics HOT 3
- Inline (explicit) and implicit tracing
- Missing seq import statement in tutorial HOT 1
- Help with parsing that "hangs" HOT 3
- Bug with backtracking and generate? HOT 4
- Parsy 1.3.0 fails to support 'group' keyword of `regex` function HOT 1
- async/await support in generate() HOT 6
- Release HOT 2
- Interested in a version of parsy with type annotations? HOT 3
- Allow providing a default to optional() HOT 2
- maintaining state while parsing HOT 3
- combine fails when nothing is produced by many HOT 2
- [bug] Parser.desc() causes loss of error information, simple fix HOT 2
- alt doesn't use fallback parsers when initial parser has .many()/.sep_by() HOT 1
- Processing list of tokens HOT 1
- Seeking Guidance on Implementing Parser Autocomplete HOT 6
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 parsy.