| 1 | # /=====================================================================\ # | ||
| 2 | # | LaTeXML::Core::Definition::CharDef | # | ||
| 3 | # | Representation of definitions of 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=/ # | ||
| 12 | package LaTeXML::Core::Definition::CharDef; | ||
| 13 | use strict; | ||
| 14 | use warnings; | ||
| 15 | use LaTeXML::Global; | ||
| 16 | use LaTeXML::Common::Object; | ||
| 17 | use LaTeXML::Common::Error; | ||
| 18 | use base qw(LaTeXML::Core::Definition::Register); | ||
| 19 | |||
| 20 | # A CharDef is a specialized register; | ||
| 21 | # You can't assign it; when you invoke the control sequence, it returns | ||
| 22 | # the result of evaluating the character (more like a regular primitive). | ||
| 23 | |||
| 24 | sub new { | ||
| 25 | my ($class, $cs, $value, $internalcs, %traits) = @_; | ||
| 26 | return bless { cs => $cs, parameters => undef, | ||
| 27 | value => $value, internalcs => $internalcs, | ||
| 28 | registerType => 'Number', readonly => 1, | ||
| 29 | locator => $STATE->getStomach->getGullet->getLocator, | ||
| 30 | %traits }, $class; } | ||
| 31 | |||
| 32 | sub valueOf { | ||
| 33 | my ($self) = @_; | ||
| 34 | return $$self{value}; } | ||
| 35 | |||
| 36 | sub setValue { | ||
| 37 | my ($self, $value) = @_; | ||
| 38 | Error('unexpected', $self, undef, "Can't assign to chardef " . $self->getCSName); | ||
| 39 | return; } | ||
| 40 | |||
| 41 | sub invoke { | ||
| 42 | my ($self, $stomach) = @_; | ||
| 43 | my $cs = $$self{internalcs}; | ||
| 44 | # Tracing ? | ||
| 45 | return (defined $cs ? $stomach->invokeToken($cs) : undef); } | ||
| 46 | |||
| 47 | sub equals { | ||
| 48 | my ($self, $other) = @_; | ||
| 49 | return (defined $other) | ||
| 50 | && ((ref $self) eq (ref $other)) | ||
| 51 | && ($$self{value}->valueOf == $$other{value}->valueOf); } | ||
| 52 | #=============================================================================== | ||
| 53 | 1; | ||
| 54 | |||
| 55 | __END__ |