diff --git a/src/Raku/Actions.nqp b/src/Raku/Actions.nqp index 74863ec769e..c8d339735c0 100644 --- a/src/Raku/Actions.nqp +++ b/src/Raku/Actions.nqp @@ -1376,8 +1376,10 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { else { my str $sigil := ~$; my str $twigil := $ ?? ~$ !! ''; - my str $desigilname := ~$; - self.compile_variable_access($/, $sigil, $twigil, $desigilname, $); + my $desigilname := $ + ?? $.ast + !! self.r('Name').from-identifier(~$); + self.compile_variable_access($/, $sigil, $twigil, $desigilname); } } @@ -1400,7 +1402,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { ])) ) ); - self.compile_variable_access($/, '&', '', $name.canonicalize, ''); + self.compile_variable_access($/, '&', '', $name); } elsif $ { self.contextualizer-for-sigil($/, ~$, $.ast); @@ -1408,16 +1410,16 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { else { my str $sigil := ~$; my str $twigil := $ ?? ~$ !! ''; - my str $desigilname := $ - ?? $.ast.canonicalize - !! ~$; - self.compile_variable_access($/, $sigil, $twigil, $desigilname, $); + my $desigilname := $ + ?? $.ast + !! self.r('Name').from-identifier(~$); + self.compile_variable_access($/, $sigil, $twigil, $desigilname); } } - method compile_variable_access($/, $sigil, $twigil, $desigilname, $longname) { - my str $name := $sigil ~ $twigil ~ $desigilname; - if $name eq $sigil { + method compile_variable_access($/, $sigil, $twigil, $desigilname) { + my str $name := $sigil ~ $twigil ~ $desigilname.canonicalize; + if $twigil eq '' && $desigilname.is-empty { # Generate an anonymous state variable. self.attach: $/, self.r('VarDeclaration', 'Anonymous').new(:$sigil, :scope('state')); } @@ -1432,9 +1434,9 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { self.attach: $/, $decl; } elsif $twigil eq '' { - if !$longname || $longname.ast.is-identifier { + if $desigilname.is-identifier { if $*LANG.pragma("strict") || $*R.resolve-lexical($name) { - self.attach: $/, self.r('Var', 'Lexical').new($name); + self.attach: $/, self.r('Var', 'Lexical').new(:$sigil, :$desigilname); } else { my $decl := self.r('VarDeclaration','Auto').new( @@ -1446,7 +1448,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { } else { # package variable self.attach: $/, self.r('Var', 'Package').new( - :name($longname.ast), + :name($desigilname), :$sigil ); } @@ -1479,13 +1481,13 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { } elsif $twigil eq '^' { my $decl := self.r('VarDeclaration', 'Placeholder', 'Positional').new: - $sigil ~ $desigilname; + $sigil ~ $desigilname.canonicalize; $*R.declare-lexical($decl); self.attach: $/, $decl; } elsif $twigil eq ':' { my $decl := self.r('VarDeclaration', 'Placeholder', 'Named').new: - $sigil ~ $desigilname; + $sigil ~ $desigilname.canonicalize; $*R.declare-lexical($decl); self.attach: $/, $decl; } @@ -1511,7 +1513,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { self.r('ApplyPostfix').new: :postfix( self.r('Call', 'Method').new( - :name(self.r('Name').from-identifier($desigilname)), + :name($desigilname), :args($ ?? $.ast !! self.r('ArgList').new), )), :operand( @@ -1519,8 +1521,8 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { )); } elsif $twigil eq '~' { - my $grammar := $/.slang_grammar($desigilname); - my $actions := $/.slang_actions($desigilname); + my $grammar := $/.slang_grammar($desigilname.canonicalize); + my $actions := $/.slang_actions($desigilname.canonicalize); self.attach: $/, self.r('Var', 'Slang').new(:$grammar, :$actions); } else { diff --git a/src/Raku/ast/literals.rakumod b/src/Raku/ast/literals.rakumod index 72f9a949464..436e55383bd 100644 --- a/src/Raku/ast/literals.rakumod +++ b/src/Raku/ast/literals.rakumod @@ -202,7 +202,9 @@ class RakuAST::QuotedString if nqp::elems($!processors) { for $!processors { if $_ eq 'val' { - nqp::push(@needed, RakuAST::Var::Lexical::Setting.new('&val')); + nqp::push(@needed, RakuAST::Var::Lexical::Setting.new( + :sigil<&>, + :desigilname(RakuAST::Name.from-identifier('val')))); last; } } diff --git a/src/Raku/ast/name.rakumod b/src/Raku/ast/name.rakumod index 1b0ed5edb08..4879960fc35 100644 --- a/src/Raku/ast/name.rakumod +++ b/src/Raku/ast/name.rakumod @@ -45,7 +45,7 @@ class RakuAST::Name } method is-empty() { - nqp::elems($!parts) ?? False !! True + (!nqp::elems($!parts) || self.is-identifier && $!parts[0].name eq '') ?? True !! False } method is-simple() { diff --git a/src/Raku/ast/variable-access.rakumod b/src/Raku/ast/variable-access.rakumod index 5ca0d999a28..543112274e4 100644 --- a/src/Raku/ast/variable-access.rakumod +++ b/src/Raku/ast/variable-access.rakumod @@ -10,22 +10,36 @@ class RakuAST::Var::Lexical is RakuAST::Var is RakuAST::Lookup { - has str $.name; + has str $.sigil; + has str $.twigil; + has RakuAST::Name $.desigilname; - method new(str $name) { + method new(str $name?, Str :$sigil, Str :$twigil, RakuAST::Name :$desigilname) { my $obj := nqp::create(self); - nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!name', $name); + if $name { + nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!sigil', nqp::substr($name, 0, 1)); + nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!twigil', ''); + nqp::bindattr($obj, RakuAST::Var::Lexical, '$!desigilname', + RakuAST::Name.from-identifier(nqp::substr($name, 1))) + } + else { + nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!sigil', $sigil); + nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!twigil', $twigil); + nqp::bindattr($obj, RakuAST::Var::Lexical, '$!desigilname', $desigilname); + } $obj } - method sigil() { nqp::substr($!name, 0, 1) } + method name() { + ($!sigil // '') ~ ($!twigil // '') ~ $!desigilname.canonicalize + } method can-be-bound-to() { self.is-resolved ?? self.resolution.can-be-bound-to !! False } method resolve-with(RakuAST::Resolver $resolver) { - my $resolved := $resolver.resolve-lexical($!name); + my $resolved := $resolver.resolve-lexical(self.name); if $resolved { self.set-resolution($resolved); } @@ -33,8 +47,8 @@ class RakuAST::Var::Lexical } method undeclared-symbol-details() { - self.sigil eq '&' - ?? RakuAST::UndeclaredSymbolDescription::Routine.new($!name) + $!sigil eq '&' + ?? RakuAST::UndeclaredSymbolDescription::Routine.new(self.name) !! Nil } @@ -330,7 +344,9 @@ class RakuAST::Var::Compiler::Routine { method new() { my $obj := nqp::create(self); - nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!name', '&?ROUTINE'); + nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!sigil', '&'); + nqp::bindattr_s($obj, RakuAST::Var::Lexical, '$!twigil', '?'); + nqp::bindattr($obj, RakuAST::Var::Lexical, '$!desigilname', RakuAST::Name.from-identifier('ROUTINE')); $obj }