Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement 'make' and support '$/' a method parameter #690

Closed
p6rt opened this issue Feb 11, 2009 · 6 comments
Closed

implement 'make' and support '$/' a method parameter #690

p6rt opened this issue Feb 11, 2009 · 6 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Feb 11, 2009

Migrated from rt.perl.org#63152 (status was 'resolved')

Searchable as RT63152$

@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

From @chrisdolan

The attached patch brings Rakudo up to the level of NQP as a language
for grammar actions. I added a builtin method called 'make' that is
sugar for $/.result_object(...). I also modified the grammar to
allow special variables ($/, $_, $<cent>) to be method arguments.
The latter has a little more copy-and-paste than I wanted, but it
works well.

To apply​:
  git pull git​://github.com/chrisdolan/rakudo.git match-make
or
  git am -3 <filename-of-patch>

@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

From @chrisdolan

0001-Implement-make-builtin-and-support-as-a-metho.patch
From 1d13cb562cdfc58af42b51dbe5366428dce1dc22 Mon Sep 17 00:00:00 2001
From: Chris Dolan <chris@chrisdolan.net>
Date: Tue, 10 Feb 2009 21:11:05 -0600
Subject: [PATCH] Implement 'make' builtin and support '$/' as a method parameter

---
 src/builtins/match.pir |    8 ++++++++
 src/parser/actions.pm  |   46 +++++++++++++++++++++++++++++-----------------
 src/parser/grammar.pg  |    4 ++--
 3 files changed, 39 insertions(+), 19 deletions(-)

diff --git a/src/builtins/match.pir b/src/builtins/match.pir
index 775ae02..d94e817 100644
--- a/src/builtins/match.pir
+++ b/src/builtins/match.pir
@@ -25,6 +25,14 @@ src/builtins/match.pir - Perl6 builtins for smart matching
     .tailcall x.'REJECTS'(topic)
 .end
 
+.sub 'make'
+    .param pmc value
+    $P0 = getinterp
+    $P1 = $P0['lexpad';1]
+    $P2 = $P1['$/']
+    $P2.'result_object'(value)
+.end
+
 =back
 
 =cut
diff --git a/src/parser/actions.pm b/src/parser/actions.pm
index 63d86fd..e281112 100644
--- a/src/parser/actions.pm
+++ b/src/parser/actions.pm
@@ -1261,24 +1261,36 @@ method parameter($/) {
 }
 
 
-method param_var($/) {
-    my $sigil  := ~$<sigil>;
-    my $twigil := ~$<twigil>[0];
-    if $sigil eq '&' { $sigil := ''; }
-    my $name := $sigil ~ $twigil ~ ~$<identifier>;
-    if $twigil eq '.' {
-        $name := $sigil ~ '!' ~ $<identifier>;
-    }
-    elsif $twigil && $twigil ne '!' {
-        $/.panic('Invalid twigil used in signature parameter.');
-    }
-    my $var := PAST::Var.new(
-        :name($name),
-        :scope('parameter'),
-        :node($/)
-    );
-    $var<twigil> := $twigil;
-    $var<itype>  := container_itype( $<sigil> );
+method param_var($/, $key) {
+    my $name;
+    my $var;
+
+    if $key eq 'special_variable' {
+        # Treat $/, $_, etc. specially
+
+        $name := ~$/;
+        $var := PAST::Var.new( :node($/), :name($name), :scope('parameter') );
+
+    } else {
+        my $sigil  := ~$<sigil>;
+        my $twigil := ~$<twigil>[0];
+        if $sigil eq '&' { $sigil := ''; }
+        $name := $sigil ~ $twigil ~ ~$<identifier>;
+        if $twigil eq '.' {
+            $name := $sigil ~ '!' ~ $<identifier>;
+        }
+        elsif $twigil && $twigil ne '!' {
+            $/.panic('Invalid twigil used in signature parameter.');
+        }
+        $var := PAST::Var.new(
+            :name($name),
+            :scope('parameter'),
+            :node($/)
+        );
+        $var<twigil> := $twigil;
+        $var<itype>  := container_itype( $<sigil> );
+    }
+
     # Declare symbol as lexical in current (signature) block.
     # This is needed in case any post_constraints try to reference
     # this new param_var.
diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg
index a182ade..c8c1639 100644
--- a/src/parser/grammar.pg
+++ b/src/parser/grammar.pg
@@ -480,8 +480,8 @@ rule post_constraint {
 }
 
 token param_var {
-    <sigil> <twigil>? <identifier>
-    {*}
+    | <sigil> <twigil>? <identifier>              {*}  #= identifier
+    | $<sym>=[ '$/' | '$!' | '$��' ] <!before \w> {*}  #= special_variable
 }
 
 token parameter {
-- 
1.6.1

@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

From @chrisdolan

I intend to add some spec tests for this, too.

@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

From @pmichaud

On Tue Feb 10 19​:24​:41 2009, chris@​chrisdolan.net wrote​:

The attached patch brings Rakudo up to the level of NQP as a language
for grammar actions. I added a builtin method called 'make' that is
sugar for $/.result_object(...). I also modified the grammar to
allow special variables ($/, $_, $&lt;cent>) to be method arguments.
The latter has a little more copy-and-paste than I wanted, but it
works well.

Now added in d44d19c. I chose a different approach for parsing
$/ as a parameter so that it would follow STD.pm a bit more
closely (also with the advantage of avoiding any modifications
to actions.pm ).

Closing ticket, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt closed this as completed Feb 11, 2009
@p6rt
Copy link
Author

p6rt commented Feb 11, 2009

@pmichaud - Status changed from 'open' to 'resolved'

@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant