package xm::pfe::grab4compiles;
use strict;
use xm::o;

sub DESC
{"
  will look for all PFE COMPILES-declaration which is a macro to
  define a global static structure outside any ITEMCDEF.
  Mark these as ITEMCDEF on the outer closure and some inner portions
  with XXXXCOMPILES.
"}

sub DO
{
    my $in = shift;

    # use-CDEFS style    
    $in =~ s{  (^|</ITEMCDEF(?:\s[^<>]*)?>)  
		   ((?:.(?!</?(?:CDOC|ITEMCDEF)[\s>]))*.?)
		   ((?: \ *<CDOC(?:\s[^<>]*)?(?=>)  
		     (?:.(?!</?CDOC[\s>]))*.  
		     </CDOC(?:\s[^<>]*)?> \ *\s? )*)
		   (\b(?:P4)?COMPILES\d*) 
		   (\s*\(\s*) (\w+) ((?:\s*,\s*\w+)+) (\s*\)\s*\;\ *\s?)
            } 
            { 
                print STDERR ":"; 
                $1.$2
                ."<ITEMCDEF>".$3
                ."<TYPECOMPILES>".$4."</TYPECOMPILES>".$5
                ."<NAMECOMPILES>".$6."</NAMECOMPILES>"
                ."<INFOCOMPILES>".$7."</INFOCOMPILES>".$8
                ."</ITEMCDEF>" 
            }gsex;
   
    return $in;
} 

sub ARGS { return    xm::o::args_stdin(@_,DESC); }
sub main { return DO(xm::o::args_stdin(@_,DESC)); }

1;