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

[svn:parrot] r35756 - in trunk/languages/pipp: src/pct t/php

From:
bernhard
Date:
January 19, 2009 06:50
Subject:
[svn:parrot] r35756 - in trunk/languages/pipp: src/pct t/php
Message ID:
20090119145035.A60CBCB9AE@x12.develooper.com
Author: bernhard
Date: Mon Jan 19 06:50:34 2009
New Revision: 35756

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

Log:
[Pipp] Add support for constants with fully qualified name.
Keep the trailing '\' in namespace names.

Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm	(original)
+++ trunk/languages/pipp/src/pct/actions.pm	Mon Jan 19 06:50:34 2009
@@ -127,7 +127,7 @@
     our $?NS;
 
     if $key eq 'open' {
-        $?NS := +$<namespace_name> ?? ~$<namespace_name>[0] !! '';
+        $?NS := +$<namespace_name> ?? ~$<namespace_name>[0] ~ '\\' !! '';
     }
     else {
         my $block :=
@@ -264,11 +264,22 @@
 
 method constant($/) {
     our $?NS;
-    make PAST::Var.new(
-        :name(~$<name>),
-        :scope('package'),
-        :namespace($?NS)
-    );
+    if $<name><leading_backslash> {
+        # fully qualified name
+        make PAST::Var.new(
+            :name(~$<name><ident>),
+            :scope('package'),
+            :namespace(~$<name><ns_path>)
+        );
+    }
+    else {
+        # access relative to current namespace
+        make PAST::Var.new(
+            :name(~$<name><ident>),
+            :scope('package'),
+            :namespace($?NS ~ $<name><ns_path>)
+        );
+    }
 }
 
 # TODO: merge with rule 'constant'

Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg	(original)
+++ trunk/languages/pipp/src/pct/grammar.pg	Mon Jan 19 06:50:34 2009
@@ -251,17 +251,20 @@
 
 token method_name              { <ident> }
 
-token namespace_name           { <ns_component>* <ident> }
+token namespace_name           { <ns_path> <ident> }
 
 token name {
     <leading_backslash=ns_sep>?           # a leading backslash is optional, but significant
-    <ns_component>*                       # namespace
+    <ns_path>                             # namespace
     <ident>                               # identifier is required
 }
 
 token ns_sep                   { '\\' }   # yes, PHP 5.3 uses backslash as the namespace separator
 
-token ns_component             { <ident> <.ns_sep> }
+
+token ns_path                  {
+    [ <ident> <.ns_sep> ]*
+} 
 
 token var_name                 { '$' <ident> }
 

Modified: trunk/languages/pipp/t/php/namespace.t
==============================================================================
--- trunk/languages/pipp/t/php/namespace.t	(original)
+++ trunk/languages/pipp/t/php/namespace.t	Mon Jan 19 06:50:34 2009
@@ -88,6 +88,30 @@
 FOO in A\B
 OUT
 
+
+language_output_is( 'Pipp', <<'CODE', <<'OUT', 'constant with fully qualified names' );
+<?php
+
+namespace A {
+    const FOO = "FOO in A\n";
+}
+
+namespace A\B {
+    const FOO = "FOO in A\\B\n";
+    echo \A\FOO;
+}
+
+namespace A\B {
+    echo \A\FOO;
+    echo \A\B\FOO;
+}
+
+?>
+CODE
+FOO in A
+FOO in A\B
+OUT
+
 =for perl6
 
 package A {



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