From 1a0ad1a5ae6d2d31c86a113f38cf1466aef8a0c3 Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Mon, 27 Nov 2017 13:00:06 +0100 Subject: [PATCH] allow string constants in :: and ::: --- .../truffle/r/parser/ParserGeneration.java | 3 ++- .../src/com/oracle/truffle/r/parser/R.g | 21 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/ParserGeneration.java b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/ParserGeneration.java index d8a65710b8..0aaa94d549 100644 --- a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/ParserGeneration.java +++ b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/ParserGeneration.java @@ -95,6 +95,7 @@ public class ParserGeneration { "convert line endings", "handle four and more dots as identifier", "allow greek characters in identifiers", - "allow everything but newlines in %<ident>% operators" + "allow everything but newlines in %<ident>% operators", + "allow strings in :: and :::" }; } diff --git a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g index ee30927021..439c593195 100644 --- a/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g +++ b/com.oracle.truffle.r.parser/src/com/oracle/truffle/r/parser/R.g @@ -483,7 +483,7 @@ basic_expr returns [T v] ; simple_expr returns [T v] - @init { Token start = input.LT(1); } + @init { Token start = input.LT(1); List<Argument<T>> args = new ArrayList<>(); Token compToken = null; } : i=id { $v = builder.lookup(src($i.v), $i.text, false); } | b=bool { $v = builder.constant(src(start, last()), $b.v); } | d=DD { $v = builder.lookup(src($d), $d.text, false); } @@ -496,14 +496,21 @@ simple_expr returns [T v] | t=NACOMPL { $v = builder.constant(src($t), RComplex.createNA()); } | num=number { $v = $num.v; } | cstr=conststring { $v = $cstr.v; } - | pkg=id op=(NS_GET|NS_GET_INT) n_ comp=id { - List<Argument<T>> args = new ArrayList<>(); + | pkg=id op=(NS_GET|NS_GET_INT) n_ { SourceSection pkgSource = src($pkg.v); - SourceSection compSource = src($comp.v); args.add(RCodeBuilder.argument(pkgSource, "pkg", builder.lookup(pkgSource, $pkg.text, false))); - args.add(RCodeBuilder.argument(compSource, "name", builder.lookup(compSource, $comp.text, false))); - $v = builder.call(src($pkg.v, $comp.v), operator($op), args); - } + } + ( compId=id { + SourceSection compSource = src($compId.v); + compToken = $compId.v; + args.add(RCodeBuilder.argument(compSource, "name", builder.lookup(compSource, $compId.text, false))); + } + | compString=STRING { + SourceSection compSource = src($compString); + compToken = $compString; + args.add(RCodeBuilder.argument(compSource, "name", builder.constant(compSource, $compString.text))); + } + ) { $v = builder.call(src($pkg.v, compToken), operator($op), args); } | op=LPAR n_ ea=expr_or_assign n_ y=RPAR { $v = builder.call(src($op, $y), operator($op), $ea.v); } | s=sequence { $v = $s.v; } | e=expr_wo_assign { $v = $e.v; } -- GitLab