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
sub parse_name rewritten in NQP #1573
Comments
From jaume.martif@gmail.comHi! I have rewritten the sub "parse_name" in NQP. Jaume. |
From jaume.martif@gmail.com0001-sub-parse_name-rewritten-in-NQP.patchFrom c068139d8e379d83876bc51f4695b86cf0b287e6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaume=20Mart=C3=AD?= <jaume.martif@gmail.com>
Date: Thu, 4 Mar 2010 01:20:26 -0800
Subject: [PATCH] sub parse_name rewritten in NQP
---
src/Perl6/Grammar.pm | 77 +++++++++++++++++++++----------------------------
1 files changed, 33 insertions(+), 44 deletions(-)
diff --git a/src/Perl6/Grammar.pm b/src/Perl6/Grammar.pm
index 41e1672..c3bb1e5 100644
--- a/src/Perl6/Grammar.pm
+++ b/src/Perl6/Grammar.pm
@@ -1239,50 +1239,39 @@ grammar Perl6::Regex is Regex::P6Regex::Grammar {
sub parse_name($name) {
- # XXX Some enterprising soul could re-write this in NQP. ;-)
- Q:PIR {
- .local string name
- $P0 = find_lex '$name'
- name = $P0
- ## remove any type parameterization for now
- .local string type_param
- type_param = ''
- $I0 = index name, '['
- if $I0 == -1 goto type_param_done
- type_param = substr name, $I0
- name = substr name, 0, $I0
- type_param_done:
- ## divide name based on ::
- .local pmc list
- list = split '::', name
- ## move any leading sigil to the last item
- .local string sigil
- $S0 = list[0]
- sigil = substr $S0, 0, 1
- $I0 = index '$@%&', sigil
- if $I0 < 0 goto sigil_done
- substr $S0, 0, 1, ''
- list[0] = $S0
- $S0 = list[-1]
- $S0 = concat sigil, $S0
- list[-1] = $S0
- sigil_done:
- ## remove any empty items from the list
- $P0 = iter list
- list = new 'ResizablePMCArray'
- iter_loop:
- unless $P0 goto iter_done
- $S0 = shift $P0
- unless $S0 goto iter_loop
- push list, $S0
- goto iter_loop
- iter_done:
- if type_param == '' goto no_add_type_param
- $S0 = pop list
- concat $S0, type_param
- push list, $S0
- no_add_type_param:
- .return (list)
+ my %is_sigil;
+ %is_sigil{'$'}:=1;
+ %is_sigil{'@'}:=1;
+ %is_sigil{'%'}:=1;
+ %is_sigil{'&'}:=1;
+
+ my $type_param:='';
+ my $sep := pir::index__ISS($name,'[');
+ if ($sep>-1) {
+ $type_param:= pir::substr__SSII($name,$sep);
+ $name:=pir::substr__SSII($name,0,$sep);
+ }
+
+ my @parts:=pir::split__PSS('::',$name);
+ my $sigil:=pir::substr__SSII(@parts[0],0,1);
+ if %is_sigil{$sigil} {
+ @parts[0]:=pir::substr__SSII(@parts[0], 1);
+ my $last_part:=@parts.pop();
+ $last_part:=~$sigil ~ ~$last_part;
+ @parts.push($last_part);
+ }
+
+ my @result;
+ for @parts {
+ @result.push($_) if ($_);
+ }
+
+ if $type_param {
+ my $last_part:=@result.pop();
+ $last_part:=~$last_part ~ ~$type_param;
+ @result.push($last_part);
}
+
+ @result;
}
--
1.6.4.4
|
From @moritzThanks for your patch, I've committed it as 1) the %is_sigil hash is now a package variable, and initialized only Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
@moritz - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#73278 (status was 'resolved')
Searchable as RT73278$
The text was updated successfully, but these errors were encountered: