Custom Format Parser


I’m thinking about writing a parser for my own file format. I’m imagining a cross between toml and markdown. I figured this would be a good project for learning Reason. The problem is I have no idea where to start. Anyone able to give me some direction or resources on at least a high level of how this should be done? I believe you would want to convert it to an AST, but I am pretty naive about that as well.

Thanks! Any information at all would be greatly appreciated.


@dardub I’m also in the process of learning Reason by writing my own parser for math expressions. It uses the shunting yard algorithm.

Another common type of parser is recursive descent parser. I find these are probably the easiest to understand and implement by hand.

There are also lots of tools for generating parsers. One common set of tools is lex and yacc. OCaml has bindings for these tools and Reason has runtimes for the lexers and parsers generated by these tools. See and I have not used either of these modules.


Great. Thank you for the info! I’ll take a look.


Real World OCaml has a nice section on parsing with OCamllex and Menhir.