Skip to content
Back to formatted view

Raw Message

Message-ID: <CABtg=KkwE5msPb1PyV3Lo1LgpkOtuiEv_BFEwZmswG-7Fa4ADA@mail.gmail.com>
Date: 2020-04-13T08:32:16Z
From: Gábor Csárdi
Subject: detect ->
In-Reply-To: <CAD4oTHFUe+W+bBtC-e9uhOGkJUMTV317xPETXS+7iW-v9m7iNg@mail.gmail.com>

On Mon, Apr 13, 2020 at 9:23 AM Gabriel Becker <gabembecker at gmail.com> wrote:
[...]
> This means the only feasible way to detect it, which a few projects do I believe, is process the code while it is still raw text, before it goes into the parser, and have clever enough regular expressions.

Well, especially considering R's news raw strings with user defined
delimiters, regular expressions are not the best here, I think. OTOH
the source references do keep the right assignment. So if you can
re-parse the data, you can detect them:

? x <- parse(text = "A -> B", keep.source=FALSE)
? x
expression(B <- A)

? x <- parse(text = "A -> B")
? x
expression(A -> B)

? getParseData(x)
  line1 col1 line2 col2 id parent        token terminal text
7     1    1     1    6  7      0         expr    FALSE
1     1    1     1    1  1      3       SYMBOL     TRUE    A
3     1    1     1    1  3      7         expr    FALSE
2     1    3     1    4  2      7 RIGHT_ASSIGN     TRUE   ->
4     1    6     1    6  4      6       SYMBOL     TRUE    B
6     1    6     1    6  6      7         expr    FALSE

Gabor

[...]