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 B0993200D46 for ; Sun, 26 Nov 2017 12:32:41 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id AF574160BFF; Sun, 26 Nov 2017 11:32:41 +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 CE991160BFA for ; Sun, 26 Nov 2017 12:32:40 +0100 (CET) Received: (qmail 6295 invoked by uid 500); 26 Nov 2017 11:32:40 -0000 Mailing-List: contact dev-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list dev@groovy.apache.org Received: (qmail 6280 invoked by uid 99); 26 Nov 2017 11:32:39 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 26 Nov 2017 11:32:39 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id DBB72180314 for ; Sun, 26 Nov 2017 11:32:38 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.793 X-Spam-Level: *** X-Spam-Status: No, score=3.793 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_SORBS_SPAM=0.5, URI_HEX=1.313] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=selskabet-org.20150623.gappssmtp.com Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id QDPl0_QNYNTk for ; Sun, 26 Nov 2017 11:32:37 +0000 (UTC) Received: from mail-lf0-f49.google.com (mail-lf0-f49.google.com [209.85.215.49]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id 640305FCC3 for ; Sun, 26 Nov 2017 11:32:36 +0000 (UTC) Received: by mail-lf0-f49.google.com with SMTP id g35so29624117lfi.13 for ; Sun, 26 Nov 2017 03:32:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=selskabet-org.20150623.gappssmtp.com; s=20150623; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=7FVOFFxPYCdj/A0y9tvESq7q7DEdWFVoXWDsddh+JZc=; b=CyLVScOLO5NX51fDLvPOQ7yYYbX5WhWFKf9c3E6CG6ELP4VZDJt25zCBbAc5k0ohQz e5MuoIKKJJBmfymNDGBEo5ce7EzYK33DWcb1rXnqQ2uuh6snhpUupMZ+bBH3pb7dgBO/ E/tAcM3wYTom7Xq0lRqov+06Wi0sVATmHiRmBWEgUhY8KxFBWfilePLMJlJkHJT2iZrN nN4dngD6rMa38mkiFlaDIU5E0b1L7PZOUr5/Y+qUX0jTqvPgRVAe0G26kfZIBXssWEdk +y90LbmFa9CwIsGzHWp2usgf2ptN18hN9yZsS64di4XDKMCjxncmSs954iVZ8WgBegfD uCYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=7FVOFFxPYCdj/A0y9tvESq7q7DEdWFVoXWDsddh+JZc=; b=rKYj8/zr9fbLSxEWBoxffkHNJCdXkcyAWW4FB0A3SeMGGCjYW22bdTaOfwOcm+oJbG g//b/IQrkVXnMWR2atSz4i1g6MgdPkPH2Lj27B/Ajnb4cXtWMfH0oQrUfBzYH0JCtWya Dzta8M3wUiJ1PD1MyIco1m+j28m3qVnwMCaN56rZbq5XumSYCsSYiiSFGFTjB7l9oksc TRpc+PW13S5H+VF6cMJaAb/6tinqHxBKSJZMgnWYL+CuwcepD+rPiej63EYOMUiFP6Iy 61cC0nAl0c1GflPniCZz7qcjmf+GoR+7MHYiaWp7EnnUMaWNjO6KH1cGnUUiswleFEGh 6d3Q== X-Gm-Message-State: AJaThX5UFFtg/RxQulsMFxfyT3MLmgCWqdhbwFeR9/+ZC+9lE0xI33QM aV8g/zFvSLe/ufEODMQNeOMYzpAVQEs= X-Google-Smtp-Source: AGs4zMbtB1P6bmba3rijuZzBFF3xsD4wJdKoXQqe2qR1DMvXJNo6PcBwhg/bXSYUycW5X/ldV0l9vg== X-Received: by 10.46.84.4 with SMTP id i4mr12000264ljb.60.1511695955400; Sun, 26 Nov 2017 03:32:35 -0800 (PST) Received: from [192.168.0.32] (x1-6-20-4e-7f-5c-af-fa.cpe.webspeed.dk. [87.52.39.65]) by smtp.gmail.com with ESMTPSA id g192sm4429794lfg.42.2017.11.26.03.32.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Nov 2017 03:32:34 -0800 (PST) From: =?utf-8?Q?Jesper_Steen_M=C3=B8ller?= Content-Type: multipart/alternative; boundary="Apple-Mail=_ED12ACF9-664C-4A43-89AF-4438E7013F4D" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: How to find out the names of variables used in a groovy expression Date: Sun, 26 Nov 2017 12:32:32 +0100 References: <1511692357583-0.post@n5.nabble.com> To: dev@groovy.apache.org In-Reply-To: <1511692357583-0.post@n5.nabble.com> Message-Id: <3230CADE-4E9E-4BDA-B361-F2EC43226765@selskabet.org> X-Mailer: Apple Mail (2.3273) archived-at: Sun, 26 Nov 2017 11:32:41 -0000 --Apple-Mail=_ED12ACF9-664C-4A43-89AF-4438E7013F4D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii HI Greg, Note: This list is primarily for developers and maintainers of the = Groovy project, not for how to use Groovy. You could try = users@groovy.apache.org instead. As for your question, which is = admittedly borderline: 1) At compile time (i.e. in a macro or AST transformer), this should be = doable, but it's not a slam-dunk oneliner (you need to drill down into = each GString-expression in the abstract syntax tree and find out how = each expression is constructed, and which variable/field names are in = use) 2) At runtime, string interpolation has already expanded into a = construction of a GString by the compiler, and by that time, the = expressions are no logner recognizable (generally speaking). I can't quite guess what you're trying to accomplish, but perhaps you = should consider a templating engine instead, for the ability to parse = and work with GString-like templates. Have a look at = http://docs.groovy-lang.org/latest/html/documentation/template-engines.htm= l = -Jesper > On 26 Nov 2017, at 11.32, bayareagreg wrote: >=20 > Hello, >=20 > I need to programmatically find out the names of variables used in a > "simple" groovy expression that reads a value from one or more = variables. > One can assume the expression is read-only, that is no modifications = of any > state will be used. E.g. in an expression like this >=20 > "${foo}", it should return "foo" > also same in "${foo.bar.zot}" >=20 > is what I am asking possible? If yes please point me in the direction = of > which API to use for this. > Thank you in advance >=20 >=20 >=20 >=20 > -- > Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html --Apple-Mail=_ED12ACF9-664C-4A43-89AF-4438E7013F4D Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
HI Greg,

Note: This list is primarily for = developers and maintainers of the Groovy project, not for how to use = Groovy. You could try users@groovy.apache.org instead. As for your question, = which is admittedly borderline:
1) At compile time = (i.e. in a macro or AST transformer), this should be doable, but it's = not a slam-dunk oneliner (you need to drill down into each = GString-expression in the abstract syntax tree and find out how each = expression is constructed, and which variable/field names are in = use)
2) At runtime, string interpolation has = already expanded into a construction of a GString by the compiler, and = by that time, the expressions are no logner recognizable (generally = speaking).

I = can't quite guess what you're trying to accomplish, but perhaps you = should consider a templating engine instead, for the ability to parse = and work with GString-like templates. Have a look at http://docs.groovy-lang.org/latest/html/documentation/template-= engines.html

-Jesper

On 26 Nov 2017, at 11.32, = bayareagreg <bayareagreg@gmail.com> wrote:

Hello,

I need to = programmatically find out the names of variables used in a
"simple" groovy expression that reads a value from one or = more variables.
One can assume the expression is = read-only, that is no modifications of any
state will be = used. E.g. in an expression like this

"${foo}", it should return "foo"
also same in = "${foo.bar.zot}"

is what I am asking = possible? If yes please point me in the direction of
which = API to use for this.
Thank you in advance




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html<= br class=3D"">

= --Apple-Mail=_ED12ACF9-664C-4A43-89AF-4438E7013F4D--