| Column based grammar [message #1075405] |
Mon, 29 July 2013 07:18  |
Eclipse User |
|
|
|
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 #1075738 is a reply to message #1075596] |
Mon, 29 July 2013 21:07   |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04210 seconds