Front page | perl.cvs.parrot |
Postings from January 2009
[svn:parrot] r35800 - in trunk/languages/pipp: docs src/common src/pct t/php
From:
bernhard
Date:
January 20, 2009 05:52
Subject:
[svn:parrot] r35800 - in trunk/languages/pipp: docs src/common src/pct t/php
Message ID:
20090120135150.C85B8CB9AE@x12.develooper.com
Author: bernhard
Date: Tue Jan 20 05:51:49 2009
New Revision: 35800
Modified:
trunk/languages/pipp/docs/internals.pod
trunk/languages/pipp/src/common/guts.pir
trunk/languages/pipp/src/pct/actions.pm
trunk/languages/pipp/src/pct/grammar.pg
trunk/languages/pipp/t/php/oo.t
Log:
[Pipp] check for keyword 'static' in class member declarations
Modified: trunk/languages/pipp/docs/internals.pod
==============================================================================
--- trunk/languages/pipp/docs/internals.pod (original)
+++ trunk/languages/pipp/docs/internals.pod Tue Jan 20 05:51:49 2009
@@ -28,6 +28,8 @@
=head1 Variables
+List of scopes and types of variables.
+
=over 4
=item globals in top file
@@ -43,6 +45,12 @@
Class constants are stored a package variables in the namespace $?NS ~ '\\' ~ $?CLASS ~ '::'.
The trailing '::' guarantees that there is no conflict with namespace constants.
+TODO: make them readonly
+
+=item Static class members
+
+Like class constants, but writable.
+
=item Class members
=item function and method scope
Modified: trunk/languages/pipp/src/common/guts.pir
==============================================================================
--- trunk/languages/pipp/src/common/guts.pir (original)
+++ trunk/languages/pipp/src/common/guts.pir Tue Jan 20 05:51:49 2009
@@ -94,7 +94,7 @@
.end
-=item tipp_add_attribute(class, attr_name, attr_value)
+=item pipp_add_attribute(class, attr_name, attr_value)
Adds an attribute with the given name to the class or role.
See C<!keyword_has> in Rakudo.
Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm (original)
+++ trunk/languages/pipp/src/pct/actions.pm Tue Jan 20 05:51:49 2009
@@ -732,38 +732,40 @@
# declare the attributes
for $<class_member_definition> {
- my $member_name := ~$_<var_name><ident>;
- $methods_block.symbol(
- $member_name,
- :scope('attribute'),
- :default( $( $_<literal> ) )
- );
-
- $block.push(
- PAST::Op.new(
- :pasttype('call'),
- :name('pipp_add_attribute'),
- PAST::Var.new(
- :name('def'),
- :scope('register')
- ),
- PAST::Val.new( :value($member_name) )
- )
- );
- $block.push(
- PAST::Op.new(
- :pasttype('call'),
- :name('!ADD_TO_WHENCE'),
- PAST::Var.new(
- :name('def'),
- :scope('register'),
- ),
- PAST::Val.new(
- :value($member_name)
- ),
- $( $_<literal> )
- )
- );
+ if $_<static> {
+ my $member_name := ~$_<var_name><ident>;
+ $methods_block.symbol(
+ $member_name,
+ :scope('attribute'),
+ :default( $( $_<literal> ) )
+ );
+
+ $block.push(
+ PAST::Op.new(
+ :pasttype('call'),
+ :name('pipp_add_attribute'),
+ PAST::Var.new(
+ :name('def'),
+ :scope('register')
+ ),
+ PAST::Val.new( :value($member_name) )
+ )
+ );
+ $block.push(
+ PAST::Op.new(
+ :pasttype('call'),
+ :name('!ADD_TO_WHENCE'),
+ PAST::Var.new(
+ :name('def'),
+ :scope('register'),
+ ),
+ PAST::Val.new(
+ :value($member_name)
+ ),
+ $( $_<literal> )
+ )
+ );
+ }
}
# It's a new class definition. Make proto-object.
@@ -798,20 +800,22 @@
# add accessors for the attributes
for $<class_member_definition> {
- $methods_block.push(
- PAST::Block.new(
- :blocktype('declaration'),
- :name(~$_<var_name><ident>),
- :pirflags(':method'),
- :node( $/ ),
- PAST::Stmts.new(
- PAST::Var.new(
- :name(~$_<var_name><ident>),
- :scope('attribute')
+ if $_<static> {
+ $methods_block.push(
+ PAST::Block.new(
+ :blocktype('declaration'),
+ :name(~$_<var_name><ident>),
+ :pirflags(':method'),
+ :node( $/ ),
+ PAST::Stmts.new(
+ PAST::Var.new(
+ :name(~$_<var_name><ident>),
+ :scope('attribute')
+ )
)
)
- )
- );
+ );
+ }
}
$block.push( $methods_block );
Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg (original)
+++ trunk/languages/pipp/src/pct/grammar.pg Tue Jan 20 05:51:49 2009
@@ -261,13 +261,18 @@
token ns_sep { '\\' } # yes, PHP 5.3 uses backslash as the namespace separator
-
token ns_path {
[ <ident> <.ns_sep> ]*
}
token var_name { '$' <ident> }
+# keywords
+
+token static {
+ 'static'
+}
+
# terms
rule method_call {
<var> '->' <method_name> '(' <argument_list> ')'
@@ -449,8 +454,9 @@
{*}
}
+# TODO: use a named literal match
rule class_member_definition {
- 'public' <var_name> '=' <literal> <.statement_delimiter>
+ 'public' <static>? <var_name> '=' <literal> <.statement_delimiter>
}
rule class_method_definition {
Modified: trunk/languages/pipp/t/php/oo.t
==============================================================================
--- trunk/languages/pipp/t/php/oo.t (original)
+++ trunk/languages/pipp/t/php/oo.t Tue Jan 20 05:51:49 2009
@@ -20,7 +20,7 @@
use FindBin;
use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
-use Parrot::Test tests => 13;
+use Parrot::Test tests => 14;
language_output_is( 'Pipp', <<'CODE', <<'OUT', 'definition of a class' );
<?php
@@ -300,3 +300,23 @@
CODE
Foo
OUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'static member', todo => 'not yet' );
+<?php
+
+class A {
+ public static $a = "static member \$a\n";
+
+ function echo_static () {
+ echo self::$a;
+ }
+}
+
+$a = new A;
+$a->echo_static();
+
+?>
+CODE
+static member $a
+OUT
+
-
[svn:parrot] r35800 - in trunk/languages/pipp: docs src/common src/pct t/php
by bernhard