Return-Path: X-Original-To: apmail-groovy-users-archive@minotaur.apache.org Delivered-To: apmail-groovy-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4F3C41835D for ; Wed, 19 Aug 2015 17:37:07 +0000 (UTC) Received: (qmail 66944 invoked by uid 500); 19 Aug 2015 17:36:08 -0000 Delivered-To: apmail-groovy-users-archive@groovy.apache.org Received: (qmail 66909 invoked by uid 500); 19 Aug 2015 17:36:08 -0000 Mailing-List: contact users-help@groovy.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.incubator.apache.org Delivered-To: mailing list users@groovy.incubator.apache.org Received: (qmail 66899 invoked by uid 99); 19 Aug 2015 17:36:08 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Aug 2015 17:36:08 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 487F8DF3E8 for ; Wed, 19 Aug 2015 17:36:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd1-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id bejYnmOE5OBZ for ; Wed, 19 Aug 2015 17:36:00 +0000 (UTC) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com [209.85.215.42]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 998F142F37 for ; Wed, 19 Aug 2015 17:35:59 +0000 (UTC) Received: by lahi9 with SMTP id i9so7563160lah.2 for ; Wed, 19 Aug 2015 10:35:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ZfyJthXRtLx002PDWtH4Y56jnl5Ku0CXo/Wt079ut60=; b=JlM2BcXPN2LlMEGGS3ybomM7qlvv8bu2XSgiPWkdeRhYscb9nVjI64oU1Dm9wU1JDQ LuPIf2/ByDOfliZdJUTeDPoPnYN8QRt0hD/BO2/QeEvByBHVF+ekmmm1qIxs7poAH9Fz Ss8IKJVAT6pQRGXqhr9TYvprtEv9n89dZlsGCTwgMX8o/fESbEFM2hpB1VD0ipOlhvbE D/L5AGORM0GhdbzoGJ2tohAlB/Q9Y3M3hM4XL4oOqGw8Vb5dmhwkkEhGHPtMSHRmQqMp Qm5pDikjWxA5YuXFwDCJTlS8tGaH6inL55hhZeOqVcL2ApM6X0z6RFXU+uA5iJ1Whynk JeMw== MIME-Version: 1.0 X-Received: by 10.152.163.35 with SMTP id yf3mr12320596lab.84.1440005752199; Wed, 19 Aug 2015 10:35:52 -0700 (PDT) Received: by 10.112.149.167 with HTTP; Wed, 19 Aug 2015 10:35:52 -0700 (PDT) In-Reply-To: References: Date: Wed, 19 Aug 2015 19:35:52 +0200 Message-ID: Subject: Re: DSL Type Checker Help From: =?UTF-8?Q?C=C3=A9dric_Champeau?= To: users@groovy.incubator.apache.org Content-Type: multipart/alternative; boundary=001a11340b1455a1a6051dad7780 --001a11340b1455a1a6051dad7780 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable That's almost the right thing to do. You should return a dummy method, and tell which return type is has, so that the type checker can infer subsequent calls. See http://docs.groovy-lang.org/latest/html/documentation/type-checking-extensi= ons.html#Typecheckingextensions-Virtualmethods 2015-08-19 19:14 GMT+02:00 Anto Aravinth : > Hey Cedric , > > Thanks for the reply. Given the fact that I'm using methodNotFound > extension, it forces me to return a method node. > > However the base script class of my dsl has the logic of handling > methodMissing. So in the type check, I feel I'm missing something by > returning a dummy method node. > > Looks I'm wrong some where on my design. Any ideas would help me. > > Thanks again. > On 19 Aug 2015 19:01, "C=C3=A9dric Champeau" = wrote: > >> The type checking DSL provides several helper methods to get access to >> the arguments. See for example: >> http://docs.groovy-lang.org/2.4.4/html/gapi/index.html?org/codehaus/groo= vy/transform/stc/GroovyTypeCheckingExtensionSupport.html >> >> In your case you're probably looking for something like : >> https://github.com/apache/incubator-groovy/blob/master/src/main/org/code= haus/groovy/transform/stc/AbstractTypeCheckingExtension.java#L217-217 >> >> Where you want a Map, but in any case, since you need to check the keys, >> it has to be *more* than a Map, it has to be a Map literal (hence why yo= u >> see MapEntryExpression). So you should check the structure of the >> ArgumentListExpression explicitly. If we can get the macro stuff merged >> into 2.5, there will be experimental support for matches, that would mak= e >> it even easier, but we're not there yet. >> >> >> >> 2015-08-19 15:27 GMT+02:00 Anto Aravinth : >> >>> I'm writing an type checker for an DSL. So the type checker looks like >>> this: >>> >>> >>> >>> class MyAppDSLTypeChecker extends >>> GroovyTypeCheckingExtensionSupport.TypeCheckingDSL { >>> >>> >>> >>> @Override >>> >>> Object run() { >>> >>> methodNotFound { receiver, name, argList, argTypes, call -> >>> >>> println argList >>> >>> handled =3D true >>> >>> } >>> >>> } >>> >>> } >>> >>> >>> >>> When my DSL runs, for now it just prints argList, which is something >>> like this: >>> >>> >>> >>> org.codehaus.groovy.ast.expr.ArgumentListExpression@1fc8bb61 >>> [org.codehaus.groovy.ast.expr.NamedArgumentListExpression@3385ed94 >>> [org.codehaus.groovy.ast.expr.MapEntryExpression@1db0a9f9(key: >>> ConstantExpression[asdasdasddsasd], value: ConstantExpression[someId])]= ] >>> >>> >>> >>> Is there any Visitor support does Groovy gives out of the box, so that = I >>> can traverse the above ArgumentListExpression AST node? So this is my i= dea, >>> if method name matches my DSL rule, and I need to check its param, whic= h >>> should be only map. And that map also should be of some keys. So need t= o >>> check them. >>> >>> >>> >>> Thanks for your input. >>> >> >> --001a11340b1455a1a6051dad7780 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
That's almost the right thing to do. You should return= a dummy method, and tell which return type is has, so that the type checke= r can infer subsequent calls. See=C2=A0http://docs.groovy-lang.org/latest/html/documentatio= n/type-checking-extensions.html#Typecheckingextensions-Virtualmethods

