Start and end positions

Benedikt Huber benedikt.huber at gmail.com
Thu Jun 4 08:38:48 EDT 2009


On 01.06.2009, at 22:29, Aaron Tomb wrote:
> Hello,
>
> A number of parsers that I've encountered before decorate their ASTs
> with two pieces of position information: a start position and an end
> position. Currently, Language.C only has one piece of position
> information, although I notice that there is a PosLength data type in
> Language.C.Data.Position.
Hi Aaron,
The function you're looking for is getLastTokenPos.
A while ago I discussed this with John von Enk (http://www.sivity.net/projects/language.c/wiki/SourceCodeAnnotations 
).
Language.C supports exactly what you asked for, given preprocessed  
source.
In the presence of macros, the position information is neccessarily  
inaccurate;
you need cooperation from the preprocessor for exact back annotation  
then.

> Does anyone have any thoughts on either adding an end position or
> making wider use of PosLength?
Please have a look at the (incomplete) sourceview example.

> Of course, there will be an issue with
> preprocessor macros, as there is with the current position
> information. However, it seems as though start and end line numbers
> would still be useful, even if column information is unreliable.
As I said, I've added this some time ago. It wasn't that easy, and I'm  
pretty sure
the current implementation is still buggy, so I'm grateful for any bug  
reports.

I'm sorry I don't have much time to spend on the project lately, but  
if the analysis stuff
you have been working on is in good shape, I'll release a new version  
on hackage this
weekend.

benedikt



More information about the Language-c mailing list