Data-SCS-DefParser

 view release on metacpan or  search on metacpan

lib/Data/SCS/DefParser.pm  view on Meta::CPAN

  my ($pre, $in) = $data =~ m/^([^\{]*)\{(.*)\}/s;
  return (trim $pre, trim $in);
}


method include_file ($file) {
  $archive_has_entry{$file} or croak
    sprintf "Couldn't find file '%s' in: %s", $file, join ", ", @mounts;
  my $inc = $archive->read_entry($file);
  utf8::decode($inc);
  my @inc = grep {$_} map {trim $_} split m/\n/, $inc;
  return @inc;
}


method parse_sii ($file) {
  utf8::decode my $sii = $archive->read_entry($file);
  my ($magic, $unit) = parse_block $sii;
  $magic =~ m/^ \N{ BYTE ORDER MARK }? SiiNunit $/x or die
    sprintf "Expected SiiNunit, found '%s' in %s", $magic, $file;
  my @input = grep {$_} map {trim $_} split m/\n/, $unit;
  my @lines;
  while (my $line = shift @input) {
    if (my ($inc) = $line =~ m/^\@include\s+"([^"]+)"$/) {
      my $inc_path = path("/$file")->parent->relative("/")->child($inc);
      unshift @input, $self->include_file($inc_path);
      next;
    }
    push @lines, $line;
  }
  @lines = map {trim $_} map {

lib/Data/SCS/DefParser.pm  view on Meta::CPAN



sub parse_sui_data_value {
  my $value = shift;
  if ( $value =~ m/^&([0-9A-Fa-f]{8})$/ ) {  # IEEE 754 binary32 float
    return 'Inf' if lc $1 eq '7f7fffff';  # max finite value / no data marker
    return sprintf '%.9g', unpack 'f', pack 'h8', scalar reverse $1;
    # 9 significant digits are sufficient to represent any 32-bit float.
  }
  if ( $value =~ m/^\(([^()]+)\)$/ ) {
    return join ', ', map { parse_sui_data_value( trim $_ ) } split m/,/, $1;
  }
  if ( $value =~ m/^"([^"]+)"$/ ) {
    my $str = $1 =~ s{ \\x( [0-9A-Fa-f]{2} ) }{ chr hex $1 }egrx;
    utf8::decode $str;
    return $str;
  }
  if ( $value =~ m/^0x( [0-9A-Fa-f]{6,8} )$/x ) {
    return $1;
  }
  if ( $value eq 'true' ) {

lib/Data/SCS/DefParser.pm  view on Meta::CPAN

      @raw = ();
      next;
    }
    if ($lines[$i] eq '}') {
      parse_sui_data $ats_data, $key, @raw;
      $key = undef;
      $block--;
      next;
    }
    if ($block && $lines[$i] !~ m/"/ && $lines[$i] =~ m/:/) {  # parse Reforma one-liners
      push @raw, split m/(?<=[a-z])\s+/, $lines[$i];
      next;
    }
    if ($block) {
      push @raw, $lines[$i];
      next;
    }
  }
}




( run in 0.574 second using v1.01-cache-2.11-cpan-71847e10f99 )