GithubHelp home page GithubHelp logo

sep_by(any(), char(',')) about combine HOT 7 CLOSED

marwes avatar marwes commented on July 20, 2024
sep_by(any(), char(','))

from combine.

Comments (7)

Marwes avatar Marwes commented on July 20, 2024

Not really from what I can think of, you may want to make a custom "sep_by" parser to handle that.

With the current parsers combine provides though I think you might be able to hack around it with the recently added look_ahead parser though.

sep_by(look_ahead(satisfy(|c| c != ',')).with(parser(other)), char(','))

It looks a bit weird but I think it should do what you want (might be some edge case I haven't considered though).

EDIT: No that will not actually work. I am not sure that what you want is actually possible in combine.

from combine.

Marwes avatar Marwes commented on July 20, 2024

I don't believe that what you want is easily possible with combine which uses recursive descent for parsing. If your other parser is able to successfully consume a ',' at some point during its parsing it needs to be "aware" in some way that the sep_by parser should take precedence which is at odds with combine's model in which each parser is unaware of where it is used.

from combine.

Qard avatar Qard commented on July 20, 2024

I don't think it's necessarily at odds. The parser just needs to store and consume all tokens until it reaches the tokens that get consumed by the separator parser, then feed everything up to that point into the item parser. It's kind of cheating at LALR, but it might work okay.

from combine.

Marwes avatar Marwes commented on July 20, 2024

It might work but if you have a grammar which requires you to work around it like that it might be better to use a more powerful tool/library instead (lalrpop comes to mind but I don't know how mature it is yet).

from combine.

Marwes avatar Marwes commented on July 20, 2024

Closing. Feel free to reopen if there is more to be said on this topic

from combine.

PSeitz avatar PSeitz commented on July 20, 2024

When searching for precendence in this repo, this is the only result, but it seems the combine_language crate enables this? (https://docs.rs/combine-language/3.0.1/combine_language/struct.Assoc.html#structfield.precedence)

from combine.

Marwes avatar Marwes commented on July 20, 2024

That's a slightly different meaning of precedence but yes. If you need to parse one is expressions, combine-language supports that.

from combine.

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.