Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions lib/LaTeXML/Core/Gullet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,26 @@ sub readingFromMouth {
my $mouth;
my $intokens;
my $sourcetype = ref $source;
if (! $sourcetype) { # for a string, create Mouth to read its content
if (!$sourcetype) { # for a string, create Mouth to read its content
$mouth = LaTeXML::Core::Mouth->new($source); }
elsif ($sourcetype =~ /^LaTeXML::Core::Tokens?$/) { # Tokens will be unread into Mouth
$mouth = LaTeXML::Core::Mouth->new();
elsif ($sourcetype =~ /^LaTeXML::Core::Tokens?$/) { # Tokens will be unread into Mouth
$mouth = LaTeXML::Core::Mouth->new();
$intokens = $source; }
elsif (! $source->isa('LaTeXML::Core::Mouth')) {
Error('expected','Mouth', $self,
elsif (!$source->isa('LaTeXML::Core::Mouth')) {
Error('expected', 'Mouth', $self,
"Input source was not a string, Tokens or Mouth: $source; ignoring it.");
$mouth = LaTeXML::Core::Mouth->new(); }
else {
$mouth = $source; }
openMouth($self, $mouth, 1); # only allow mouth to be explicitly closed here.
$self->unread($intokens) if $intokens; # Preload the mouth
openMouth($self, $mouth, 1); # only allow mouth to be explicitly closed here.
$self->unread($intokens) if $intokens; # Preload the mouth
my ($result, @result);
if (wantarray) {
@result = &$closure($self); }
else {
$result = &$closure($self); }
$self->skipSpaces; # Skip any remaining spaces on input.
# $mouth must still be open, with (at worst) empty autoclosable mouths in front of it
$self->skipSpaces; # Skip any remaining spaces on input.
# $mouth must still be open, with (at worst) empty autoclosable mouths in front of it
while (1) {
if ($$self{mouth} eq $mouth) {
closeMouth($self, 1); last; }
Expand Down Expand Up @@ -186,10 +186,10 @@ sub showUnexpected {
my ($self) = @_;
my $message = "Input is empty";
if (my $token = peekToken($self)) {
my @pb = @{ $$self{pushback} }[1..-1];
my @pb = @{ $$self{pushback} }[1 .. -1];
$message = "Next token is " . Stringify($token)
. " ( == " . Stringify($STATE->lookupMeaning($token)) . ")"
. (@pb ? " more: " . ToString(TokensI(@pb)) : ''); }
. (@pb ? " more: " . ToString(TokensI(@pb)) : ''); }
return $message; }

sub show_pushback {
Expand Down Expand Up @@ -328,7 +328,7 @@ sub readToken {
# This might be needed in more places?
sub peekToken {
my ($self) = @_;
local $LaTeXML::ALIGN_STATE = 1000000; # Inhibit readToken from processing {}!!!
local $LaTeXML::ALIGN_STATE = 1000000; # Inhibit readToken from processing {}!!!
if (my $token = readToken($self)) {
unshift(@{ $$self{pushback} }, $token);
return $token; }
Expand Down Expand Up @@ -734,7 +734,7 @@ sub readArg {
else {
if ($expanded) {
return $self->readingFromMouth(Tokens(T_BEGIN, $token, T_END), sub {
readBalanced($self, $expanded, 0, 1); } ); }
readBalanced($self, $expanded, 0, 1); }); }
else {
return Tokens($token); } } }

Expand Down Expand Up @@ -795,7 +795,14 @@ sub readRegisterValue {
local $LaTeXML::CURRENT_TOKEN = $token;
my $parms = $$defn{parameters};
my $value = $defn->valueOf(($parms ? $parms->readArguments($self) : ()));
if ($type eq $rtype) {
if (!ref $value) {
Warn('malformed', 'register_value', $self,
"Register " . ToString($token) . " did not return a proper value, got " . Stringify($value));
if ($coercer) {
return &$coercer($sign * $value); }
else {
return Number($value); } } # Default to Number fallback
elsif ($type eq $rtype) {
return ($sign < 0 ? $value->negate : $value); }
else {
return &$coercer($sign * $value->valueOf); } }
Expand Down