Author: cotto
Date: Thu Nov 6 12:46:58 2008
New Revision: 32405
Added:
trunk/languages/pipp/t/php/tags.t (contents, props changed)
Modified:
trunk/MANIFEST
trunk/languages/pipp/MAINTAINER
trunk/languages/pipp/src/common/pipp.pir
trunk/languages/pipp/src/pct/actions.pm
trunk/languages/pipp/src/pct/grammar.pg
trunk/languages/pipp/t/in_php/02_sanity.t
Log:
[pipp] make grammar slightly smarter about PHP tags, plus various minor changes
Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST (original)
+++ trunk/MANIFEST Thu Nov 6 12:46:58 2008
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Nov 6 17:35:11 2008 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Nov 6 20:15:18 2008 UT
#
# See tools/dev/install_files.pl for documentation on the
# format of this file.
@@ -2395,6 +2395,7 @@
languages/pipp/t/php/string.t [pipp]
languages/pipp/t/php/strings.t [pipp]
languages/pipp/t/php/superglobals.t [pipp]
+languages/pipp/t/php/tags.t [pipp]
languages/pipp/t/php/type.t [pipp]
languages/pipp/t/php/var.t [pipp]
languages/pipp/t/php/variables.t [pipp]
Modified: trunk/languages/pipp/MAINTAINER
==============================================================================
--- trunk/languages/pipp/MAINTAINER (original)
+++ trunk/languages/pipp/MAINTAINER Thu Nov 6 12:46:58 2008
@@ -2,3 +2,7 @@
N: Bernhard Schmalhofer
E: [EMAIL PROTECTED]
+
+N: Christoph Otto
+D: PhpArray PMC implementation
+E: [EMAIL PROTECTED]
Modified: trunk/languages/pipp/src/common/pipp.pir
==============================================================================
--- trunk/languages/pipp/src/common/pipp.pir (original)
+++ trunk/languages/pipp/src/common/pipp.pir Thu Nov 6 12:46:58 2008
@@ -130,7 +130,8 @@
source_fn = rest
goto GOT_PHP_SOURCE_FN
GOT_NO_FILE_ON_COMMAND_LINE:
- printerr 'Got no PHP file.'
+ #XXX: should do REPL or read from stdin
+ printerr "No input file specified.\n"
exit -1
GOT_PHP_SOURCE_FN:
Modified: trunk/languages/pipp/src/pct/actions.pm
==============================================================================
--- trunk/languages/pipp/src/pct/actions.pm (original)
+++ trunk/languages/pipp/src/pct/actions.pm Thu Nov 6 12:46:58 2008
@@ -44,7 +44,7 @@
);
}
-method code_tp1($/) {
+method code_short_tag($/) {
my $past := PAST::Stmts.new( :node($/) );
for $<statement> {
$past.push( $($_) );
@@ -53,7 +53,7 @@
make $past;
}
-method code_tp2($/) {
+method code_script_tag($/) {
my $past := PAST::Stmts.new( :node($/) );
for $<statement> {
$past.push( $($_) );
@@ -75,7 +75,7 @@
make $( $/{$key} );
}
-method inline_sea_tp1($/) {
+method inline_sea_short_tag($/) {
make PAST::Op.new(
PAST::Val.new(
:value(~$<SEA_empty_allowed>),
Modified: trunk/languages/pipp/src/pct/grammar.pg
==============================================================================
--- trunk/languages/pipp/src/pct/grammar.pg (original)
+++ trunk/languages/pipp/src/pct/grammar.pg Thu Nov 6 12:46:58 2008
@@ -15,23 +15,25 @@
| <multilinecomment>
]*
}
+token ws_char { [ \h | \v ] }
token singlelinecomment { '#' \N*
| '//' \N*
}
token multilinecomment { '/*' .*? '*/' }
-# embedding code into a sea of HTML
-token sea_or_code { <code_tp1> {*} #= code_tp1
- | <code_tp2> {*} #= code_tp2
- | <SEA> {*} #= SEA
- }
-regex SEA { '<'? .+? ( <before '<'> | $ )
{*} }
-rule code_tp1 { <.CODE_START_TP1> <statement>* <.CODE_END_TP1>?
{*} }
-rule code_tp2 { <.CODE_START_TP2> <statement>* <.CODE_END_TP2>?
{*} }
-token CODE_START_TP1 { '<?php'
}
-token CODE_START_TP2 { '<script language="php">'
}
-token CODE_END_TP1 { '?>' \n?
}
-token CODE_END_TP2 { '</script>' \n?
}
+# embedding code into a sea of text
+token sea_or_code { <code_short_tag> {*} #= code_short_tag
+ | <code_script_tag> {*} #= code_script_tag
+ | <SEA> {*} #= SEA
+ }
+regex SEA { '<'? .+? ( <before '<'> | $ )
{*} }
+rule code_short_tag { <.CODE_START_SHORT_TAG> <statement>*
<.CODE_END_SHORT_TAG>? {*} }
+rule code_script_tag { <.CODE_START_SCRIPT_TAG> <statement>*
<.CODE_END_SCRIPT_TAG>? {*} }
+token CODE_START_SHORT_TAG { '<?' 'php'?
}
+token CODE_START_SCRIPT_TAG { '<script' <ws_char> 'language' '='
<quoted_lang_name> '>' }
+token quoted_lang_name { [ '"php"' | '\'php\'' ]
}
+token CODE_END_SHORT_TAG { '?>' \n?
}
+token CODE_END_SCRIPT_TAG { '</script' '>'
}
# block and statements
rule block { '{' <statement>* '}'
{*} }
@@ -40,8 +42,8 @@
| <if_statement> {*} #= if_statement
| <while_statement> {*} #= while_statement
| <for_statement> {*} #= for_statement
- | <inline_sea_tp1> {*} #= inline_sea_tp1
- | <inline_sea_tp2> {*} #= inline_sea_tp2
+ | <inline_sea_short_tag> {*} #=
inline_sea_short_tag
+ | <inline_sea_script_tag> {*} #=
inline_sea_script_tag
| <var_assign> {*} #= var_assign
| <function_definition> {*} #=
function_definition
| <class_definition> {*} #= class_definition
@@ -64,8 +66,8 @@
<expression>
')' <block>
{*}
}
-token inline_sea_tp1 { <.CODE_END_TP1> <SEA_empty_allowed>
<.CODE_START_TP1> {*} }
-token inline_sea_tp2 { <.CODE_END_TP2> <SEA_empty_allowed>
<.CODE_START_TP2> {*} }
+token inline_sea_short_tag { <.CODE_END_SHORT_TAG> <SEA_empty_allowed>
<.CODE_START_SHORT_TAG> {*} }
+token inline_sea_script_tag { <.CODE_END_SCRIPT_TAG> <SEA_empty_allowed>
<.CODE_START_SCRIPT_TAG> {*} }
regex SEA_empty_allowed { <-[<]>*? <before '<'>
}
rule var_assign { <var> '=' <expression>
<.statement_delimiter> {*} }
Modified: trunk/languages/pipp/t/in_php/02_sanity.t
==============================================================================
--- trunk/languages/pipp/t/in_php/02_sanity.t (original)
+++ trunk/languages/pipp/t/in_php/02_sanity.t Thu Nov 6 12:46:58 2008
@@ -28,4 +28,5 @@
is();
isnt();
+# vim: expandtab shiftwidth=4 ft=php:
?>
Added: trunk/languages/pipp/t/php/tags.t
==============================================================================
--- (empty file)
+++ trunk/languages/pipp/t/php/tags.t Thu Nov 6 12:46:58 2008
@@ -0,0 +1,82 @@
+# Copyright (C) 2008, The Perl Foundation.
+# $Id$
+
+=head1 NAME
+
+t/php/tags.t - PHP code tags
+
+=head1 SYNOPSIS
+
+ % perl -I../lib pipp/t/php/tags.t
+
+=head1 DESCRIPTION
+
+Tests Pipp's parsing of PHP code tags
+
+See L<http://www.php.net/manual/en/language.basic-syntax.php>
+
+=cut
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
+
+use Test::More tests => 7;
+use Parrot::Test;
+
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'short tags w/ close' );
+<?echo "hello world\n";?>
+CODE
+hello world
+OUTPUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'short tags w/o close' );
+<?echo "hello world\n";
+CODE
+hello world
+OUTPUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'short php tags w/ close' );
+<?php echo "hello world\n";
+CODE
+hello world
+OUTPUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'short echoing tags', todo
=> 'not implemented' );
+<?= "hello world\n";
+CODE
+hello world
+OUTPUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'clean script tags, single
quotes' );
+<script language='php'> echo "hello world\n"; </script>
+CODE
+hello world
+OUTPUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'clean script tags, double
quotes' );
+<script language="php"> echo "hello world\n"; </script>
+CODE
+hello world
+OUTPUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'messy script tags', todo =>
"grammar needs work" );
+<script
+ language =
+ 'php'
+ >
+ echo "hello world\n";
+ </script >
+CODE
+hello world
+OUTPUT
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4: