Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Content Assist Filtering(Filtering proposals Content Assist)
Content Assist Filtering [message #1720958] Fri, 22 January 2016 08:32 Go to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 56
Registered: May 2015
Member
I am developing in Eclipse Xtext a small language.
I have a problem to filter out proposals for Content Assist.

Algo:
types=TypeDecls?
declares=DatasDecl
(modules+=Module)*
;

/*
* MODULE
*/
Module: // Use symbol notion (Global)
'Module' name = NameSymbol '(' ')'
declares=DatasDecl
'Début'
statements+=Statement*
'Fin'
;

ModuleCall:
module=NameRef '(' ')'
;

/*
* DECLARATIONs
*/
DatasDecl:
{Declare}
(consts=ConstDecls)?
(vars=VarDecls)?
;

ConstDecls:
'Const:' (consts += ConstDeclare)(';'? consts += ConstDeclare)*
;

VarDecls:
'Var:' (vars += VarDeclare)(';'? vars += VarDeclare)*
;

/*
* STATEMENTs
*/

Statement:
StatementAssignment
// | ModuleCall
;

StatementAssignment:
statement=ExpressionVariable // '<-' value=Expression Reduce for test
;

/*
* EXPRESSIONs
*/
Expression:
expr=ExpressionPlusMinus
;

ExpressionPlusMinus returns Expression:
ExpressionTerminal (
('+' {Expression_Plus.left=current} right=ExpressionTerminal) |
('-' {Expression_Minus.left=current} right=ExpressionTerminal)
)* ;

ExpressionTerminal returns Expression :
('(' Expression ')')
| expr=ExpressionValue // Litéral: Value : INT | FLOAT | BOOL | STRING
/* | expr=ExpressionData // Constante or Variable
| call=ModuleCall */ // Not need for test
| expr=ExpressionVariable
;

ExpressionValue:
{IntegerLiteral} value=INT |
{FloatLiteral} value=FLOAT |
{StringLiteral} value=STRING |
{StringLiteral} value=EXIT |
{BooleanLiteral} value=BOOL
;


// Only variables (Filter to remove constants (see AlgoFiltrageProposalProvider.xtend))
ExpressionVariable:
VarRef
;

/*
* DATAs
*/
ConstDeclare:
type=Type ':' (name+=ConstSymbol '<-' expr+=Expression) (','? name+=ConstSymbol '<-' expr+=Expression)*
;

VarDeclare:
type=Type ':' (name+=VarSymbol ('<-' expr+=Expression)?) (','? name+=VarSymbol ('<-' expr+=Expression)?)*
;

ConstSymbol returns SymbolConst:
NameId
;

ConstRef:
{SymbolConst} symbolConst = [SymbolConst]
;

VarSymbol returns SymbolVar:
NameId
;

VarRef:
{SymbolVar} symbolVar = [SymbolVar]
;

NameSymbol returns Symbol:
NameId
;

NameId: name=ID;

/* ------------------------------------------------------------------------
* TYPEs
* ------------------------------------------------------------------------
*/
Type:
TypePrimitif | TypeUser
;

TypePrimitif:
TypeBool | TypeInt | TypeFloat | TypeString | TypeCharacter
;

TypeBool: {TypeBool} 'Booléen';
TypeInt: {TypeInt} 'Entier';
TypeFloat: {TypeFloat} 'Réel';
TypeString: {TypeString} 'Chaine';
TypeCharacter: {TypeCharacter} 'Caractère';

TypeDecls:
'Type:' types+=TypeDecl (';'? types+=TypeDecl)*
;

TypeDecl returns SymbolType: // Use Symbol notions (Global)
base=Type ':' name=ID
;

TypeUser: // Reference to SymbolType (Global)
{SymbolType} symbolType = [SymbolType]
;

/* ------------------------------------------------------------------------
* TERMINALs
* ------------------------------------------------------------------------
*/
terminal fragment DIGIT: ('0'..'9');
terminal BOOL: ('VRAI'|'FAUX') ;
terminal EXIT: ('SUCCES' | 'ECHEC');
terminal FLOAT returns ecore::EFloat :
('+' | '-')? (('1'..'9' DIGIT* '.' DIGIT+ /* ? */) (('E' | 'e') ('+' | '-')? DIGIT+)?
| '0'? ('.' DIGIT+)? (('E' | 'e') ('+' | '-')? DIGIT+)? );

Access tree type and identification of ExpressionVariable, VarRef.

model ModuleImpl (id=474)
declares DeclareImpl (id=492)
eContainer AlgoImpl (id=497)
eFlags -196604
eStorage Adapter[2] (id=500)
name NameIdImpl (id=501)
eContainer ModuleImpl (id=474)
eFlags -65532
eStorage Adapter[4] (id=528)
name "mod1" (id=529)
symbol null
statements EObjectContainmentEList<E> (id=512)
data Statement[4] (id=530)
[0] StatementAssignmentImpl (id=534)
eContainer ModuleImpl (id=474)
eFlags -196604
eStorage Adapter[2] (id=722)
statement ExpressionVariableImpl (id=723)
eContainer StatementAssignmentImpl (id=534)
eFlags -65532
eStorage Adapter[2] (id=724)
name SymbolImpl (id=725)
eContainer ExpressionVariableImpl (id=723)
eFlags -65532
eStorage Adapter[2] (id=726)
symbol NameIdImpl (id=727)
eContainer ConstDeclareImpl (id=728)
eFlags -131068
eStorage Adapter[4] (id=729)
name "G_CONST_STR" (id=730)
symbol null
[1] StatementAssignmentImpl (id=538)
[2] StatementAssignmentImpl (id=539)
[3] StatementAssignmentImpl (id=540)
dataClass Class<T> (com.infoly.xtext.algo.filtrage.algoFiltrage.Statement) (id=532)
featureID 2
modCount 4
owner ModuleImpl (id=474)
size 4
value "Fin" (id=479)

Test algorithm:
// Global Datas
Const:
Chaine : G_CONST_STR <- "Constante Globale"
Var:
Entier : globalE, gE2, gE3 ; // ';' optional
Booléen : gMarche, gOuvert

// Modules
Module mod1()
// Local datas
Const:
Chaine : INVITE <- "Une invite:"
Var:
Entier : localE1
// Executive part
Début
G_CONST_STR
gE2
lE3
INVITE

Fin

Module mod2()
Var:
Entier : localE2
Début
G_CONST_STR
gE2
localE2
INVITE
¤ Ctrl+Space
Fin

Module mod3()
Var:
Entier : lE3
Début
lE3

Fin

The Ctrl + Space in this location ¤ gives this proposal:
"G_CONST_STR"
gE2
gE3
globalE
gMarche
gOuvert
INVITE
lE3
localE1
localE2
mod1
mod2
mod3
Fin

I would only obtain this list of global variables, locals aware module (here mod2) without constants and modules:
gE2, gE3, globalE, gMarche, gOuvert, localE2 and Fin to complete the proposal.

I can see in the model tree the way to go to achieve the type or identifier of a constant (in the example) or a variable on which to base filtering, but my ignorance of the API not allow me to code it.
I tried to adapt my grammar but I read that it was best not to do so in the grammar, but rather:
<MyProject>ProposalProvider or <MyProject>ScopeProvider but that despite many trials I cannot do what I just described. Could you put me on the track?

Thanks
Yves
Re: Content Assist Filtering [message #1720960 is a reply to message #1720958] Fri, 22 January 2016 08:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
Hi,

this sounds like an Adaption of scoping and not of Content assist.

in your scopeprovider you can use delegateGetScope in Combination with FilteringScope to achieve a filtered scope.
Content assist will automatically pick up what you give in scope Provider

alternatively you can call lookupCrossReference in your scope Provider wih a filter predicate


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assist Filtering [message #1720961 is a reply to message #1720958] Fri, 22 January 2016 08:52 Go to previous messageGo to next message
Yves LEDUC is currently offline Yves LEDUCFriend
Messages: 56
Registered: May 2015
Member
Tested code:
I did a lot of testing in the file but I AlgoFiltrageProposalProvider.xtend crashes when accessing the content of a statement to find the type of data pointed to by the reference (constant, variable or module).

override completeVarRef_SymbolVar(EObject model, Assignment assignment, ContentAssistContext
context, ICompletionProposalAcceptor acceptor) {
val modules = model.eContainer as Module
val statements = modules.statements // elements.filter(AnnotationDecl)
val ss = statements.size
val statement0 = statements.get(0) as Statement
val stSize = statement0.eContents.size // StatementAssignment, statement, ...
// val type = statement0.symbolVar.eContainer // VarDecl
// val name = statement0.symbolVar.name // G_CONST_STR
// val statementi as Statement

}

I cannot access the type (model.statements.data [i] .name.eContainer Ex: -> ConstDeclare) and value model.statements.data [i] .name.name Ex: -> "mod1") for filtering, such as constants.
Re: Content Assist Filtering [message #1720971 is a reply to message #1720961] Fri, 22 January 2016 09:22 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14669
Registered: July 2009
Senior Member
what is the trace you get?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Combining simple and qualified names
Next Topic:Change Editor
Goto Forum:
  


Current Time: Fri Apr 26 19:35:20 GMT 2024

Powered by FUDForum. Page generated in 0.03291 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top