Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Define parser and printer consistently
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-12-09 (04:47)
From: Dawid Toton <d0@w...>
Subject: Define parser and printer consistently
I'm going to define a parser and a printer for a simple grammar.
Is there a way to define both of them in a single construct using some 
existing OCaml tool?

For example, I have a keyword "function". The usual parser would contain 
a mapping like:
"function" -> `Function
and the straightforward printer would do:
`Function -> "function"

What is the best way to combine these definitions, so that duplication 
would be minimized?
To be precise, avoiding duplication is not exactly what I need. I'm 
looking for something that would prevent making inconsistent changes to 
the parser and the printer.