|
Re: How to emit error message if line length exceeds some threshold [message #918236 is a reply to message #917874] |
Thu, 20 September 2012 21:45 |
Henrik Lindberg Messages: 2509 Registered: July 2009 |
Senior Member |
|
|
On 2012-20-09 16:20, Tim Geisler wrote:
> Hi,
>
> in one project we have to implement a rather old-style language using
> Xtext where the length of lines is limited to 72 characters (seems to be
> designed for punched cards ... ;).
>
> Now, I'd like to have my Xtext-based editor to show error markers when a
> line exceeds 72 characters. The exceeding characters should be underlined.
>
> We already have an external lexer for this language which handles line
> comments correctly.
>
> One idea is to override the method nextToken() of the lexer. In this
> method, I can recognize the tokens which are outside the bounds. But,
> how to properly show the error markers using Xtext for these tokens?
>
> Best regards,
>
> Tim
That does not sound like the right place (for many reasons).
The easiest may be to do it with a Builder that manages its own markers.
It runs on resource changes however, so if you want it to be
interactive, you need to insert the logic in the sequence that is
normally run (lexing/parsing/linking).
The place to do this is the callback that occurs "afterModelLinked"
(override the linker and call your own additional validation). You then
simply obtain the text for the root and scan for lines that are longer
than your limit.
If possible (given the language), you could help users by fixing the
problem and split the lines on save automatically. If so, the builder
may be the better option.
For example of both a validating builder, and an overridden linker that
issues errors/warnings you can take a look at cloudsmith / geppetto @
github. Its linker is called PPResourceLinker.
Hope that helps.
- henrik
|
|
|
Re: How to emit error message if line length exceeds some threshold [message #918740 is a reply to message #918236] |
Fri, 21 September 2012 09:45 |
Sebastian Zarnekow Messages: 3118 Registered: July 2009 |
Senior Member |
|
|
Hi,
overriding #afterModelLinked or #beforeModelLinked and creating
RangeBasedDiagnostics (and add them resource.getErrors) seems the right
thing to do.
Regards,
Sebastian
--
Looking for professional support for Xtext, Xtend or Eclipse Modeling?
Go visit: http://xtext.itemis.com
Am 20.09.12 23:45, schrieb Henrik Lindberg:
> On 2012-20-09 16:20, Tim Geisler wrote:
>> Hi,
>>
>> in one project we have to implement a rather old-style language using
>> Xtext where the length of lines is limited to 72 characters (seems to be
>> designed for punched cards ... ;).
>>
>> Now, I'd like to have my Xtext-based editor to show error markers when a
>> line exceeds 72 characters. The exceeding characters should be
>> underlined.
>>
>> We already have an external lexer for this language which handles line
>> comments correctly.
>>
>> One idea is to override the method nextToken() of the lexer. In this
>> method, I can recognize the tokens which are outside the bounds. But,
>> how to properly show the error markers using Xtext for these tokens?
>>
>> Best regards,
>>
>> Tim
>
> That does not sound like the right place (for many reasons).
>
> The easiest may be to do it with a Builder that manages its own markers.
> It runs on resource changes however, so if you want it to be
> interactive, you need to insert the logic in the sequence that is
> normally run (lexing/parsing/linking).
>
> The place to do this is the callback that occurs "afterModelLinked"
> (override the linker and call your own additional validation). You then
> simply obtain the text for the root and scan for lines that are longer
> than your limit.
>
> If possible (given the language), you could help users by fixing the
> problem and split the lines on save automatically. If so, the builder
> may be the better option.
>
> For example of both a validating builder, and an overridden linker that
> issues errors/warnings you can take a look at cloudsmith / geppetto @
> github. Its linker is called PPResourceLinker.
>
> Hope that helps.
> - henrik
>
>
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02818 seconds