Author: bernhard
Date: Thu Mar 22 13:26:21 2007
New Revision: 17693
Modified:
trunk/languages/plumhead/src/partridge/Plumhead.pg
trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
Log:
[Plumhead partridge]
Make it work for files without PHP code islands.
Modified: trunk/languages/plumhead/src/partridge/Plumhead.pg
==============================================================================
--- trunk/languages/plumhead/src/partridge/Plumhead.pg (original)
+++ trunk/languages/plumhead/src/partridge/Plumhead.pg Thu Mar 22 13:26:21 2007
@@ -9,7 +9,8 @@
token TOP { <program> }
-regex SEA { .*? <?before: \<> }
+regex SEA { <-[<]>+? ( <?before: \<> | $ ) }
+regex SEA_empty_allowed { <-[<]>*? <?before: \<> }
token CODE_START { <'<?php'> }
token CODE_END { <'?>'> <' '>* \n? }
token DOUBLEQUOTE_STRING { " <-["]>* " }
@@ -35,7 +36,8 @@
token IF { <'if'> }
token ELSE { <'else'> }
-token program { ^ <SEA> <code> }
+token program { ^ <sea_or_code>+ }
+token sea_or_code { <SEA> | <code> }
rule code { <?CODE_START> <statement>* <?CODE_END>? }
@@ -54,7 +56,7 @@
# TODO: rel_op_clause is not a nice name
rule rel_op_clause { <REL_OP> <expression> }
rule else_clause { <?ELSE> \{ <statement>* \} }
-token inline_sea { <?CODE_END> <SEA> <?CODE_START> }
+token inline_sea { <?CODE_END> <SEA_empty_allowed> <?CODE_START> }
rule scalar_assign { <var> <ASSIGN_OP> <expression> ; }
rule array_assign { <array_elem> <ASSIGN_OP> <expression> ; }
Modified: trunk/languages/plumhead/src/partridge/PlumheadPAST.tg
==============================================================================
--- trunk/languages/plumhead/src/partridge/PlumheadPAST.tg (original)
+++ trunk/languages/plumhead/src/partridge/PlumheadPAST.tg Thu Mar 22
13:26:21 2007
@@ -19,26 +19,37 @@
.return (past)
}
-# TODO: handle multiple code and sea blocks
transform past (Plumhead::Grammar::program) :language('PIR') {
.local pmc past
past = new 'PAST::Stmts'
past.'init'( 'node' => node )
- $P0 = node['SEA']
- if null $P0 goto handled_sea
- .local pmc past_sea
- past_sea = tree.'get'('past', $P0, 'Plumhead::Grammar::SEA')
- past.'push'(past_sea)
- handled_sea:
-
- $P0 = node['code']
- if null $P0 goto handled_code
- .local pmc past_code
- past_code = tree.'get'('past', $P0, 'Plumhead::Grammar::code')
- past.'push'(past_code)
- handled_code:
+ $P0 = node['sea_or_code']
+ .local pmc sea_or_code_iter
+ sea_or_code_iter = new .Iterator, $P0
+ iter_loop:
+ unless sea_or_code_iter goto iter_end
+
+ .local pmc cnode, past_sea, past_code
+ cnode = shift sea_or_code_iter
+ if null cnode goto iter_loop
+
+ $P1 = cnode['SEA']
+ if null $P1 goto no_SEA
+ past_sea = tree.'get'('past', $P1, 'Plumhead::Grammar::SEA')
+ past.'push'(past_sea)
+ no_SEA:
+
+ $P1 = cnode['code']
+ if null $P1 goto no_code
+ past_code = tree.'get'('past', $P1, 'Plumhead::Grammar::code')
+ past.'push'(past_code)
+ no_code:
+
+ goto iter_loop
+
+ iter_end:
.return (past)
}
@@ -140,7 +151,7 @@
$P1 = cnode['inline_sea']
if null $P1 goto no_inline_sea
- $P2 = $P1['SEA']
+ $P2 = $P1['SEA_empty_allowed']
past_sea = tree.'get'('past', $P2,
'Plumhead::Grammar::SEA')
past.'push'(past_sea)
goto iter_loop