Browse thread
GenerateFold
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Nicolas Pouillard <nicolas.pouillard@g...> |
| Subject: | Re: GenerateFold |
On 5/31/07, Joel Reymont <joelr1@gmail.com> wrote:
> What is the proper use of GenerateFold here?
>
> What I'm trying to do is dig into my AST tree, starting with a list
> of statements at the top, to find out if I have any `FunArgDecl bits.
>
> At the top of the AST I have
>
> statement =
> [
> | `InputDecls of input_decl list
> ]
>
> and then
>
> input_decl =
> [
> | `InputDecl of id * ty * expr
> | `FunArgDecl of id * ty * subscript
> ]
>
> I tried the following approach but it's obviously wrong.
>
> class fold = Camlp4Filters.GenerateFold.generated;;
>
> let is_fun_arg = object
> inherit fold as super
> method input_decl x =
> match super#input_decl x with
> | `FunArgDecl _ -> true
> | _ -> false
> end
>
> let is_fun x = is_fun_arg#statement x;;
>
You must use the object itself that is threaded through the traversal
(or use an exception in that simple case).
Something like (not tested).
class fold = Camlp4Filters.GenerateFold.generated;;
let is_fun_arg = object
inherit fold as super
val found = false
method found = found
method input_decl x =
match super#input_decl x with
| `FunArgDecl _ -> {< found = true >}
| _ -> self
end
let is_fun x = (is_fun_arg#statement x)#found;;
--
Nicolas Pouillard