Trying to parse a function #672
Unanswered
TeaDrinkingProgrammer
asked this question in
Q&A
Replies: 1 comment
-
In being fully declarative, I would write: let identifier = repeat(1.., parse_alpha_numerical);
let params = delimited('(', separated(1.., parse_param, ','), ')');
seq!{Function {
identifier,
params,
}).parse_next(input) alternatively, you could do: (
repeat(1.., parse_alpha_numerical),
delimited('(', separated(1.., parse_param, ','), ')')
)
.map(|(identifier, params)| Function { identifier, params })
.parse_next(input) However, do not feel obligated to force everything into being declarative. Imperative parsing has its place. btw I'd recommend |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
hey y'all, I have been building a parser using winnow for my regex-like language, and I have been very pleased with the library. I have been able to build a lot of parts of my parser, but I am stuck on this problem. I want to parse a function, where I parse the identifier first and then parse the arguments. I have come up with this, but the problem with it is that it obviously doesn't use the combinators:
Input
identifier(param1,param2)
Output (OK variant of result):
What would be a more ergonomic way of doing this?
flat_map
andand_then
seem to come close, but only allow one value to be returned, when I was looking for a similar function that allows you to return tuples. If there is some obvious different solution I am missing here, I would love to hear that too.Beta Was this translation helpful? Give feedback.
All reactions