How to write Content Assist [message #757725] |
Mon, 21 November 2011 06:08  |
Eclipse User |
|
|
|
Hi,
I like to wirte content assist for my language. Where I am employeed, they are using there custom langauge framework. But it lacks the IDE enviroment. My task is to write content assist for their framework, so that development gets bit easier.
Language is javascript based and adopted to objected oriented paradigm. Now I have to write content assistant for it.
I have posted a similer thread before. At that time I was tring to write complete grammer again. But now I have been said to not write the actuall grammer, just somehow provide the contenet assistant for it.
Now need your support to start the task, as I still have no idea how to do it...
Regards
Zeeshan Safder
|
|
|
|
|
|
|
Re: How to write Content Assist [message #758452 is a reply to message #758152] |
Wed, 23 November 2011 05:43   |
Eclipse User |
|
|
|
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 Content Assist [message #759324 is a reply to message #758457] |
Mon, 28 November 2011 06:36   |
Eclipse User |
|
|
|
Hi This is my grammer
grammar org.gvs.ngcore.dsl.NGCore with org.eclipse.xtext.common.Terminals
generate nGCore "http://www.gvs.org/ngcore/dsl/NGCore"
//file extension = .js
Domainmodel :
(elements += ClassDeclaration
| variables+=VariableDeclaration
| actions+=ActionStatement | requireStatements += RequireStatements
| globalFunction += GlobalFunction)*
;
//var Element = exports.Element = Class.subclass
ClassDeclaration returns NGClass:
('var' localFileName = ID '=')? 'exports' '.' name = ID '='
(
(
super = [NGClass] '.' ('subclass' | 'singleton') '(' '{'( (features += Feature)(','features += Feature)* )? ','?'}' ')'
)
|
(
'{' ( (features += Feature)(','features += Feature)* )? ','? '}'
)
)
';'?
;
RequireStatements:
'var'? name = ID '=' 'require''(' STRING ')' ('.'ID)*';'?
;
AbstractType:
Function | MemberVariable | ThisVariable
;
Feature:
Function | MemberVariable
;
Function returns NGFunction:
'$'?name = ID ':' 'function''(' ( param+=ID (','param+=ID)* )? ')''{'
(features += FuntionFeatures)*
'}'
;
FuntionFeatures:
ThisFeatures
;
ThisFeatures:
('this''.' ClassMembers) | ('this''+'ThisVariable)
;
ClassMembers:
memberFeatures = [Feature]
;
ThisVariable:
varName = ID ('=' INT)? ';'?
;
MemberVariable:
'$'?name = ID ':' (STRING | ID('.'ID)* | INT)
;
VariableDeclaration:
'var' name=ID '=' 'new' resource=[NGClass] '('')' ';'?
;
ClassObject:
variable=[VariableDeclaration]
;
ActionStatement:
path=ClassObject '.' action=[AbstractType] ( '(' ( ID (','ID)* )? ')' )? ';'?
;
GlobalFunction:
name = ID '=' 'function''(' ( param+=ID (','param+=ID)* )? ')''{'
'}'';'?
;
I have define scope for Action Statement like -
public IScope scope_ActionStatement_action(final ActionStatement context, EReference ref){...}
And it is working fine
Now I want to define scope for 'ClassMembers' and have wrote function like
public IScope scope_ClassMembers_memberFeatures(final ActionStatement context, EReference ref){...}
but it is not working...
|
|
|
|
|
|
|
|
|
Re: How to write Content Assist [message #759915 is a reply to message #759567] |
Wed, 30 November 2011 09:54  |
Eclipse User |
|
|
|
With help of all of you, now my grammer and content assist start making some sense. I always thanks all of you for such a nice support. I have stuck again in grammer wrting. Consider the following case
Function:
'$'?name = ID':' 'function''('
( params+=ID(',' params+=ID)* )?
')''{'
.......................
'}'
;
A Simple java script function.
abc: function( p1, p2 ){
return p1 + p2
}
I like to know grammer of it. That use parameter in function local scope. Just want grammer to accept that parameters inside the function
|
|
|
Powered by
FUDForum. Page generated in 0.05819 seconds