Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9B551200BEE for ; Sat, 31 Dec 2016 17:32:57 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 99F24160B28; Sat, 31 Dec 2016 16:32:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id BC23B160B15 for ; Sat, 31 Dec 2016 17:32:56 +0100 (CET) Received: (qmail 5979 invoked by uid 500); 31 Dec 2016 16:32:55 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 5969 invoked by uid 99); 31 Dec 2016 16:32:55 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 31 Dec 2016 16:32:55 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 51DF7C096B for ; Sat, 31 Dec 2016 16:32:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.8 X-Spam-Level: X-Spam-Status: No, score=-0.8 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Authentication-Results: spamd4-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=ameritech.net Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id WvWqyUHZ9mmJ for ; Sat, 31 Dec 2016 16:32:53 +0000 (UTC) Received: from nm18-vm10.access.bullet.mail.bf1.yahoo.com (nm18-vm10.access.bullet.mail.bf1.yahoo.com [216.109.115.89]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id CC71D5F19D for ; Sat, 31 Dec 2016 16:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ameritech.net; s=s2048; t=1483201966; bh=HI2tWG30lr+xWtbd7atVDj27Oxt5KN+Uqsa6+F2huYs=; h=Subject:To:References:From:Date:In-Reply-To:From:Subject; b=S31DI+xDu44Xn6cFRPJ6tWhQpx0wRI1amjg9mcwt+3fFgMLcAVzIfozfO/g9zGbfdFWCwmQtic9rksp+zWiNgvcZ3laaWTmk2+emjigQ395S3xY0RKb/5spB3GkGZacTj7X7X0LbiFg5dQ63f7vcmgRxb1ezJLNRgRyGwBpWaY9Hp6TUoA8sqaqoRmUSTYGY6fvQ3XUe6NZVyb5HvSa7fqLBISBMgnH9dzhk51UwFvnMsq9Mg1Q4uyVdfAMFiTZDXF0InT//f+SHxmAh44hl/lD/KnRwDN2xYRYv8etiNQdvbOIIX+8L4gx5OVOb49jo16qpo8g5rE4KMe+gK/WmkQ== Received: from [66.196.81.160] by nm18.access.bullet.mail.bf1.yahoo.com with NNFMP; 31 Dec 2016 16:32:46 -0000 Received: from [98.138.226.244] by tm6.access.bullet.mail.bf1.yahoo.com with NNFMP; 31 Dec 2016 16:32:46 -0000 Received: from [127.0.0.1] by smtp115.sbc.mail.ne1.yahoo.com with NNFMP; 31 Dec 2016 16:32:46 -0000 X-Yahoo-Newman-Id: 658339.87817.bm@smtp115.sbc.mail.ne1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 9RgvZTAVM1kSh5iQTMwRA1W.7tc7NplvZgcV6.mtl5LhdZZ b2oEoTbLTPRO53DRL4UeLqZHZPr6PDHLhVWu.H7bbqtbGLJ7YzqIKFXwYB7. wVC4eSHDHEskPAZAAsIP9weTwmdrudBA7MiGtU8hfdHrTaDYQhe0DHe.M3pv eh4CFMnmNzV_TF65NkNMiBwqvo5ZPv7QF_obMkXM6waj2NmMbmX6C.Rpp.px 0dxeF21nkDUQiFICqUg15W.M0qK_EQluEXdV8rGhLsTbBUhXdQQ_t2uRQvgi ea.hZ2XNcXKN7KiZ2ZmZbXUCekMLyV3ap_ztalb7XR9Z_l3qG4665pAhItdG 8b0QeXd4M_.pIhkMkWpCkrcS.SUFchBFWtn7qzvWR8zf8jh7M9UH8vskihu5 tAzRnmNH7mxEwNI8vzf0Z9iSGSMBFmS02QIeu9DDIz_Uvw_nYxOcXjZHu2M_ v2vhhaAJwrotXC5KL000OCoFotrLNi7bBDPL_B2PRwL0K0URlFc9VbPEpwss CjuZqyHuYIiX.fcMCDUSUnL6bRhobe3O.4JSNBbnccnj4E2DNSsmzYDvJSmC UZFxXgA-- X-Yahoo-SMTP: Bq.YuS2swBAnAqrQertsUb6eYlocRqEVdq4_Cfw6KBXRHg-- Subject: Re: help with an AST To: users@groovy.apache.org References: <5866C1A8.6020809@gmx.org> From: Ed Clark Message-ID: <337fe01e-3af4-5345-cd5f-8836cd565a94@ameritech.net> Date: Sat, 31 Dec 2016 11:32:45 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <5866C1A8.6020809@gmx.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit archived-at: Sat, 31 Dec 2016 16:32:57 -0000 Hi Jochen, Thanks for the suggestions. Replies in line... On 12/30/2016 03:20 PM, Jochen Theodorou wrote: > Hi Ed, > > I am wondering if categories would actually do what you want already without touching the AST. > Groovy Categories are actually no syntactic construct and their scope is not lexical (thread local > instead)... but maybe > > Let us assume you have two Strings obj1 and obj2, then you can define a category: > > class StringCategory { > static String plus(String obj1, String obj2) { "from StringCategory $obj1 $obj2" } > } > > and code like this: > > use (StringCategory) { > assert "a"+"b" == "from StringCategory a b" > } > > the construct supports nesting from inside out, that means the inner context wins over the outer > context and the rightmost over the leftmost. > > What this does not support is an instance based context. I don't think categories will meet my wants. Categories are a way to enhance a specific class, whereas I'd like to have my "contexts" deal with objects of a variety of class types. > > Assuming you still want to do something like this with more... AST involvement... > >> My questions for you are, >> >> - is an AST the way to go? > > first you have to decide what you want to compile to and then we can think about how the AST for > that has to look like. So this is actually the last step. But assuming you have some kind of > handler object you could compile a+b to handler.invoke("plus",a,b)... in other words you would > replace almost any expression by a MethodCallExpression. Hint: ExpressonTransformer and helper > classes. Hmmm, I will have a handler object - sort of - and that's the context object itself. Well, at least in the case of instance based contexts. For class based contexts, there won't be an instantiated handler, but I could still see having a static "invoke" method. I hadn't considered the invoke approach; it is interesting. I think it would provide some additional flexibility that the context developer could use to add "operators" beyond the ones built into the Groovy parser/AST. I'll have to think about this some more. > >> - I'm guessing that I can do the context nesting and composing by building on >> methodMissing (with ctx2 chaining to ctx3 chaining to Ctx1 above), but is there >> a better way? > > I guess the code path for categories won´t help you here, since that is kind of special treated. > You could create a special meta class and all the context methods to it, then use its mechanisms > to select an appropriate method... hint getMetaMethod, init Just to be clear, I don't think there is anything special about the contexts - they are just POGOs. Their methods just happen to be focused on manipulating objects that fall under their scope. So, I'm not sure how creating a meta class would help. Remember, I'm trying to get away from the semantics of associating the "plus" in "obj1 + obj2" back to obj1 (or any potential meta class). Instead, I'm trying to associate the "plus" back to the surrounding context (or possibly handler as you suggest above). > > >> - what might I be breaking in Groovy by doing this? > > that depends on how you do it. > >> - what help/hints can I get from the compiler vs. doing this all at runtime? > > worry about such things once you have come up with something that works ;) Yeah, one of my problems is I think too far ahead ;). I start worrying about what it might take to run a marathon when I haven't even learned to walk. So I don't even get started. Part of the this resolution is to just get off my butt and write some code.