XText Syntax [message #1741153] |
Tue, 23 August 2016 11:35 |
Michael Müller Messages: 20 Registered: August 2016 |
Junior Member |
|
|
Hello community,
I'm new with xtext. So i tried to write my first own DSL.
It's very similar to a if condition, just without variables.
e.g selector operator argument
selector and argument is typed by the user.
The operator is "hard coded"
MyDsl:
Module:
(statements+=Statement)*;
Statement:
left=Selector op=(Expression) right=Argument;
Selector:
name=ID;
Argument:
name=ID;
Equal:
'==';
NotEqual:
'!=';
Expression:
Equal|NotEqual;
If i start the RCP, i just can type the first selector, but i get no autocompletion for the operators.
So what's wrong? For me looks fine
[Updated on: Tue, 23 August 2016 11:38] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: XText Syntax [message #1741515 is a reply to message #1741512] |
Thu, 25 August 2016 14:49 |
|
the problem is that lexers are context free.
means the whole file is lexed regardless the place in the file you are,
means: once lexed as VALUE, always lexed as value
means
Greeting:
'Hello' name=INT '!';
terminal VALUE:
('*' | 'a'..'z'|'A'..'Z')+ | INT;
will never parse
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
Re: XText Syntax [message #1741537 is a reply to message #1741524] |
Thu, 25 August 2016 17:03 |
|
well that should be easy
import javax.inject.Inject
import org.eclipse.xtext.RuleCall
import org.eclipse.xtext.ide.editor.contentassist.ContentAssistContext
import org.eclipse.xtext.ide.editor.contentassist.IIdeContentProposalAcceptor
import org.eclipse.xtext.ide.editor.contentassist.IdeContentProposalProvider
import org.xtext.example.mydsl2.services.MyDslGrammarAccess
class MyDslIdeContentProposalProvider extends IdeContentProposalProvider {
@Inject extension MyDslGrammarAccess
override dispatch createProposals(RuleCall rc, ContentAssistContext context,
IIdeContentProposalAcceptor acceptor) {
if (VALUERule === rc.rule) {
//TODO check context.prefix
val e1 = proposalCreator.createProposal("1",context)
acceptor.accept(e1, proposalPriorities.getDefaultPriority(e1))
val e2 = proposalCreator.createProposal("*",context)
acceptor.accept(e2, proposalPriorities.getDefaultPriority(e2))
val e3 = proposalCreator.createProposal("ID",context)
acceptor.accept(e1, proposalPriorities.getDefaultPriority(e3))
} else {
super._createProposals(rc, context, acceptor)
}
}
} class MyDslWebModule extends AbstractMyDslWebModule {
def void configureIPreferenceValuesProvider(Binder binder) {
binder.bind(IPreferenceValuesProvider).annotatedWith(FormatterPreferences).to(FormatterPreferenceValuesProvider)
}
def Class<? extends IdeContentProposalProvider> bindIdeContentProposalProvider() {
MyDslIdeContentProposalProvider
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.05633 seconds