Version française
Home     About     Download     Resources     Contact us    
Browse thread
AST transformation and scrapping boilerplate code
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Joel Reymont <joelr1@g...>
Subject: AST transformation and scrapping boilerplate code
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/