groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From C├ędric Champeau <cedric.champ...@gmail.com>
Subject Re: DSL Type Checker Help
Date Wed, 19 Aug 2015 17:01:19 GMT
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/groovy/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/codehaus/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 you 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 make
it even easier, but we're not there yet.



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

> 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 = 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 idea,
> if method name matches my DSL rule, and I need to check its param, which
> should be only map. And that map also should be of some keys. So need to
> check them.
>
>
>
> Thanks for your input.
>

Mime
View raw message