Skip to content
Prev 40249 / 63421 Next

Recursively parsing srcrefs

On 12/05/2011 3:59 PM, Hadley Wickham wrote:
I don't think you will get exactly the same thing.  The problem is that 
srcrefs are attributes, and not all statements can have attributes 
attached to them, so the attributes are attached to the container of the 
statements.  (For example, NULL is a statement and it is stored as the 
NULL object, but the NULL object can't have any attributes on it.) In 
those two cases, the containers are different, so I would expect some 
differences between what's in f and what's in f_inside (though I expect 
you could convert one to the other).
It searches through the parse tree for the smallest source ref that 
contains a given line.  So for example,

if(condition) {
   blah
   blah
   blah
}

is a single statement, and there will be a srcref stored in its 
container that goes from line N to line N+4.  But it also contains the 
compound statement

{
   blah
   blah
   blah
}

and there will be srcrefs attached to that for each of the statements in 
it.  (I forget right now whether there are 3 or 4 statements there:  R 
treats braces in a funny way, and I'd have to look at an example to 
check.)  Each of the "blah"'s will get a srcref spanning one line, and 
it will be stored in the container.
You can't easily do that.  The current parser only attaches srcrefs down 
to the statement level, and the + is part of the statement which parses 
to "+ 2".  (The 1 is a separate statement.)

Duncan Murdoch