caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* AST transformation and scrapping boilerplate code
@ 2007-04-29 14:40 Joel Reymont
  2007-04-30  8:21 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 11+ messages in thread
From: Joel Reymont @ 2007-04-29 14:40 UTC (permalink / raw)
  To: Caml List

Folks,

I have a large AST [2] that I would like to strip of token locations.  
Using the "Scrap your boilerplate" approach [1] the Haskell code  
looks like this:

strip :: (Data a) => a -> a
strip = everywhere (mkT f)
     where f (TokenPos a _) = a
           f x = x

Is there a way to accomplish a similar feat in OCaml without writing  
out heaps of code that recursively invokes strip for various  
constructors to get to expr and strip it of TokenPos?

	Thanks, Joel

[1] http://tinyurl.com/36jj3q

[2] Incomplete AST

let statement =
     [
     ...
     | `InputDecls of input_decl list
     | `VarDecls of var_decl list
     ...
     ]

and subscript = expr list

and input_decl =
     [
     | `InputDecl of id * ty * expr
     | `FunArgDecl of id * ty * subscript
     ]

and expr =
     [
     ...
     | `FunCall of ty * string * expr list * bars_ago * instrument
     | `Mul of expr * expr
     ...
     | `PrintExpr of expr * expr * expr
     ...
     | `TokenPos of expr * pos list
     ]

--
http://wagerlabs.com/






^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2007-04-30 13:09 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-29 14:40 AST transformation and scrapping boilerplate code Joel Reymont
2007-04-30  8:21 ` [Caml-list] " Nicolas Pouillard
2007-04-30  8:41   ` Joel Reymont
2007-04-30  9:47     ` Nicolas Pouillard
2007-04-30  8:53   ` Joel Reymont
2007-04-30 12:19   ` Joel Reymont
2007-04-30 12:42     ` Nicolas Pouillard
2007-04-30 12:46       ` Joel Reymont
2007-04-30 12:58         ` Nicolas Pouillard
2007-04-30 13:06           ` Joel Reymont
2007-04-30 13:09             ` Nicolas Pouillard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).