-
-
Save lizmat/e6723770d2d7d880ae7497630c952ca4 to your computer and use it in GitHub Desktop.
Trying to handle wrap $.foo handling into a proper class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Raku/Actions.nqp b/src/Raku/Actions.nqp | |
index d2a21643f..9a249213d 100644 | |
--- a/src/Raku/Actions.nqp | |
+++ b/src/Raku/Actions.nqp | |
@@ -1878,6 +1878,9 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { | |
elsif $twigil eq '!' { | |
$ast := Nodify('Var','Attribute').new($name); | |
} | |
+ elsif $twigil eq '.' { | |
+ $ast := Nodify('Var','Attribute','Public').new($name); | |
+ } | |
elsif $twigil eq '?' { | |
my $origin-source := $*ORIGIN-SOURCE; | |
$ast := $name eq '$?FILE' | |
@@ -1917,28 +1920,6 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions { | |
nqp::die("Pod variable $name NYI"); | |
} | |
} | |
- elsif $twigil eq '.' { | |
- | |
- # self.foo.item | |
- $ast := Nodify('ApplyPostfix').new( | |
- operand => Nodify('ApplyPostfix').new( | |
- operand => Nodify('Term','Self').new, | |
- postfix => Nodify('Call','Method').new( | |
- name => $desigilname, | |
- args => ($<arglist> | |
- ?? $<arglist>.ast | |
- !! Nodify('ArgList').new | |
- ) | |
- ) | |
- ), | |
- postfix => Nodify('Call','Method').new( | |
- name => Nodify('Name').from-identifier( | |
- nqp::lc(sigil-to-context($sigil)) | |
- ), | |
- args => Nodify('ArgList').new | |
- ) | |
- ); | |
- } | |
elsif $twigil eq '~' { | |
my $name := $desigilname.canonicalize; | |
$ast := Nodify('Var','Slang').new( | |
diff --git a/src/Raku/ast/variable-access.rakumod b/src/Raku/ast/variable-access.rakumod | |
index 3895f5c91..e6fd4396c 100644 | |
--- a/src/Raku/ast/variable-access.rakumod | |
+++ b/src/Raku/ast/variable-access.rakumod | |
@@ -209,7 +209,7 @@ class RakuAST::Var::Dynamic | |
} | |
} | |
-# An attribute access (e.g. $!foo). | |
+# A (private) attribute access (e.g. $!foo). | |
class RakuAST::Var::Attribute | |
is RakuAST::Var | |
is RakuAST::ImplicitLookups | |
@@ -300,6 +300,52 @@ class RakuAST::Var::Attribute | |
} | |
} | |
+# Wrapper for $.foo "attribute" accesses | |
+class RakuAST::Var::Attribute::Public | |
+ is RakuAST::Var | |
+ is RakuAST::CheckTime | |
+{ | |
+ has str $.name; | |
+ has RakuAST::ApplyPostfix $!expression; | |
+ | |
+ method new(str $name) { | |
+ my str $sigil := nqp::substr($name,0,1); | |
+ | |
+ my $obj := nqp::create(self); | |
+ nqp::bindattr_s($obj, RakuAST::Var::Attribute::Public, '$!name', $name); | |
+ nqp::bindattr( $obj, RakuAST::Var::Attribute::Public, '$!expression', | |
+ # self.foo.item | |
+ RakuAST::ApplyPostfix.new( | |
+ operand => RakuAST::ApplyPostfix.new( | |
+ operand => RakuAST::Term::Self.new, | |
+ postfix => RakuAST::Call::Method.new( | |
+ name => nqp::substr($name,2), | |
+ args => RakuAST::ArgList.new | |
+ ) | |
+ ), | |
+ postfix => RakuAST::Call::Method.new( | |
+ name => RakuAST::Name.from-identifier( | |
+ $sigil eq '@' ?? 'list' !! $sigil eq '%' ?? 'hash' !! 'item' | |
+ ), | |
+ args => RakuAST::ArgList.new | |
+ ) | |
+ ) | |
+ ); | |
+ $obj | |
+ } | |
+ | |
+ method PERFORM-CHECK( | |
+ RakuAST::Resolver $resolver, | |
+ RakuAST::IMPL::QASTContext $context | |
+ ) { | |
+ $!expression.PERFORM-CHECK($resolver, $context) | |
+ } | |
+ | |
+ method IMPL-TO-QAST(RakuAST::IMPL::QASTContext $context) { | |
+ $!expression.IMPL-TO-QAST($context) | |
+ } | |
+} | |
+ | |
# The base for special compiler variables ($?FOO). | |
class RakuAST::Var::Compiler | |
is RakuAST::Var { } | |
diff --git a/src/core.c/RakuAST/Deparse.rakumod b/src/core.c/RakuAST/Deparse.rakumod | |
index 31a67e561..48dd9ade2 100644 | |
--- a/src/core.c/RakuAST/Deparse.rakumod | |
+++ b/src/core.c/RakuAST/Deparse.rakumod | |
@@ -2568,6 +2568,10 @@ CODE | |
self.hsyn('var-attribute', $ast.name) | |
} | |
+ multi method deparse(RakuAST::Var::Attribute::Public:D $ast --> Str:D) { | |
+ self.hsyn('var-public', $ast.name) | |
+ } | |
+ | |
multi method deparse(RakuAST::Var::Compiler::File:D $ast --> Str:D) { | |
self.hsyn('var-compile',$.var-compiler-file) | |
} | |
diff --git a/src/core.c/RakuAST/Raku.rakumod b/src/core.c/RakuAST/Raku.rakumod | |
index 7717e05f0..5f9b2e236 100644 | |
--- a/src/core.c/RakuAST/Raku.rakumod | |
+++ b/src/core.c/RakuAST/Raku.rakumod | |
@@ -1197,6 +1197,10 @@ augment class RakuAST::Node { | |
self!positional(self.name) | |
} | |
+ multi method raku(RakuAST::Var::Attribute::Public:D: --> Str:D) { | |
+ self!positional(self.name) | |
+ } | |
+ | |
multi method raku(RakuAST::Var::Compiler::File:D: --> Str:D) { | |
self!positional(self.file) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment