1# /=====================================================================\ # 2# | LaTeXML::Core::Parameters | # 3# | Representation of Parameters for Control Sequences | # 4# |=====================================================================| # 5# | Part of LaTeXML: | # 6# | Public domain software, produced as part of work done by the | # 7# | United States Government & not subject to copyright in the US. | # 8# |---------------------------------------------------------------------| # 9# | Bruce Miller <bruce.miller@nist.gov> #_# | # 10# | http://dlmf.nist.gov/LaTeXML/ (o o) | # 11# \=========================================================ooo==U==ooo=/ # 12package LaTeXML::Core::Parameters; 13use strict; 14use warnings; 15use LaTeXML::Global; 16use LaTeXML::Common::Object; 17use LaTeXML::Common::Error; 18use LaTeXML::Core::Parameter; 19use LaTeXML::Core::Tokens; 20use base qw(LaTeXML::Common::Object); 21 22sub new { 23 my ($class, @paramspecs) = @_; 24 return bless [@paramspecs], $class; } 25 26sub getParameters { 27 my ($self) = @_; 28 return @$self; } 29 30sub stringify { 31 my ($self) = @_; 32 my $string = ''; 33 foreach my $parameter (@$self) { 34 my $s = $parameter->stringify; 35 $string .= ' ' if ($string =~ /\w$/) && ($s =~ /^\w/); 36 $string .= $s; } 37 return $string; } 38 39sub equals { 40 my ($self, $other) = @_; 41 return (defined $other) 42 && ((ref $self) eq (ref $other)) && ($self->stringify eq $other->stringify); } 43 44sub getNumArgs { 45 my ($self) = @_; 46 my $n = 0; 47 foreach my $parameter (@$self) { 48 $n++ unless $$parameter{novalue}; } 49 return $n; } 50 51sub revertArguments { 52 my ($self, @args) = @_; 53 my @tokens = (); 54 foreach my $parameter (@$self) { 55 next if $$parameter{novalue}; 56 push(@tokens, $parameter->revert(shift(@args))); } 57 return @tokens; } 58 59sub readArguments { 60 my ($self, $gullet, $fordefn) = @_; 61 my @args = (); 62 $gullet->setup_scan(); 63 my ($p, $v); 64 return map { $p = $_; $v = $p && $p->read($gullet, $fordefn); ($$p{novalue} ? () : $v); } @$self; } 65 66sub readArgumentsAndDigest { 67 my ($self, $stomach, $fordefn) = @_; 68 my @args = (); 69 my $gullet = $stomach->getGullet; 70 $gullet->setup_scan(); 71 foreach my $parameter (@$self) { 72 my $value = $parameter->read($gullet, $fordefn); 73 if (!$$parameter{novalue}) { 74 $value = $parameter->digest($stomach, $value, $fordefn); 75 push(@args, $value); } } 76 return @args; } 77 78sub reparseArgument { 79 my ($self, $gullet, $tokens) = @_; 80 if (defined $tokens) { 81 return $gullet->readingFromMouth(LaTeXML::Core::Mouth->new(), sub { # start with empty mouth 82 my ($gulletx) = @_; 83 $gulletx->unread($tokens); # but put back tokens to be read 84 my @values = $self->readArguments($gulletx); 85 $gulletx->skipSpaces; 86 return @values; }); } 87 else { 88 return (); } } 89 90#====================================================================== 911; 92 93__END__ 94 95=pod 96 97=head1 NAME 98 99C<LaTeXML::Core::Parameters> - formal parameters. 100 101=head1 DESCRIPTION 102 103Provides a representation for the formal parameters of L<LaTeXML::Core::Definition>s: 104It extends L<LaTeXML::Common::Object>. 105 106=head2 METHODS 107 108=over 4 109 110=item C<< @parameters = $parameters->getParameters; >> 111 112Return the list of C<LaTeXML::Core::Parameter> contained in C<$parameters>. 113 114=item C<< @tokens = $parameters->revertArguments(@args); >> 115 116Return a list of L<LaTeXML::Core::Token> that would represent the arguments 117such that they can be parsed by the Gullet. 118 119=item C<< @args = $parameters->readArguments($gullet,$fordefn); >> 120 121Read the arguments according to this C<$parameters> from the C<$gullet>. 122This takes into account any special forms of arguments, such as optional, 123delimited, etc. 124 125=item C<< @args = $parameters->readArgumentsAndDigest($stomach,$fordefn); >> 126 127Reads and digests the arguments according to this C<$parameters>, in sequence. 128this method is used by Constructors. 129 130=back 131 132=head1 SEE ALSO 133 134L<LaTeXML::Core::Parameter>. 135 136=head1 AUTHOR 137 138Bruce Miller <bruce.miller@nist.gov> 139 140=head1 COPYRIGHT 141 142Public domain software, produced as part of work done by the 143United States Government & not subject to copyright in the US. 144 145=cut 146