Changeset 3488
- Timestamp:
- Mar 23, 2005, 2:15:15 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Metadata-Config/lib/PS/IPP/Metadata/Config.pm
r3485 r3488 1 1 # Copyright (c) 2005 Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1.1 1 2005-03-23 21:30:37jhoblitt Exp $3 # $Id: Config.pm,v 1.12 2005-03-24 00:15:15 jhoblitt Exp $ 4 4 5 5 package PS::IPP::Metadata::Config; … … 45 45 return undef unless defined $tree; 46 46 47 # look for duplicate names, there should be none after processing the 48 # multi-symbols 49 $self->_merge_duplicates( $tree ) or return undef; 50 47 51 #print Dumper($tree); 48 52 49 53 return $tree; 54 } 55 56 sub _merge_duplicates { 57 my ( $self, $tree ) = @_; 58 59 # encountered names 60 my %names; 61 62 # Iteratate through the parse tree looking for duplicate declarations and 63 # resolving them by discarding elements according to the value of 64 # 'overwrite'. 65 for (my $i = 0; $i < @{$tree}; $i++) { 66 my $elem = $tree->[$i]; 67 68 # stop if the prevous pass removed the last element and called redo 69 last unless defined $elem; 70 71 # recurse through nested metadata 72 if ( $elem->{class} eq "metadata" ) { 73 $self->_merge_duplicates( $elem->{value} ); 74 } 75 76 # ignore elements with the "multi" flag 77 if ( defined $elem->{multi} ) { 78 delete $elem->{multi}; 79 next; 80 } 81 82 if ( defined $names{ $elem->{name} } ) { 83 if ( $self->{overwrite} ) { 84 # remove the previous occurance 85 carp "duplicate variable name: ", $elem->{name} 86 , ", removed previous occurance\n"; 87 splice @{$tree}, $names{ $elem->{name} }, 1; 88 } else { 89 # remove the current occurance 90 carp "duplicate variable name: ", $elem->{name} 91 , ", removed\n"; 92 splice @{$tree}, $i, 1; 93 } 94 95 # the list just got shorter by one element so we don't want to 96 # increment the cursor 97 redo; 98 } 99 100 # add element name and location to record of previously seen names 101 $names{ $elem->{name} } = $i; 102 } 103 104 return 1; 50 105 } 51 106 … … 86 141 <skip:'[ \t\r]*'> name type <matchrule:$item{type}> comment(?) "\n" 87 142 { 143 $thisparser->{local}{name}{ $item{name} }++ 144 unless defined $thisparser->{local}{name}{ $item{name} }; 145 88 146 $return = { 89 147 class => 'scalar', … … 95 153 $return->{comment} = $item{'comment(?)'}[0] 96 154 if $item{'comment(?)'}[0]; 155 156 if ( defined $thisparser->{local}{name}{ $item{name} } ) { 157 $return->{multi}++ 158 if $thisparser->{local}{name}{ $item{name} } =~ /MULTI/; 159 } else { 160 $thisparser->{local}{name}{ $item{name} }++; 161 } 97 162 } 98 163 … … 100 165 <skip:'[ \t\r]*'> vname vtype vvalue[ $item{vtype} ] comment(?) "\n" 101 166 { 167 $thisparser->{local}{name}{ $item{vname} }++ 168 unless defined $thisparser->{local}{name}{ $item{vname} }; 169 102 170 $return = { 103 171 class => 'vector', … … 113 181 114 182 multi_declare: 115 <skip:'[ \t\r]*'> name /MULTI/i comment(?) "\n" 116 {{ 117 class => 'comment_line', 118 }} 183 <skip:'[ \t\r]*'> name /MULTI/i <commit> comment(?) "\n" 184 { 185 if ( ! defined $thisparser->{local}{name}{ $item{name} } ) { 186 $thisparser->{local}{name}{ $item{name} } = "MULTI"; 187 $return = { class => 'comment_line' }; 188 } else { 189 $return = undef; 190 } 191 } 192 | <error?:redefinition of MULTI> <reject> 119 193 120 194 metadata:
Note:
See TracChangeset
for help on using the changeset viewer.
