Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Make a block ignored by Parser
Make a block ignored by Parser [message #1733818] Wed, 01 June 2016 07:40 Go to next message
Jonathan L. is currently offline Jonathan L.Friend
Messages: 24
Registered: May 2016
Junior Member
Hi,

I'm implementing an Editor for an existing Language.
In this Language a C integration is possible with the structure:
native do
/* C code*/
end

Since a real C integration would be difficult (or are there any recommendations?) I want to make the Parser ignoring the block between 'do' and 'end'.
How do I realize this?

I can't do it with the '->' operator in a terminal rule, because in other rules there are also 'do'-'end'-blocks used.

Can someone please help me with this?
Re: Make a block ignored by Parser [message #1733854 is a reply to message #1733818] Wed, 01 June 2016 13:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
sounds like a good usecase for a custom/stateful lexer.

or you enumerate all stuff like ( dont know if this works i a smooth way)

CODE: "keyword1"|...."keywordn" | ID | INT | ANY_OTHER | ....;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Make a block ignored by Parser [message #1733862 is a reply to message #1733854] Wed, 01 June 2016 14:16 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
but do you not want to ignore "native do"->"end" ?
Re: Make a block ignored by Parser [message #1733866 is a reply to message #1733862] Wed, 01 June 2016 14:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
spaces in keywords a VERY bad thing in xtext

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

[Updated on: Wed, 01 June 2016 14:26]

Report message to a moderator

Re: Make a block ignored by Parser [message #1733897 is a reply to message #1733866] Thu, 02 June 2016 04:55 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 250
Registered: June 2013
Senior Member
Christian Dietrich wrote on Wed, 01 June 2016 10:26
spaces in keywords a VERY bad thing in xtext

... but will it do what is required?
I don't think enumerating all possible C-code elements are a feasible option.

[Updated on: Thu, 02 June 2016 04:56]

Report message to a moderator

Re: Make a block ignored by Parser [message #1733899 is a reply to message #1733897] Thu, 02 June 2016 05:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
well you can wlqays give it a try.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Make a block ignored by Parser [message #1733906 is a reply to message #1733854] Thu, 02 June 2016 07:00 Go to previous messageGo to next message
Jonathan L. is currently offline Jonathan L.Friend
Messages: 24
Registered: May 2016
Junior Member
Hi,

thanks for the quick answers.

Quote:
but do you not want to ignore "native do"->"end" ?


The meaning of the rule would look like
Native:
  ('native' | 'native/pre') 'do' -> 'end'
;

So the keywords are given and shall be highlighted, but everything between 'do' and 'end' shall be ignored and doesn't need to be highlighted. Basically like an ML_COMMENT, but without the '/*' and '*/'

Quote:
or you enumerate all stuff like ( dont know if this works i a smooth way)

CODE: "keyword1"|...."keywordn" | ID | INT | ANY_OTHER | ....;


do you mean something like this? :
Native:
	('native' | 'native/pre') 'do' e=enumRule 'end'
;
enum enumRule:
	ID | INT | STRING | ANY_OTHER
;

When I tried this it also doesn't accept anything within the block Confused
Re: Make a block ignored by Parser [message #1733909 is a reply to message #1733906] Thu, 02 June 2016 07:25 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
no i mean

Native:
('native' | 'native/pre') 'do' e=Stuff 'end'
;
Stuff:
(ID | INT | STRING | ANY_OTHER)*
;


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Make a block ignored by Parser [message #1733919 is a reply to message #1733818] Thu, 02 June 2016 08:47 Go to previous messageGo to next message
Jonathan L. is currently offline Jonathan L.Friend
Messages: 24
Registered: May 2016
Junior Member
Ah yes that works better thanks!
I guess I have to see if it will suffice.

But I got a weird problem.. In a smaller Test-"language" it works, but in my final implementation it produces the error: " extraneous input 'content of block' expecting 'end' "
in both the rules are the same...

Another idea I have is to do a workaround with the Validator or something. Is there a possibility to suppress error messages at certain positions?

Else I guess I will give the custom Lexer a try.

Thanks in advance!
Re: Make a block ignored by Parser [message #1733921 is a reply to message #1733919] Thu, 02 June 2016 08:58 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
as i said you may have to enlist keywords as well

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:xtext create custom import wizard
Next Topic:Highlighting Issues with related keyword varieties
Goto Forum:
  


Current Time: Tue Apr 23 13:12:59 GMT 2024

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

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

Back to the top