|
|
Re: How to Write Grammer For Function Defination [message #758440 is a reply to message #754749] |
Wed, 23 November 2011 10:16 |
Zeeshan Safder Messages: 27 Registered: November 2011 |
Junior Member |
|
|
hi,
This is my langauge
Domainmodel :
(elements += Type
| variables+=VariableDeclaration
| actions+=ActionStatement)*
;
Type:
ClassDeclaration
;
ClassDeclaration returns classs:
name = ID '=' '{'
(feature += Feature)*
'}'
;
Feature:
Function
;
Function returns function:
name = ID ':' 'function''(' ( parameters+=ID (','parameters+=ID)* )? ')''{'
'}'
;
VariableDeclaration:
'var' name=ID '=' 'new' resource=[classs] '('')'
;
ResourcePathHead:
variable=[VariableDeclaration]
;
ActionStatement:
path=ResourcePathHead '.' action=[function]
;
And this is the simple 'AbstractDeclarativeScopeProvider' extended class method
public IScope scope_ActionStatement_action(final ActionStatement context, EReference ref) {
//get the tail end of the resource path
classs tailResource = context.getPath().getVariable().getResource();
return Scopes.scopeFor (tailResource.getFeature());
}
Suppose the follwing language code
a = {
abc: function(t1, t2){
}
xyz: function(){
}
zst: function(){
}
}
var ab = new a()
Now when I do
'ab.' it will list all functions defined. But I want more information. It must show how many parameter it receives.
Currenlt 'ab.' will assist 'abc', 'xyz', 'zst' it should assist like 'abs(t1,t2)', 'xyz()' etc
For that point I just come to know that I have to implement a custom IScope Providor, but have got the idea how to implement it. After almost 5 hrz of google, I have decided to post here and hope will got the best possible help...
|
|
|
|
|
Re: How to Write Grammer For Function Defination [message #758478 is a reply to message #758474] |
Wed, 23 November 2011 12:20 |
Meinte Boersma Messages: 434 Registered: July 2009 Location: Leiden, Netherlands |
Senior Member |
|
|
Well, then I can only conclude that you are easily discouraged... Obviously, a lot of stuff is not explicitly covered by the User's Guide which is indeed where the community could help. However, about 90% of your question material is covered by the User Guide. At the same time, your knowledge of Xtext makes it quite hard to help you as we have to explain quite a lot of stuff from scratch (which, again, is covered by the User Guide).
Communities exist to help you with your work, not do the work for you (in spite of Christian's efforts!). I could do the work for you too, by the way: http://www.dslconsultancy.com/ You see, it's my living and there's no economical point in doing your work for you for free.
Strange: googling for 5 hours is OK, but apparently spending the same amount of time really trying to understand something to some depth is not OK?
Xtext blogs: executable models...again? | workshop material | custom scoping with Xtend
|
|
|
|
|
|
|
|
Re: How to Write Grammer For Function Defination [message #758656 is a reply to message #758644] |
Thu, 24 November 2011 06:48 |
|
Hi,
if you would have (as i told you) had a look at YourDslProposalProvider + read the docs you would have found
(1) in AbstractMyDslProposalProvider there is a completeActionStatement_Action method
(2) this method calls lookupCrossReference
(3) following some refs you would have found that the actual work is done in DefaultProposalCreator .
(4) this calls getStyledDisplayString(IEObjectDescription description)
first you have to care that the IEObjectDescriptions contain the infos you need
this could look like
public class MyDslScopeProvider extends AbstractDeclarativeScopeProvider {
public IScope scope_ActionStatement_action(final ActionStatement context, EReference ref) {
//get the tail end of the resource path
classs tailResource = context.getPath().getVariable().getResource();
List<IEObjectDescription> scope = new ArrayList<IEObjectDescription>();
for (Feature o : tailResource.getFeature()) {
if (o instanceof function) {
function f = (function) o;
Map<String, String> data = new HashMap<String, String>();
String sig = "(" + StringUtils.join(f.getParameters(), ",")+ ")";
data.put("sig", sig);
IEObjectDescription d = EObjectDescription.create(QualifiedName.create(f.getName()), f, data);
scope.add(d);
}
}
return new SimpleScope(scope);
}
}
and then make use of it
public class MyDslProposalProvider extends AbstractMyDslProposalProvider {
@Override
protected StyledString getStyledDisplayString(
IEObjectDescription description) {
if (description.getEClass().equals(MyDslPackage.Literals.FUNCTION)) {
return new StyledString(description.getName().toString() + (description.getUserData("sig") == null ? "" : description.getUserData("sig")));
}
return super.getStyledDisplayString(description);
}
}
in a quick and dirty solution you may have overwritten getStyledDisplayString(Eobject element ...
this is easy even for a beginner that trys to get the xtext black belt at his first day
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04795 seconds