Giter Site home page Giter Site logo

Native/abstracted sub-parsers about combine HOT 6 OPEN

ckiee avatar ckiee commented on May 27, 2024
Native/abstracted sub-parsers

from combine.

Comments (6)

Marwes avatar Marwes commented on May 27, 2024

Could you post what kind of input you are trying to parse and how the output is expected to look like? I am not sure I understand it entirely, best I can tell the syntax seem rather ambigous.

**hi** // Could be parsed with the 1st and 4th `*` and the 2nd and 3rd as the start/end of a block or it could be parsed with the 1st and 2nd and the 3rd and 4th in the same block

With combine being LL it will consume eagerly so the first case (1+4 and 2+3) is the one that is parsed.

from combine.

ckiee avatar ckiee commented on May 27, 2024

Overall it's a mix of Org-mode and Markdown so 1+4 and 2+3 seem right, although they don't really have any special meaning and will just get optimized out later:

*hi*                         ; BlockExprNode::Bold(BlockExprNode::Text("hi"))
*/italics & bold/*           ; BlockExprNode::Bold(BlockExprNode::Italics(BlockExprNode::Text("italics & bold")))
**this is kinda useless**    ; BlockExprNode::Bold(BlockExprNode::Bold(BlockExprNode::Text("this is kinda useless")))

from combine.

Marwes avatar Marwes commented on May 27, 2024

If that is the case, why is bold calling itself recursively? Why not just (token('*'), many1(char()), token('*')) ?

from combine.

ckiee avatar ckiee commented on May 27, 2024

why is bold calling itself recursively?

Because eventually block_expr_node's choice! will have more options (like italics, etc..) so I'm just preparing it for that.

Ideally I could make block_expr_node's choice! skip bold in the second, nested call from bold but this isn't the reason I opened the issue. What do you think about the flat_map abstraction?

from combine.

Marwes avatar Marwes commented on May 27, 2024

It wouldn't be an unreasonable addition, however **this is kinda useless** would not be parsed as you expect with the and_reparse_with parser you showed, it would be parsed as Bold(""), Text("this is kinda useless"), Bold("") so I am not sure it is the solution you are looking for.

To parse it as BlockExprNode::Bold(BlockExprNode::Bold(BlockExprNode::Text("this is kinda useless"))) you would effectively need infinite lookahead to figure out which * are opening and closing a block which doesn't seem right.

Another solution may be to do something like (many1(choice(bold_char(), italics_char(), etc)).then(|prefix| text().skip(string(prefix.reverse()))) which would consume a "block prefix", then parse the text and finally check that the prefix appears in reverse order after.

from combine.

ckiee avatar ckiee commented on May 27, 2024

Another solution may be to do something like [..]

That would probably work, but you still need to treat hello* world as normal text (no matching bold_char) so it might be a bit more tricky.. For now I think I will leave this edge case alone since I want to get the whole pipeline kinda-working instead of parsing perfectly right away :P

It wouldn't be an unreasonable addition

Should I have a go at making a PR then? It seems tricky and I am still scared of all the types so I would need some mentoring probably

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.