Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Column oriented editors
icon5.gif  Column oriented editors [message #762760] Thu, 08 December 2011 15:31 Go to next message
Jeff MAURY is currently offline Jeff MAURYFriend
Messages: 44
Registered: July 2009
Member
I am using Xtext to build an editor for an old language that have some constraints on the location for some tokens.
So, my idea was to validate using the validation api those tokens against their position in the document.
Do you know if we can retrieve the line and column informations for a given token/rule ?

Regards
Jeff MAURY
Re: Column oriented editors [message #762848 is a reply to message #762760] Thu, 08 December 2011 17:40 Go to previous messageGo to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
The line and offset information is available in the node model, but not
column position on line. You have to calculate that afaik.

Note, that when validating, you may not have a node model attached yet
(serialization from model, a semantic quickfix, etc.), so you need to
figure out what to do in those cases.

- henrik

On 2011-08-12 16:31, Jeff MAURY wrote:
> I am using Xtext to build an editor for an old language that have some
> constraints on the location for some tokens.
> So, my idea was to validate using the validation api those tokens
> against their position in the document.
> Do you know if we can retrieve the line and column informations for a
> given token/rule ?
>
> Regards
> Jeff MAURY
Re: Column oriented editors [message #762851 is a reply to message #762848] Thu, 08 December 2011 17:51 Go to previous messageGo to next message
Jeff MAURY is currently offline Jeff MAURYFriend
Messages: 44
Registered: July 2009
Member
Do you mean in the EMF generated model ?
I can figure out where the info is ?
Do you have a sample ?

Thanks
Jeff MAURY
Re: Column oriented editors [message #762867 is a reply to message #762851] Thu, 08 December 2011 18:28 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
On 2011-08-12 18:51, Jeff MAURY wrote:
> Do you mean in the EMF generated model ?
> I can figure out where the info is ?
> Do you have a sample ?
>
When the text is parsed it builds a node model. It is separate from the
the semantic model, and you can find the node model by using the
NodeModelUtils class (nodes are attached to the semantic model elements
via EMF adapters) - the utils makes it easy to find things.

The closest thing I have written is the comment processing for
cloudsmith/geppetto (at github). You would be doing something similar,
to find the beginning of a line.

Look at
org.cloudsmith.geppetto.pp.dsl.linking.DocumentationAssociator.processCommentNode(INode,
List<PPTask>) as an example.


Basically, the brute force method is:
- get the text of the resource as a string
- for each element to validate, use util to get the node
- get start offset for the node
- scan backwards in the text from the start offset (until start or NL)
- offset diff is the column

You also have to deal with the formatter - it is important that your
model serializes correctly or you will not be able to produce valid
source from model (which is required if you want to perform certain
operations like semantic quick fix). (i.e. if formatting does not place
things where they are required to be, you will get error markers as side
effect of formatting).

Hope that helps.
- henrik
Previous Topic:Null Pointer Exception while opening xtext editor with a non workspace file
Next Topic:Generator Problems with xtext 2.1.1
Goto Forum:
  


Current Time: Thu Apr 25 04:30:20 GMT 2024

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

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

Back to the top