develooper Front page | perl.cvs.parrot | Postings from January 2009

[svn:parrot] r35809 - trunk/languages/pipp/src/pct

From:
bernhard
Date:
January 20, 2009 06:26
Subject:
[svn:parrot] r35809 - trunk/languages/pipp/src/pct
Message ID:
20090120142643.05E39CB9AE@x12.develooper.com
Author: bernhard
Date: Tue Jan 20 06:26:42 2009
New Revision: 35809

Modified:
   trunk/languages/pipp/src/pct/actions.pm
   trunk/languages/pipp/src/pct/grammar.pg

Log:
[Pipp] Put code for class_member_definition into an action

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 06:26:42 2009
@@ -604,6 +604,51 @@
     }
 }
 
+method class_member_definition($/) {
+    my $member_name := ~$<var_name><ident>;
+
+    make PAST::Stmts.new(
+        PAST::Op.new(
+            :pasttype('call'),
+            :name('pipp_add_attribute'),
+            PAST::Var.new(
+                :name('def'),
+                :scope('register')
+            ),
+            PAST::Val.new( :value($member_name) )
+        ),
+        PAST::Op.new(
+            :pasttype('call'),
+            :name('!ADD_TO_WHENCE'),
+            PAST::Var.new(
+                :name('def'),
+                :scope('register'),
+            ),
+            PAST::Val.new(
+                :value($member_name)
+            ),
+            $( $<literal> )
+        ),
+        # add accessors for the attribute
+        PAST::Block.new(
+            :blocktype('declaration'),
+            :name($member_name),
+            :pirflags(':method'),
+            :node( $/ ),
+            PAST::Stmts.new(
+                PAST::Var.new(
+                    :name($member_name),
+                    :scope('attribute')
+                )
+            )
+        )
+    );
+}
+
+method class_static_member_definition($/) {
+    make PAST::Block.new();
+}
+
 method class_method_definition($/, $key) {
     our @?BLOCK; # A stack of PAST::Block
 
@@ -706,56 +751,7 @@
 
         # declare the attributes
         for $<class_member_definition> {
-            if $_<static> {
-                my $member_name := ~$_<var_name><ident>;
-                $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> )
-                    )
-                );
-
-                # add accessors for the attribute
-                $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( $($_) );
         }
 
         # It's a new class definition. Make proto-object.

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 06:26:42 2009
@@ -267,12 +267,6 @@
 
 token var_name                 { '$' <ident> }
 
-# keywords
-
-token static {
-    'static'
-}
-
 # terms
 rule method_call {
     <var> '->' <method_name> '(' <argument_list> ')'
@@ -443,6 +437,7 @@
     '{'
         [ | <constant_definition>
           | <class_member_definition>
+          | <class_static_member_definition>
           | <class_method_definition>
         ]*
     '}'                                                      {*}  #= close
@@ -455,9 +450,12 @@
     {*}
 }
 
-# TODO: use a named literal match
 rule class_member_definition {
-    'public' <static>? <var_name> '=' <literal> <.statement_delimiter>
+    'public' <var_name> '=' <literal> <.statement_delimiter> {*}
+}
+
+rule class_static_member_definition {
+    'public' 'static' <var_name> '=' <literal> <.statement_delimiter> {*}
 }
 
 rule class_method_definition {



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About