Author: cotto
Date: Thu Nov 6 15:48:16 2008
New Revision: 32413
Modified:
trunk/languages/pipp/src/pct/actions.pm
trunk/languages/pipp/src/pct/grammar.pg
trunk/languages/pipp/t/php/tags.t
Log:
[pipp] tighten tag parsing, add echo tags
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 15:48:16 2008
@@ -53,6 +53,20 @@
make $past;
}
+method code_echo_tag($/) {
+ my $past := PAST::Stmts.new( :node($/) );
+
+ my $echo := $( $<arguments> );
+ $echo.name( 'echo' );
+ $past.push( $echo );
+
+ for $<statement> {
+ $past.push( $($_) );
+ }
+
+ make $past;
+}
+
method code_script_tag($/) {
my $past := PAST::Stmts.new( :node($/) );
for $<statement> {
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 15:48:16 2008
@@ -22,18 +22,33 @@
token multilinecomment { '/*' .*? '*/' }
# embedding code into a sea of text
-token sea_or_code { <code_short_tag> {*} #= code_short_tag
+token sea_or_code { <code_echo_tag> {*} #= code_echo_tag
+ | <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_echo_tag { <.CODE_START_ECHO_TAG>
+ <arguments> <.statement_delimiter>
+ <statement>*
+ <.CODE_END_SHORT_TAG>?
{*}
+ }
rule code_script_tag { <.CODE_START_SCRIPT_TAG> <statement>*
<.CODE_END_SCRIPT_TAG>? {*} }
+rule code_short_tag { <.CODE_START_SHORT_TAG> <statement>*
<.CODE_END_SHORT_TAG>? {*} }
+
+regex CODE_START_SCRIPT_TAG { '<script' <ws_char>+:
+ 'language' <ws_char>*:
+ '=' <ws_char>*:
+ <quoted_lang_name> <ws_char>*:
+ '>'
+ }
+regex CODE_END_SCRIPT_TAG { '</script' <ws_char>*: '>'
}
+token quoted_lang_name { [ '"php"' | '\'php\'' ]
}
+
+token CODE_START_ECHO_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' '>'
}
+token CODE_END_SHORT_TAG { '?>' \n?
}
# block and statements
rule block { '{' <statement>* '}'
{*} }
Modified: trunk/languages/pipp/t/php/tags.t
==============================================================================
--- trunk/languages/pipp/t/php/tags.t (original)
+++ trunk/languages/pipp/t/php/tags.t Thu Nov 6 15:48:16 2008
@@ -23,7 +23,7 @@
use FindBin;
use lib "$FindBin::Bin/../../../../lib", "$FindBin::Bin/../../lib";
-use Test::More tests => 7;
+use Test::More tests => 8;
use Parrot::Test;
@@ -45,7 +45,7 @@
hello world
OUTPUT
-language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'short echoing tags', todo
=> 'not implemented' );
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'short echoing tags' );
<?= "hello world\n";
CODE
hello world
@@ -63,7 +63,13 @@
hello world
OUTPUT
-language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'messy script tags', todo =>
"grammar needs work" );
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'broken script tag' );
+<scriptlanguage="php"> echo "hello world\n"; </script>
+CODE
+<scriptlanguage="php"> echo "hello world\n"; </script>
+OUTPUT
+
+language_output_is( 'Pipp', <<'CODE', <<'OUTPUT', 'messy script tags' );
<script
language =
'php'