1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
# /=====================================================================\ #
# | LaTeXML::Core::Array | #
# | Support for Lists or Arrays of digestable stuff for LaTeXML | #
# |=====================================================================| #
# | Part of LaTeXML: | #
# | Public domain software, produced as part of work done by the | #
# | United States Government & not subject to copyright in the US. | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov> #_# | #
# | http://dlmf.nist.gov/LaTeXML/ (o o) | #
# \=========================================================ooo==U==ooo=/ #
package LaTeXML::Core::Array;
use strict;
use warnings;
use LaTeXML::Global;
use LaTeXML::Common::Object;
use LaTeXML::Core::Parameter;
use base qw(LaTeXML::Common::Object);
# This class represents (potentially) delimited lists of things;
# currently it does not cover the actual parameter type/parser, just the result,
# since there are a variety of syntaxes, commas or not, etc.
# The following tokens (individual Token's or Tokens') describe how to revert the Array
# open,close and separator are the outermost delimiter and separator between items
# itemopen,itemclose are delimiters for each item -- If any
sub new {
my ($class, %options) = @_;
return bless { type => $options{type},
open => $options{open}, close => $options{close}, separator => $options{separator},
itemopen => $options{itemopen}, itemclose => $options{itemclose},
values => $options{values} }, $class; }
sub getValue {
my ($self, $n) = @_;
return $$self{values}[$n]; }
sub setValue {
my ($self, $n, $value) = @_;
return $$self{values}[$n] = $value; }
sub getValues {
my ($self) = @_;
return @{ $$self{values} }; }
sub beDigested {
my ($self, $stomach) = @_;
my @v = ();
my $type = $$self{type};
foreach my $item (@{ $$self{values} }) {
push(@v, ($type ? $type->digest($stomach, $item, undef) : ($item ? $item->beDigested($stomach) : $item))); }
return (ref $self)->new(open => $$self{open}, close => $$self{close}, separator => $$self{separator},
itemopen => $$self{itemopen}, itemclose => $$self{itemclose},
type => $$self{type}, values => [@v]); }
sub revert {
my ($self) = @_;
my @tokens = ();
foreach my $item (@{ $$self{values} }) {
push(@tokens, $$self{separator}->unlist) if $$self{separator} && @tokens;
push(@tokens, $$self{itemopen}->unlist) if $$self{itemopen};
push(@tokens, Revert($item));
push(@tokens, $$self{itemclose}->unlist) if $$self{itemclose}; }
unshift(@tokens, $$self{open}->unlist) if $$self{open};
push(@tokens, $$self{close}->unlist) if $$self{close};
return @tokens; }
sub unlist {
my ($self) = @_;
return @{ $$self{values} }; } # ????
sub toString {
my ($self) = @_;
my $string = '';
foreach my $item (@{ $$self{values} }) {
$string .= ', ' if $string;
$string .= ToString($item); }
return '[[' . $string . ']]'; }
#======================================================================
1;
__END__
=pod
=head1 NAME
C<LaTeXML::Core::Array> - support for Arrays of objects
=head1 DESCRIPTION
Provides a representation of arrays of digested objects.
It extends L<LaTeXML::Common::Object>.
=head2 Methods
=over 4
=item C<< LaTeXML::Core::Array->new(%options); >>
Creates an Array object
Options are
values List of values; typically Tokens, initially.
type The type of objects (as a ParameterType)
The following are Tokens lists that are used for reverting to raw TeX,
each can be undef
open the opening delimiter eg "{"
close the closing delimiter eg "}"
separator the separator between items, eg ","
itemopen the opening delimiter for each item
itemclose the closing delimiter for each item
=back
=head2 Accessors
=over 4
=item C<< $value = $array->getValue($n) >>
Return the C<$n>-th item in the list.
=item C<< $array->setValue($n,$value) >>
Sets the C<$n>-th value to C<$value>.
=item C<< @values = $keyval->getValues(); >>
Return the list of values.
=item C<< $keyval->beDigested; >>
Return a new C<LaTeXML::Core::Array> object with all values digested as appropriate.
=back
=head1 AUTHOR
Bruce Miller <bruce.miller@nist.gov>
=head1 COPYRIGHT
Public domain software, produced as part of work done by the
United States Government & not subject to copyright in the US.
=cut
|