Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Enable use of $¢ in grammars
Unfortunately only works inside regex/token/rules, bare regexes (like
$foo ~~ /bar/) don't get the right $¢ . I've tried everything to fix
this, but the solution is apparently not going to be that simple.

    my token foo {AB {say $¢.pos} C}; "ABC" ~~ /<&foo>/; # says '2'
    "ABC" ~~ /AB {say $¢.pos} C/;                        # says 'Nil'

Closest I got was manually removing $¢ from $past in regex_coderef after
qbuildsub (and since qbuildsub will put a $¢ in there if you don't,
better to put one in there you could more reliably remove afterward),
but then eval'd regexes, e.g. EVAL('$foo ~~ /bar/'), complain about not
being able to resolve lexical $¢ .

The best I can guess is that the bare regexes pass a clean slate for the
$block arg of 'regex_coderef', instead of the popped lexpad
rule/token/regex gives, but I don't know how exactly that affects
things, much less how to fix the issue based on that (if it's the source
of the problems).
  • Loading branch information
ShimmerFairy committed Aug 22, 2015
1 parent 28faf19 commit edffe05
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/Perl6/Actions.nqp
Expand Up @@ -1133,7 +1133,7 @@ Compilation unit '$file' contained the following violations:
unless $BLOCK.symbol('$_') || $*IMPLICIT {
$*W.install_lexical_magical($BLOCK, '$_');
}
for <$/ $!> {
for <$/ $!> {
unless $BLOCK.symbol($_) {
$*W.install_lexical_magical($BLOCK, $_);
}
Expand Down Expand Up @@ -3010,7 +3010,7 @@ Compilation unit '$file' contained the following violations:
if nqp::istype($_, QAST::Var) && $_.scope eq 'lexical' {
my $name := $_.name;
return 0 if $name ne '$*DISPATCHER' && $name ne '$_' &&
$name ne '$/' && $name ne '$!' &&
$name ne '$/' && $name ne '$¢' && $name ne '$!' &&
!nqp::existskey(%arg_placeholders, $name);
}
elsif nqp::istype($_, QAST::Block) {
Expand Down Expand Up @@ -3480,7 +3480,7 @@ Compilation unit '$file' contained the following violations:
my $consider := $BLOCK[0][$i];
if nqp::istype($consider, QAST::Var) {
my $name := $consider.name;
if $name eq '$_' || $name eq '$/' || $name eq '$!' {
if $name eq '$_' || $name eq '$/' || $name eq '$!' || $name eq '' {
$BLOCK[0][$i] := QAST::Op.new( :op('null') );
}
}
Expand Down Expand Up @@ -3573,8 +3573,7 @@ Compilation unit '$file' contained the following violations:
$past := $block;
}
else {
$block[0].unshift(QAST::Var.new(:name<>, :scope<lexical>, :decl('var')));
$block.symbol('', :scope<lexical>);
$*W.install_lexical_magical($block, '');
unless $use_outer_match {
$*W.install_lexical_magical($block, '$/');
}
Expand Down Expand Up @@ -6586,7 +6585,7 @@ Compilation unit '$file' contained the following violations:
);
if self.handle_and_check_adverbs($/, %MATCH_ALLOWED_ADVERBS, 'm', $past) {
# if this match returns a list of matches instead of a single
# match, don't assing to $/ (which imposes item context)
# match, don't assign to $/ (which imposes item context)
make $past;
} else {
make QAST::Op.new( :op('p6store'),
Expand Down
2 changes: 1 addition & 1 deletion src/Perl6/Grammar.nqp
Expand Up @@ -1967,7 +1967,7 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
| <sigil> $<index>=[\d+] [<?{ $*IN_DECL }> <.typed_panic: "X::Syntax::Variable::Numeric">]?
| <sigil> <?[<]> <postcircumfix> [<?{ $*IN_DECL }> <.typed_panic('X::Syntax::Variable::Match')>]?
| :dba('contextualizer') <sigil> '(' ~ ')' <sequence> [<?{ $*IN_DECL }> <.panic: "Cannot declare a contextualizer">]?
| $<sigil>=['$'] $<desigilname>=[<[/_!]>]
| $<sigil>=['$'] $<desigilname>=[<[/_!¢]>]
| {} <sigil> <!{ $*QSIGIL }> <?MARKER('baresigil')> # try last, to allow sublanguages to redefine sigils (like & in regex)
]
[ <?{ $<twigil> && $<twigil> eq '.' }>
Expand Down

0 comments on commit edffe05

Please sign in to comment.