|
|
|
|
|
| Re: Content Assistant in a Xtext custom language [message #1765351 is a reply to message #1765348] |
Thu, 08 June 2017 11:35   |
Eclipse User |
|
|
|
a minimal grammar would look likeModel:
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Content Assistant in a Xtext custom language [message #1766691 is a reply to message #1766484] |
Sun, 25 June 2017 21:57   |
Eclipse User |
|
|
|
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 #1767520 is a reply to message #1766692] |
Thu, 06 July 2017 13:48   |
Eclipse User |
|
|
|
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: Thu, 06 July 2017 23:46] by Moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Content Assistant in a Xtext custom language [message #1767709 is a reply to message #1767681] |
Mon, 10 July 2017 03:54   |
Eclipse User |
|
|
|
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 233 times)
[Updated on: Mon, 10 July 2017 03:56] by Moderator
|
|
|
|
|
|
|
| Re: Content Assistant in a Xtext custom language [message #1767872 is a reply to message #1767869] |
Tue, 11 July 2017 15:50   |
Eclipse User |
|
|
|
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' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|