Comments (6)
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.
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.
If that is the case, why is bold
calling itself recursively? Why not just (token('*'), many1(char()), token('*'))
?
from combine.
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.
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.
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)
- Is there a way to get `Stream<Token=char>` from `io::Read`? HOT 1
- Tools for debugging recursion problems? HOT 4
- Some issue with error reporting
- Errors include unprintable or awkwardly printed characters. HOT 6
- `expected` error strings always quote what was expected, even if it isn't a literal HOT 3
- How about offset into some data? HOT 3
- Outdated tutorial HOT 1
- XML parsing for React.js to Solid.js conversion HOT 4
- Comparison with LALRPOP
- Unbounded mutual recursion in Parser impl HOT 3
- Adivce on reducing code size in WASM target HOT 7
- Docs unclear whether `parser!` should be used on nightly rust HOT 2
- Parse `std::process::Child` stdout
- Successful parser will not clear the error stack HOT 1
- build failure
- Implement Pratt parsing or precedence climbing HOT 4
- Choice with Vec of parsers HOT 4
- Documentation request: no_partial
- Worse performance after parsing 2 large values HOT 9
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 combine.