Changeset 3456
- Timestamp:
- Mar 18, 2005, 2:45:37 PM (21 years ago)
- Location:
- trunk/PS-IPP-Metadata-Config
- Files:
-
- 2 edited
-
lib/PS/IPP/Metadata/Config.pm (modified) (3 diffs)
-
t/09_sdrs_type_example.t (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Metadata-Config/lib/PS/IPP/Metadata/Config.pm
r3454 r3456 1 1 # Copyright (c) 2005 Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1. 6 2005-03-18 23:38:05jhoblitt Exp $3 # $Id: Config.pm,v 1.7 2005-03-19 00:45:37 jhoblitt Exp $ 4 4 5 5 package PS::IPP::Metadata::Config; … … 155 155 156 156 __DATA__ 157 158 { 159 use strict; 160 use warnings FATAL => qw( all ); 161 162 use Carp qw( croak ); 163 } 157 164 158 165 startrule: grammar … … 234 241 {{ 235 242 class => 'blank_line', 236 comment => $item{comment},237 243 }} 238 244 239 245 typedef_declare: 240 <skip:'[ \t\r]*'> 'TYPE' <commit> name name(s) "\n"246 <skip:'[ \t\r]*'> 'TYPE' <commit> name name(s) comment(?) "\n" 241 247 { 242 248 use Carp; 243 249 244 my $len = scalar @{ $item{'name(s)'} };245 246 250 if (defined $thisparser->{local}{typedef}{ $item{name} }) { 247 251 croak "refinition of TYPE $item{name}"; 248 252 } 249 253 250 $thisparser->{local}{typedef}{ $item{name} } = $len; 251 252 $return = { 254 my $type = { 253 255 class => 'typedef_declare', 254 256 name => $item{name}, 255 value => $item{'name(s)'}, 257 fields => $item{'name(s)'}, 258 length => scalar @{ $item{'name(s)'} }, 256 259 }; 257 } 258 | <skip:'[ \t\r]*'> 'TYPE' <commit> name name(s) comment "\n" 259 {{ 260 class => 'typedef_declare', 261 name => $item{name}, 262 value => $item{'name(s)'}, 263 comment => $item{comment}, 264 }} 260 261 $thisparser->{local}{typedef}{ $item{name} } = $type; 262 263 # don't return anything in the parse tree 264 $return = { class => 'blank_line' }; 265 } 265 266 266 267 typedef: 267 <skip:'[ \t\r]*'> name typedef_type name(s) "\n"268 <skip:'[ \t\r]*'> name typedef_type name(s) comment(?) "\n" 268 269 { 270 my $type = $thisparser->{local}{typedef}{ $item{typedef_type} }; 271 272 unless ( scalar @{ $item{'name(s)'} } == $type->{length} ) { 273 croak "\"$item{name} $item{typedef_type}\"" 274 . " does not have enough fields"; 275 } 276 277 my @md; 278 my $i = 0; 279 foreach my $name ( @{ $type->{fields} } ) { 280 push @md, { 281 name => $name, 282 class => 'scalar', 283 type => 'STR', 284 value => $item{'name(s)'}[$i], 285 }; 286 287 $i++; 288 } 289 269 290 $return = { 270 class => ' typedef',291 class => 'metadata', 271 292 name => $item{name}, 272 type => $item{typedef_type}, 273 value => $item{'name(s)'}, 293 value => \@md, 274 294 }; 275 295 } -
trunk/PS-IPP-Metadata-Config/t/09_sdrs_type_example.t
r3421 r3456 3 3 # Copyright (C) 2005 Joshua Hoblitt 4 4 # 5 # $Id: 09_sdrs_type_example.t,v 1. 1 2005-03-15 04:41:44jhoblitt Exp $5 # $Id: 09_sdrs_type_example.t,v 1.2 2005-03-19 00:45:37 jhoblitt Exp $ 6 6 7 7 use strict; … … 12 12 #$::RD_TRACE = 1; 13 13 14 use Test::More tests => 3;14 use Test::More tests => 5; 15 15 use PS::IPP::Metadata::Config; 16 16 … … 22 22 23 23 { 24 my $pt = $config_parser->parse( $example[0] ); 24 my $pt = $config_parser->parse( shift @example ); 25 ok( defined( $pt ), "valid parase tree"); 26 } 27 28 { 29 my $pt = $config_parser->parse( shift @example ); 25 30 ok( defined( $pt ), "valid parase tree"); 26 31 } 27 32 28 33 eval { 29 my $pt = $config_parser->parse( $example[1] ); 34 my $pt = $config_parser->parse( shift @example ); 35 }; 36 like( $@, qr/does not have enough fields/, "missing fields"); 37 38 eval { 39 my $pt = $config_parser->parse( shift @example ); 30 40 }; 31 41 like( $@, qr/refinition of TYPE/, "TYPE redefinition"); 32 42 33 43 eval { 34 my $pt = $config_parser->parse( $example[2]);44 my $pt = $config_parser->parse( shift @example ); 35 45 }; 36 46 like( $@, qr/missing TYPE defintion/, "missing TYPE defnition"); … … 39 49 TYPE CELL EXTNAME BIASSEC CHIP 40 50 CELL.00 CELL CCD00 BSEC-00 CHIP.00 51 CELL.01 CELL CCD01 BSEC-01 CHIP.00 52 % 53 TYPE CELL EXTNAME BIASSEC CHIP # comment 54 CELL.00 CELL CCD00 BSEC-00 CHIP.00 # foo 55 CELL.01 CELL CCD01 BSEC-01 CHIP.00 # 56 % 57 TYPE CELL EXTNAME BIASSEC CHIP 58 CELL.00 CELL CCD00 BSEC-00 41 59 CELL.01 CELL CCD01 BSEC-01 CHIP.00 42 60 %
Note:
See TracChangeset
for help on using the changeset viewer.
