Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to make Xtext parser stop if a particular word is found?
How to make Xtext parser stop if a particular word is found? [message #723867] Fri, 09 September 2011 18:06 Go to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Greetings,

I have, IMHO, an unusual use case. There is an old version of the protocol buffer language that is very different to the actual (the open source) one. The problem is that the old and current version use the same file extension (.proto).

Since the old version is different that the current one, protobuf-dt (the Xtext-based editor for protos) shows syntax errors on files using the old syntax. There is no way to distinguish this two language versions from each other. Except for one keyword that is present in the old but not in the current language version.

Is there way to tell the Xtext parser something like "if you find keyword 'X' stop parsing and ignore any previous syntax errors"?

Many thanks in advance,
-Alex

(no subject) [message #723962 is a reply to message #723867] Sat, 10 September 2011 02:31 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Why not add the old syntax to the grammar to make it valid?
You can then detect if it is old or new syntax in the validator and flag
errors accordingly.

But maybe I misunderstood what you are trying to achieve...

- henrik

On 9/9/11 8:06 PM, Alex Ruiz wrote:
> Greetings,
>
> I have, IMHO, an unusual use case. There is an old version of the
> protocol buffer language that is very different to the actual (the open
> source) one. The problem is that the old and current version use the
> same file extension (.proto).
>
> Since the old version is different that the current one, protobuf-dt
> (the Xtext-based editor for protos) shows syntax errors on files using
> the old syntax. There is no way to distinguish this two language
> versions from each other. Except for one keyword that is present in the
> old but not in the current language version.
>
> Is there way to tell the Xtext parser something like "if you find
> keyword 'X' stop parsing and ignore any previous syntax errors"?
>
> Many thanks in advance,
> -Alex
>
>
Re: (no subject) [message #725098 is a reply to message #723962] Tue, 13 September 2011 23:48 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Thanks Henrik,

Adding the old syntax will make things go horrible wrong if a user accidentally uses syntax 1 mixed with sintax 2.

What I would like to do is to make the parser stop and ignore a file if one or more "words" are found. I hope there is a way to do this Smile

Cheers,
-Alex
Re: (no subject) [message #725109 is a reply to message #725098] Wed, 14 September 2011 00:23 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 9/14/11 1:48 AM, Alex Ruiz wrote:
> Thanks Henrik,
>
> Adding the old syntax will make things go horrible wrong if a user
> accidentally uses syntax 1 mixed with sintax 2.
>
Since you have to discover this somehow, you could just a well discover
that in validation. Flag the mix as an error?

> What I would like to do is to make the parser stop and ignore a file if
> one or more "words" are found. I hope there is a way to do this :)
>

What is supposed to happen if a user tries to open an "old file". What
do they get in the editor?

Normally the editor is registered by file extension. You would need to
do this by examining content instead - i.e. parse the file to see if it
should be parsed. In order to do this, you need a parser (unless you can
do it with a simpler scanner).

Regards
- henrik
Re: (no subject) [message #725416 is a reply to message #725109] Wed, 14 September 2011 17:57 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
Thanks Henrik.

The use case is not very usual, and it can be seeing as an odd one. The old syntax is valid, but:

1. We don't want to support the old syntax in the editor (as a way to encourage people to upgrade to the new version)
2. If users open a file with the old syntax, the editor should treat is as plain text (no syntax highlighting, outline, etc.)
3. Currently, if users open a file with the old syntax, the parser generates syntax errors that are inherited by imported files that use the new syntax. Users are complaining big time!
4. Both the old syntax and the new one have the same file extension!!

I'm not familiar with the solution you propose. I'll look into it in more detail.

Cheers!
-Alex
Re: (no subject) [message #725418 is a reply to message #725416] Wed, 14 September 2011 17:57 Go to previous messageGo to next message
Alex Ruiz is currently offline Alex RuizFriend
Messages: 103
Registered: March 2011
Senior Member
I meant I'm not familiar with custom scanners and parsers Smile
Re: (no subject) [message #725539 is a reply to message #725416] Thu, 15 September 2011 06:37 Go to previous messageGo to next message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

it might be possible to register your editor for a custom content type rather than the file extension alone. See the extension point definitions for
content type and editors.

The solution should rather be "open with the correct editor" rather than "let the editor handle wrong content".

Alex
Re: (no subject) [message #725540 is a reply to message #725416] Thu, 15 September 2011 06:39 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
How about allowing the old syntax and the new one in parallel but adapt
syntax highlighting?

Am 14.09.11 19:57, schrieb Alex Ruiz:
> Thanks Henrik.
>
> The use case is not very usual, and it can be seeing as an odd one. The
> old syntax is valid, but:
>
> 1. We don't want to support the old syntax in the editor (as a way to
> encourage people to upgrade to the new version)
> 2. If users open a file with the old syntax, the editor should treat is
> as plain text (no syntax highlighting, outline, etc.)
> 3. Currently, if users open a file with the old syntax, the parser
> generates syntax errors that are inherited by imported files that use
> the new syntax. Users are complaining big time!
> 4. Both the old syntax and the new one have the same file extension!!
>
> I'm not familiar with the solution you propose. I'll look into it in
> more detail.
>
> Cheers!
> -Alex


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
(no subject) [message #725541 is a reply to message #725416] Thu, 15 September 2011 06:37 Go to previous message
Alexander Nittka is currently offline Alexander NittkaFriend
Messages: 1193
Registered: July 2009
Senior Member
Hi,

it might be possible to register your editor for a custom content type rather than the file extension alone. See the extension point definitions for
http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_core_runtime_contentTypes.html and http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_core_runtime_contentTypes.html.

The solution should rather be "open with the correct editor" rather than "let the editor handle wrong content".

Alex


Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext@itemis.de
Re: (no subject) [message #725542 is a reply to message #725416] Thu, 15 September 2011 06:39 Go to previous message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
Senior Member
How about allowing the old syntax and the new one in parallel but adapt
syntax highlighting?

Am 14.09.11 19:57, schrieb Alex Ruiz:
> Thanks Henrik.
>
> The use case is not very usual, and it can be seeing as an odd one. The
> old syntax is valid, but:
>
> 1. We don't want to support the old syntax in the editor (as a way to
> encourage people to upgrade to the new version)
> 2. If users open a file with the old syntax, the editor should treat is
> as plain text (no syntax highlighting, outline, etc.)
> 3. Currently, if users open a file with the old syntax, the parser
> generates syntax errors that are inherited by imported files that use
> the new syntax. Users are complaining big time!
> 4. Both the old syntax and the new one have the same file extension!!
>
> I'm not familiar with the solution you propose. I'll look into it in
> more detail.
>
> Cheers!
> -Alex


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


---
Get professional support from the Xtext committers at www.typefox.io
Previous Topic:ImportUriGlobalScopeProvider can not find resource
Next Topic:Using Xtend2 in a non-xtext project
Goto Forum:
  


Current Time: Thu Sep 19 22:38:10 GMT 2024

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

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

Back to the top