Skip to content
Browse files

Perlito5 - parser - string interpolation fix

  • Loading branch information...
1 parent 09eb964 commit efdbc04b061a4f36cd4a8fb4e889336221a0ba5b @fglock committed Nov 14, 2012
Showing with 92 additions and 1 deletion.
  1. +0 −1 TODO-perlito5
  2. +34 −0 html/perlito5.js
  3. +31 −0 perlito5.pl
  4. +27 −0 src5/lib/Perlito5/Grammar/String.pm
View
1 TODO-perlito5
@@ -61,7 +61,6 @@ TODO list for Perlito5
--- check signature in sort()
--- fix the prototype for 'stat(*)' (see t/test.pl in the perl test suite)
--- $v->{x} doesn't interpolate inside double quotes
-- deref inside double quotes:
$ node perlito5.js -Bjs -e ' my $x = "123"; my $y = \$x; print "[$$y]\n" '
[$[object Object]]
View
34 html/perlito5.js
@@ -9564,6 +9564,40 @@ var p5100 = p5pkg['main'];
var v_p;
(v_p = (v_pos));
var v_m_index;
+ if ( (p5pkg["Perlito5::Grammar::String"].substr([v_str, v_p, 3], 0) == '->[') ) {
+ (function () {
+ (v_p = ((p5num(v_p) + 3)));
+ (v_m_index = (p5call(p5pkg["Perlito5::Expression"], "list_parse", [v_str, v_p], 0)));
+ if ( p5bool(v_m_index) ) {
+ null;
+ }
+ else {
+ p5pkg["Perlito5::Grammar::String"].die([['syntax error']], null);
+ };
+ var v_exp;
+ (v_exp = ((v_m_index || (v_m_index = new p5HashRef({})))._hash_.p5hget('capture')));
+ (v_p = ((v_m_index || (v_m_index = new p5HashRef({})))._hash_.p5hget('to')));
+ if ( ((p5str(v_exp) == '*undef*') || (p5pkg["Perlito5::Grammar::String"].substr([v_str, v_p, 1], 0) != ']')) ) {
+ p5pkg["Perlito5::Grammar::String"].die([['syntax error']], null);
+ };
+ (v_p)++;
+ (v_m_index || (v_m_index = new p5HashRef({})))._hash_.p5hset('capture', (p5call(p5pkg["Perlito5::AST::Call"], "new", p5list_to_a('method', 'postcircumfix:<[ ]>', 'invocant', (v_m_var || (v_m_var = new p5HashRef({})))._hash_.p5hget('capture'), 'arguments', v_exp), 0)));
+ (v_m_index || (v_m_index = new p5HashRef({})))._hash_.p5hset('to', (v_p));
+ throw(p5call(v_self, "double_quoted_var_with_subscript", [v_m_index, v_interpolate], p5want));
+ })();
+ };
+ if ( (p5pkg["Perlito5::Grammar::String"].substr([v_str, v_p, 3], 0) == '->{') ) {
+ (v_pos = ((p5num(v_pos) + 2)));
+ (v_m_index = (p5call(p5pkg["Perlito5::Expression"], "term_curly", [v_str, v_pos], 0)));
+ if ( p5bool(v_m_index) ) {
+ null;
+ }
+ else {
+ p5pkg["Perlito5::Grammar::String"].die([['syntax error']], null);
+ };
+ (v_m_index || (v_m_index = new p5HashRef({})))._hash_.p5hset('capture', (p5call(p5pkg["Perlito5::AST::Call"], "new", p5list_to_a('method', 'postcircumfix:<{ }>', 'invocant', (v_m_var || (v_m_var = new p5HashRef({})))._hash_.p5hget('capture'), 'arguments', (p5pkg["Perlito5::Match"].flat([v_m_index], p5want) || (p5pkg["Perlito5::Match"].flat([v_m_index], p5want) = new p5ArrayRef([])))._array_.p5aget_array(2)._array_.p5aget(0)), 0)));
+ throw(p5call(v_self, "double_quoted_var_with_subscript", [v_m_index, v_interpolate], p5want));
+ };
if ( (p5pkg["Perlito5::Grammar::String"].substr([v_str, v_p, 1], 0) == '[') ) {
if ( (p5num(v_interpolate) == 2) ) {
(function () {
View
31 perlito5.pl
@@ -5086,6 +5086,37 @@ sub Perlito5::Grammar::String::double_quoted_var_with_subscript {
((my $pos) = $m_var->{'to'});
((my $p) = $pos);
(my $m_index);
+ if ((substr($str, $p, 3) eq '->[')) {
+ ($p = ($p + 3));
+ ($m_index = Perlito5::Expression->list_parse($str, $p));
+ if ($m_index) {
+
+ }
+ else {
+ die('syntax error')
+ };
+ ((my $exp) = $m_index->{'capture'});
+ ($p = $m_index->{'to'});
+ if ((($exp eq '*undef*') || (substr($str, $p, 1) ne ']'))) {
+ die('syntax error')
+ };
+ ($p)++;
+ ($m_index->{'capture'} = Perlito5::AST::Call->new('method', 'postcircumfix:<[ ]>', 'invocant', $m_var->{'capture'}, 'arguments', $exp));
+ ($m_index->{'to'} = $p);
+ return ($self->double_quoted_var_with_subscript($m_index, $interpolate))
+ };
+ if ((substr($str, $p, 3) eq '->{')) {
+ ($pos = ($pos + 2));
+ ($m_index = Perlito5::Expression->term_curly($str, $pos));
+ if ($m_index) {
+
+ }
+ else {
+ die('syntax error')
+ };
+ ($m_index->{'capture'} = Perlito5::AST::Call->new('method', 'postcircumfix:<{ }>', 'invocant', $m_var->{'capture'}, 'arguments', Perlito5::Match::flat($m_index)->[2]->[0]));
+ return ($self->double_quoted_var_with_subscript($m_index, $interpolate))
+ };
if ((substr($str, $p, 1) eq '[')) {
if (($interpolate == 2)) {
((my $m) = ((Perlito5::Expression->term_digit($str, ($p + 1)) || (((substr($str, ($p + 1), 1) eq '-') && Perlito5::Expression->term_digit($str, ($p + 2))))) || Perlito5::Grammar::Sigil->term_sigil($str, ($p + 1))));
View
27 src5/lib/Perlito5/Grammar/String.pm
@@ -715,6 +715,33 @@ sub double_quoted_var_with_subscript {
my $pos = $m_var->{to};
my $p = $pos;
my $m_index;
+ if (substr($str, $p, 3) eq '->[') {
+ $p += 3;
+ $m_index = Perlito5::Expression->list_parse($str, $p);
+ die "syntax error" unless $m_index;
+ my $exp = $m_index->{capture};
+ $p = $m_index->{to};
+ die "syntax error" if $exp eq '*undef*' || substr($str, $p, 1) ne ']';
+ $p++;
+ $m_index->{capture} = Perlito5::AST::Call->new(
+ method => 'postcircumfix:<[ ]>',
+ invocant => $m_var->{capture},
+ arguments => $exp,
+ );
+ $m_index->{to} = $p;
+ return $self->double_quoted_var_with_subscript($m_index, $interpolate);
+ }
+ if (substr($str, $p, 3) eq '->{') {
+ $pos += 2;
+ $m_index = Perlito5::Expression->term_curly($str, $pos);
+ die "syntax error" unless $m_index;
+ $m_index->{capture} = Perlito5::AST::Call->new(
+ method => 'postcircumfix:<{ }>',
+ invocant => $m_var->{capture},
+ arguments => Perlito5::Match::flat($m_index)->[2][0],
+ );
+ return $self->double_quoted_var_with_subscript($m_index, $interpolate);
+ }
if (substr($str, $p, 1) eq '[') {
if ($interpolate == 2) {

0 comments on commit efdbc04

Please sign in to comment.
Something went wrong with that request. Please try again.