Permalink
Browse files

can parse unquotes in quasis

This now works:

    $ ./perl6 -e 'say "OH HAI"; my $a; {{{$a}}}'
    ===SORRY!===
    Can only use unquote syntax inside a quasi block
    at -e:1

    $ ./perl6 -e 'say "OH HAI"; my $a; quasi { say "woo!"; {{{$a}}} }'
    OH HAI
  • Loading branch information...
1 parent 5ceefd9 commit 98591b486467b72f925d3cea0bcfa7155f6e313c @masak masak committed Jul 28, 2012
Showing with 16 additions and 1 deletion.
  1. +12 −1 src/Perl6/Grammar.pm
  2. +4 −0 src/core/Exception.pm
View
@@ -448,6 +448,9 @@ grammar Perl6::Grammar is HLL::Grammar {
:my $*POD_PAST;
:my $*DECLARATOR_DOCS;
+ # Quasis and unquotes
+ :my $*IN_QUASI := 0; # whether we're currently in a quasi block
+
# Setting loading and symbol setup.
{
# Create unit outer (where we assemble any lexicals accumulated
@@ -934,6 +937,12 @@ grammar Perl6::Grammar is HLL::Grammar {
token term:sym<lambda> { <?lambda> <pblock> }
token term:sym<type_declarator> { <type_declarator> }
token term:sym<value> { <value> }
+ token term:sym<unquote> {
+ '{{{'
+ [<?{ !$*IN_QUASI }> <.typed_panic: "X::Syntax::UnquoteOutsideQuasi">]
+ <EXPR>
+ '}}}'
+ }
# XXX temporary Bool::True/Bool::False until we can get a permanent definition
token term:sym<boolean> { 'Bool::'? $<value>=[True|False] » }
@@ -2277,7 +2286,9 @@ grammar Perl6::Grammar is HLL::Grammar {
}
token quote:sym<quasi> {
- <sym> <.ws> <!before '('> <block>
+ <sym> <.ws> <!before '('>
+ :my $*IN_QUASI := 1;
+ <block>
}
token quote_escape:sym<$> {
View
@@ -658,6 +658,10 @@ my class X::Syntax::InfixInTermPosition does X::Syntax {
}
}
+my class X::Syntax::UnquoteOutsideQuasi does X::Syntax {
+ method message() { 'Can only use unquote syntax inside a quasi block'; }
+}
+
my class X::Attribute::Package does X::Comp {
has $.package-kind;
has $.name;

0 comments on commit 98591b4

Please sign in to comment.