Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Content Assistant in a Xtext custom language
Content Assistant in a Xtext custom language [message #1765307] Thu, 08 June 2017 10:08 Go to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
I want to add content assistant facility to my custom language. If I am not using cross references what is the best way to start?
Can you provide some resources?
I went through this blog post which was mentioned in some other forum question reply.
https://kthoms.wordpress.com/2012/05/22/xtext-content-assist-filtering-keyword-proposals/
Re: Content Assistant in a Xtext custom language [message #1765311 is a reply to message #1765307] Thu, 08 June 2017 10:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
can you be a bit more precise about what proposal places you are talking about

mayb you should have a look at the complete methods in the abstract superclass and simply implement them if they are empty


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1765318 is a reply to message #1765311] Thu, 08 June 2017 11:39 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
I thought first I would implement proposals for keywords. I referred to one of your comments in a blog post as follows:
@Inject MyDslGrammarAccess grammarAccess;

@Override
public void completeKeyword(Keyword keyword,
ContentAssistContext contentAssistContext,
ICompletionProposalAcceptor acceptor) {
if (!grammarAccess.getGreetingAccess().getHelloKeyword_0().equals(keyword)) {
super.completeKeyword(keyword, contentAssistContext, acceptor);
}
}


I tried to put this code segment in custom proposal provider class. But getHelloKeyword_0() this type of method couldn't found. How can I implement content assistant for keywords ?

Thank you.
Re: Content Assistant in a Xtext custom language [message #1765319 is a reply to message #1765318] Thu, 08 June 2017 12:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
i dont know which grammar you are talking about.
and is it on missing keywords or surplus keywords.
and how does the grammar (part !!!!) look like


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1765348 is a reply to message #1765319] Thu, 08 June 2017 15:20 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
A part of grammar is as follows.
definition_stream:
	(ann += annotation)* DEFINE STREAM source '(' feature += Features (',' feature += Features )* ')'';'?		 		
;
annotation:
	'@' name = name ('(' (ann_element += annotation_element | ann += annotation) 
		( ',' (ann_element += annotation_element | ann += annotation))* ')'	)
;
annotation_element:
	(prop_name = property_name '=')? prop_val = property_value
;

property_value:
	string_value
;

property_name:
	{property_name} name (property_separator name += name )*
;

property_separator:
	DOT | MINUS | COL
;
source:
	inner='#'? (str_id = stream_id)
;

stream_id:
	name
;

Features:
	(att_name = attribute_name) (type = attribute_type)
;

attribute_name:
	name
;
attribute_type:
	STRINGS | INTS| LONG | FLOAT | DOUBLE| BOOL| OBJECT 
;
keyword:
	STREAM 
	| DEFINE 
;
fragment STREAM: ('stream');
fragment DEFINE: ('define' );

fragment STRINGS: ('string');
fragment INTS: ('int');
fragment LONG: ('long');
fragment DOUBLE: ('double');
fragment FLOAT: ('float');
fragment BOOL: ('bool');
fragment OBJECT: ('object');

COL : ':';
DOT : '.';
MINUS : '-';


I want to auto complete the define and stream keywords in define_stream rule. How can I achieve this? Also when I press ctrl+space no default proposals are shown in the editor.
Thank you.

[Updated on: Thu, 08 June 2017 15:23]

Report message to a moderator

Re: Content Assistant in a Xtext custom language [message #1765351 is a reply to message #1765348] Thu, 08 June 2017 15:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
a minimal grammar would look like
Model:
	DEFINE STREAM name=ID 		
;

fragment STREAM: ('stream');
fragment DEFINE: ('define' );




well these should be automatically done. but they are not.

thats a bug

https://github.com/eclipse/xtext-core/issues/341

workaround

Model:
	DEFINE STREAM name=ID 		
;

fragment STREAM: (str='stream');
fragment DEFINE: (def='define' );


or
class MyDslProposalProvider extends AbstractMyDslProposalProvider {
	
	@Inject MyDslGrammarAccess ga
	
	override complete_DEFINE(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		super.complete_DEFINE(model, ruleCall, context, acceptor)
		completeKeyword(ga.DEFINEAccess.defineKeyword, context, acceptor)
	}
	
	override complete_STREAM(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		super.complete_STREAM(model, ruleCall, context, acceptor)
		completeKeyword(ga.STREAMAccess.streamKeyword, context, acceptor)
	}
	
	
	
}







p.s: please please please use xtext naming conventions


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1765383 is a reply to message #1765351] Fri, 09 June 2017 05:12 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
As for naming conventions I could find that terminal rules should be uppercase and a rule should be written as Rule: attr=SomeRule;

Can you provide some resource if there are additional conventions?
Thank you.
Re: Content Assistant in a Xtext custom language [message #1765384 is a reply to message #1765383] Fri, 09 June 2017 05:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
no thats basically it. maybe aditionally CamelCase for rules and yourAttributes and XXXXX_YYYYY for terminals if of multiple parts

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1765509 is a reply to message #1765384] Sun, 11 June 2017 16:52 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
I want to customize my content assistant facility as follows.
define stream cseEventStream;
from cseEventStream;


I want to give cseEventStream defined stream as a suggestion for from statement when ctrl+space is pressed. How can I achieve this?
The grammar is as follows:
ExecutionPlan:
DefinitionStream| Query
;
DefinitionStream:
DEFINE STREAM src=Source;
;
Query:
FROM src=Source;
;
Source:
	inner='#'? (strId = StreamId)
;

StreamId:
	na=Name
;

fragment STREAM: (str='stream');
fragment DEFINE: (define='define' );
fragment FROM: (from='from');

Keyword:
	{Keyword} STREAM 
	|{Keyword} DEFINE 
        |{Keyword} FROM
;


Thank you.
Re: Content Assistant in a Xtext custom language [message #1765511 is a reply to message #1765509] Sun, 11 June 2017 17:27 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Well usually you would use cross references but

In your case you would have to adapt iqualifiednameprovider as well

Or you change the grammar

(Assuming Name is a Datatype or terminal rule )

Source: name=Name;

SourceReference: src=[Source|Name];

... FROM sourceRef=SourceReference .. ;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1766170 is a reply to message #1765511] Fri, 16 June 2017 19:10 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi

I want to customize my content assistant facility as follows.
define stream cseEventStream;
from cseEventStream;


I want to give cseEventStream defined stream as a suggestion for from statement when ctrl+space is pressed. How can I achieve this?
The grammar is as follows:

ExecutionPlan:
DefinitionStream| Query
;
DefinitionStream:
DEFINE STREAM src=Source;
;
Query:
FROM mSrc=MainSource ;
;
StandardStream:
MainSource 'Standard stream'
;

MainSource :
src=Source
;

Source:
	inner='#'? (strId = StreamId)
;

StreamId:
	na=Name
;

fragment STREAM: (str='stream');
fragment DEFINE: (define='define' );
fragment FROM: (from='from');

Keyword:
	{Keyword} STREAM 
	|{Keyword} DEFINE 
        |{Keyword} FROM
;


I have written the code as follows. What needs to be corrected there in order to make it work?
public class SiddhiQualifiedNameProvider extends DefaultDeclarativeQualifiedNameProvider {
	 QualifiedName qualifiedName(DefinitionStream ds){
		 MainSource  ms = (MainSource)ds.eContainer();
		return QualifiedName.create(ms.getSrc().toString(), ds.getSrc().toString());
		 
	 }

}


Thank you.
Re: Content Assistant in a Xtext custom language [message #1766173 is a reply to message #1766170] Fri, 16 June 2017 19:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
The syntax for cross references is

ref=[TypeToareference|RuleToParseTheName]

Consult the docs for details


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1766174 is a reply to message #1766173] Fri, 16 June 2017 19:46 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
In the earlier reply you have mentioned to try iqualifiednameprovider since it is a bit complex to put cross references in the actual grammar where I have put a very simplified version of the grammar here. I have tried changing grammar but many instances it says "The rule '......' is not valid for a cross reference since it does not return an EString. You'll have to wrap it in a data type rule in xtext". Does every rule that come this error need to be wrapped in a data type rule? Can't I use iqualifiednameprovider here?
Thank you.
Re: Content Assistant in a Xtext custom language [message #1766175 is a reply to message #1766174] Fri, 16 June 2017 19:56 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
as i said you need a terminal or datatype rule. how does yours (Name)look like?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Fri, 16 June 2017 20:10]

Report message to a moderator

Re: Content Assistant in a Xtext custom language [message #1766198 is a reply to message #1766175] Sat, 17 June 2017 14:54 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
Name is as follows:

Name:
	k_word=Keyword | id_n=IdNew;
IdNew: ID| ID_QUOTES;

terminal ID_QUOTES: 
    '`'('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* '`' ;
 
@Override 
terminal ID:
	('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;
Keyword:
	{Keyword} STREAM 
	|{Keyword} DEFINE 
        |{Keyword} FROM
;

Thank you.
Re: Content Assistant in a Xtext custom language [message #1766202 is a reply to message #1766198] Sat, 17 June 2017 16:42 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi Christian,

Is there a way to get qualified names and use them in for instance in the custom implementation of AbstractProposalProvider class's following method.
public void complete_Query(EObject model, RuleCall ruleCall, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
		// subclasses may override
	}

I have followed the tutorial in https://christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/ and it is a bit hard to map it to my problem due to the complexity in grammar.

Thank you.
Re: Content Assistant in a Xtext custom language [message #1766203 is a reply to message #1766202] Sat, 17 June 2017 16:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Strange grammar you have

You could inroduce

PureName: IdNew | ....

And use that

... Is keyword stuff without the strange {Keyword}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1766204 is a reply to message #1766203] Sat, 17 June 2017 17:08 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
What did you mean by "Is keyword stuff without the strange {Keyword} " ? Sorry I didn't get it.
Thank you.

Re: Content Assistant in a Xtext custom language [message #1766208 is a reply to message #1766204] Sat, 17 June 2017 18:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
With your

Keyword: {Keyword} STREAM

And


Name: k_word=Keyword | id_n=IdNew;

Thos takes name and keyword objects

(No longer a dataype rule)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1766216 is a reply to message #1766208] Sun, 18 June 2017 02:34 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi

Yes when I am trying to put cross references as follows:
MainSource:
	src=[Source|Name] (preWindowHandlers = BasicSourceStreamHandlers)? (window = Win)?
;


it gives exactly the same error as I mentioned above. "The rule 'Name' is not valid for a cross reference since it does not return an EString. You'll have to wrap it in a data type rule.". What needs to be done in order to overcome this? Since keywords are not data types, cannot define them as data type rules I guess.
Re: Content Assistant in a Xtext custom language [message #1766218 is a reply to message #1766216] Sun, 18 June 2017 05:06 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
So why do you do the thing

K_keyword=...
Id_n=....
{Keyword }


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1766220 is a reply to message #1766218] Sun, 18 June 2017 09:39 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
IdNew is as follows:
IdNew: ID| ID_QUOTES;

terminal ID_QUOTES: 
    '`'('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* '`' ;
 
@Override 
terminal ID:
	('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
; 


I also think no need to put keyword in Name. I comment it out as follows and run the program and all the test cases worked fine.
Name:
	 id_n=IdNew//k_word=Keyword |
;

But now also when I try :
MainSource:
	src=[Source|Name] (preWindowHandlers = BasicSourceStreamHandlers)? (window = Win)?
;

the same error appears. What needs to be done in order to convert Name into a data type rule?
Thank you.
Re: Content Assistant in a Xtext custom language [message #1766221 is a reply to message #1766220] Sun, 18 June 2017 10:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Arggg don't know how to explain this do you

Ref=[Type|IdNew]


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1766291 is a reply to message #1766221] Tue, 20 June 2017 03:20 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
Yes I have put like that :
Source:
	inner='#'? strId = [Name|IdNew]
;

Name:
	 id_n=IdNew//k_word=Keyword |
;
IdNew: ID| ID_QUOTES;

terminal ID_QUOTES: 
    '`'('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* '`' ;
 
@Override 
terminal ID:
	('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;


In the editor in places where source rule is used for instance:
//The rule
DefinitionStream:
	(ann += Annotation)* DEFINE STREAM src=Source '(' feature += Features (',' feature += Features )* ')'';'?		 		
;
//test case
define stream cseEventStream (symbol string, price float, volume long); 

It shows errors as "Couldn't resolve reference to Name 'cseEventStream'". I think what I had done is correct when putting cross references.
Thank you.

Re: Content Assistant in a Xtext custom language [message #1766302 is a reply to message #1766291] Tue, 20 June 2017 07:19 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
this is the name provider thing. your "Name" objects dont have an attribute called "name" which Xtext expects by default

=> change the grammar to

Name:
name=IdNew;

or implement IQualifiedNameProvider customization as described here in my blog at https://christiandietrich.wordpress.com/2011/07/16/iqualifiednameproviders-in-xtext-2-0/


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1766482 is a reply to message #1766302] Thu, 22 June 2017 02:20 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi

Thank you very much and the names suggest as proposals when ctrl+space is pressed. But once I type below in the editor it works fine.
@info(name1 = 'query2')
define stream cseEventStream (symbol string, price float, volume long); 


and when I type the below:
@info(name1 = 'query2')
define stream StockStream (symbol string, price float, volume long);


it says "Couldn't resolve reference to Name 'StockStream'". That is because the stream name expects only a completion proposal.
My grammar related is:
DefinitionStream:
	 DEFINE STREAM src=Source 
;
Source:
	inner='#'? strId =[Name|IdNew] 
;
Name:
	 name=IdNew//k_word=Keyword |
;
IdNew: ID| ID_QUOTES;

terminal ID_QUOTES: 
    '`'('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* '`' ;
 
@Override 
terminal ID:
	('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
;
Keyword:
	{Keyword} STREAM 
	|{Keyword} DEFINE
;

Why is it this happening?
Thank you.

[Updated on: Thu, 22 June 2017 02:21]

Report message to a moderator

Re: Content Assistant in a Xtext custom language [message #1766484 is a reply to message #1766482] Thu, 22 June 2017 03:00 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi

I added a new rule for source reference and now it works fine. Thank you very much for your time.
Re: Content Assistant in a Xtext custom language [message #1766691 is a reply to message #1766484] Mon, 26 June 2017 01:57 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,

In the same previous grammar:
DefinitionStream:
	 DEFINE STREAM src=Source1 
;

Source:
	strId=[Source1|IdNew]//inner='#'? strId =[Name|IdNew] 
;

Source1:
	inner='#'? name = IdNew
;

QueryInput:
 FROM src=Source
;


Here all the previously used id values of Source1 type are shown as suggestions in the editor. I want only to show the stream name right before the query. Can I achieve it using cross references itself ?
For instance:
define stream inputStream (symbol string, price object, volume long);
@info(name = 'query1') from inputStream select symbol,price, 
cast(price, 'double') as priceInDouble insert into outputStream;

define stream cseEventStream (symbol string, price1 double, price2 float, volume long , quantity int);
@info(name = 'query1') from cseEventStream select symbol, coalesce(price1,price2) as price,quantity 
insert into outputStream ;

When there are 2 queries like this I want only "cseEventStream " stream name to be suggested for the second query.
Thank you.
Re: Content Assistant in a Xtext custom language [message #1766692 is a reply to message #1766691] Mon, 26 June 2017 03:29 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Adapt scoping

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767520 is a reply to message #1766692] Thu, 06 July 2017 17:48 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
Thank you very much for the information. I have referred https://eclipse.org/Xtext/documentation/303_runtime_concepts.html , https://github.com/LorenzoBettini/xtext-scoping/blob/master/org.xtext.example.helloscoping/org.xtext.example.helloscoping/src/org/xtext/example/helloscoping/scoping/HelloScopingScopeProvider.java and https://web.archive.org/web/20120618184943/http://blogs.itemis.de:80/stundzig/archives/809 on scoping in xtext. I think local scoping needed to be implemented in my scenario.

The grammar is:
DefinitionStream:
	 DEFINE STREAM src=Source1 
;

Source:
	strId=[Source1|IdNew]//inner='#'? strId =[Name|IdNew] 
;

Source1:
	inner='#'? name = IdNew
;

QueryInput:
 FROM src=Source
;


Since DefinitionStream and QueryInput are not directly I am having a doubt whether local scoping can be done here.
define stream inputStream (symbol string, price object, volume long);
from inputStream 

define stream cseEventStream (symbol string, price1 double, price2 float, volume long , quantity int);
 from cseEventStream 


I want only 'cseEventStream ' to suggest for the query.

I have extended custom ScopeProvider from AbstractDeclarativeScopeProvider and added the following override the getScope method as follows.
@Override
	public IScope getScope(EObject context, EReference reference) {
		if (context instanceof Source1) {
			Source1 src1 = (Source1)context;
			MainSource src = (MainSource) src1.eContainer();
		}
		
		return super.getScope(context, reference);
		
	}

But no local scoping happens here. Can you provide some reference? Thank you.

[Updated on: Fri, 07 July 2017 03:46]

Report message to a moderator

Re: Content Assistant in a Xtext custom language [message #1767521 is a reply to message #1767520] Thu, 06 July 2017 17:53 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
In the above message MainSource rule is as follows.
QueryInput:
FROM MainSource ;

MainSource :
src=Source;


Thank you.
Re: Content Assistant in a Xtext custom language [message #1767523 is a reply to message #1767521] Thu, 06 July 2017 19:20 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
sorry, which cross reference do you want to scope?

strId=[Source1|IdNew]

???

=> ereference == MyDslPackage.Literals.SOURCE__STR_ID (or something like that)

and context instanceof Source or context instanceof DefinitionStream (during content assist)

(you should change your grammar to

DefinitionStream:
{DefinitionStream} DEFINE STREAM src=Source1
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767540 is a reply to message #1767523] Fri, 07 July 2017 04:09 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
Yes I want to scope strId=[Source1|IdNew].

As I said in the previous post I want to have a local scope for ,
define stream inputStream (symbol string, price object, volume long);
from inputStream 

But I am having a doubt whether I can achieve this since they are two separate rules. I want only to suggest the user defined stream name for query.

MyDslPackage.Literals.SOURCE__STR_ID cannot be found in MyDslPackage instead MyDslPackage.SOURCE__STR_ID can be found which is a string.
Re: Content Assistant in a Xtext custom language [message #1767541 is a reply to message #1767540] Fri, 07 July 2017 04:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
this happens when grammar is too big

=>

MydslPackage.eINSTANCE.get<XXXXX> (dont know howit exactly will be named)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767556 is a reply to message #1767541] Fri, 07 July 2017 07:01 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
Yes MydslPackage.eINSTANCE.get<XXXXX> worked. I added the getScope method as follows.
@Override
	public IScope getScope(EObject context, EReference reference){
		
		if(context instanceof DefinitionStream && reference == SiddhiQLPackage.eINSTANCE.getSource_StrId()){
			DefinitionStream source = (DefinitionStream) context;
			MainSource mainSrc = (MainSource)source.eContainer();
			
			return Scopes.scopeFor(mainSrc.getSrc());
		}
		return super.getScope(context, reference);
		
	}


But in Scopes.scopeFor(mainSrc.getSrc()), it says mainSrc.getSrc() needs to be cast to Iterable<?extends EObject>. When I put the cast and run the program it gives errors since getSrc retruns only one object.
Re: Content Assistant in a Xtext custom language [message #1767619 is a reply to message #1767556] Fri, 07 July 2017 16:49 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
I have a grammar as follows.
AttributeReference:
	=>attrName2 = AttributeName
	|{AttributeReference} name1=(Source|EventReference)	
;
Source:
	strId=[Source1|IdNew]//inner='#'? strId =[Name|IdNew] 
;

Source1:
	inner='#'? name = IdNew
;
StandardStatefulSource:
	(name=IdNew '=')? basic_src=BasicSource
;

EventReference:
	na=[StandardStatefulSource|IdNew]
;


In name1=(Source|EventReference) in AttributeReference rule from the two alternatives only the first alternative is considered. I have tried switching the alternatives and the same thing happened. Is this happening since the both Source and EventReference rules are having cross references?
Thank you.
Re: Content Assistant in a Xtext custom language [message #1767620 is a reply to message #1767619] Fri, 07 July 2017 17:00 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Lists.newArrayList(object) should give you that iterable?

and it is not possible to have different references with same syntax

but what about a common reference

name1=SourceOrEventReference;

Source1OrStandardStatefulSource: StandardStatefulSource | Source1;

SourceOrEventReference: myRef=[Source1OrStandardStatefulSource|IdNew];


or you need something with a different syntax


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767643 is a reply to message #1767620] Sat, 08 July 2017 06:54 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
ists.newArrayList(object) worked but scoping didn't happen. Since the following DefinitionStream and QueryInput are different rules can I achieve local scoping?
DefinitionStream:
	 DEFINE STREAM src=Source1 
;

Source:
	strId=[Source1|IdNew]//inner='#'? strId =[Name|IdNew] 
;

Source1:
	inner='#'? name = IdNew
;

QueryInput:
FROM MainSource ;

MainSource :
src=Source;


I want to only suggest user defined stream name right before the query, not previous ones or later ones.
My getScope mthod is:
@Override
	public IScope getScope(EObject context, EReference reference){
		
		if(context instanceof DefinitionStream && reference == SiddhiQLPackage.eINSTANCE.getSource_StrId()){
			DefinitionStream source = (DefinitionStream) context;
			MainSource mainSrc = (MainSource)source.eContainer();
			
			return Scopes.scopeFor(Lists.newArrayList(mainSrc.getSrc()));
		}
		return super.getScope(context, reference);
		
	}


Thank you.
Re: Content Assistant in a Xtext custom language [message #1767644 is a reply to message #1767643] Sat, 08 July 2017 07:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
i strongly recommend you to use ad debugger.

context can be a DefinitionStream !!! during content assist but will be a Source !!!! during build.

=> you need to handle that in your scoping !!!

you can use context object to move up and down the ast and search whatever you want.

and fron the snippet you posted i dont see how DefinitionStream and Source relate to each other

=> with that kind of question quality i feel pain to give you any answers


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767649 is a reply to message #1767644] Sat, 08 July 2017 12:21 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Yes DefinitionStream and Source are not related to each other whereas DefinitionStream and Source1 are related and Queryinput and Source are related. May be I have not exactly understood the example in https://eclipse.org/Xtext/documentation/303_runtime_concepts.html.
Re: Content Assistant in a Xtext custom language [message #1767651 is a reply to message #1767649] Sat, 08 July 2017 13:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Can you please come up with

A complete but minimal example of what you want to do
How that part of the grammar looks like
How an example model looks like
And what should be inside the scope


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767655 is a reply to message #1767651] Sat, 08 July 2017 16:19 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
A complete example would be as follows.
define stream stream1 ;
from stream1 ;

define stream stream2 ;
from stream2 ;

define stream stream3 ;
from stream3 ;


Here I want to give suggestions as follows. For the 'from ' after 'define stream stream1 ;' need to suggest stream1. For the 'from' after 'define stream stream2 ;' need to suggest stream2 only, not both the stream1 and stream2. For the 'from' after 'define stream stream3 ;' need to suggest only stream3, not all stream1, stream2 and stream3. Currently all names stream1, stream2 and stream3 are suggested.

The relevant minimal grammar would be:
DefinitionStream:
	 DEFINE STREAM src=Source1 
;

Source1:
	inner='#'? name = IdNew
;

Source:
	strId=[Source1|IdNew]
;

MainSource :
src=Source;

QueryInput:
FROM MainSource ;

fragment STREAM: (str='stream');
fragment DEFINE: (define='define' );
fragment FROM: (from='from');


I didn't understand what you meant by model.
Scope need to filter the suggestions of stream names and give only the stream name right before 'from'.
Thank you.
Re: Content Assistant in a Xtext custom language [message #1767656 is a reply to message #1767655] Sat, 08 July 2017 16:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Your grammar misses the part that puts queryinput and Definition stream together.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767657 is a reply to message #1767656] Sat, 08 July 2017 16:46 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
There's no rule like that. They are separate rules. That's why I asked earlier can local scoping be achieved here.

Re: Content Assistant in a Xtext custom language [message #1767658 is a reply to message #1767657] Sat, 08 July 2017 17:03 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Sorry actually there's a rule as follows where queryInput and DefinitionStream are considered which is at the beginning.
ExecutionPlan:
(defStream+=DefinitionStream)* ';'?
|(qi+=queryInput) (';' qi+=queryInput)* ';'?
|(defStream+=DefinitionStream)(';' defStream+=DefinitionStream)*(';' qi+=queryInput) ';'?
;

Re: Content Assistant in a Xtext custom language [message #1767659 is a reply to message #1767658] Sat, 08 July 2017 17:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
And all query inputs should refer to the very last definition stream in the same execution plan?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767661 is a reply to message #1767659] Sat, 08 July 2017 17:57 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
No. It's like this.

define stream stream1 ;
from stream1 ;

define stream stream2 ;
define stream stream3 ;
from stream2 ;


If it is like this for the 'from' before define stream stream1 only stream1 need be suggested. For the 'from' before define stream stream2 & define stream stream3 both stream2 and stream3 should be suggested which are on the same execution plan. Thank you.
Re: Content Assistant in a Xtext custom language [message #1767662 is a reply to message #1767661] Sat, 08 July 2017 18:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Then you should walk the eContainer hierarchy of context up until you find a ExecutionPlan and ask the plain for the stuff you want to put into scope

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767666 is a reply to message #1767662] Sat, 08 July 2017 20:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
here is an example for such a code

class MyDslScopeProvider extends AbstractMyDslScopeProvider {

override getScope(EObject context, EReference reference) {
if (reference === MyDslPackage.eINSTANCE.source_StrId) {
val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
if (execPlan !== null) {
return Scopes.scopeFor(execPlan.defStream.map[src].toList)
}
}
super.getScope(context, reference)
}

}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767672 is a reply to message #1767666] Sun, 09 July 2017 07:34 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Thank you very much for the example. I have tried using that.
define stream stream1;
from stream1;


In the 'stream1' after 'from' it says an error message "Couldn't resolve reference to Source1 'stream1' ".
Re: Content Assistant in a Xtext custom language [message #1767673 is a reply to message #1767672] Sun, 09 July 2017 07:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Can you please share a complete but minimal grammar
(Create a new Test grammar for that)
And share it


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767678 is a reply to message #1767673] Sun, 09 July 2017 11:46 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,

I have tried to find why that error is coming using that minimal grammar. However for the following grammar no errors are coming.
Model:
	ExecutionPlan
;

ExecutionPlan:
{ExecutionPlan}(defStream+=DefinitionStream|defTable+=DefinitionTable)(';' defStream+=DefinitionStream|defTable+=DefinitionTable)* ';'?
|(qi+=QueryInput) (';' qi+=QueryInput)* ';'?
|(defStream+=DefinitionStream|defTable+=DefinitionTable)(';' defStream+=DefinitionStream|defTable+=DefinitionTable)*(';' qi+=QueryInput) ';'?
;

DefinitionStream:
	 DEFINE STREAM src=Source1 
;

DefinitionTable:
	DEFINE TABLE src=Source1
;

Source1:
	inner='#'? name = IdNew
;

Source:
	strId=[Source1|IdNew]
;

QueryInput:
	FROM src=Source//ss=StandardStream
 ;
 
IdNew: ID| ID_QUOTES;

terminal ID_QUOTES: 
    '`'('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* '`' 
;
 
@Override 
terminal ID:
	('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
; 

fragment STREAM: (str='stream');
fragment TABLE: (tab='table');
fragment DEFINE: (define='define' );
fragment FROM: (from='from');



But for the following grammar the error is coming.
Model:
	(execPlan+=ExecutionPlan)* 
;

ExecutionPlan:
{ExecutionPlan}(defStream+=DefinitionStream|defTable+=DefinitionTable)(';' defStream+=DefinitionStream|defTable+=DefinitionTable)* ';'?
|(qi+=QueryInput) (';' qi+=QueryInput)* ';'?
|(defStream+=DefinitionStream|defTable+=DefinitionTable)(';' defStream+=DefinitionStream|defTable+=DefinitionTable)*(';' qi+=QueryInput) ';'?
;

DefinitionStream:
	 DEFINE STREAM src=Source1 
;

DefinitionTable:
	DEFINE TABLE src=Source1
;

Source1:
	inner='#'? name = IdNew
;

Source:
	strId=[Source1|IdNew]
;

QueryInput:
	FROM src=Source//ss=StandardStream
 ;
 
IdNew: ID| ID_QUOTES;

terminal ID_QUOTES: 
    '`'('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* '`' 
;
 
@Override 
terminal ID:
	('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*
; 

fragment STREAM: (str='stream');
fragment TABLE: (tab='table');
fragment DEFINE: (define='define' );
fragment FROM: (from='from');


Re: Content Assistant in a Xtext custom language [message #1767679 is a reply to message #1767678] Sun, 09 July 2017 11:49 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Actually the difference between two grammars is when there are several execution plans in the model the error is coming.
Re: Content Assistant in a Xtext custom language [message #1767680 is a reply to message #1767679] Sun, 09 July 2017 13:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
the grammar you share is ambigous.
i wonder how this works at all.
do you still have backtracking enabled?

there is nothing that properly separates two execution plans.
what are the rules for that?

why are there somtimes multiple querys why sometimes only one?


maybe you want to do something like

ExecutionPlan:
{ExecutionPlan}
(defStream+=DefinitionStream|defTable+=DefinitionTable)(->';' (defStream+=DefinitionStream|defTable+=DefinitionTable))* (->';' qi+=QueryInput) ';'?
|
(qi+=QueryInput) (->';' qi+=QueryInput)* ';'?
;





Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767681 is a reply to message #1767680] Sun, 09 July 2017 14:02 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Yes what I sent in the ExecutionPlan rule is ambiguous. I had mistakenly done that. There are more parts in real grammar. I'll share a more descriptive grammar.
Re: Content Assistant in a Xtext custom language [message #1767709 is a reply to message #1767681] Mon, 10 July 2017 07:54 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Yes I have backtracking enabled and now I have disabled it. There are several errors and warnings coming up. The errors are as follows.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:151:6: [fatal] rule ruleExecutionPlan has non-LL(*) decision due to recursive rule invocations reachable from alts 2,3.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:257:7: [fatal] rule ruleExecutionPlan has non-LL(*) decision due to recursive rule invocations reachable from alts 2,3.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:358:6: [fatal] rule ruleExecutionPlan has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:129:4: [fatal] rule ruleExecutionPlan has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:385:4: [fatal] rule ruleExecutionPlan has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:411:2: [fatal] rule ruleExecutionElement has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:3446:2: [fatal] rule ruleJoinStream has non-LL(*) decision due to recursive rule invocations reachable from alts 3,4.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:3972:3: [fatal] rule ruleMainSource has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:4711:2: [fatal] rule ruleEveryPatternSourceChain1 has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:5106:2: [fatal] rule rulePatternSource has non-LL(*) decision due to recursive rule invocations reachable from alts 1,3.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:5364:2: [fatal] rule ruleLogicalStatefulSource has non-LL(*) decision due to recursive rule invocations reachable from alts 2,3.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:6014:2: [fatal] rule ruleSequenceSource has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.
error(211): ../org.example.siddhi/src-gen/org/xtext/example/siddhiql/parser/antlr/internal/InternalSiddhiQLParser.g:6484:2: [fatal] rule rulePartitionWithStream has non-LL(*) decision due to recursive rule invocations reachable from alts 1,2.  Resolve by left-factoring or using syntactic predicates or using backtrack=true option.



The relevant grammar rules are as follows.
ExecutionPlan:
	(appAnn+=AppAnnotation)* ( //(defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction | err+=Error) (';' (defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction | err+=Error))* ';'?
	((exElement+=ExecutionElement) 
	|(defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction)(';' (defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction))*) (';' (exElement+=ExecutionElement))* ';'?) 
;

ExecutionElement:
	que=Query|execPartition=ExecPartition
;

JoinStream:
	left_source=JoinSource right_source=JoinSource right_uni=UNIDIRECTIONAL (on=ON expr=Expression)? wt=WithinTime? 
	|left_source=JoinSource join=joins right_source=JoinSource (on=ON expr=Expression)? wt=WithinTime?
	|left_source=JoinSource left_uni=UNIDIRECTIONAL join=joins right_source=JoinSource (on=ON expr=Expression)? wt=WithinTime?
	|ss=StandardStream
;

MainSource:
	src=Source (preWindowHandlers = BasicSourceStreamHandlers)? (window = Win)?
;

EveryPatternSourceChain:
	EveryPatternSourceChain1 ({EveryPatternSourceChain.left=current} op= '->' right=EveryPatternSourceChain1)*     
;

EveryPatternSourceChain1 returns EveryPatternSourceChain:
	'('eps=EveryPatternSourceChain')' wt=WithinTime?
	|psc=PatternSourceChain 
	//|EVERY psc1=PatternSourceChain1 
	|every=EVERY '('psc=PatternSourceChain ')' wt=WithinTime? //every error
	|every=EVERY ps1=PatternSource wt=WithinTime? 
;

PatternSource:
	{PatternSource}lss=LogicalStatefulSource|{PatternSource}pss=PatternCollectionStatefulSource|{PatternSource}stdss=StandardStatefulSource
;

LogicalStatefulSource:
	not=NOT stdSource+=StandardStatefulSource (and=AND stdSource+=StandardStatefulSource) //and error,not error
    |stdSource+=StandardStatefulSource and=AND stdSource+=StandardStatefulSource //and error
    |stdSource+=StandardStatefulSource or=OR stdSource+=StandardStatefulSource
;

SequenceSource:
	LogicalStatefulSource|SequenceCollectionStatefulSource|StandardStatefulSource
;

PartitionWithStream:
	attr=Attribute of=OF str_id1=Source //str_id1=StreamId ...
	|ConditionRanges of=OF str_id2=Source //str_id2=StreamId
;


Can you provide a clue for error fixing for these ?
The grammar file is attached here.
  • Attachment: MyDsl.xtext
    (Size: 18.14KB, Downloaded 183 times)

[Updated on: Mon, 10 July 2017 07:56]

Report message to a moderator

Re: Content Assistant in a Xtext custom language [message #1767733 is a reply to message #1767709] Mon, 10 July 2017 12:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
sry am currently too busy for that. maybe you can nail down the problem and ask a new question with a minimal but complete grammar

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767736 is a reply to message #1767733] Mon, 10 July 2017 13:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
do you know you can addd this to your workflow

parserGenerator = {
debugGrammar = true
}

and then use antlrworks to understand the ambiguities


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767737 is a reply to message #1767736] Mon, 10 July 2017 13:13 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Thank you for the information. I'll use antlrworks and try.
Re: Content Assistant in a Xtext custom language [message #1767869 is a reply to message #1767737] Tue, 11 July 2017 19:16 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Antlrworks throws "Cannot launch the debugger Time-out waiting to connect to the remote parser" when trying to debug an input. I have tried several things on internet and still the same error throws. I typed "netstat -aon | find /i "49100" "in the command prompt and nothing showed relevant to 49100 port. Is this happens due to not enough time out given in preferences?
Re: Content Assistant in a Xtext custom language [message #1767872 is a reply to message #1767869] Tue, 11 July 2017 19:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
sorry i have no idea on this.

i meant mainly to use antlrworks to find out where the ambiguities are if you are not able to find out with using more minimalized grammars and stuff.
doing so you would have find out that e.g.

SequenceSource | LogicalStatefulSource | SequenceCollectionStatefulSource

is one source of this pile

maybe something like

SequenceSource:
	=>LogicalStatefulSource|=>SequenceCollectionStatefulSource|StandardStatefulSource
;


LogicalStatefulSource:
	=>(not=NOT stdSource+=StandardStatefulSource (and=AND stdSource+=StandardStatefulSource)) //and error,not error
    |=>(stdSource+=StandardStatefulSource and=AND stdSource+=StandardStatefulSource) //and error
    |=>(stdSource+=StandardStatefulSource or=OR stdSource+=StandardStatefulSource)
;


SequenceCollectionStatefulSource:
	=>(StandardStatefulSource ('<' coll=Collect '>'|zero_or_more='*'|zero_or_one='?'|one_or_more='+'))
;


helps

unfortunately your grammar is way way too big upfront to do a reasonable analysis without spending days or hard work and brain wiggeling
thus maybe backtracking is the way to go,
but then you have to deal with at other places.

the usualy way is:

start with a small grammar, make sure it works and add new stuff step by step
Model:
	(elements += ExecutionPlan)*
;
ExecutionPlan:
	(appAnn+=AppAnnotation)* ( //(defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction | err+=Error) (';' (defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction | err+=Error))* ';'?
	((exElement+=ExecutionElement) 
	|(defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction)(';' (defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction))*) (';' (exElement+=ExecutionElement))* ';'?) 
;

ExecutionElement:
	que=Query|execPartition=ExecPartition
;


AppAnnotation:
	 '@' APP ':' na=Name ('(' ann5+=AnnotationElement (',' ann5+=AnnotationElement )* ')' )?
;

APP: (ap='app');

Query:
	"query" name=ID
;

ExecPartition:
	"execPart" name=ID
;

DefinitionStream:
	{DefinitionStream} (ann += Annotation)* DEFINE STREAM src=Source1 '(' feature += Features (',' feature += Features )* ')'';'?		 		
;

DefinitionTable:
	(ann1 += Annotation)* DEFINE TABLE src=Source1 '(' feature += Features (',' feature += Features )* ')'';'?			
;

DefinitionWindow:
	(ann2 += Annotation)* DEFINE WINDOW src=Source1 '(' feature += Features (',' feature += Features )* ')' funcOp = FunctionOperation ( OUTPUT opEventType=OutputEventType )? ';'? 
;

fragment OUTPUT: (output='output' );
OutputEventType:
	{OutputEventType}ALL EVENTS |{OutputEventType} ALL RAW EVENTS |{OutputEventType} EXPIRED EVENTS |{OutputEventType} EXPIRED RAW EVENTS |{OutputEventType} CURRENT? EVENTS
;

fragment FALSE: (fals='false');
fragment TRUE: (tr='true');
fragment RAW: (raw='raw' );
fragment EVENTS: (events='events' );
fragment ALL: (all='all' );
fragment EXPIRED: (expired='expired' );
fragment CURRENT: (currt='current' );

AttributeList:
	{AttributeList}((attr += Attribute) (',' attr += Attribute)* ) |{AttributeList}'*'
;

ConstantValue:
	{ConstantValue}bv=BoolValue

	;

BoolValue:
	TRUE|FALSE
;


Attribute:
	mathOp=ConstantValue
;

FunctionOperation:
	{FunctionOperation}(funcNamespace=FunctionNamespace ':')? funcId=FunctionId '(' (attrList=AttributeList)? ')'
;

FunctionNamespace:
	na=Name
;

FunctionId:
	na=Name
;

Source1:
	inner='#'? name = IdNew
;

Features:
	(name = AttributeName) (type = AttributeType)
;

AttributeName:
	name = IdNew
;

fragment STRINGS: (string='string');
fragment INTS: (int='int');
fragment LONG: (long='long');
fragment DOUBLE: (double='double');
fragment FLOAT: (float='float');
fragment BOOL: (bool='bool');
fragment OBJECT: (object='object');
fragment RETURN: (return='return');


AttributeType:
	{AttributeType}STRINGS |{AttributeType} INTS|{AttributeType} LONG |{AttributeType} FLOAT |{AttributeType} DOUBLE|{AttributeType} BOOL|{AttributeType} OBJECT 
;

DefinitionTrigger:
	DEFINE TRIGGER tn=TriggerName AT (every=EVERY tv=TimeValue | sv=StringValue) ';'?
;

TimeValue:
	v=INT "ms"
;

FunctionBody:
	value=SCRIPT
;

terminal SCRIPT:
	'{' -> '}'
;

DefinitionFunction:
	DEFINE FUNCTION fn=FunctionName '[' ln=LanguageName ']' RETURN attr_type=AttributeType func_body=FunctionBody ';'?
;

FunctionName:
	id=ID
;

LanguageName:
	id=ID
;


TriggerName:
	id=ID
;

EVERY: (every='every' );

fragment AT: (at='at' );

    
Annotation:
	'@' na = Name ('(' (annElement += AnnotationElement | ann += Annotation) 
		( ',' (annElement += AnnotationElement | ann += Annotation))* ')'	)
;

AnnotationElement:
	(propName = PropertyName '=')? propVal = PropertyValue
;

PropertyValue:
	sv=StringValue
;

PropertyName:
	{PropertyName} na+=Name (ps+=PropertySeparator na += Name )*
;

StringValue:
	sl=STRING_LITERAL
;


STRING_LITERAL:
	STRING
;

PropertySeparator:
	{PropertySeparator}DOT |{PropertySeparator} MINUS |{PropertySeparator} COL
;

COL : ':';

MINUS : '-';

DOT : '.';

IdNew: ID;

Name:
	 na=IdNew//k_word=Keyword |
;


fragment TRIGGER: (trigger='trigger' );
fragment FUNCTION: (function='function');
fragment STREAM: (str='stream');
fragment DEFINE: (define='define' );
fragment TABLE: (table='table' );
fragment WINDOW: (window='window' );



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767876 is a reply to message #1767872] Tue, 11 July 2017 20:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
you might to use predicates here as well. but i am not sure if it will do the right thing.
there is still the major issue of all that optional semiklon where where parser does not know where to put them.

ExecutionPlan:
	(appAnn+=AppAnnotation)* 
	( //(defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction | err+=Error) (';' (defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction | err+=Error))* ';'?
	(
		(exElement+=ExecutionElement) 
	|
	=>(defStream+=DefinitionStream
		| def_table+=DefinitionTable
		| def_window+=DefinitionWindow 
		| defTrigger+=DefinitionTrigger 
		| defFunction+=DefinitionFunction
	)(';' =>(
		defStream+=DefinitionStream|
		 def_table+=DefinitionTable|
		  def_window+=DefinitionWindow |
		   defTrigger+=DefinitionTrigger |
		    defFunction+=DefinitionFunction
	))*) =>(';' (exElement+=ExecutionElement))* ';'?) 
;

DefinitionStream:
	=>({DefinitionStream} (ann += Annotation)* DEFINE STREAM) src=Source1 '(' feature += Features (',' feature += Features )* ')'';'?		 		
;

DefinitionTable:
	=>((ann1 += Annotation)* DEFINE TABLE) src=Source1 '(' feature += Features (',' feature += Features )* ')'';'?			
;

DefinitionWindow:
	=>((ann2 += Annotation)* DEFINE WINDOW) src=Source1 '(' feature += Features (',' feature += Features )* ')' funcOp = FunctionOperation ( OUTPUT opEventType=OutputEventType )? ';'? 
;

DefinitionTrigger:
	=>(DEFINE TRIGGER) tn=TriggerName AT (every=EVERY tv=TimeValue | sv=StringValue) ';'?
;



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767878 is a reply to message #1767876] Tue, 11 July 2017 20:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
(the semikolon is here:

DefinitionStream:
=>({DefinitionStream} (ann += Annotation)* DEFINE STREAM) src=Source1 '(' feature += Features (',' feature += Features )* ')'';'?
;

and is here

(';' (defStream+=DefinitionStream| def_table+=DefinitionTable| def_window+=DefinitionWindow | defTrigger+=DefinitionTrigger | defFunction+=DefinitionFunction | err+=Error))*


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1767958 is a reply to message #1767878] Wed, 12 July 2017 12:03 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Thank you very much for your help.
When I put the predicates as follows error disappears.
DefinitionStream:
	=>({DefinitionStream} (ann += Annotation)* DEFINE STREAM) src=Source1 '(' feature += Features (',' feature += Features )* ')'';'?		 		
;

DefinitionTable:
	=>((ann1 += Annotation)* DEFINE TABLE) src=Source1 '(' feature += Features (',' feature += Features )* ')'';'?			
;

DefinitionWindow:
	=>((ann2 += Annotation)* DEFINE WINDOW) src=Source1 '(' feature += Features (',' feature += Features )* ')' funcOp = FunctionOperation ( OUTPUT opEventType=OutputEventType )? ';'? 
;

DefinitionTrigger:
	=>(DEFINE TRIGGER) tn=TriggerName AT (every=EVERY tv=TimeValue | sv=StringValue) ';'?
;



But there are errors in internalMyDslParser.java file in synpred3_InternalSiddhiQLParser_fragment() these types of methods.
Also using Antlrworks I could resolve most of the errors but there are some issues when running test cases.

JoinStream:
	left_source=JoinSource right_source=JoinSource right_uni=UNIDIRECTIONAL (on=ON expr=Expression)? wt=WithinTime? //unidirectional error, on error
	|left_source=JoinSource join=joins right_source=JoinSource (on=ON expr=Expression)? wt=WithinTime?
	|left_source=JoinSource left_uni=UNIDIRECTIONAL join=joins right_source=JoinSource (on=ON expr=Expression)? wt=WithinTime?//on error, uni error
	|ss=StandardStream
;


I have changed this rule as follows. Is it correct? The editor is complaining with the changed rule.
JoinStream:
	=>ss=StandardStream
	|left_source=JoinSource (right_source=JoinSource right_uni=UNIDIRECTIONAL|join=joins right_source=JoinSource|left_uni=UNIDIRECTIONAL join=joins right_source=JoinSource) (on=ON expr=Expression)? wt=WithinTime? 
;


Thank you.
Re: Content Assistant in a Xtext custom language [message #1767962 is a reply to message #1767958] Wed, 12 July 2017 12:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
sry no time to diff for the rest of the week

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768727 is a reply to message #1767962] Sat, 22 July 2017 15:35 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
How to provide scoping capability for two places ? I mean can scoping for two rules be done within same getScope method or is there any other way?

Thank you.
Re: Content Assistant in a Xtext custom language [message #1768728 is a reply to message #1768727] Sat, 22 July 2017 17:28 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
What my problem is I wanna put the following code snippet in getScope method. How can I do this? Two return statements cannot be used within one method inside if conditions.
if (reference === SiddhiQLPackage.eINSTANCE.source_StrId) {
			val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
				if (execPlan !== null) {
					return Scopes.scopeFor(execPlan.defStream.map[src])
				}
		}
		
		if (reference === SiddhiQLPackage.eINSTANCE.source_StrId) {
			val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
				if (execPlan !== null) {
					return Scopes.scopeFor(execPlan.def_table.map[src])
				}
		}


Thank you.
Re: Content Assistant in a Xtext custom language [message #1768730 is a reply to message #1768728] Sat, 22 July 2017 18:40 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Don't understand

Both ifs are the same


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768731 is a reply to message #1768730] Sat, 22 July 2017 18:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
And the way is to simply if else in the scope method


The method will be calll for alll references


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Sat, 22 July 2017 18:56]

Report message to a moderator

Re: Content Assistant in a Xtext custom language [message #1768732 is a reply to message #1768731] Sat, 22 July 2017 19:11 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33147
Registered: July 2009
Senior Member
There's always org.eclipse.xtext.scoping.IScope.NULLSCOPE you can return when there's nothing in scope...

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Content Assistant in a Xtext custom language [message #1768745 is a reply to message #1768732] Sun, 23 July 2017 11:13 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi

I have used if else as follows in the getScope method. But only first if works.
if (reference === SiddhiQLPackage.eINSTANCE.source_StrId) {
			val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
				if (execPlan !== null) {
					return Scopes.scopeFor(execPlan.defStream.map[src])
				}
		}
		else if (reference === SiddhiQLPackage.eINSTANCE.source_StrId) {
			val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
				if (execPlan !== null) {
					return Scopes.scopeFor(execPlan.def_table.map[src])
				}
		}
		else if (reference === SiddhiQLPackage.eINSTANCE.attributeNameReference_AttrName1) {
			val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
				if (execPlan !== null) {					
					for(i:0..<execPlan.defStream.map[feature].length){
						return Scopes.scopeFor(execPlan.defStream.map[feature].get(i))
					}					
				}
		}

Re: Content Assistant in a Xtext custom language [message #1768746 is a reply to message #1768745] Sun, 23 July 2017 11:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
sorry i dont understand.

please use a a debugger to find out what the problem is.
i dont know which references you want to scope.
i dont know what the code inside the ifs is intended to do
....

you have still reference === SiddhiQLPackage.eINSTANCE.source_StrId twice



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768747 is a reply to message #1768746] Sun, 23 July 2017 11:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
and the for loop makes no sense when the first one will leave the loop


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768750 is a reply to message #1768747] Sun, 23 July 2017 12:44 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
Yes now only I realize that mistake in for loop.
A simple grammar would be:
ExecutionPlan:
	(appAnn+=AppAnnotation)* ( 	((exElement+=Query) 
	|=>(defStream+=DefinitionStream| def_table+=DefinitionTable)(->';' 
	=>(	defStream+=DefinitionStream|def_table+=DefinitionTable))*) =>(->';' (exElement+=Query))* ';'?) 
;

DefinitionStream:
	=>({DefinitionStream} DEFINE STREAM) src=Source1 '(' feature += Features (',' feature += Features )* ')'//';'?		 		
;

DefinitionTable:
	=>(DEFINE TABLE) src=Source1 '(' feature += Features (',' feature += Features )* ')'//';'?			
;

Source:
	strId=[Source1|IdNew] 
;

Source1:
	inner='#'? name = IdNew
;

Features:
	(name=IdNew)
;

Query:
        qi=QueryInput qs=QuerySection
;

QueryInput:
       FROM Source
;

QuerySection:
      SELECT attr= [Features|IdNew]
;

fragment STREAM: (str='stream');
fragment DEFINE: (define='define' );
fragment TABLE: (table='table' );
fragment FROM: (from='from');
fragment SELECT: (select='select');


What I want to achieve is:

//execution plan 1
define stream1 (f1,f2);
from stream1 select f1,f2;

//execution plan 2
define stream2 (f3,f4);
from stream2 select f3;

For 'from' in execution plan 1provide only stream1 as the suggestion & for 'from' in execution plan 2 provide only stream2 as the suggestion. For 'select' in execution plan 1 provide only f1,f2 as suggestions and for 'select' in execution plan 2 provide only f3,f4 as suggestions.

Thank you.
Re: Content Assistant in a Xtext custom language [message #1768751 is a reply to message #1768750] Sun, 23 July 2017 12:48 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
I have missed this
IdNew: ID;
Re: Content Assistant in a Xtext custom language [message #1768752 is a reply to message #1768751] Sun, 23 July 2017 12:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
But why don't you simply collect all stuff you need and call scopes.scopeFor for that

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768753 is a reply to message #1768752] Sun, 23 July 2017 13:30 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
e.g.

val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
if (execPlan !== null) {
Scopes.scopeFor(execPlan.defStream.map[feature].flatten)
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768756 is a reply to message #1768753] Sun, 23 July 2017 16:29 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
Thank you very much.
You said reference === SiddhiQLPackage.eINSTANCE.source_StrId is used twice. I have merged it as follows. But it seems to have issues.
if (reference === SiddhiQLPackage.eINSTANCE.source_StrId) {
			val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
				if (execPlan.defStream !== null) {					
					return Scopes.scopeFor(execPlan.defStream.map[src])
				}
				else if(execPlan.def_table !== null){
					return Scopes.scopeFor(execPlan.def_table.map[src])
				}
		}

Re: Content Assistant in a Xtext custom language [message #1768759 is a reply to message #1768756] Sun, 23 July 2017 17:01 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Sry you have to explain what the issue is

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768762 is a reply to message #1768759] Sun, 23 July 2017 17:48 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
I am very sorry to give less information.
When I write:
define stream stream1 (f1,f2);
define table table1 (f3,f4);
from table1 select f3;


Here the editor shows "Couldn't resolve reference to Source1 'table1' ".
Re: Content Assistant in a Xtext custom language [message #1768764 is a reply to message #1768762] Sun, 23 July 2017 17:58 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Did you debug the code?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768765 is a reply to message #1768764] Sun, 23 July 2017 18:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
p.s.: the problem might be

you should no compare lists to null,
in emf lists are never null, they are empty


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768768 is a reply to message #1768765] Sun, 23 July 2017 18:31 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
No I didn't use a debugger. Can antlrworks be used ?
I checked:
if (execPlan.defStream.length !== 0)


but it didn't solve the issue. I am checking on it.
Re: Content Assistant in a Xtext custom language [message #1768769 is a reply to message #1768768] Sun, 23 July 2017 18:41 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
you can use debug menu in eclipse and setting breakpoints as i java to debug the xtend code.

the following work fine for me for the "table" reference

if (reference === MyDslPackage.eINSTANCE.source_StrId) {
println("b")
val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
if (!execPlan.defStream.empty) {
val x = execPlan.defStream.map[src]
return Scopes.scopeFor(x)
}
else if(!execPlan.def_table.empty){
val x = execPlan.def_table.map[src]
return Scopes.scopeFor(x)
}
}


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768770 is a reply to message #1768769] Sun, 23 July 2017 18:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
btw what should your code do if there are tables and streams?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768771 is a reply to message #1768770] Sun, 23 July 2017 18:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
so maybe you actually want to do a

if (reference === MyDslPackage.eINSTANCE.source_StrId) {
val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
val scope = <Source1>newArrayList()
scope.addAll(execPlan.defStream.map[src])
scope.addAll(execPlan.def_table.map[src])
return Scopes.scopeFor(scope)

}

bu i dont know i dont have a language spec for your dsl


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768832 is a reply to message #1768771] Mon, 24 July 2017 08:45 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi

Thank you very much for the examples.
ExecutionPlan:
	(appAnn+=AppAnnotation)* ( 	((exElement+=ExecutionElement) 
	|=>(defStream+=DefinitionStream| def_table+=DefinitionTable)(->';' 
	=>(	defStream+=DefinitionStream|def_table+=DefinitionTable))*) =>(->';' (exElement+=ExecutionElement))* ';'?) 
;

ExecutionElement:
         qu=Query
;
DefinitionStream:
	=>({DefinitionStream} DEFINE STREAM) src=Source1 '(' feature += Features (',' feature += Features )* ')'//';'?		 		
;

DefinitionTable:
	=>(DEFINE TABLE) src=Source1 '(' feature += Features (',' feature += Features )* ')'//';'?			
;

Source:
	strId=[Source1|IdNew] 
;

Source1:
	inner='#'? name = IdNew
;

Features:
	(name=IdNew)
;

Query:
        qi=QueryInput qs=QuerySection
;

QueryInput:
       FROM Source|ps=StandardStatefulSource:
;

StandardStatefulSource:
       	(name=IdNew '=')
;

QuerySection:
      SELECT attr= [Features|IdNew]  stss=[StandardStatefulSource|IdNew]
;

IdNew :
        ID;

fragment STREAM: (str='stream');
fragment DEFINE: (define='define' );
fragment TABLE: (table='table' );
fragment FROM: (from='from');
fragment SELECT: (select='select');



Here in there's a cross reference in QuerySection rule which is not directly related to ExecutionPlan rule. So in order to navigate through the model Can I do the following inside getScope method?
   val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
   val execElement = EcoreUtil2.getContainerOfType(execPlan, ExecutionElement)
   val query = EcoreUtil2.getContainerOfType(execElement, Query)
   val queryInput = EcoreUtil2.getContainerOfType(query, QueryInput)


And to return scopes I did :
if(queryInput !==null){
	return Scopes.scopeFor(queryInput .ps.eContents)
}


But it didn't work. Is there an easy method to navigate the model and get related cross references?
Re: Content Assistant in a Xtext custom language [message #1768834 is a reply to message #1768832] Mon, 24 July 2017 09:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
what do you mean

EcoreUtil2.getAllContentsOfType ???


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768863 is a reply to message #1768834] Mon, 24 July 2017 13:00 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
I meant
QuerySection:
      SELECT attr= [Features|IdNew]  stss=[StandardStatefulSource|IdNew]
;

Since this rule is not directly connected to the ExecutionPlan rule and to give the names of the cross reference stss=[StandardStatefulSource|IdNew] need to traverse through the created model for local scoping. That's why I had done,
val execPlan = EcoreUtil2.getContainerOfType(context, ExecutionPlan)
   val execElement = EcoreUtil2.getContainerOfType(execPlan, ExecutionElement)
   val query = EcoreUtil2.getContainerOfType(execElement, Query)
   val queryInput = EcoreUtil2.getContainerOfType(query, QueryInput)


Can traverse through the model using?
val execPlan = EcoreUtil2.getAllContentsOfType(context,ExecutionPlan)


Then how mapping is done to get the scopes as in other cases like,
execPlan.def_table.map[src]
Re: Content Assistant in a Xtext custom language [message #1768864 is a reply to message #1768863] Mon, 24 July 2017 13:05 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
sorry i cannot write the code for you.
if you feel bad working with xtend write the code in java.

use EcoreUtil2.getContainerOfType(context, <RootOfYourModel>) to get the root.
travetse with EcoreUtil2.getAllContentsOfTtype() from there


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1768865 is a reply to message #1768864] Mon, 24 July 2017 13:14 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi,
I am sorry for asking that, But in xtext documentation also a cross reference from the root is only given. So I couldn't understand how to traverse the model. Thank you very much for this information :) and again sorry to ask this.
Re: Content Assistant in a Xtext custom language [message #1768868 is a reply to message #1768865] Mon, 24 July 2017 13:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
sorry i dont understand

can you please picture the ast you have and what you want to collect


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1769915 is a reply to message #1768868] Sat, 05 August 2017 15:24 Go to previous messageGo to next message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Hi
The proposals are correctly shown in content assisting after scoping is done. I have removed almost all the ambiguities in grammar too. But I have one issue that is once I add a particular rule called QueryOutput as follows content assisting is not working as expected.
Query:
	{Query}(ann3 += Annotation)* FROM (qInp = QueryInput ) (querySec = QuerySection)? outRate=OutputRate? (qOutput = QueryOutput)
;


But when I put (qOutput = QueryOutput)? like this no issue is coming. I have attached the grammar file below. I have added following in mwe2 file.
parserGenerator = {
				debugGrammar=true
				antlrParam = "-Xconversiontimeout"
    			antlrParam = "40000"
				options = {
					ignoreCase = true
					backtrack=false
					memoize = true
					classSplitting=true
                	fieldsPerClass = "300"
                	methodsPerClass= "800"
				}
			}


Can you provide a clue why this is happenning?
  • Attachment: grammar.xtext
    (Size: 18.46KB, Downloaded 150 times)

[Updated on: Sat, 05 August 2017 15:26]

Report message to a moderator

Re: Content Assistant in a Xtext custom language [message #1769918 is a reply to message #1769915] Sat, 05 August 2017 17:03 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14677
Registered: July 2009
Senior Member
Please ask new questions in a new thread

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Content Assistant in a Xtext custom language [message #1769931 is a reply to message #1769918] Sun, 06 August 2017 11:37 Go to previous message
Udeshika Sewwandi is currently offline Udeshika SewwandiFriend
Messages: 118
Registered: March 2017
Senior Member
Sorry I'll use a new topic :)
Previous Topic:Using CompilationTestHelper with a custom classloader
Next Topic:DSL with a free text
Goto Forum:
  


Current Time: Wed May 15 03:07:56 GMT 2024

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

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

Back to the top