-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing a C-like language #9
Comments
I too would like to know this. An example from the author would be useful. While we're waiting, I'd like to note that:
let rec while_ state = (
while' >> parens (cond) >>= fun cond ->
(braces block) >>= fun bl -> return (While(cond, bl))
) state
and block state = (
braces (many statement)
) state
and statement state = (
attempt assign <|>
attempt call <|>
attempt while_
) state Ugly, I know, but should satisfy OCaml's demands on recursive definitions. An alternative would be to introduce some indirection. For example first define your recursive parsers as |
Any update on this? I created a similar issue in angstrom inhabitedtype/angstrom#213 which allows recursive parser (via the fix trick), but does not allow mutually recursive parsers. |
cc @murmour |
This is not a bug, but I'm wondering how I can use MParser to write a parser for a C-like language? The main issue I'm running into is when defining the different kinds statements which need to be mutually recursive:
Here
assign
andcall
have been defined separately and work fine. However,while
needs to be mutually recursive withblock
andstatement
, but this definition violates OCaml's rules for mutually recursive definitions.Is there some other way to define rules like this using MParser?
The text was updated successfully, but these errors were encountered: