Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Xtext Grammar - Exclusion of a specific Rule
Xtext Grammar - Exclusion of a specific Rule [message #1064689] Thu, 20 June 2013 14:47 Go to next message
Edwin Tuzar is currently offline Edwin Tuzar
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

So I have the following rules:

HtmlAcceptedElement:
	BinaryElements | Image | Link | Text
;


and

BinaryElements:
	Bold | Italic | Underline | Paragraph
;

now I want for Bold to do the following:
Bold:
	'b' (htmlaccelement+=HtmlAcceptedElement)+ '/b'
;

but I want to don't allow Bold rule to be inside this: (htmlaccelement+=HtmlAcceptedElement)+
is this possible? to say somehow HtmlAcceptedElement except Bold ?

Thanks in advance!
Best regards,


Edwin W.T.
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064691 is a reply to message #1064689] Thu, 20 June 2013 14:49 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
HtmlAcceptedElementSpezial returns HtmlAcceptedElement:
BinaryElementsSpezial | Image | Link | Text
;
BinaryElementsSpezial returns BinaryElements:
Italic | Underline | Paragraph
;


Bold:
'b' (htmlaccelement+=HtmlAcceptedElementSpezial )+ '/b'
;
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064692 is a reply to message #1064691] Thu, 20 June 2013 14:52 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin Tuzar
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

so is not an easier way? because then I have to do the same for italic and all others
and thanks for the quick answer!


Edwin W.T.
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064703 is a reply to message #1064692] Thu, 20 June 2013 15:07 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
Hat about a check?

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064715 is a reply to message #1064703] Thu, 20 June 2013 16:07 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin Tuzar
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Sorry, I don't get what you mean. What check? Or if you suggest to check in the grammar, how exactly is done that ?

Edwin W.T.
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064722 is a reply to message #1064715] Thu, 20 June 2013 16:29 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
No i Mean to solve it with Semantic validaton (javavalidator) instead of solving it in grammar
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064740 is a reply to message #1064722] Thu, 20 June 2013 18:34 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin Tuzar
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

yes i could do that, but then the suggestion (ctrl+space) will still show what I don't need (the Bold again)

Edwin W.T.
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064746 is a reply to message #1064740] Thu, 20 June 2013 18:54 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
Hi,

you could try to fix content assist but this might be even more work than introducing the additional rules as i suggested before.

Update: i dont know if there is a nice place to hook into content assist maybe
org.eclipse.xtext.ui.editor.contentassist.AbstractContentProposalProvider.createProposals(ContentAssistContext, ICompletionProposalAcceptor)
could serve as starting point.

[Updated on: Thu, 20 June 2013 19:00]

Report message to a moderator

Re: Xtext Grammar - Exclusion of a specific Rule [message #1064748 is a reply to message #1064746] Thu, 20 June 2013 19:01 Go to previous messageGo to next message
Edwin Tuzar is currently offline Edwin Tuzar
Messages: 33
Registered: April 2013
Location: Kaiserslautern
Member

Hi,
in the additional rules is a flaw imagine that you have the following use case: b i <<here>> /i /b or i b <<here>> /b /i
at <<here>> i can add again b (or i) and /b (or /i) that I don't want. This assuming what you proposed plus:

HtmlAcceptedElementSpezial returns HtmlAcceptedElement:
BinaryElementsSpezialItalic | Image | Link | Text
;
BinaryElementsSpezialItalic returns BinaryElements:
Bold | Underline | Paragraph
;


Italic:
'i' (htmlaccelement+=HtmlAcceptedElementSpezialItalic )+ '/i'
;


Thanks for all the effort!


Edwin W.T.
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064749 is a reply to message #1064748] Thu, 20 June 2013 19:10 Go to previous messageGo to next message
Christian Dietrich is currently online Christian Dietrich
Messages: 6305
Registered: July 2009
Senior Member
Sorry i dont know any out of the box solutions for this usecase.
and you are right the rules might explode.
unfortunately ParserBasedContentAssistContextFactory does not seem to have nice hooks for filtering.
and i dont know how easy skipping elements works on later states. (org.eclipse.xtext.ui.editor.contentassist.AbstractContentProposalProvider.createProposals(ContentAssistContext, ICompletionProposalAcceptor))
or even later.
Re: Xtext Grammar - Exclusion of a specific Rule [message #1064796 is a reply to message #1064689] Fri, 21 June 2013 07:30 Go to previous message
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 656
Registered: July 2009
Senior Member
You could write a separate rule for elements that can appear inside a
'Bold'. I would not recommend this, as the user would get an error from
the parser (unexpected token) instead of a helpful message (e.g. 'bold
not allowed within bold'). So rather be generous in the grammar and
cover these constraints with validation rules.


Am 20.06.13 16:47, schrieb Edwin Tuzar:
> So I have the following rules:
>
> HtmlAcceptedElement:
> BinaryElements | Image | Link | Text
> ;
>
>
> and
>
> BinaryElements:
> Bold | Italic | Underline | Paragraph
> ;
>
> now I want for Bold to do the following:
>
> Bold:
> 'b' (htmlaccelement+=HtmlAcceptedElement)+ '/b'
> ;
>
> but I want to don't allow Bold rule to be inside this:
> (htmlaccelement+=HtmlAcceptedElement)+ is this possible? to say somehow
> HtmlAcceptedElement except Bold ?
> Thanks in advance!
> Best regards,


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Previous Topic:Performing automatic corrections
Next Topic:How to test global scoping / xtext index
Goto Forum:
  


Current Time: Sat Sep 20 06:03:08 GMT 2014

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

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