2015-08-19 19= :14 GMT+02:00 Anto Aravinth <anto.aravinth.cse@gmail.com>= :

Hey Cedric ,

Thanks for the reply. Given the fact that I'm using meth= odNotFound extension, it forces me to return a method node.

However the base script class of my dsl has the logic of han= dling methodMissing. So in the type check, I feel I'm missing something= by returning a dummy method node.

Looks I'm wrong some where on my design. Any ideas would= help me.

Thanks again.

On 19 Aug 2015 19:01, "C=C3=A9dric Champeau= " <c= edric.champeau@gmail.com> wrote:
The type checking DSL provides several= helper methods to get access to the arguments. See for example:=C2=A0http://docs.groovy-lang.org/2.4.4/html/gapi/index.html?org/codehaus/gro= ovy/transform/stc/GroovyTypeCheckingExtensionSupport.html

In your case you're probably looking for something like :=C2=A0https://github.com/apache/incubator-groovy/blob/master/= src/main/org/codehaus/groovy/transform/stc/AbstractTypeCheckingExtension.ja= va#L217-217

Where you want a Map, but in any c= ase, since you need to check the keys, it has to be *more* than a Map, it h= as to be a Map literal (hence why you see MapEntryExpression). So you shoul= d check the structure of the ArgumentListExpression explicitly. If we can g= et the macro stuff merged into 2.5, there will be experimental support for = matches, that would make it even easier, but we're not there yet.
=



2015-08-19 15:27 GMT+02:00 Anto Aravinth <ant= o.aravinth.cse@gmail.com>:
=

I'm writing an type checker for an DSL. So the type chec= ker looks like this:

=C2=A0

class MyAppDSLTypeChecker extends GroovyTypeCheckingExtensio= nSupport.TypeCheckingDSL {

=C2=A0

=C2=A0 =C2=A0 @Override

=C2=A0 =C2=A0 Object run() {

=C2=A0 =C2=A0 =C2=A0 =C2=A0 methodNotFound { receiver, name,= argList, argTypes, call ->

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 println argList

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 handled =3D true

=C2=A0 =C2=A0 =C2=A0 =C2=A0 }

=C2=A0 =C2=A0 }

}

=C2=A0

When my DSL runs, for now it just prints argList, which is s= omething like this:

=C2=A0

org.codehaus.groovy.ast.expr.ArgumentListExpression@1fc8bb61= [org.codehaus.groovy.ast.expr.NamedArgumentListExpression@3385ed94[org.code= haus.groovy.ast.expr.MapEntryExpression@1db0a9f9(key: ConstantExpression[as= dasdasddsasd], value: ConstantExpression[someId])]]

=C2=A0

Is there any Visitor support does Groovy gives out of the bo= x, so that I can traverse the above ArgumentListExpression AST node? So thi= s is my idea, if method name matches my DSL rule, and I need to check its p= aram, which should be only map. And that map also should be of some keys. S= o need to check them.

=C2=A0

Thanks for your input.



--001a11340b1455a1a6051dad7780--