Skip to content

[Help]How to implement a parser with the same functionality as this regular expression #559

Answered by epage
yyy33 asked this question in Q&A
Discussion options

You must be logged in to vote

The main way people do backtracking is using alt() but that requires having distinct fallback cases. In the situation you gave, there doesn't seem to be distinct fallback cases. This is why I was asking for clarification to see if that was intended literally or if, with more information, we'd be able to identify fallback cases.

I'm assuming there is more to the need of your parser than just this. In that case, Winnow is designed to allow you to drop down to writing parse code like this by hand, like the rsplit_once code I mentioned.

One example is

let (head, tail1, tail2) = preceded('(', take_until(1.., ')')).try_map(|head| {
   let (head, tail2) = head.rsplit_once(' ').ok_or_else(...)?;
   

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@yyy33
Comment options

@epage
Comment options

@yyy33
Comment options

@epage
Comment options

Answer selected by yyy33
@yyy33
Comment options

@epage
Comment options

@yyy33
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants