Home » Modeling » TMF (Xtext) » Keywords with whitespaces and same prefix(Lexer issue? )
Keywords with whitespaces and same prefix [message #635874] |
Thu, 28 October 2010 13:10 |
Thomas Delissen Messages: 11 Registered: September 2010 Location: Eindhoven |
Junior Member |
|
|
Hello,
I am creating a very verbose language, in which I would like to use keywords with spaces in them.
For instance, I have the rule:
CreateTask:
'create' task=[Task] 'with related resource' resource=[Resource]
;
On itself, this works fine. After I have selected the Task from the tasks defined earlier, I can just hit Ctrl+Space and the sentence 'with related resource' is created.
However, at some point, I've introduced a sentence in a completely different part of language as such:
UseMaterial:
'use' material=[Material] 'with' task=[Task]
;
Now, the editor stumbles over the sentence 'with related resource', as it cannot tell the difference between the first part of the keyword 'with related resources' and 'with'.
I think this is an issue with the lexer or something. The weird part is that autocompletion works fine in this case: You press Ctrl+space and after this 'with related resources' appears, but immediately after this an error is raised.
My question is: Is there an easy way to fix this, so that I can still use keywords with spaces in them, or should I avoid keywords with spaces in them?
I know I can use the alternative to make three separate keywords 'with' 'related' and 'resources', but in this case I should press Ctrl+space three times, which is also not desirable.
Kind regards,
Thomas
|
|
|
Re: Keywords with whitespaces and same prefix [message #635940 is a reply to message #635874] |
Thu, 28 October 2010 16:06 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
Keywords with spaces will get you into trouble IMO.
You can easily provide entire sentences as proposals, they are not auto
generated though.
Sentence1 : 'hit' 'monster' 'with' 'axe' ;
Then, when computing a proposal for SENTENCE1, just return the entire
string "hit monster with axe" as the proposal.
In your DSL's ProposalProvider...
public void completeSentence1(EObject model, Assignment assignment,
ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
ICompletionProposal completionProposal = createCompletionProposal(
"hit monster with axe", new StyledString(
"A complete monster hitting sentence"), context);
acceptor.accept(completionProposal);
super.completeBranch_Name(model, assignment, context, acceptor);
}
Where "createCompletionProposal" creates a suitable instance with things
like priority, icon etc.
An additional benefit with separate words is that user can place the
words as far apart as wanted, on different lines, include comments etc.
hit monster with
/* let's confuse the monster with a: */ penguin
- henrik
On 10/28/10 3:10 PM, Thomas Delissen wrote:
> Hello,
> I am creating a very verbose language, in which I would like to use
> keywords with spaces in them.
> For instance, I have the rule:
> CreateTask:
> 'create' task=[Task] 'with related resource' resource=[Resource]
> ;
>
>
> On itself, this works fine. After I have selected the Task from the
> tasks defined earlier, I can just hit Ctrl+Space and the sentence 'with
> related resource' is created.
> However, at some point, I've introduced a sentence in a completely
> different part of language as such:
>
> UseMaterial:
> 'use' material=[Material] 'with' task=[Task]
> ;
>
>
> Now, the editor stumbles over the sentence 'with related resource', as
> it cannot tell the difference between the first part of the keyword
> 'with related resources' and 'with'.
> I think this is an issue with the lexer or something. The weird part is
> that autocompletion works fine in this case: You press Ctrl+space and
> after this 'with related resources' appears, but immediately after this
> an error is raised.
> My question is: Is there an easy way to fix this, so that I can still
> use keywords with spaces in them, or should I avoid keywords with spaces
> in them?
> I know I can use the alternative to make three separate keywords 'with'
> 'related' and 'resources', but in this case I should press Ctrl+space
> three times, which is also not desirable.
|
|
| | |
Goto Forum:
Current Time: Sat Apr 20 02:34:40 GMT 2024
Powered by FUDForum. Page generated in 0.02624 seconds
|