Skip to content

Commit

Permalink
Get strings working. With this, we pass a few of the simple tests in …
Browse files Browse the repository at this point in the history
…t/nqp again.
  • Loading branch information
jnthn committed Aug 4, 2012
1 parent 375dfd0 commit 753dc29
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions src/NQPQ/Actions.pm
Expand Up @@ -1076,7 +1076,7 @@ class NQP::Actions is HLL::Actions {
# XXX This should be in Parrot-specific module and need a pragma.
my $cpast := $<circumfix>[0].ast;
$/.CURSOR.panic("Trait 'parrot_vtable' requires constant scalar argument")
unless $cpast ~~ PAST::Val;
unless $cpast ~~ QAST::SVal;
my $name := $cpast.value;
my $package := $*PACKAGE;
my $is_dispatcher := $*SCOPE eq 'proto';
Expand All @@ -1089,7 +1089,7 @@ class NQP::Actions is HLL::Actions {
# XXX This should be in Parrot-specific module and need a pragma.
my $cpast := $<circumfix>[0].ast;
$/.CURSOR.panic("Trait 'parrot_vtable_handler' requires constant scalar argument")
unless $cpast ~~ PAST::Val;
unless $cpast ~~ QAST::SVal;
my $name := $cpast.value;
my $package := $*PACKAGE;
make -> $match {
Expand Down Expand Up @@ -1345,6 +1345,53 @@ class NQP::Actions is HLL::Actions {
QAST::NVal.new( :value($value) ) !!
QAST::IVal.new( :value($value) );
}

method quote_EXPR($/) {
my $past := $<quote_delimited>.ast;
if %*QUOTEMOD<w> {
if nqp::istype($past, QAST::SVal) {
my @words := HLL::Grammar::split_words($/, $past.value);
if +@words != 1 {
$past := QAST::Op.new( :op('list'), :node($/) );
for @words { $past.push($_); }
}
else {
$past := ~@words[0];
}
}
else {
$/.CURSOR.panic("Can't form :w list from non-constant strings (yet)");
}
}
make $past;
}

method quote_delimited($/) {
my @parts;
my $lastlit := '';
for $<quote_atom> {
my $ast := $_.ast;
if !nqp::istype($ast, QAST::Node) {
$lastlit := $lastlit ~ $ast;
}
elsif nqp::istype($ast, QAST::SVal) {
$lastlit := $lastlit ~ $ast.value;
}
else {
if $lastlit gt '' {
@parts.push(QAST::SVal.new( :value($lastlit) ));
}
@parts.push($ast);
$lastlit := '';
}
}
if $lastlit gt '' { @parts.push(QAST::SVal.new( :value($lastlit) )); }
my $past := @parts ?? @parts.shift !! QAST::SVal.new( :value('') );
while @parts {
$past := QAST::Op.new( $past, @parts.shift, :op('concat') );
}
make $past;
}

method quote:sym<apos>($/) { make $<quote_EXPR>.ast; }
method quote:sym<dblq>($/) { make $<quote_EXPR>.ast; }
Expand Down

0 comments on commit 753dc29

Please sign in to comment.