Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Column based grammar
Column based grammar [message #1075405] Mon, 29 July 2013 11:18 Go to next message
Paulo Dias is currently offline Paulo DiasFriend
Messages: 4
Registered: July 2013
Junior Member
I want to implement a grammar that uses the columns to validate the syntax.
For example, I want to validate that a specific keyword is written between the column 1 and the column 3 and that from the column 30 to the end of line it will be considered as a comment.
Is that possible using xtext and if yes can you provide an example?
Thanks very much,
Re: Column based grammar [message #1075500 is a reply to message #1075405] Mon, 29 July 2013 14:36 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-29-07 15:24, Paulo Dias wrote:
> I want to implement a grammar that uses the columns to validate the syntax.
> For example, I want to validate that a specific keyword is written
> between the column 1 and the column 3 and that from the column 30 to the
> end of line it will be considered as a comment.
> Is that possible using xtext and if yes can you provide an example?
> Thanks very much,

The easiest is to do this in the validator. Simply get the source
position from the node model and perform your validation based on that.

Regards
- henrik
Re: Column based grammar [message #1075596 is a reply to message #1075500] Mon, 29 July 2013 18:08 Go to previous messageGo to next message
Paulo Dias is currently offline Paulo DiasFriend
Messages: 4
Registered: July 2013
Junior Member
I think I do not explained correctly the issue.

I'm not talking about validation, but to have that rules enforced by the grammar. Explaining better (I hope so):

Is there a way to specify on a rule that expresses that a specific keyword is only upper case with 3 of size and starts at column 1 or that the comment can be any character starting at position (column) 30 til the end of line.

Thanks
Re: Column based grammar [message #1075738 is a reply to message #1075596] Tue, 30 July 2013 01:07 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2013-29-07 20:08, Paulo Dias wrote:
> I think I do not explained correctly the issue.
>
> I'm not talking about validation, but to have that rules enforced by the
> grammar. Explaining better (I hope so):
>
It is a really bad idea - because the user will be hammered with syntax
errors without further explanation or help. IMHO, you want to do this in
validation; that is almost the same as having the grammar enforce it. If
you want other features like code completion to behave differently
depending on where on the line it is invoked, you need to also handle
that naturally.

As a rule of thumb, the grammar should be as forgiving as possible since
this enables you to give the user a better editing/quick fix experience.

When you implement it this way, and something is in error, you can
provide the user with quick fixes like "move it/indent it, put it first
on the line, etc...".

> Is there a way to specify on a rule that expresses that a specific
> keyword is only upper case with 3 of size and starts at column 1 or that
> the comment can be any character starting at position (column) 30 til
> the end of line.
>
No.

The way to do it would be to enforce/check it in the lexer and emit
different tokens. This would only lead to grammatical errors which will
manifest themselves as syntax errors to the user.

> Thanks
Re: Column based grammar [message #1075858 is a reply to message #1075738] Tue, 30 July 2013 08:04 Go to previous message
Paulo Dias is currently offline Paulo DiasFriend
Messages: 4
Registered: July 2013
Junior Member
Ok, I understand the implications.

Thanks for your help.
Previous Topic:Scoping: "Nested" references
Next Topic:import statement
Goto Forum:
  


Current Time: Fri Apr 26 15:24:12 GMT 2024

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

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

Back to the top