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
correction and extension of the pair implementation #63
Comments
From @cognominalsupport of :a :!a and :$a, beginning of .perl method for Pair, .perl -- |
From @cognominalparrot_colonpair.patchIndex: languages/perl6/src/parser/actions.pm
===================================================================
--- languages/perl6/src/parser/actions.pm (revision 26135)
+++ languages/perl6/src/parser/actions.pm (working copy)
@@ -780,7 +780,10 @@
}
-method scoped($/) {
+ method scoped($/) {
+ if $<typename> {
+ $/.panic('statically typed variables are not yet implemented');
+ }
my $past := $( $<variable_decl> );
make $past;
}
@@ -1239,13 +1242,12 @@
make $past;
}
-
method colonpair($/, $key) {
my $pair_key;
my $pair_val;
if $key eq 'false' {
- my $pair_key := PAST::Val.new( :value(~$<key>) );
+ $pair_key := PAST::Val.new( :value(~$<ident>) );
$pair_val := PAST::Var.new(
:name('False'),
:namespace('Bool'),
@@ -1253,7 +1255,7 @@
);
}
elsif $key eq 'value' {
- my $pair_key := PAST::Val.new( :value(~$<key>) );
+ $pair_key := PAST::Val.new( :value(~$<ident>) );
if $<postcircumfix> {
# XXX TODO
$/.panic('postcircumfix on colonpair not yet implemented');
@@ -1266,7 +1268,16 @@
);
}
}
- else {
+ elsif $key eq 'varname' {
+ my $nm := $<variable><name>;
+ my $idx := $<variable><matchidx>;
+ # say $nm;
+ # if (! $nm || ! $idx ) {
+ # $/.panic( "bad sigiled pair")
+ # }
+ $pair_key := PAST::Val.new( :value( ~$nm || ~$idx) );
+ $pair_val := $( $<variable> );
+ } else {
$/.panic($key ~ " pairs not yet implemented.");
}
Index: languages/perl6/src/parser/grammar.pg
===================================================================
--- languages/perl6/src/parser/grammar.pg (revision 26135)
+++ languages/perl6/src/parser/grammar.pg (working copy)
@@ -479,7 +479,7 @@
rule scoped {
- <variable_decl> {*}
+ <typename>? <variable_decl> {*}
}
rule scope_declarator {
@@ -657,10 +657,10 @@
token colonpair {
':'
[
- | '!' <ident> {*} #= false
+ || '!' <ident> {*} #= false
| <ident> [ <.unsp>? <postcircumfix> ]? {*} #= value
| <postcircumfix> {*} #= structural
- | <sigil> <twigil>? <desigilname> {*} #= varname
+ | <variable> {*} #= varname
]
}
Index: languages/perl6/src/classes/Bool.pir
===================================================================
--- languages/perl6/src/classes/Bool.pir (revision 26135)
+++ languages/perl6/src/classes/Bool.pir (working copy)
@@ -28,6 +28,14 @@
.end
+.sub 'perl' :method
+ $I0 = $P0
+ if $I0 goto true
+ .return ("False")
+true:
+ .return ("True")
+.end
+
.sub 'ACCEPTS' :method
.param pmc topic
.return (self)
Index: languages/perl6/src/classes/Pair.pir
===================================================================
--- languages/perl6/src/classes/Pair.pir (revision 26135)
+++ languages/perl6/src/classes/Pair.pir (working copy)
@@ -17,6 +17,74 @@
$P1('Pair', 'Pair')
.end
+
+.sub get_string :method
+ $S0 = self.'perl'()
+ return ( $S0 )
+.end
+
+# should be pedagical and gives the smartest representation of a pair
+.sub perl :method
+ $P0 = self.'key'()
+ $P1 = self.'value'()
+ $S0 = $P0.'WHAT'()
+ $S1 = $P1.'WHAT'()
+ if $S0 != 'Str' goto keyisnotstring
+ $S2 = $P0
+ $S3 = escape $S2
+ if $S3 != $S2 goto keyescaped
+ if $S1 != 'Bool' goto valnobool
+ $S5 = ":"
+ if $P1 goto trueval
+ concat $S5, "!"
+trueval:
+ concat $S5, $S2
+ .return ($S5)
+valnobool:
+ if $S1 == 'Str' goto valliteral
+ if $S1 == 'Int' goto valnum
+ if $S1 == 'Num' goto valnum
+ die "TBD"
+
+valliteral:
+ $S6 = ":"
+ $S7 = $P0
+ concat $S6, $S7
+ concat $S6, '<'
+ $S7 = $P1
+ concat $S6, $S7
+ concat $S6, '>'
+ .return ( $S6 )
+
+valnum:
+ $S6 = ":"
+ $S7 = $P0
+ concat $S6, $S7
+ concat $S6, '('
+ $S7 = $P1
+ concat $S6, $S7
+ concat $S6, ')'
+ .return ( $S6 )
+
+
+keyescaped:
+ die "TBD"
+
+keyisnotstring:
+ # ugly, probably not correct, certainly not yet supported
+ $S2 = "{ (my $p=Pair.new()), "
+ concat $S2, "$p[ "
+ $S3 = $P0.perl()
+ concat $S2, $S3
+ concat $S2, "] = "
+ $S3 = $P1.perl()
+ concat $S2, $S3
+ concat $S3, "}"
+keyissnottring:
+ die "TBD"
+.end
+
+
=back
=cut
|
From @pmichaudEvents have since overtaken this patch, so marking it as resolved. If (Also, it's easier to comment+apply if separate features are submitted Thanks for the patch! Pm |
@pmichaud - Status changed from 'new' to 'resolved' |
Migrated from rt.perl.org#51350 (status was 'resolved')
Searchable as RT51350$
The text was updated successfully, but these errors were encountered: