From @vi@e@gross m@iii@g oii gm@ii@com  Fri Mar  1 15:30:30 2024
From: @vi@e@gross m@iii@g oii gm@ii@com (@vi@e@gross m@iii@g oii gm@ii@com)
Date: Fri, 1 Mar 2024 09:30:30 -0500
Subject: [Rd] capture "->"
In-Reply-To: <1cef84f8-a9d4-436a-a606-765a084a4a91@gmail.com>
References: <CAJL_pojF-Qc8YA0_eB+Ab9w3qD5sgMkjm0C3b0ooOmoOUy769w@mail.gmail.com>
 <ff87b48a-ccad-40ec-b79e-3fb4c945d3a9@gmail.com>
 <CAJL_pogbYhhLxsXQN0jjm83sZybh1nO1wE6F+CwNV18F9EkYUA@mail.gmail.com>
 <79f6c330-e5bf-4ad4-9ccc-ed47ab8dcb69@gmail.com>
 <CAJL_poiOUuBfPLqa3uTswA=1LG=1CZeBR9XudSaFQYbesQG+cA@mail.gmail.com>
 <1cef84f8-a9d4-436a-a606-765a084a4a91@gmail.com>
Message-ID: <005b01da6be5$0361b9f0$0a252dd0$@gmail.com>

I am wondering what the specific need for this is or is it just an exercise?

Where does it matter if a chunk of code assigns using "<-" beforehand or "->" after hand, or for that matter assigns indirectly without a symbol?

And whatever you come up with, will it also support the global assignment of "->>" as compared to ""<<-" too?

I do wonder if you can re-declare the assignment operators or would that mess up the parser.

-----Original Message-----
From: R-devel <r-devel-bounces at r-project.org> On Behalf Of Duncan Murdoch
Sent: Friday, March 1, 2024 9:23 AM
To: Dmitri Popavenko <dmitri.popavenko at gmail.com>
Cc: r-devel <r-devel at r-project.org>
Subject: Re: [Rd] capture "->"

On 01/03/2024 8:51 a.m., Dmitri Popavenko wrote:
> On Fri, Mar 1, 2024 at 1:00?PM Duncan Murdoch <murdoch.duncan at gmail.com 
> <mailto:murdoch.duncan at gmail.com>> wrote:
> 
>     ...
>     I was thinking more of you doing something like
> 
>        parse(text = "A -> B", keep.source = TRUE)
> 
>     I forget what the exact rules are for attaching srcrefs to arguments of
>     functions, but I do remember they are a little strange, because not
>     every possible argument can accept a srcref attribute.  For example,
>     you
>     can't attach one to NULL, or to a name.
> 
>     Srcrefs are also fairly big and building them is slow, so I think we
>     tried to limit them to where they were needed, we didn't try to attach
>     them to every subexpression, just one per statement.  Each expression
>     within {} is a separate statement, so we get srcrefs attached to the {.
>     But in "foo(A -> B)" probably you only get one on the foo call.
> 
>     In some circumstances you could get the srcref on that call by looking
>     at sys.call().  But then things are complicated again, because R
>     doesn't
>     attach srcrefs to things typed at the console, only to things that are
>     sourced from files or text strings (and parsed with keep.source=TRUE).
> 
>     So I think you should probably require input from a string or a
>     file, or
>     not expect foo(A -> B) to work without some decoration.
> 
> 
> Indeed, the more challenging task is to identify "->" at the console
> (from a script or a string, seems trivial now).
> 
> I would be willing to decorate as much as it takes to make this work, I 
> am just empty on more ideas how to persuade the parser.

By "decorate", I meant putting it in quotes and parsing it using 
parse(text=...), or putting it in braces as you found.  I think parsing 
a string is most likely to be reliable because someone might turn off 
`keep.source` and then the braced approach would fail.  But you have 
control over it when you call parse() yourself.

Duncan Murdoch

______________________________________________
R-devel at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] capture "->"
@vi@e@gross m@iii@g oii gm@ii@com