lib/LaTeXML/Core/Gullet.pm

filter: Statementstmt 9.4% 67 / 707 Branchbran 0.0% 0 / 440 Conditioncond 0.0% 0 / 265 MC/DCmcdc 0.0% 0 / 146 Subroutinesub 26.6% 20 / 75 Podpod 43.6% 24 / 55 totaltotal 6.5% 111 / 1688 CC 317 SCAR 60.9
CC
317
Cov
5%
readBalanced
2049.3
readXToken
1171.8
readToken
650.0
CRAP 439.6
« lib/LaTeXML/Common/Glue.pm ↑ Summary lib/LaTeXML/Core/Rewrite.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Core::Gullet | #
3 # | Analog of TeX's Gullet; deals with expansion and arg parsing | #
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  
13 package LaTeXML::Core::Gullet;
14 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use LaTeXML::Core::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use LaTeXML::Core::Tokens;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use LaTeXML::Core::Mouth;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use LaTeXML::Util::Pathname;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use LaTeXML::Common::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use LaTeXML::Common::Float;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use LaTeXML::Common::Dimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 5 ▶use LaTeXML::Common::Glue;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 5 ▶use LaTeXML::Core::MuDimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 5 ▶use LaTeXML::Core::MuGlue;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 5 ▶use base qw(LaTeXML::Common::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
30 #**********************************************************************
31 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
32 0 my ($class, %options) = @_;
33 return bless {
34 mouth => undef, mouthstack => [], pushback => [], autoclose => 1, pending_comments => [],
35 0 ▶ verbosity => $options{verbosity} || 0,
Condition0%0/2
$options{'verbosity'} || 0
l!l
00
MC/DC0%0/1
$options{'verbosity'} || 0
$options{'verbosity'}
Truth table0%0/2
A
A= $options{'verbosity'}
Aresult
11
00
36 progress => 0,
37 }, $class; }
38  
39 5 our $TOKEN_PROGRESS_QUANTUM = 30000;
40  
41 #**********************************************************************
42 # Start reading tokens from a new Mouth.
43 # This pushes the mouth as the current source that $gullet->readToken (etc) will read from.
44 # Once this Mouth has been exhausted, readToken, etc, will return undef,
45 # until you call $gullet->closeMouth to clear the source.
46 # Exception: if $toplevel=1, readXToken will step to next source
47 # Note that a Tokens can act as a Mouth.
48 0 ▶sub openMouth {
Subroutine openMouth: not called CC=3 SCAR=24.8
Pod documented
49 0 my ($self, $mouth, $noautoclose) = @_;
50 0 ▶ return unless $mouth;
Branch: 1 branch
BranchTrueFalseTotal
unless $mouth 0 0 0
51 0 ▶ unshift(@{ $$self{mouthstack} }, [$$self{mouth}, $$self{pushback}, $$self{autoclose}]) if $$self{mouth};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"mouth"} 0 0 0
52 0 $$self{mouth} = $mouth;
53 0 $$self{pushback} = [];
54 0 $$self{autoclose} = !$noautoclose;
55 0 return; }
56  
57 0 ▶sub closeMouth {
Subroutine closeMouth: not called CC=5 SCAR=34.0
Pod documented
58 0 my ($self, $forced) = @_;
59 0 ▶ if (!$forced && (@{ $$self{pushback} } || $$self{mouth}->hasMoreInput)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $forced and @{$self->{"pushback"};} || $self->{"mouth"}->hasMoreInput) 0 0 0
Condition0%0/6
not $forced and @{$self->{"pushback"};} || $self->{"mouth"}->hasMoreInput
!ll&&!rl&&r
000
@{$self->{"pushback"};} or $self->{"mouth"}->hasMoreInput
l!l&&r!l&&!r
000
MC/DC0%0/3
not $forced and @{$self->{"pushback"};} || $self->{"mouth"}->hasMoreInput
not $forced @{$self->{"pushback"};} $self->{"mouth"}->hasMoreInput
Truth table0%0/4
not(A) and B or C
A= not $forcedB= @{$self->{"pushback"};}C= $self->{"mouth"}->hasMoreInput
ABCresult
0XX0
1000
11X1
1011
60 0 my $next = Stringify(readToken($self));
61 0 Error('unexpected', $next, $self, "Closing mouth with input remaining '$next'"); }
62 0 $$self{mouth}->finish;
63 0 ▶ if (@{ $$self{mouthstack} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{'mouthstack'};}) { } 0 0 0
64 0 ($$self{mouth}, $$self{pushback}, $$self{autoclose}) = @{ shift(@{ $$self{mouthstack} }) }; }
65 else {
66 0 $$self{pushback} = [];
67 0 $$self{mouth} = LaTeXML::Core::Mouth->new();
68 0 $$self{autoclose} = 1; }
69 0 return; }
70  
71 0 ▶sub getMouth {
Subroutine getMouth: not called CC=1 SCAR=6.9
Pod undocumented
72 0 my ($self) = @_;
73 0 return $$self{mouth}; }
74  
75 0 ▶sub mouthIsOpen {
Subroutine mouthIsOpen: not called CC=3 SCAR=24.8
Pod undocumented
76 0 my ($self, $mouth) = @_;
77 return ($$self{mouth} eq $mouth)
78 0 ▶ || grep { $_ && ($$_[0] eq $mouth) } @{ $$self{mouthstack} }; }
Condition0%0/6
$self->{'mouth'} eq $mouth || grep({$_ and $_->[0] eq $mouth;} @{$$self{'mouthstack'};})
l!l&&r!l&&!r
000
$_ && $_->[0] eq $mouth
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'mouth'} eq $mouth || grep({$_ and $_->[0] eq $mouth;} @{$$self{'mouthstack'};})
$self->{'mouth'} eq $mouth grep({$_ and $_->[0] eq $mouth;} @{$$self{'mouthstack'};})
MC/DC0%0/2
$_ && $_->[0] eq $mouth
$_ $_->[0] eq $mouth
Truth table0%0/3
A || B
A= $self->{'mouth'} eq $mouthB= grep({$_ and $_->[0] eq $mouth;} @{$$self{'mouthstack'};})
ABresult
1X1
011
000
Truth table0%0/3
A && B
A= $_B= $_->[0] eq $mouth
ABresult
0X0
100
111
79  
80 # This flushes a mouth so that it will be automatically closed, next time it's read
81 # Corresponds to TeX's \endinput
82 0 ▶sub flushMouth {
Subroutine flushMouth: not called CC=2 SCAR=17.9
Pod undocumented
83 0 my ($self) = @_;
84 0 my $mouth = $$self{mouth};
85 # Put the remainder of Mouth's current line at the END of the pushback stack, to be read
86 0 ▶ while (!$mouth->isEOL) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($mouth->isEOL) 0 0 0
87 0 push(@{ $$self{pushback} }, $mouth->readToken); }
88 0 $mouth->finish; # then finish the mouth (it'll get closed on next read)
89 0 return; }
90  
91 # Obscure, but the only way I can think of to End!! (see \bye or \end{document})
92 # Flush all sources (close all pending mouth's)
93 0 ▶sub flush {
Subroutine flush: not called CC=2 SCAR=17.9
Pod documented
94 0 my ($self) = @_;
95 0 $$self{mouth}->finish;
96 0 ▶ while (@{ $$self{mouthstack} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"mouthstack"};}) 0 0 0
97 0 my $entry = shift @{ $$self{mouthstack} };
98 0 $$entry[0]->finish; }
99 0 $$self{pushback} = [];
100 0 $$self{mouth} = LaTeXML::Core::Mouth->new();
101 0 $$self{mouthstack} = [];
102 0 return; }
103  
104 # Do something, while reading stuff from a specific Mouth.
105 # This reads ONLY from that mouth (or any mouth openned by code in that source),
106 # and the mouth should end up empty afterwards, and only be closed here.
107 0 ▶sub readingFromMouth {
Subroutine readingFromMouth: not called CC=8 SCAR=42.8
Pod undocumented
108 0 my ($self, $mouth, $closure) = @_;
109 0 openMouth($self, $mouth, 1); # only allow mouth to be explicitly closed here.
110 0 my ($result, @result);
111 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
112 0 @result = &$closure($self); }
113 else {
114 0 $result = &$closure($self); }
115 # $mouth must still be open, with (at worst) empty autoclosable mouths in front of it
116 0 while (1) {
117 0 ▶ if ($$self{mouth} eq $mouth) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'mouth'} eq $mouth) { } 0 0 0
elsif (not @{$self->{'mouthstack'};}) { } 0 0 0
elsif (not $self->{'autoclose'} or @{$self->{'pushback'};} or $self->{'mouth'}->hasMoreInput) { } 0 0 0
118 0 closeMouth($self, 1); last; }
119 0 elsif (!@{ $$self{mouthstack} }) {
120 0 Error('unexpected', '<closed>', $self, "Mouth is unexpectedly already closed",
121 0 "Reading from " . Stringify($mouth) . ", but it has already been closed."); last; }
122 0 ▶ elsif (!$$self{autoclose} || @{ $$self{pushback} } || $$self{mouth}->hasMoreInput) {
Condition0%0/6
not $self->{"autoclose"} or @{$self->{"pushback"};} or $self->{"mouth"}->hasMoreInput
l!l&&r!l&&!r
000
not $self->{"autoclose"} or @{$self->{"pushback"};}
l!l&&r!l&&!r
000
MC/DC0%0/3
not $self->{"autoclose"} or @{$self->{"pushback"};} or $self->{"mouth"}->hasMoreInput
not $self->{"autoclose"} @{$self->{"pushback"};} $self->{"mouth"}->hasMoreInput
Truth table0%0/4
not(A) or B or C
A= not $self->{"autoclose"}B= @{$self->{"pushback"};}C= $self->{"mouth"}->hasMoreInput
ABCresult
1XX1
01X1
0011
0000
123 0 my $next = Stringify(readToken($self));
124 0 Error('unexpected', $next, $self, "Unexpected input remaining: '$next'",
125 "Finished reading from " . Stringify($mouth) . ", but it still has input.");
126 0 $$self{mouth}->finish;
127 0 closeMouth($self, 1); } # ?? if we continue?
128 else {
129 0 closeMouth($self); } }
130 0 ▶ return (wantarray ? @result : $result); }
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
131  
132 # User feedback for where something (error?) occurred.
133 0 ▶sub getLocator {
Subroutine getLocator: not called CC=8 SCAR=42.8
Pod documented
134 0 my ($self) = @_;
135 0 my $mouth = $$self{mouth};
136 0 my $i = 0;
137 0 ▶ while ((defined $mouth) && (!defined $$mouth{source})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mouth and not defined $mouth->{"source"} and $i < scalar @{$self->{"mouthstack"};}) 0 0 0
Condition0%0/6
defined $mouth and not defined $mouth->{"source"} and $i < scalar @{$self->{"mouthstack"};}
!ll&&!rl&&r
000
defined $mouth and not defined $mouth->{"source"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $mouth and not defined $mouth->{"source"} and $i < scalar @{$self->{"mouthstack"};}
defined $mouth not defined $mouth->{"source"} $i < scalar @{$self->{"mouthstack"};}
Truth table0%0/4
A and not(B) and C
A= defined $mouthB= not defined $mouth->{"source"}C= $i < scalar @{$self->{"mouthstack"};}
ABCresult
0XX0
10X0
1100
1111
138 0 && ($i < scalar(@{ $$self{mouthstack} }))) {
139 0 $mouth = $$self{mouthstack}[$i++][0]; }
140 0 ▶ my $loc = (defined $mouth ? $mouth->getLocator : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $mouth ? : 0 0 0
141 0 ▶ return $loc if defined $loc;
Branch: 1 branch
BranchTrueFalseTotal
if defined $loc 0 0 0
142 0 foreach my $frame (@{ $$self{mouthstack} }) {
143 0 my $ml = $$frame[0]->getLocator;
144 0 ▶ return $ml if defined $ml; }
Branch: 1 branch
BranchTrueFalseTotal
if defined $ml 0 0 0
145 0 return; }
146  
147 0 ▶sub getSource {
Subroutine getSource: not called CC=5 SCAR=34.0
Pod undocumented
148 0 my ($self) = @_;
149 0 ▶ my $source = defined $$self{mouth} && $$self{mouth}->getSource;
Condition0%0/3
defined $self->{'mouth'} && $self->{'mouth'}->getSource
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{'mouth'} && $self->{'mouth'}->getSource
defined $self->{'mouth'} $self->{'mouth'}->getSource
Truth table0%0/3
A && B
A= defined $self->{'mouth'}B= $self->{'mouth'}->getSource
ABresult
0X0
100
111
150 0 ▶ if (!defined($source)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source) 0 0 0
151 0 foreach my $frame (@{ $$self{mouthstack} }) {
152 0 $source = $$frame[0]->getSource;
153 0 ▶ last if defined($source); } }
Branch: 1 branch
BranchTrueFalseTotal
if defined $source 0 0 0
154 0 return $source; }
155  
156 0 ▶sub getSourceMouth {
Subroutine getSourceMouth: not called CC=5 SCAR=34.0
Pod undocumented
157 0 my ($self) = @_;
158 0 my $mouth = $$self{mouth};
159 0 ▶ my $source = defined $mouth && $mouth->getSource;
Condition0%0/3
defined $mouth && $mouth->getSource
!ll&&!rl&&r
000
MC/DC0%0/2
defined $mouth && $mouth->getSource
defined $mouth $mouth->getSource
Truth table0%0/3
A && B
A= defined $mouthB= $mouth->getSource
ABresult
0X0
100
111
160 0 ▶ if (!defined($source)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source) 0 0 0
161 0 foreach my $frame (@{ $$self{mouthstack} }) {
162 0 $mouth = $$frame[0];
163 0 $source = $mouth->getSource;
164 0 ▶ last if defined($source); } }
Branch: 1 branch
BranchTrueFalseTotal
if defined $source 0 0 0
165 0 return $mouth; }
166  
167 # Handy message generator when we didn't get something expected.
168 0 ▶sub showUnexpected {
Subroutine showUnexpected: not called CC=3 SCAR=24.8
Pod undocumented
169 0 my ($self) = @_;
170 0 my $message = "Input is empty";
171 0 ▶ if (my $token = readToken($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $token = readToken($self)) 0 0 0
172 0 my @pb = @{ $$self{pushback} };
173 0 ▶ $message = "Next token is " . Stringify($token)
Branch: 1 branch
BranchTrueFalseTotal
@pb ? : 0 0 0
174 . " ( == " . Stringify($STATE->lookupMeaning($token)) . ")"
175 . (@pb ? " more: " . ToString(TokensI(@pb)) : '');
176 0 unshift(@{ $$self{pushback} }, $token);
177 }
178 0 return $message; }
179  
180 0 ▶sub show_pushback {
Subroutine show_pushback: not called CC=3 SCAR=24.8
Pod undocumented
181 0 my ($pb) = @_;
182 0 my @pb = @$pb;
183 0 ▶ @pb = (@pb[0 .. 50], T_OTHER('...')) if scalar(@pb) > 55;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @pb > 55 0 0 0
184 0 ▶ return (@pb ? "\n To be read again " . ToString(Tokens(@pb)) : ''); }
Branch: 1 branch
BranchTrueFalseTotal
@pb ? : 0 0 0
185  
186 #**********************************************************************
187 # Low-level readers: read token, read expanded token
188 #**********************************************************************
189 # Get the next pending comment token (if any)
190 0 ▶sub getPendingComment {
Subroutine getPendingComment: not called CC=1 SCAR=6.9
Pod undocumented
191 0 my ($self) = @_;
192 0 return shift @{ $$self{pending_comments} } }
193  
194 # Note that every char (token) comes through here (maybe even twice, through args parsing),
195 # So, be Fast & Clean! This method only reads from the current input stream (Mouth).
196 5 our @CATCODE_HOLD = (
197 0, 0, 0, 0,
198 0, 0, 0, 0,
199 0, 0, 0, 0,
200 0, 0, 1, 0,
201 0, 1, 0, 0);
202  
203 0 ▶sub handleMarker {
Subroutine handleMarker: not called CC=6 SCAR=37.4
Pod undocumented
204 0 my ($self, $markertoken) = @_;
205 0 my $arg = $$markertoken[0];
206 0 ▶ if (ref $arg) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $arg) { } 0 0 0
elsif ($arg eq 'before-column') { } 0 0 0
elsif ($arg eq 'after-column') { } 0 0 0
207 0 LaTeXML::Core::Definition::stopProfiling($markertoken, 'expand'); }
208 elsif ($arg eq 'before-column') { # Were in before-column template
209 0 my $alignment = $STATE->lookupValue('Alignment');
210 0 ▶ Debug("Halign $alignment: alignment state => 0") if $LaTeXML::DEBUG{halign};
Branch: 1 branch
BranchTrueFalseTotal
if $LaTeXML::DEBUG{"halign"} 0 0 0
211 0 $LaTeXML::ALIGN_STATE = 0; } # switch to column proper!
212 elsif ($arg eq 'after-column') { # Were in before-column template
213 0 my $alignment = $STATE->lookupValue('Alignment');
214 0 ▶ Debug("Halign $alignment: alignment state: after column") if $LaTeXML::DEBUG{halign};
Branch: 1 branch
BranchTrueFalseTotal
if $LaTeXML::DEBUG{"halign"} 0 0 0
215 }
216 0 return; }
217  
218 0 ▶sub handleTemplate {
Subroutine handleTemplate: not called CC=10 SCAR=47.0
Pod undocumented
219 0 my ($self, $alignment, $token, $type, $hidden) = @_;
220 Debug("Halign $alignment: ALIGNMENT Column ended at " . Stringify($token)
221 . " type $type [" . Stringify($STATE->lookupMeaning($token)) . "]"
222 . "@ " . ToString(getLocator($self)))
223 0 ▶ if $LaTeXML::DEBUG{halign};
Branch: 1 branch
BranchTrueFalseTotal
if $LaTeXML::DEBUG{"halign"} 0 0 0
224 # Append expansion to end!?!?!?!
225 0 local $LaTeXML::CURRENT_TOKEN = $token;
226 0 my $post = $alignment->getColumnAfter;
227 0 $LaTeXML::ALIGN_STATE = 1000000;
228 ### NOTE: Truly fishy smuggling w/ \hidden@cr
229 0 my $arg;
230 0 ▶ if (($type eq 'cr') && $hidden) { # \hidden@cr gets an argument as payload!!!!!
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "cr" and $hidden) 0 0 0
Condition0%0/3
$type eq "cr" and $hidden
!ll&&!rl&&r
000
MC/DC0%0/2
$type eq "cr" and $hidden
$type eq "cr" $hidden
Truth table0%0/3
A and B
A= $type eq "cr"B= $hidden
ABresult
0X0
100
111
231 0 $arg = readArg($self); }
232 0 ▶ Debug("Halign $alignment: column after " . ToString($post)) if $LaTeXML::DEBUG{halign};
Branch: 1 branch
BranchTrueFalseTotal
if $LaTeXML::DEBUG{"halign"} 0 0 0
233 0 ▶ if ((($type eq 'cr') || ($type eq 'crcr'))
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "cr" || $type eq "crcr" and $alignment->{"in_row"} and not $alignment->currentRow->{"pseudorow"}) 0 0 0
Condition0%0/9
$type eq "cr" || $type eq "crcr" and $alignment->{"in_row"} and not $alignment->currentRow->{"pseudorow"}
!ll&&!rl&&r
000
$type eq "cr" || $type eq "crcr" and $alignment->{"in_row"}
!ll&&!rl&&r
000
$type eq "cr" or $type eq "crcr"
l!l&&r!l&&!r
000
MC/DC0%0/4
$type eq "cr" || $type eq "crcr" and $alignment->{"in_row"} and not $alignment->currentRow->{"pseudorow"}
$type eq "cr" $type eq "crcr" $alignment->{"in_row"} not $alignment->currentRow->{"pseudorow"}
Truth table0%0/7
A or B and C and not(D)
A= $type eq "cr"B= $type eq "crcr"C= $alignment->{"in_row"}D= not $alignment->currentRow->{"pseudorow"}
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
234 && $$alignment{in_row} && !$alignment->currentRow->{pseudorow}) {
235 0 unshift(@{ $$self{pushback} }, T_CS('\@row@after')); }
236 0 ▶ if ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 0 0
237 0 unshift(@{ $$self{pushback} }, T_BEGIN, $arg->unlist, T_END); }
238 0 unshift(@{ $$self{pushback} }, $token);
239 0 unshift(@{ $$self{pushback} }, $post->unlist);
240 0 return; }
241  
242 # If it is a column ending token, Returns the token, a keyword and whether it is "hidden"
243 5 our @column_ends = ( # besides T_ALIGN
244 [T_CS('\cr'), 'cr', 0],
245 [T_CS('\crcr'), 'crcr', 0],
246 [T_CS('\hidden@cr'), 'cr', 1],
247 [T_CS('\hidden@crcr'), 'crcr', 1],
248 [T_CS('\hidden@align'), 'insert', 1],
249 [T_CS('\span'), 'span', 0]);
250  
251 0 ▶sub isColumnEnd {
Subroutine isColumnEnd: not called CC=10 SCAR=47.0
Pod undocumented
252 0 my ($self, $token) = @_;
253 0 my $cc = $$token[1];
254 0 ▶ return ($token, 'align', 0) if $cc == CC_ALIGN;
Branch: 1 branch
BranchTrueFalseTotal
if $cc == 4 0 0 0
255 0 ▶ return unless ($cc == CC_CS) || ($cc == CC_ACTIVE);
Branch: 1 branch
BranchTrueFalseTotal
unless $cc == 16 or $cc == 13 0 0 0
Condition0%0/3
$cc == 16 or $cc == 13
l!l&&r!l&&!r
000
MC/DC0%0/2
$cc == 16 or $cc == 13
$cc == 16 $cc == 13
Truth table0%0/3
A or B
A= $cc == 16B= $cc == 13
ABresult
1X1
011
000
256 # Embedded version of Equals, knowing both are tokens
257 0 ▶ my $defn = $STATE->lookupMeaning($token) || $token;
Condition0%0/3
$LaTeXML::Core::Gullet::STATE->lookupMeaning($token) || $token
l!l&&r!l&&!r
000
MC/DC0%0/2
$LaTeXML::Core::Gullet::STATE->lookupMeaning($token) || $token
$LaTeXML::Core::Gullet::STATE->lookupMeaning($token) $token
Truth table0%0/3
A || B
A= $LaTeXML::Core::Gullet::STATE->lookupMeaning($token)B= $token
ABresult
1X1
011
000
258 0 ▶ return ($token, 'align', 0) if (ref $defn eq 'LaTeXML::Core::Token') && ($$defn[1] == CC_ALIGN);
Branch: 1 branch
BranchTrueFalseTotal
if ref $defn eq "LaTeXML::Core::Token" and $defn->[1] == 4 0 0 0
Condition0%0/3
ref $defn eq "LaTeXML::Core::Token" and $defn->[1] == 4
!ll&&!rl&&r
000
MC/DC0%0/2
ref $defn eq "LaTeXML::Core::Token" and $defn->[1] == 4
ref $defn eq "LaTeXML::Core::Token" $defn->[1] == 4
Truth table0%0/3
A and B
A= ref $defn eq "LaTeXML::Core::Token"B= $defn->[1] == 4
ABresult
0X0
100
111
259 0 foreach my $end (@column_ends) {
260 0 my $e = $$end[0];
261 # Would be nice to cache the defns, but don't know when they're present & constant!
262 0 ▶ return @$end if $defn->equals($STATE->lookupMeaning($e) || $e); }
Branch: 1 branch
BranchTrueFalseTotal
if $defn->equals($LaTeXML::Core::Gullet::STATE->lookupMeaning($e) || $e) 0 0 0
Condition0%0/3
$LaTeXML::Core::Gullet::STATE->lookupMeaning($e) || $e
l!l&&r!l&&!r
000
MC/DC0%0/2
$LaTeXML::Core::Gullet::STATE->lookupMeaning($e) || $e
$LaTeXML::Core::Gullet::STATE->lookupMeaning($e) $e
Truth table0%0/3
A || B
A= $LaTeXML::Core::Gullet::STATE->lookupMeaning($e)B= $e
ABresult
1X1
011
000
263 0 return; }
264  
265 0 ▶sub readToken {
Subroutine readToken: not called CC=25 SCAR=64.8
Pod documented
266 0 my ($self) = @_;
267 # my $token = shift(@{$$self{pushback}});
268 0 my ($token, $cc, $atoken, $atype, $ahidden);
269 0 while (1) {
270 0 ▶ while (($token = shift(@{ $$self{pushback} }))
Branch: 1 branch
BranchTrueFalseTotal
if ($token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]) 0 0 0
Condition0%0/3
$token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
!ll&&!rl&&r
000
MC/DC0%0/2
$token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
$token = shift @{$$self{"pushback"};} $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
Truth table0%0/3
A and B
A= $token = shift @{$$self{"pushback"};}B= $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
ABresult
0X0
100
111
271 && $CATCODE_HOLD[$cc = $$token[1]]) {
272 0 ▶ if ($cc == CC_COMMENT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 14) { } 0 0 0
elsif ($cc == 17) { } 0 0 0
273 0 push(@{ $$self{pending_comments} }, $token); }
274 elsif ($cc == CC_MARKER) {
275 0 handleMarker($self, $token); } }
276 # Not in pushback, use the current mouth
277 0 ▶ if (!defined $token) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $token) 0 0 0
278 0 ▶ while (($token = $$self{mouth}->readToken()) && $CATCODE_HOLD[$cc = $$token[1]]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]) 0 0 0
Condition0%0/3
$token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
!ll&&!rl&&r
000
MC/DC0%0/2
$token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
$token = $self->{"mouth"}->readToken $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
Truth table0%0/3
A and B
A= $token = $self->{"mouth"}->readTokenB= $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
ABresult
0X0
100
111
279 0 ▶ if ($cc == CC_COMMENT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 14) { } 0 0 0
elsif ($cc == 17) { } 0 0 0
280 0 push(@{ $$self{pending_comments} }, $token); } # What to do with comments???
281 elsif ($cc == CC_MARKER) {
282 0 handleMarker($self, $token); } } }
283 0 ▶ ProgressStep() if ($$self{progress}++ % $TOKEN_PROGRESS_QUANTUM) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"progress"}++ % $LaTeXML::Core::Gullet::TOKEN_PROGRESS_QUANTUM == 0 0 0 0
284 # some infinite loops are hard to predict and may be
285 # better guarded against via a global token limit.
286 0 ▶ if ($LaTeXML::TOKEN_LIMIT and $$self{progress} > $LaTeXML::TOKEN_LIMIT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LaTeXML::TOKEN_LIMIT and $self->{"progress"} > $LaTeXML::TOKEN_LIMIT) 0 0 0
Condition0%0/3
$LaTeXML::TOKEN_LIMIT and $self->{"progress"} > $LaTeXML::TOKEN_LIMIT
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::TOKEN_LIMIT and $self->{"progress"} > $LaTeXML::TOKEN_LIMIT
$LaTeXML::TOKEN_LIMIT $self->{"progress"} > $LaTeXML::TOKEN_LIMIT
Truth table0%0/3
A and B
A= $LaTeXML::TOKEN_LIMITB= $self->{"progress"} > $LaTeXML::TOKEN_LIMIT
ABresult
0X0
100
111
287 0 Fatal('timeout', 'token_limit', $self,
288 "Token limit of $LaTeXML::TOKEN_LIMIT exceeded, infinite loop?"); }
289 0 ▶ if ($LaTeXML::PUSHBACK_LIMIT and scalar(@{ $$self{pushback} }) > $LaTeXML::PUSHBACK_LIMIT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LaTeXML::PUSHBACK_LIMIT and scalar @{$self->{"pushback"};} > $LaTeXML::PUSHBACK_LIMIT) 0 0 0
Condition0%0/3
$LaTeXML::PUSHBACK_LIMIT and scalar @{$self->{"pushback"};} > $LaTeXML::PUSHBACK_LIMIT
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::PUSHBACK_LIMIT and scalar @{$self->{"pushback"};} > $LaTeXML::PUSHBACK_LIMIT
$LaTeXML::PUSHBACK_LIMIT scalar @{$self->{"pushback"};} > $LaTeXML::PUSHBACK_LIMIT
Truth table0%0/3
A and B
A= $LaTeXML::PUSHBACK_LIMITB= scalar @{$self->{"pushback"};} > $LaTeXML::PUSHBACK_LIMIT
ABresult
0X0
100
111
290 0 Fatal('timeout', 'pushback_limit', $self,
291 "Pushback limit of $LaTeXML::PUSHBACK_LIMIT exceeded, infinite loop?"); }
292 # Wow!!!!! See TeX the Program \S 309
293 0 ▶ if ((defined $token)
Branch: 2 branches
BranchTrueFalseTotal
if (defined $token and not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)) { } 0 0 0
elsif (defined $token and $token->[1] == 16 and $token->[0] eq '\\dont_expand') { } 0 0 0
Condition0%0/9
defined $token and not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)
!ll&&!rl&&r
000
defined $token and not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT
!ll&&!rl&&r
000
defined $token and not $LaTeXML::ALIGN_STATE
!ll&&!rl&&r
000
MC/DC0%0/4
defined $token and not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)
defined $token not $LaTeXML::ALIGN_STATE $LaTeXML::READING_ALIGNMENT () = isColumnEnd($self, $token)
Truth table0%0/5
A and not(B) and C and D
A= defined $tokenB= not $LaTeXML::ALIGN_STATEC= $LaTeXML::READING_ALIGNMENTD= () = isColumnEnd($self, $token)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
294 && !$LaTeXML::ALIGN_STATE # SHOULD count nesting of { }!!! when SCANNED (not digested)
295 && $LaTeXML::READING_ALIGNMENT
296 && (($atoken, $atype, $ahidden) = isColumnEnd($self, $token))) {
297 0 handleTemplate($self, $LaTeXML::READING_ALIGNMENT, $token, $atype, $ahidden); }
298 ▶ elsif ((defined $token) && ($$token[1] == CC_CS) && ($$token[0] eq '\dont_expand')) {
Condition0%0/6
defined $token and $token->[1] == 16 and $token->[0] eq "\\dont_expand"
!ll&&!rl&&r
000
defined $token and $token->[1] == 16
!ll&&!rl&&r
000
MC/DC0%0/3
defined $token and $token->[1] == 16 and $token->[0] eq "\\dont_expand"
defined $token $token->[1] == 16 $token->[0] eq "\\dont_expand"
Truth table0%0/4
A and B and C
A= defined $tokenB= $token->[1] == 16C= $token->[0] eq "\\dont_expand"
ABCresult
0XX0
10X0
1100
1111
299 0 my $unexpanded = readToken($self); # Replace next token with a special \relax
300 0 return T_CS('\special_relax'); }
301 else {
302 0 last; } }
303 0 ▶ if ($token) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token) 0 0 0
304 0 $cc = $$token[1];
305 0 ▶ if ($cc == CC_BEGIN) { $LaTeXML::ALIGN_STATE++; }
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 1) { } 0 0 0
elsif ($cc == 2) { } 0 0 0
306 0 elsif ($cc == CC_END) { $LaTeXML::ALIGN_STATE--; }
307 }
308 0 return $token; }
309  
310 # Unread tokens are assumed to be not-yet expanded.
311 0 ▶sub unread {
Subroutine unread: not called CC=7 SCAR=40.3
Pod documented
312 0 my ($self, @tokens) = @_;
313 0 my $level = 0;
314 0 my $pb = $$self{pushback};
315 0 ▶ while (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 0 0 0
316 0 my $token = pop(@tokens);
317 0 my $r = ref $token;
318 0 ▶ if (!defined $token) { }
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $token) { } 0 0 0
elsif ($r eq 'LaTeXML::Core::Tokens') { } 0 0 0
elsif ($r eq 'LaTeXML::Core::Token') { } 0 0 0
319 elsif ($r eq 'LaTeXML::Core::Tokens') {
320 0 push(@tokens, @$token); }
321 elsif ($r eq 'LaTeXML::Core::Token') {
322 0 my $cc = $$token[1];
323 0 ▶ if ($cc == CC_BEGIN) { $level--; } # Retract scanned braces
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 1) { } 0 0 0
elsif ($cc == 2) { } 0 0 0
324 0 elsif ($cc == CC_END) { $level++; }
325 0 unshift(@$pb, $token); }
326 else {
327 0 Error('misdefined', $r, undef, "Expected a Token, got " . Stringify($_));
328 0 unshift(@$pb, T_OTHER($token)); } }
329 0 $LaTeXML::ALIGN_STATE += $level;
330 0 return; }
331  
332 # Read the next non-expandable token (expanding tokens until there's a non-expandable one).
333 # Note that most tokens pass through here, so be Fast & Clean! readToken is folded in.
334 # `Toplevel' processing, (if $toplevel is true), used at the toplevel processing by Stomach,
335 # will step to the next input stream (Mouth) if one is available,
336 # $toplevel is doing TWO distinct things. When true:
337 # * If a mouth is exhausted, move on to the containing mouth to continue reading
338 # * expand even protected defns, essentially this means expand "for execution"
339 # Note that, unlike readBalanced, this does NOT defer expansion of \the & friends.
340 # Also, \noexpand'd tokens effectively act ilke \relax
341 # For arguments to \if,\ifx, etc use $for_conditional true,
342 # which handles \noexpand and CS which have been \let to tokens specially.
343 0 ▶sub readXToken {
Subroutine readXToken: not called CC=35 SCAR=70.7
Pod documented
344 0 my ($self, $toplevel, $for_conditional) = @_;
345 0 ▶ $toplevel = 1 unless defined $toplevel;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $toplevel 0 0 0
346 0 my $autoclose = $toplevel; # Potentially, these should have distinct controls?
347 0 my $for_evaluation = $toplevel;
348 0 my ($token, $cc, $defn, $atoken, $atype, $ahidden);
349 0 while (1) {
350 0 ▶ while (($token = shift(@{ $$self{pushback} })) && $CATCODE_HOLD[$cc = $$token[1]]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]) 0 0 0
Condition0%0/3
$token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
!ll&&!rl&&r
000
MC/DC0%0/2
$token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
$token = shift @{$$self{"pushback"};} $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
Truth table0%0/3
A and B
A= $token = shift @{$$self{"pushback"};}B= $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
ABresult
0X0
100
111
351 0 ▶ if ($cc == CC_COMMENT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 14) { } 0 0 0
elsif ($cc == 17) { } 0 0 0
352 0 push(@{ $$self{pending_comments} }, $token); }
353 elsif ($cc == CC_MARKER) {
354 0 handleMarker($self, $token); } }
355 0 ▶ if (!defined $token) { # Else read from current mouth
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $token) 0 0 0
356 0 ▶ while (($token = $$self{mouth}->readToken()) && $CATCODE_HOLD[$cc = $$token[1]]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]) 0 0 0
Condition0%0/3
$token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
!ll&&!rl&&r
000
MC/DC0%0/2
$token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
$token = $self->{"mouth"}->readToken $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
Truth table0%0/3
A and B
A= $token = $self->{"mouth"}->readTokenB= $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
ABresult
0X0
100
111
357 0 ▶ if ($cc == CC_COMMENT) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 14) { } 0 0 0
elsif ($cc == 17) { } 0 0 0
358 0 push(@{ $$self{pending_comments} }, $token); }
359 elsif ($cc == CC_MARKER) {
360 0 handleMarker($self, $token); } } }
361 0 ▶ ProgressStep() if ($$self{progress}++ % $TOKEN_PROGRESS_QUANTUM) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"progress"}++ % $LaTeXML::Core::Gullet::TOKEN_PROGRESS_QUANTUM == 0 0 0 0
362 0 ▶ if (!defined $token) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $token) { } 0 0 0
elsif ($cc == 16 and $token->[0] eq '\\dont_expand') { } 0 0 0
elsif (not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)) { } 0 0 0
elsif ($LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token))) { } 0 0 0
elsif ($token->[1] == 16 and not defined $defn) { } 0 0 0
363 0 ▶ return unless $autoclose && $$self{autoclose} && @{ $$self{mouthstack} };
Branch: 1 branch
BranchTrueFalseTotal
unless $autoclose and $self->{"autoclose"} and @{$self->{"mouthstack"};} 0 0 0
Condition0%0/6
$autoclose and $self->{"autoclose"} and @{$self->{"mouthstack"};}
!ll&&!rl&&r
000
$autoclose and $self->{"autoclose"}
!ll&&!rl&&r
000
MC/DC0%0/3
$autoclose and $self->{"autoclose"} and @{$self->{"mouthstack"};}
$autoclose $self->{"autoclose"} @{$self->{"mouthstack"};}
Truth table0%0/4
A and B and C
A= $autocloseB= $self->{"autoclose"}C= @{$self->{"mouthstack"};}
ABCresult
0XX0
10X0
1100
1111
364 0 closeMouth($self); } # Next input stream.
365 ▶ elsif (($cc == CC_CS) && ($$token[0] eq '\dont_expand')) {
Condition0%0/3
$cc == 16 and $token->[0] eq "\\dont_expand"
!ll&&!rl&&r
000
MC/DC0%0/2
$cc == 16 and $token->[0] eq "\\dont_expand"
$cc == 16 $token->[0] eq "\\dont_expand"
Truth table0%0/3
A and B
A= $cc == 16B= $token->[0] eq "\\dont_expand"
ABresult
0X0
100
111
366 0 my $unexpanded = readToken($self);
367 0 ▶ return ($for_conditional && ($$unexpanded[1] == CC_ACTIVE) ? $unexpanded : T_CS('\special_relax')); }
Branch: 1 branch
BranchTrueFalseTotal
$for_conditional && $unexpanded->[1] == 13 ? : 0 0 0
Condition0%0/3
$for_conditional and $unexpanded->[1] == 13
!ll&&!rl&&r
000
MC/DC0%0/2
$for_conditional and $unexpanded->[1] == 13
$for_conditional $unexpanded->[1] == 13
Truth table0%0/3
A and B
A= $for_conditionalB= $unexpanded->[1] == 13
ABresult
0X0
100
111
368 ## Wow!!!!! See TeX the Program \S 309
369 ▶ elsif (!$LaTeXML::ALIGN_STATE # SHOULD count nesting of { }!!! when SCANNED (not digested)
Condition0%0/6
not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)
!ll&&!rl&&r
000
not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT
!ll&&!rl&&r
000
MC/DC0%0/3
not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)
not $LaTeXML::ALIGN_STATE $LaTeXML::READING_ALIGNMENT () = isColumnEnd($self, $token)
Truth table0%0/4
not(A) and B and C
A= not $LaTeXML::ALIGN_STATEB= $LaTeXML::READING_ALIGNMENTC= () = isColumnEnd($self, $token)
ABCresult
0XX0
10X0
1100
1111
370 && $LaTeXML::READING_ALIGNMENT
371 && (($atoken, $atype, $ahidden) = isColumnEnd($self, $token))) {
372 0 handleTemplate($self, $LaTeXML::READING_ALIGNMENT, $token, $atype, $ahidden); }
373 ## Note: use general-purpose lookup, since we may reexamine $defn below
374 ▶ elsif ($LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc]
Condition0%0/3
$LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token))
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token))
$LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token))
Truth table0%0/3
A and B
A= $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc]B= defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token))
ABresult
0X0
100
111
375 && defined($defn = $STATE->lookupMeaning($token))) {
376 0 ▶ if ((ref $defn) eq 'LaTeXML::Core::Token') { # \let to a token? Return it!
Branch: 2 branches
BranchTrueFalseTotal
if (ref $defn eq 'LaTeXML::Core::Token') { } 0 0 0
elsif (not $defn->isExpandable or $defn->{'isProtected'} and not $for_evaluation) { } 0 0 0
377 0 ▶ return ($for_conditional ? $defn : $token); }
Branch: 1 branch
BranchTrueFalseTotal
$for_conditional ? : 0 0 0
378 ▶ elsif (!$defn->isExpandable # Not expandable or is protected
Condition0%0/6
not $defn->isExpandable or $defn->{"isProtected"} and not $for_evaluation
l!l&&r!l&&!r
000
$defn->{"isProtected"} and not $for_evaluation
!ll&&!rl&&r
000
MC/DC0%0/3
not $defn->isExpandable or $defn->{"isProtected"} and not $for_evaluation
not $defn->isExpandable $defn->{"isProtected"} not $for_evaluation
Truth table0%0/4
not(A) or B and not(C)
A= not $defn->isExpandableB= $defn->{"isProtected"}C= not $for_evaluation
ABCresult
1XX1
0111
00X0
0100
379 || ($$defn{isProtected} && !$for_evaluation)) {
380 0 return $token; }
381 else {
382 0 local $LaTeXML::CURRENT_TOKEN = $token;
383 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
384 0 my $expansion = $defn->invoke($self);
385 # add the newly expanded tokens back into the gullet stream, in the ordinary case.
386 0 ▶ unread($self, $expansion) if $expansion; } }
Branch: 1 branch
BranchTrueFalseTotal
if $expansion 0 0 0
387 ▶ elsif ($$token[1] == CC_CS && !(defined $defn)) {
Condition0%0/3
$token->[1] == 16 and not defined $defn
!ll&&!rl&&r
000
MC/DC0%0/2
$token->[1] == 16 and not defined $defn
$token->[1] == 16 not defined $defn
Truth table0%0/3
A and not(B)
A= $token->[1] == 16B= not defined $defn
ABresult
0X0
100
111
388 0 $STATE->generateErrorStub($self, $token); # cs SHOULD have defn by now; report early!
389 0 return $token; }
390 else {
391 0 ▶ if ($cc == CC_BEGIN) { $LaTeXML::ALIGN_STATE++; }
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 1) { } 0 0 0
elsif ($cc == 2) { } 0 0 0
392 0 elsif ($cc == CC_END) { $LaTeXML::ALIGN_STATE--; }
393 0 return $token; } # just return it
394 }
395 0 return; } # never get here.
396  
397 # readBalanced approximates TeX's scan_toks (but doesn't parse \def parameter lists)
398 # and only optionally requires the openning "{".
399 # It may return comments in the token lists.
400 # it optionally ($expand) expands while reading, but deferring \the and related.
401 # The $macrodef flag affects whether # parameters are "packed" for macro bodies.
402 # If $require_open is true, the opening T_BEGIN has not yet been read, and is required.
403 5 our $DEFERRED_COMMANDS = {
404 '\the' => 1,
405 '\showthe' => 1,
406 '\unexpanded' => 1,
407 '\detokenize' => 1
408 };
409  
410 0 ▶sub readBalanced {
Subroutine readBalanced: not called CC=46 SCAR=76.3
Pod documented
411 0 my ($self, $expanded, $macrodef, $require_open) = @_;
412 0 ▶ $LaTeXML::ALIGN_STATE-- unless $require_open; # assume matching } [BEFORE masking ALIGN_STATE]
Branch: 1 branch
BranchTrueFalseTotal
unless $require_open 0 0 0
413 0 local $LaTeXML::ALIGN_STATE = 1000000;
414 0 ▶ my $startloc = ($$self{verbosity} > 0) && getLocator($self);
Condition0%0/3
$self->{'verbosity'} > 0 && getLocator($self)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{'verbosity'} > 0 && getLocator($self)
$self->{'verbosity'} > 0 getLocator($self)
Truth table0%0/3
A && B
A= $self->{'verbosity'} > 0B= getLocator($self)
ABresult
0X0
100
111
415 # Does we need to expand to get the { ???
416 0 ▶ if ($require_open) {
Branch: 1 branch
BranchTrueFalseTotal
if ($require_open) 0 0 0
417 0 ▶ my $token = ($expanded ? readXToken($self, 0) : readToken($self));
Branch: 1 branch
BranchTrueFalseTotal
$expanded ? : 0 0 0
418 0 ▶ if ((!$token) || ($$token[1] != CC_BEGIN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $token or $token->[1] != 1) 0 0 0
Condition0%0/3
not $token or $token->[1] != 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not $token or $token->[1] != 1
not $token $token->[1] != 1
Truth table0%0/3
not(A) or B
A= not $tokenB= $token->[1] != 1
ABresult
1X1
011
000
419 0 Error('expected', '{', $self, "Expected opening '{'");
420 0 return TokensI(); } }
421 0 my @tokens = ();
422 0 my $level = 1;
423 0 my ($token, $cc, $defn, $atoken, $atype, $ahidden);
424 # Inlined readToken (we'll keep comments in the result)
425 0 while (1) {
426 0 ▶ if (@{ $$self{pending_comments} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"pending_comments"};}) 0 0 0
427 0 push(@tokens, @{ $$self{pending_comments} });
428 0 $$self{pending_comments} = []; }
429 # Examine pushback first
430 0 ▶ while (($token = shift(@{ $$self{pushback} })) && $CATCODE_HOLD[$cc = $$token[1]]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]) 0 0 0
Condition0%0/3
$token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
!ll&&!rl&&r
000
MC/DC0%0/2
$token = shift @{$$self{"pushback"};} and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
$token = shift @{$$self{"pushback"};} $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
Truth table0%0/3
A and B
A= $token = shift @{$$self{"pushback"};}B= $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
ABresult
0X0
100
111
431 0 ▶ if ($cc == CC_COMMENT) { push(@tokens, $token); }
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 14) { } 0 0 0
elsif ($cc == 17) { } 0 0 0
432 0 elsif ($cc == CC_MARKER) { handleMarker($self, $token); } }
433 0 ▶ if (!defined $token) { # Else read from current mouth
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $token) 0 0 0
434 0 ▶ while (($token = $$self{mouth}->readToken()) && $CATCODE_HOLD[$cc = $$token[1]]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]) 0 0 0
Condition0%0/3
$token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
!ll&&!rl&&r
000
MC/DC0%0/2
$token = $self->{"mouth"}->readToken and $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
$token = $self->{"mouth"}->readToken $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
Truth table0%0/3
A and B
A= $token = $self->{"mouth"}->readTokenB= $LaTeXML::Core::Gullet::CATCODE_HOLD[$cc = $token->[1]]
ABresult
0X0
100
111
435 0 ▶ if ($cc == CC_COMMENT) { push(@tokens, $token); }
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 14) { } 0 0 0
elsif ($cc == 17) { } 0 0 0
436 0 elsif ($cc == CC_MARKER) { handleMarker($self, $token); } } }
437 0 ▶ ProgressStep() if ($$self{progress}++ % $TOKEN_PROGRESS_QUANTUM) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"progress"}++ % $LaTeXML::Core::Gullet::TOKEN_PROGRESS_QUANTUM == 0 0 0 0
438 0 ▶ if (!defined $token) {
Branch: 6 branches
BranchTrueFalseTotal
if (not defined $token) { } 0 0 0
elsif ($cc == 16 and $token->[0] eq '\\dont_expand') { } 0 0 0
elsif ($cc == 2) { } 0 0 0
elsif ($cc == 1) { } 0 0 0
elsif (not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)) { } 0 0 0
elsif ($expanded and $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token)) and ref $defn ne 'LaTeXML::Core::Token' and $defn->isExpandable and not $defn->{'isProtected'}) { } 0 0 0
439 # What's the right error handling now?
440 0 last; }
441 ▶ elsif (($cc == CC_CS) && ($$token[0] eq '\dont_expand')) {
Condition0%0/3
$cc == 16 and $token->[0] eq "\\dont_expand"
!ll&&!rl&&r
000
MC/DC0%0/2
$cc == 16 and $token->[0] eq "\\dont_expand"
$cc == 16 $token->[0] eq "\\dont_expand"
Truth table0%0/3
A and B
A= $cc == 16B= $token->[0] eq "\\dont_expand"
ABresult
0X0
100
111
442 0 push(@tokens, readToken($self)); } # Pass on NEXT token, unchanged.
443 elsif ($cc == CC_END) {
444 0 $LaTeXML::ALIGN_STATE--;
445 0 $level--;
446 0 ▶ if (!$level) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($level) 0 0 0
447 0 last; }
448 0 push(@tokens, $token); }
449 elsif ($cc == CC_BEGIN) {
450 0 $LaTeXML::ALIGN_STATE++;
451 0 $level++;
452 0 push(@tokens, $token); }
453 ## Wow!!!!! See TeX the Program \S 309
454 # Not sure if this code still applies within scan_toks???
455 ▶ elsif (!$LaTeXML::ALIGN_STATE # SHOULD count nesting of { }!!! when SCANNED (not digested)
Condition0%0/6
not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)
!ll&&!rl&&r
000
not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT
!ll&&!rl&&r
000
MC/DC0%0/3
not $LaTeXML::ALIGN_STATE and $LaTeXML::READING_ALIGNMENT and () = isColumnEnd($self, $token)
not $LaTeXML::ALIGN_STATE $LaTeXML::READING_ALIGNMENT () = isColumnEnd($self, $token)
Truth table0%0/4
not(A) and B and C
A= not $LaTeXML::ALIGN_STATEB= $LaTeXML::READING_ALIGNMENTC= () = isColumnEnd($self, $token)
ABCresult
0XX0
10X0
1100
1111
456 && $LaTeXML::READING_ALIGNMENT
457 && (($atoken, $atype, $ahidden) = isColumnEnd($self, $token))) {
458 0 handleTemplate($self, $LaTeXML::READING_ALIGNMENT, $token, $atype, $ahidden); }
459 ## Note: use general-purpose lookup, since we may reexamine $defn below
460 ▶ elsif ($expanded &&
Condition0%0/15
$expanded and $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token)) and ref $defn ne "LaTeXML::Core::Token" and $defn->isExpandable and not $defn->{"isProtected"}
!ll&&!rl&&r
000
$expanded and $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token)) and ref $defn ne "LaTeXML::Core::Token" and $defn->isExpandable
!ll&&!rl&&r
000
$expanded and $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token)) and ref $defn ne "LaTeXML::Core::Token"
!ll&&!rl&&r
000
$expanded and $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token))
!ll&&!rl&&r
000
$expanded and $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc]
!ll&&!rl&&r
000
MC/DC0%0/6
$expanded and $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] and defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token)) and ref $defn ne "LaTeXML::Core::Token" and $defn->isExpandable and not $defn->{"isProtected"}
$expanded $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc] defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token)) ref $defn ne "LaTeXML::Core::Token" $defn->isExpandable not $defn->{"isProtected"}
Truth table0%0/7
A and B and C and D and E and not(F)
A= $expandedB= $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc]C= defined($defn = $LaTeXML::Core::Gullet::STATE->lookupMeaning($token))D= ref $defn ne "LaTeXML::Core::Token"E= $defn->isExpandableF= not $defn->{"isProtected"}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
461 $LaTeXML::Core::State::CATCODE_ACTIVE_OR_CS[$cc]
462 && defined($defn = $STATE->lookupMeaning($token))
463 && ((ref $defn) ne 'LaTeXML::Core::Token') # an actual definition
464 && $defn->isExpandable
465 && (!$$defn{isProtected})) { # is this the right logic here? don't expand unless di
466 0 local $LaTeXML::CURRENT_TOKEN = $token;
467 0 my $r;
468 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
469 0 my $expansion = $defn->invoke($self);
470 0 ▶ next unless $expansion;
Branch: 1 branch
BranchTrueFalseTotal
unless $expansion 0 0 0
471 # If a special \the type command, push the expansion directly into the result
472 # Well, almost directly: handle any MARKER tokens now, and possibly un-pack T_PARAM
473 0 ▶ if ($$DEFERRED_COMMANDS{ $$defn{cs}[0] }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$LaTeXML::Core::Gullet::DEFERRED_COMMANDS{$defn->{'cs'}[0]}) { } 0 0 0
474 0 foreach my $t (@$expansion) {
475 0 my $cc = $$t[1];
476 0 ▶ if ($cc == CC_MARKER) { handleMarker($self, $t); }
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 17) { } 0 0 0
elsif ($cc == 6 and $macrodef) { } 0 0 0
477 ▶ elsif (($cc == CC_PARAM) && $macrodef) {
Condition0%0/3
$cc == 6 and $macrodef
!ll&&!rl&&r
000
MC/DC0%0/2
$cc == 6 and $macrodef
$cc == 6 $macrodef
Truth table0%0/3
A and B
A= $cc == 6B= $macrodef
ABresult
0X0
100
111
478 0 push(@tokens, $t, $t); } # "unpack" to cover the packParameters at end!
479 else {
480 0 push(@tokens, $t); } }
481 }
482 else { # otherwise, prepend to pushback to be expanded further.
483 0 ▶ unread($self, $expansion) if $expansion; } }
Branch: 1 branch
BranchTrueFalseTotal
if $expansion 0 0 0
484 else {
485 0 ▶ if ($expanded && ($$token[1] == CC_CS) && !(defined $defn)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expanded and $token->[1] == 16 and not defined $defn) 0 0 0
Condition0%0/6
$expanded and $token->[1] == 16 and not defined $defn
!ll&&!rl&&r
000
$expanded and $token->[1] == 16
!ll&&!rl&&r
000
MC/DC0%0/3
$expanded and $token->[1] == 16 and not defined $defn
$expanded $token->[1] == 16 not defined $defn
Truth table0%0/4
A and B and not(C)
A= $expandedB= $token->[1] == 16C= not defined $defn
ABCresult
0XX0
10X0
1100
1111
486 0 $STATE->generateErrorStub($self, $token); } # cs SHOULD have defn by now; report early!
487 0 push(@tokens, $token); } # just return it
488 }
489 0 ▶ if ($level > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level > 0) 0 0 0
490 # TODO: The current implementation has a limitation where if the balancing end is in a different mouth,
491 # it will not be recognized.
492 0 ▶ my $loc_message = $startloc ? ("Started at " . ToString($startloc)) : ("Ended at " . ToString(getLocator($self)));
Branch: 1 branch
BranchTrueFalseTotal
$startloc ? : 0 0 0
493 0 Error('expected', "}", $self, "Gullet->readBalanced ran out of input in an unbalanced state.",
494 $loc_message); }
495 0 ▶ return ($macrodef ? TokensI(@tokens)->packParameters : TokensI(@tokens)); }
Branch: 1 branch
BranchTrueFalseTotal
$macrodef ? : 0 0 0
496  
497 #======================================================================
498  
499 # Read the next raw line (string);
500 # primarily to read from the Mouth, but keep any unread input!
501 0 ▶sub readRawLine {
Subroutine readRawLine: not called CC=3 SCAR=24.8
Pod undocumented
502 0 my ($self) = @_;
503 # If we've got unread tokens, they presumably should come before the Mouth's raw data
504 # but we'll convert them back to string.
505 0 my @tokens = @{ $$self{pushback} };
506 0 my @markers = grep { $_->getCatcode == CC_MARKER } @tokens;
507 0 ▶ if (@markers) { # Whoops, profiling markers!
Branch: 1 branch
BranchTrueFalseTotal
if (@markers) 0 0 0
508 0 @tokens = grep { $_->getCatcode != CC_MARKER } @tokens; # Remove
509 0 map { LaTeXML::Core::Definition::stopProfiling($_, 'expand') } @markers; }
510 0 $$self{pushback} = [];
511 # If we still have peeked tokens, we ONLY want to combine it with the remainder
512 # of the current line from the Mouth (NOT reading a new line)
513 0 ▶ if (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) { } 0 0 0
514 0 return ToString(TokensI(@tokens)) . $$self{mouth}->readRawLine(1); }
515 # Otherwise, read the next line from the Mouth.
516 else {
517 0 return $$self{mouth}->readRawLine; } }
518  
519 #**********************************************************************
520 # Mid-level readers: checking and matching tokens, strings etc.
521 #**********************************************************************
522 # General note: TeX uses different tests for Space tokens in different places
523 # (possibilities: catcode equality, ->equals, Equals and XEquals)
524  
525 # The following higher-level parsing methods are built upon readToken & unread.
526 0 ▶sub readNonSpace {
Subroutine readNonSpace: not called CC=3 SCAR=24.8
Pod documented
527 0 my ($self) = @_;
528 0 my $token;
529 0 ▶ do { $token = readToken($self);
Branch: 1 branch
BranchTrueFalseTotal
defined $token and $token->[1] == 10 and do { do { $token = readToken($self) } } 0 0 0
Condition0%0/3
defined $token and $token->[1] == 10
!ll&&!rl&&r
000
MC/DC0%0/2
defined $token and $token->[1] == 10
defined $token $token->[1] == 10
Truth table0%0/3
A and B
A= defined $tokenB= $token->[1] == 10
ABresult
0X0
100
111
530 } while (defined $token && $$token[1] == CC_SPACE); # Inline ->getCatcode!
531 0 return $token; }
532  
533 0 ▶sub readXNonSpace {
Subroutine readXNonSpace: not called CC=3 SCAR=24.8
Pod undocumented
534 0 my ($self) = @_;
535 0 my $token;
536 0 ▶ do { $token = readXToken($self, 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $token and $token->[1] == 10 and do { do { $token = readXToken($self, 0) } } 0 0 0
Condition0%0/3
defined $token and $token->[1] == 10
!ll&&!rl&&r
000
MC/DC0%0/2
defined $token and $token->[1] == 10
defined $token $token->[1] == 10
Truth table0%0/3
A and B
A= defined $tokenB= $token->[1] == 10
ABresult
0X0
100
111
537 } while (defined $token && $$token[1] == CC_SPACE); # Inline ->getCatcode!
538 0 return $token; }
539  
540 0 ▶sub skipSpaces {
Subroutine skipSpaces: not called CC=2 SCAR=17.9
Pod documented
541 0 my ($self) = @_;
542 0 my $tok = readNonSpace($self);
543 0 ▶ unread($self, $tok) if defined $tok;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tok 0 0 0
544 0 return; }
545  
546 # Skip one space
547 # if $expanded is true, it acts like <one optional space>, expanding the next token.
548 0 ▶sub skip1Space {
Subroutine skip1Space: not called CC=4 SCAR=30.0
Pod documented
549 0 my ($self, $expanded) = @_;
550 0 ▶ my $token = ($expanded ? readXToken($self) : readToken($self));
Branch: 1 branch
BranchTrueFalseTotal
$expanded ? : 0 0 0
551 0 ▶ unread($self, $token) if $token && !$token->defined_as(T_SPACE);
Branch: 1 branch
BranchTrueFalseTotal
if $token and not $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' )) 0 0 0
Condition0%0/3
$token and not $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
!ll&&!rl&&r
000
MC/DC0%0/2
$token and not $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
$token not $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
Truth table0%0/3
A and not(B)
A= $tokenB= not $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
ABresult
0X0
100
111
552 0 return; }
553  
554 # <filler> = <optional spaces> | <filler>\relax<optional spaces>
555 0 ▶sub skipFiller {
Subroutine skipFiller: not called CC=3 SCAR=24.8
Pod undocumented
556 0 my ($self) = @_;
557 0 while (1) {
558 0 my $tok = readNonSpace($self);
559 0 ▶ return unless defined $tok;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tok 0 0 0
560 # Should \foo work too (where \let\foo\relax) ??
561 0 ▶ if (!$tok->equals(T_CS('\relax'))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok->equals(T_CS("\\relax"))) 0 0 0
562 0 unread($self, $tok);
563 0 return; }
564 }
565 0 return; }
566  
567 0 ▶sub ifNext {
Subroutine ifNext: not called CC=2 SCAR=17.9
Pod documented
568 0 my ($self, $token) = @_;
569 0 ▶ if (my $tok = readToken($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tok = readToken($self)) { } 0 0 0
570 0 unread($self, $tok);
571 0 return $tok->equals($token); }
572 0 else { return 0; } }
573  
574 # Match the input against one of the Token or Tokens in @choices; return the matching one or undef.
575 0 ▶sub readMatch {
Subroutine readMatch: not called CC=11 SCAR=48.8
Pod documented
576 0 my ($self, @choices) = @_;
577 0 foreach my $choice (@choices) {
578 0 my @tomatch = $choice->unlist;
579 0 my @matched = ();
580 0 my $token;
581 0 ▶ while (@tomatch && defined($token = readToken($self))
Branch: 1 branch
BranchTrueFalseTotal
if (@tomatch and defined($token = readToken($self)) and push @matched, $token and $token->equals($tomatch[0])) 0 0 0
Condition0%0/9
@tomatch and defined($token = readToken($self)) and push @matched, $token and $token->equals($tomatch[0])
!ll&&!rl&&r
000
@tomatch and defined($token = readToken($self)) and push @matched, $token
!ll&&!rl&&r
000
@tomatch and defined($token = readToken($self))
!ll&&!rl&&r
000
MC/DC0%0/4
@tomatch and defined($token = readToken($self)) and push @matched, $token and $token->equals($tomatch[0])
@tomatch defined($token = readToken($self)) push @matched, $token $token->equals($tomatch[0])
Truth table0%0/5
A and B and C and D
A= @tomatchB= defined($token = readToken($self))C= push @matched, $tokenD= $token->equals($tomatch[0])
ABCDresult
0XXX0
10XX0
110X0
11100
11111
582 && push(@matched, $token) && ($token->equals($tomatch[0]))) {
583 0 shift(@tomatch);
584 0 ▶ if ($$token[1] == CC_SPACE) { # If this was space, SKIP any following!!!
Branch: 1 branch
BranchTrueFalseTotal
if ($token->[1] == 10) 0 0 0
585 0 ▶ while (defined($token = readToken($self)) && ($$token[1] == CC_SPACE)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($token = readToken($self)) and $token->[1] == 10) 0 0 0
Condition0%0/3
defined($token = readToken($self)) and $token->[1] == 10
!ll&&!rl&&r
000
MC/DC0%0/2
defined($token = readToken($self)) and $token->[1] == 10
defined($token = readToken($self)) $token->[1] == 10
Truth table0%0/3
A and B
A= defined($token = readToken($self))B= $token->[1] == 10
ABresult
0X0
100
111
586 0 push(@matched, $token); }
587 0 ▶ unread($self, $token) if defined $token; } }
Branch: 1 branch
BranchTrueFalseTotal
if defined $token 0 0 0
588 0 ▶ return $choice unless @tomatch; # All matched!!!
Branch: 1 branch
BranchTrueFalseTotal
unless @tomatch 0 0 0
589 0 unread($self, @matched); # Put 'em back and try next!
590 }
591 0 return; }
592  
593 # Match the input against a set of keywords; Similar to readMatch, but the keywords are strings,
594 # and Case and catcodes are ignored; additionally, leading spaces are skipped.
595 # AND, macros are expanded.
596 0 ▶sub readKeyword {
Subroutine readKeyword: not called CC=8 SCAR=42.8
Pod documented
597 0 my ($self, @keywords) = @_;
598 0 skipSpaces($self);
599 0 foreach my $keyword (@keywords) {
600 0 ▶ $keyword = ToString($keyword) if ref $keyword;
Branch: 1 branch
BranchTrueFalseTotal
if ref $keyword 0 0 0
601 0 my @tomatch = split('', uc($keyword));
602 0 my @matched = ();
603 0 my $tok;
604 0 ▶ while (@tomatch && defined($tok = readXToken($self, 0)) && push(@matched, $tok)
Branch: 1 branch
BranchTrueFalseTotal
if (@tomatch and defined($tok = readXToken($self, 0)) and push @matched, $tok and uc $tok->[0] eq $tomatch[0]) 0 0 0
Condition0%0/9
@tomatch and defined($tok = readXToken($self, 0)) and push @matched, $tok and uc $tok->[0] eq $tomatch[0]
!ll&&!rl&&r
000
@tomatch and defined($tok = readXToken($self, 0)) and push @matched, $tok
!ll&&!rl&&r
000
@tomatch and defined($tok = readXToken($self, 0))
!ll&&!rl&&r
000
MC/DC0%0/4
@tomatch and defined($tok = readXToken($self, 0)) and push @matched, $tok and uc $tok->[0] eq $tomatch[0]
@tomatch defined($tok = readXToken($self, 0)) push @matched, $tok uc $tok->[0] eq $tomatch[0]
Truth table0%0/5
A and B and C and D
A= @tomatchB= defined($tok = readXToken($self, 0))C= push @matched, $tokD= uc $tok->[0] eq $tomatch[0]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
605 && (uc($$tok[0]) eq $tomatch[0])) {
606 0 shift(@tomatch); }
607 0 ▶ return $keyword unless @tomatch; # All matched!!!
Branch: 1 branch
BranchTrueFalseTotal
unless @tomatch 0 0 0
608 0 unread($self, @matched); } # Put 'em back tand try next!
609 0 return; }
610  
611 # Return a (balanced) sequence tokens until a match against one of the Tokens in @delims.
612 # Note that Braces on input hides the contents from matching,
613 # so this assumes there wont be braces in $delim!
614 # But, see readUntilBrace for that case.
615 0 ▶sub readUntil {
Subroutine readUntil: not called CC=18 SCAR=58.3
Pod documented
616 0 my ($self, $delim) = @_;
617 0 my @tokens = ();
618 0 my $token;
619 0 my $nbraces = 0;
620 0 my @want = $delim->unlist;
621 0 my $ntomatch = scalar(@want);
622 0 ▶ if ($ntomatch == 1) { # Common, easy case: read till we match a single token
Branch: 1 branch
BranchTrueFalseTotal
if ($ntomatch == 1) { } 0 0 0
623 0 my $want = $want[0];
624 0 ▶ while (($token = readToken($self)) && !$token->equals($want)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = readToken($self) and not $token->equals($want)) 0 0 0
Condition0%0/3
$token = readToken($self) and not $token->equals($want)
!ll&&!rl&&r
000
MC/DC0%0/2
$token = readToken($self) and not $token->equals($want)
$token = readToken($self) not $token->equals($want)
Truth table0%0/3
A and not(B)
A= $token = readToken($self)B= not $token->equals($want)
ABresult
0X0
100
111
625 0 my $cc = $$token[1];
626 0 ▶ if ($cc == CC_MARKER) { # would have been handled by readToken, but we're bypassing
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 17) { } 0 0 0
elsif ($token->[1] == 1) { } 0 0 0
627 0 handleMarker($self, $token); }
628 elsif ($$token[1] == CC_BEGIN) { # And if it's a BEGIN, copy till balanced END
629 0 push(@tokens, $token);
630 0 $nbraces++;
631 0 push(@tokens, readBalanced($self)->unlist, T_END); }
632 else {
633 0 push(@tokens, $token); } } }
634 else {
635  
636 0 my @ring = ();
637 0 while (1) {
638 # prefill the required number of tokens
639 0 ▶ while ((scalar(@ring) < $ntomatch) && ($token = readToken($self))) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @ring < $ntomatch and $token = readToken($self)) 0 0 0
Condition0%0/3
scalar @ring < $ntomatch and $token = readToken($self)
!ll&&!rl&&r
000
MC/DC0%0/2
scalar @ring < $ntomatch and $token = readToken($self)
scalar @ring < $ntomatch $token = readToken($self)
Truth table0%0/3
A and B
A= scalar @ring < $ntomatchB= $token = readToken($self)
ABresult
0X0
100
111
640 0 ▶ if ($$token[1] == CC_BEGIN) { # read balanced, and refill ring.
Branch: 1 branch
BranchTrueFalseTotal
if ($token->[1] == 1) { } 0 0 0
641 0 $nbraces++;
642 0 push(@tokens, @ring, $token, readBalanced($self)->unlist, T_END); # Copy directly to result
643 0 @ring = (); } # and retry
644 else {
645 0 push(@ring, $token); } }
646 0 my $i;
647 0 ▶ for ($i = 0 ; ($i < $ntomatch) && $ring[$i] && ($ring[$i]->equals($want[$i])) ; $i++) { } # Test match
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $ntomatch and $ring[$i] and $ring[$i]->equals($want[$i])) 0 0 0
Condition0%0/6
$i < $ntomatch and $ring[$i] and $ring[$i]->equals($want[$i])
!ll&&!rl&&r
000
$i < $ntomatch and $ring[$i]
!ll&&!rl&&r
000
MC/DC0%0/3
$i < $ntomatch and $ring[$i] and $ring[$i]->equals($want[$i])
$i < $ntomatch $ring[$i] $ring[$i]->equals($want[$i])
Truth table0%0/4
A and B and C
A= $i < $ntomatchB= $ring[$i]C= $ring[$i]->equals($want[$i])
ABCresult
0XX0
10X0
1100
1111
648 0 ▶ last if $i >= $ntomatch; # Matched all!
Branch: 1 branch
BranchTrueFalseTotal
if $i >= $ntomatch 0 0 0
649 0 ▶ last unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
650 0 push(@tokens, shift(@ring)); } }
651 0 ▶ if (!defined $token) { # Ran out!
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $token) 0 0 0
652 0 unread($self, @tokens); # Not more correct, but maybe less confusing?
653 0 return; }
654 # Notice that IFF the arg looks like {balanced}, the outer braces are stripped
655 # so that delimited arguments behave more similarly to simple, undelimited arguments.
656 0 ▶ if (($nbraces == 1) && ($tokens[0][1] == CC_BEGIN) && ($tokens[-1][1] == CC_END)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nbraces == 1 and $tokens[0][1] == 1 and $tokens[-1][1] == 2) 0 0 0
Condition0%0/6
$nbraces == 1 and $tokens[0][1] == 1 and $tokens[-1][1] == 2
!ll&&!rl&&r
000
$nbraces == 1 and $tokens[0][1] == 1
!ll&&!rl&&r
000
MC/DC0%0/3
$nbraces == 1 and $tokens[0][1] == 1 and $tokens[-1][1] == 2
$nbraces == 1 $tokens[0][1] == 1 $tokens[-1][1] == 2
Truth table0%0/4
A and B and C
A= $nbraces == 1B= $tokens[0][1] == 1C= $tokens[-1][1] == 2
ABCresult
0XX0
10X0
1100
1111
657 0 shift(@tokens); pop(@tokens); }
658 0 return TokensI(@tokens); }
659  
660 0 ▶sub readUntilBrace {
Subroutine readUntilBrace: not called CC=3 SCAR=24.8
Pod undocumented
661 0 my ($self) = @_;
662 0 my @tokens = ();
663 0 my $token;
664 0 ▶ while (defined($token = readToken($self))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($token = readToken($self))) 0 0 0
665 0 ▶ if ($$token[1] == CC_BEGIN) { # INLINE Catcode
Branch: 1 branch
BranchTrueFalseTotal
if ($token->[1] == 1) 0 0 0
666 0 $LaTeXML::ALIGN_STATE--;
667 0 unshift(@{ $$self{pushback} }, $token); # Unread
668 0 last; }
669 0 push(@tokens, $token); }
670 0 return TokensI(@tokens); }
671  
672 5 ▶use constant T_csname => T_CS('\csname');
Subroutine BEGIN: called CC=1 SCAR=0.0
673 5 ▶use constant T_endcsname => T_CS('\endcsname');
Subroutine BEGIN: called CC=1 SCAR=0.0
674  
675 0 ▶sub readCSName {
Subroutine readCSName: not called CC=6 SCAR=37.4
Pod undocumented
676 0 my ($self) = @_;
677 0 my $token;
678 # Deyan Ginev & Dennis Mueller were right! Or partly so.
679 # TeX does NOT store the csname with the leading `\`, BUT stores active chars with a flag
680 # However, so long as the Mouth's CS and \string properly respect \escapechar, all's well!
681 0 my $cs = '\\';
682 0 ▶ while (($token = readXToken($self, 1)) && (!$token->defined_as(T_endcsname))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = readXToken($self, 1) and not $token->defined_as(bless( ["\\endcsname",16], 'LaTeXML::Core::Token' ))) 0 0 0
Condition0%0/3
$token = readXToken($self, 1) and not $token->defined_as(bless( ["\\endcsname",16], 'LaTeXML::Core::Token' ))
!ll&&!rl&&r
000
MC/DC0%0/2
$token = readXToken($self, 1) and not $token->defined_as(bless( ["\\endcsname",16], 'LaTeXML::Core::Token' ))
$token = readXToken($self, 1) not $token->defined_as(bless( ["\\endcsname",16], 'LaTeXML::Core::Token' ))
Truth table0%0/3
A and not(B)
A= $token = readXToken($self, 1)B= not $token->defined_as(bless( ["\\endcsname",16], 'LaTeXML::Core::Token' ))
ABresult
0X0
100
111
683 0 my $cc = $$token[1];
684 0 ▶ if ($cc == CC_CS) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cc == 16) { } 0 0 0
elsif ($cc == 10) { } 0 0 0
685 0 ▶ if (defined $STATE->lookupDefinition($token)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $LaTeXML::Core::Gullet::STATE->lookupDefinition($token)) { } 0 0 0
686 0 Error('unexpected', $token, $self,
687 "The control sequence " . ToString($token)
688 . " should not appear between \\csname and \\endcsname"); }
689 else {
690 0 Error('undefined', $token, $self,
691 "The token " . Stringify($token) . " is not defined"); } }
692 0 elsif ($cc == CC_SPACE) { $cs .= ' '; } # Keep newlines from having \n!
693 0 else { $cs .= $$token[0]; } }
694 0 return T_CS($cs); }
695  
696 #**********************************************************************
697 # Higher-level readers: Read various types of things from the input:
698 # tokens, non-expandable tokens, args, Numbers, ...
699 #**********************************************************************
700 0 ▶sub readArg {
Subroutine readArg: not called CC=3 SCAR=24.8
Pod documented
701 0 my ($self) = @_;
702 0 my $token = readNonSpace($self);
703 0 ▶ if (!defined $token) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $token) { } 0 0 0
elsif ($token->[1] == 1) { } 0 0 0
704 0 return; }
705 elsif ($$token[1] == CC_BEGIN) { # Inline ->getCatcode!
706 0 return readBalanced($self, 0); }
707 else {
708 0 return Tokens($token); } }
709  
710 # Note that this returns an empty array if [] is present,
711 # otherwise $default or undef.
712 0 ▶sub readOptional {
Subroutine readOptional: not called CC=3 SCAR=24.8
Pod documented
713 0 my ($self, $default) = @_;
714 0 my $tok = readNonSpace($self);
715 0 ▶ if (!defined $tok) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $tok) { } 0 0 0
elsif ($tok->equals(T_OTHER('['))) { } 0 0 0
716 0 return; }
717 elsif (($tok->equals(T_OTHER('[')))) {
718 0 return readUntil($self, T_OTHER(']')); }
719 else {
720 0 unread($self, $tok);
721 0 return $default; } }
722  
723 #**********************************************************************
724 # Numbers, Dimensions, Glue
725 # See TeXBook, Ch.24, pp.269-271.
726 #**********************************************************************
727 0 ▶sub readValue {
Subroutine readValue: not called CC=9 SCAR=45.0
Pod documented
728 0 my ($self, $type) = @_;
729 0 ▶ if ($type eq 'Number') { return readNumber($self); }
Branch: 7 branches
BranchTrueFalseTotal
if ($type eq 'Number') { } 0 0 0
elsif ($type eq 'Dimension') { } 0 0 0
elsif ($type eq 'Glue') { } 0 0 0
elsif ($type eq 'MuGlue') { } 0 0 0
elsif ($type eq 'Tokens') { } 0 0 0
elsif ($type eq 'Token') { } 0 0 0
elsif ($type eq 'any') { } 0 0 0
730 0 elsif ($type eq 'Dimension') { return readDimension($self); }
731 0 elsif ($type eq 'Glue') { return readGlue($self); }
732 0 elsif ($type eq 'MuGlue') { return readMuGlue($self); }
733 0 elsif ($type eq 'Tokens') { return readTokensValue($self); }
734 elsif ($type eq 'Token') {
735 0 my $token = readNonSpace($self);
736 0 ▶ if ($token->defined_as(T_csname)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token->defined_as(['\\csname', 16])) { } 0 0 0
737 0 return readCSName($self); }
738 else {
739 0 return $token; } }
740 0 elsif ($type eq 'any') { return readArg($self); }
741 else {
742 0 Error('unexpected', $type, $self,
743 "Gullet->readValue Didn't expect this type: $type");
744 0 return; }
745 }
746  
747 # Read a value from a numeric register, possibly changing sign,
748 # possibly coercing from a bigger type (eg. a Number from a Dimension)
749 5 our %RegisterCoercionTypes = (
750 Number => { Dimension => \&Number, Glue => \&Number },
751 Dimension => { Glue => \&Dimension },
752 MuDimension => { MuGlue => \&MuDimension },
753 );
754  
755 0 ▶sub readRegisterValue {
Subroutine readRegisterValue: not called CC=11 SCAR=48.8
Pod documented
756 0 my ($self, $type, $sign, $coerce) = @_;
757 0 my $token = readXToken($self);
758 0 ▶ return unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
759 0 my ($defn, $rtype, $coercer);
760 0 ▶ if (($defn = $STATE->lookupDefinition($token))
Branch: 1 branch
BranchTrueFalseTotal
if ($defn = $LaTeXML::Core::Gullet::STATE->lookupDefinition($token) and $rtype = $defn->isRegister and $rtype eq $type || $coerce && ($coercer = $LaTeXML::Core::Gullet::RegisterCoercionTypes{$type}{$rtype})) { } 0 0 0
Condition0%0/12
$defn = $LaTeXML::Core::Gullet::STATE->lookupDefinition($token) and $rtype = $defn->isRegister and $rtype eq $type || $coerce && ($coercer = $LaTeXML::Core::Gullet::RegisterCoercionTypes{$type}{$rtype})
!ll&&!rl&&r
000
$defn = $LaTeXML::Core::Gullet::STATE->lookupDefinition($token) and $rtype = $defn->isRegister
!ll&&!rl&&r
000
$rtype eq $type or $coerce and $coercer = $LaTeXML::Core::Gullet::RegisterCoercionTypes{$type}{$rtype}
l!l&&r!l&&!r
000
$coerce and $coercer = $LaTeXML::Core::Gullet::RegisterCoercionTypes{$type}{$rtype}
!ll&&!rl&&r
000
MC/DC0%0/5
$defn = $LaTeXML::Core::Gullet::STATE->lookupDefinition($token) and $rtype = $defn->isRegister and $rtype eq $type || $coerce && ($coercer = $LaTeXML::Core::Gullet::RegisterCoercionTypes{$type}{$rtype})
$defn = $LaTeXML::Core::Gullet::STATE->lookupDefinition($token) $rtype = $defn->isRegister $rtype eq $type $coerce $coercer = $LaTeXML::Core::Gullet::RegisterCoercionTypes{$type}{$rtype}
Truth table0%0/6
A and B and C or D and E
A= $defn = $LaTeXML::Core::Gullet::STATE->lookupDefinition($token)B= $rtype = $defn->isRegisterC= $rtype eq $typeD= $coerceE= $coercer = $LaTeXML::Core::Gullet::RegisterCoercionTypes{$type}{$rtype}
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
761 && ($rtype = $defn->isRegister) # Got a register?
762 && (($rtype eq $type) || ($coerce && ($coercer = $RegisterCoercionTypes{$type}{$rtype})))) {
763 0 ▶ $sign = +1 unless defined $sign;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sign 0 0 0
764 0 local $LaTeXML::CURRENT_TOKEN = $token;
765 0 my $parms = $$defn{parameters};
766 0 ▶ my $value = $defn->valueOf(($parms ? $parms->readArguments($self) : ()));
Branch: 1 branch
BranchTrueFalseTotal
$parms ? : 0 0 0
767 0 ▶ if ($type eq $rtype) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq $rtype) { } 0 0 0
768 0 ▶ return ($sign < 0 ? $value->negate : $value); }
Branch: 1 branch
BranchTrueFalseTotal
$sign < 0 ? : 0 0 0
769 else {
770 0 return &$coercer($sign * $value->valueOf); } }
771 else {
772 0 unread($self, $token);
773 0 return; } }
774  
775 # Apparent behaviour of a token value (ie \toks#=<arg>)
776 # Expand except within braces?
777 0 ▶sub readTokensValue {
Subroutine readTokensValue: not called CC=8 SCAR=42.8
Pod undocumented
778 0 my ($self) = @_;
779 0 my $token = readNonSpace($self);
780 0 ▶ if (!defined $token) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $token) { } 0 0 0
elsif ($token->[1] == 1) { } 0 0 0
elsif (my $defn = $LaTeXML::Core::Gullet::STATE->lookupDefinition($token)) { } 0 0 0
781 0 return; }
782 elsif ($$token[1] == CC_BEGIN) { # Inline ->getCatcode!
783 0 return readBalanced($self); }
784 elsif (my $defn = $STATE->lookupDefinition($token)) {
785 0 ▶ if ($defn->isRegister eq 'Tokens') {
Branch: 2 branches
BranchTrueFalseTotal
if ($defn->isRegister eq 'Tokens') { } 0 0 0
elsif ($defn->isExpandable) { } 0 0 0
786 0 my $parms = $$defn{parameters};
787 0 ▶ return $defn->valueOf(($parms ? $parms->readArguments($self) : ())); }
Branch: 1 branch
BranchTrueFalseTotal
$parms ? : 0 0 0
788 elsif ($defn->isExpandable) {
789 0 ▶ if (my $x = $defn->invoke($self)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $x = $defn->invoke($self)) 0 0 0
790 0 unread($self, $x->unlist); }
791 0 return readTokensValue($self); }
792 else {
793 0 return $token; } } # ?
794 else {
795 0 return $token; } }
796  
797 #======================================================================
798 # some helpers...
799 # Note that <one optional space> is kinda special:
800 # The following Token(s) are expanded until an unexpandable token is found;
801 # it is discarded if it is a space, but with an Equals() equality test!
802  
803 # <optional signs> = <optional spaces> | <optional signs><plus or minus><optional spaces>
804 # return +1 or -1
805 0 ▶sub readOptionalSigns {
Subroutine readOptionalSigns: not called CC=7 SCAR=40.3
Pod undocumented
806 0 my ($self) = @_;
807 0 my ($sign, $t) = ("+1", '');
808 0 ▶ while (defined($t = readXToken($self))
Branch: 1 branch
BranchTrueFalseTotal
if (defined($t = readXToken($self)) and $t->[0] eq "+" || $t->[0] eq "-" || $t->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))) 0 0 0
Condition0%0/9
defined($t = readXToken($self)) and $t->[0] eq "+" || $t->[0] eq "-" || $t->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
!ll&&!rl&&r
000
$t->[0] eq "+" or $t->[0] eq "-" or $t->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
l!l&&r!l&&!r
000
$t->[0] eq "+" or $t->[0] eq "-"
l!l&&r!l&&!r
000
MC/DC0%0/4
defined($t = readXToken($self)) and $t->[0] eq "+" || $t->[0] eq "-" || $t->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
defined($t = readXToken($self)) $t->[0] eq "+" $t->[0] eq "-" $t->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
Truth table0%0/5
A and B or C or D
A= defined($t = readXToken($self))B= $t->[0] eq "+"C= $t->[0] eq "-"D= $t->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
ABCDresult
0XXX0
10000
11XX1
101X1
10011
809 && (($$t[0] eq '+') || ($$t[0] eq '-') || $t->defined_as(T_SPACE))) {
810 0 ▶ $sign = -$sign if ($$t[0] eq '-'); }
Branch: 1 branch
BranchTrueFalseTotal
if $t->[0] eq "-" 0 0 0
811 0 ▶ unread($self, $t) if $t;
Branch: 1 branch
BranchTrueFalseTotal
if $t 0 0 0
812 0 return $sign; }
813  
814 # Read digits (within $range), while expanding and if $skip, skip <one optional space> (expanded!)
815 0 ▶sub readDigits {
Subroutine readDigits: not called CC=6 SCAR=37.4
Pod undocumented
816 0 my ($self, $range, $skip) = @_;
817 0 my $string = '';
818 0 my ($token, $digit);
819 0 ▶ while (($token = readXToken($self)) && (($digit = $$token[0]) =~ /^[$range]$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token = readXToken($self) and ($digit = $token->[0]) =~ /^[$range]$/) 0 0 0
Condition0%0/3
$token = readXToken($self) and ($digit = $token->[0]) =~ /^[$range]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$token = readXToken($self) and ($digit = $token->[0]) =~ /^[$range]$/
$token = readXToken($self) ($digit = $token->[0]) =~ /^[$range]$/
Truth table0%0/3
A and B
A= $token = readXToken($self)B= ($digit = $token->[0]) =~ /^[$range]$/
ABresult
0X0
100
111
820 0 $string .= $digit; }
821 0 ▶ unread($self, $token) if $token && !($skip && $token->defined_as(T_SPACE)); #Inline
Branch: 1 branch
BranchTrueFalseTotal
if $token and not $skip && $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' )) 0 0 0
Condition0%0/6
$token and not $skip && $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
!ll&&!rl&&r
000
$skip && $token->defined_as([' ', 10])
!ll&&!rl&&r
000
MC/DC0%0/3
$token and not $skip && $token->defined_as(bless( [" ",10], 'LaTeXML::Core::Token' ))
$token $skip $token->defined_as([' ', 10])
Truth table0%0/4
A and not(B && C)
A= $tokenB= $skipC= $token->defined_as([' ', 10])
ABCresult
0XX0
1110
10X1
1101
822 0 return $string; }
823  
824 # <factor> = <normal integer> | <decimal constant>
825 # <decimal constant> = . | , | <digit><decimal constant> | <decimal constant><digit>
826 # Return a number (perl number)
827 0 ▶sub readFactor {
Subroutine readFactor: not called CC=7 SCAR=40.3
Pod undocumented
828 0 my ($self) = @_;
829 0 my $string = readDigits($self, '0-9');
830 0 my $token = readXToken($self);
831 0 ▶ if ($token && $$token[0] =~ /^[\.\,]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $token->[0] =~ /^[\.\,]$/) 0 0 0
Condition0%0/3
$token and $token->[0] =~ /^[\.\,]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$token and $token->[0] =~ /^[\.\,]$/
$token $token->[0] =~ /^[\.\,]$/
Truth table0%0/3
A and B
A= $tokenB= $token->[0] =~ /^[\.\,]$/
ABresult
0X0
100
111
832 0 $string .= '.' . readDigits($self, '0-9');
833 0 $token = readXToken($self); }
834 0 ▶ if (length($string) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string > 0) { } 0 0 0
835 0 ▶ unread($self, $token) if $token && $$token[1] != CC_SPACE;
Branch: 1 branch
BranchTrueFalseTotal
if $token and $token->[1] != 10 0 0 0
Condition0%0/3
$token and $token->[1] != 10
!ll&&!rl&&r
000
MC/DC0%0/2
$token and $token->[1] != 10
$token $token->[1] != 10
Truth table0%0/3
A and B
A= $tokenB= $token->[1] != 10
ABresult
0X0
100
111
836 0 return $string; }
837 else {
838 0 unread($self, $token);
839 0 my $n = readNormalInteger($self);
840 0 ▶ return (defined $n ? $n->valueOf : undef); } }
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 0 0 0
841  
842 #======================================================================
843 # Integer, Number
844 #======================================================================
845 # <number> = <optional signs><unsigned number>
846 # <unsigned number> = <normal integer> | <coerced integer>
847 # <coerced integer> = <internal dimen> | <internal glue>
848  
849 0 ▶sub readNumber {
Subroutine readNumber: not called CC=4 SCAR=30.0
Pod documented
850 0 my ($self) = @_;
851 0 my $s = readOptionalSigns($self);
852 0 ▶ if (defined(my $n = readNormalInteger($self))) { return ($s < 0 ? $n->negate : $n); }
Branch: 3 branches
BranchTrueFalseTotal
if (defined(my $n = readNormalInteger($self))) { } 0 0 0
elsif (defined($n = readRegisterValue($self, 'Number', $s, 1))) { } 0 0 0
$s < 0 ? : 0 0 0
853 0 elsif (defined($n = readRegisterValue($self, 'Number', $s, 1))) { return $n; }
854 else {
855 0 my $next = readToken($self);
856 0 unread($self, $next);
857 0 Warn('expected', '<number>', $self, "Missing number, treated as zero",
858 "while processing " . ToString($LaTeXML::CURRENT_TOKEN), showUnexpected($self));
859 0 return Number(0); } }
860  
861 # <normal integer> = <internal integer> | <integer constant>
862 # | '<octal constant><one optional space> | "<hexadecimal constant><one optional space>
863 # | `<character token><one optional space>
864 # Return a Number or undef
865 0 ▶sub readNormalInteger {
Subroutine readNormalInteger: not called CC=9 SCAR=45.0
Pod undocumented
866 0 my ($self) = @_;
867 0 my $token = readXToken($self); # expand more
868 0 ▶ if (!defined $token) {
Branch: 5 branches
BranchTrueFalseTotal
if (not defined $token) { } 0 0 0
elsif ($token->[1] == 12 and $token->[0] =~ /^[0-9]$/) { } 0 0 0
elsif ($token->equals(T_OTHER(q[']))) { } 0 0 0
elsif ($token->equals(T_OTHER('"'))) { } 0 0 0
elsif ($token->equals(T_OTHER('`'))) { } 0 0 0
869 0 return; }
870 ▶ elsif (($$token[1] == CC_OTHER) && ($$token[0] =~ /^[0-9]$/)) { # Read decimal literal
Condition0%0/3
$token->[1] == 12 and $token->[0] =~ /^[0-9]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$token->[1] == 12 and $token->[0] =~ /^[0-9]$/
$token->[1] == 12 $token->[0] =~ /^[0-9]$/
Truth table0%0/3
A and B
A= $token->[1] == 12B= $token->[0] =~ /^[0-9]$/
ABresult
0X0
100
111
871 0 return Number(int($$token[0] . readDigits($self, '0-9', 1))); }
872 elsif ($token->equals(T_OTHER("'"))) { # Read Octal literal
873 0 return Number(oct(readDigits($self, '0-7', 1))); }
874 elsif ($token->equals(T_OTHER("\""))) { # Read Hex literal
875 0 return Number(hex(readDigits($self, '0-9A-F', 1))); }
876 elsif ($token->equals(T_OTHER("`"))) { # Read Charcode
877 0 my $next = readToken($self);
878 0 ▶ my $s = ($next && $$next[0]) || '';
Condition0%0/5
$next && $next->[0] || ''
l!l
00
$next and $next->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$next && $next->[0] || ''
$next $next->[0]
Truth table0%0/3
A and B
A= $nextB= $next->[0]
ABresult
111
0X0
100
879 0 $s =~ s/^\\//;
880 0 skip1Space($self, 1);
881 0 return Number(ord($s)); } # Only a character token!!! NOT expanded!!!!
882 else {
883 0 unread($self, $token);
884 0 return readRegisterValue($self, 'Number'); } }
885  
886 #======================================================================
887 # Float, a floating point number.
888 # Similar to factor, but does NOT accept comma!
889 # This is NOT part of TeX, but is convenient.
890 0 ▶sub readFloat {
Subroutine readFloat: not called CC=9 SCAR=45.0
Pod undocumented
891 0 my ($self) = @_;
892 0 my $s = readOptionalSigns($self);
893 0 my $string = readDigits($self, '0-9');
894 0 my $token = readXToken($self);
895 0 ▶ if ($token && $$token[0] =~ /^[\.]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token and $token->[0] =~ /^[\.]$/) 0 0 0
Condition0%0/3
$token and $token->[0] =~ /^[\.]$/
!ll&&!rl&&r
000
MC/DC0%0/2
$token and $token->[0] =~ /^[\.]$/
$token $token->[0] =~ /^[\.]$/
Truth table0%0/3
A and B
A= $tokenB= $token->[0] =~ /^[\.]$/
ABresult
0X0
100
111
896 0 $string .= '.' . readDigits($self, '0-9');
897 0 $token = readXToken($self); }
898 0 my $n;
899 0 ▶ if (length($string) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string > 0) { } 0 0 0
900 0 ▶ unread($self, $token) if $token && $$token[1] != CC_SPACE;
Branch: 1 branch
BranchTrueFalseTotal
if $token and $token->[1] != 10 0 0 0
Condition0%0/3
$token and $token->[1] != 10
!ll&&!rl&&r
000
MC/DC0%0/2
$token and $token->[1] != 10
$token $token->[1] != 10
Truth table0%0/3
A and B
A= $tokenB= $token->[1] != 10
ABresult
0X0
100
111
901 0 $n = $string; }
902 else {
903 0 ▶ unread($self, $token) if $token;
Branch: 1 branch
BranchTrueFalseTotal
if $token 0 0 0
904 0 $n = readNormalInteger($self);
905 0 ▶ $n = $n->valueOf if defined $n; }
Branch: 1 branch
BranchTrueFalseTotal
if defined $n 0 0 0
906 0 ▶ return (defined $n ? Float($s * $n) : undef); }
Branch: 1 branch
BranchTrueFalseTotal
defined $n ? : 0 0 0
907  
908 #======================================================================
909 # Dimensions
910 #======================================================================
911 # <dimen> = <optional signs><unsigned dimen>
912 # <unsigned dimen> = <normal dimen> | <coerced dimen>
913 # <coerced dimen> = <internal glue>
914 0 ▶sub readDimension {
Subroutine readDimension: not called CC=4 SCAR=30.0
Pod documented
915 0 my ($self) = @_;
916 0 my $s = readOptionalSigns($self);
917 0 ▶ if (defined(my $d = readRegisterValue($self, 'Dimension', $s, 1))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $d = readRegisterValue($self, 'Dimension', $s, 1))) { } 0 0 0
elsif (defined($d = readFactor($self))) { } 0 0 0
918 0 return $d; }
919 elsif (defined($d = readFactor($self))) {
920 0 my $unit = readUnit($self);
921 0 ▶ if (!defined $unit) { # but leave undefined (effectively not rescaled)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $unit) 0 0 0
922 0 Warn('expected', '<unit>', $self, "Illegal unit of measure (pt inserted)."); }
923 0 return Dimension(fixpoint($s * $d, $unit)); }
924 else {
925 0 Warn('expected', '<number>', $self, "Missing number (Dimension), treated as zero.",
926 "while processing " . ToString($LaTeXML::CURRENT_TOKEN), showUnexpected($self));
927 0 return Dimension(0); } }
928  
929 # <unit of measure> = <optional spaces><internal unit>
930 # | <optional true><physical unit><one optional space>
931 # <internal unit> = em <one optional space> | ex <one optional space>
932 # | <internal integer> | <internal dimen> | <internal glue>
933 # <physical unit> = pt | pc | in | bp | cm | mm | dd | cc | sp
934  
935 # Read a unit, returning the equivalent number of scaled points,
936 0 ▶sub readUnit {
Subroutine readUnit: not called CC=4 SCAR=30.0
Pod undocumented
937 0 my ($self) = @_;
938 0 ▶ if (defined(my $u = readKeyword($self, 'ex', 'em'))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $u = readKeyword($self, 'ex', 'em'))) { } 0 0 0
elsif (defined($u = readRegisterValue($self, 'Number', 1, 1))) { } 0 0 0
939 0 skip1Space($self, 1);
940 0 return $STATE->convertUnit($u); }
941 elsif (defined($u = readRegisterValue($self, 'Number', +1, 1))) {
942 0 return $u->valueOf; } # These are coerced to number=>sp
943 else {
944 0 readKeyword($self, 'true'); # But ignore, we're not bothering with mag...
945 0 my $units = $STATE->lookupValue('UNITS');
946 0 $u = readKeyword($self, keys %$units);
947 0 ▶ if ($u) {
Branch: 1 branch
BranchTrueFalseTotal
if ($u) { } 0 0 0
948 0 skip1Space($self, 1);
949 0 return $STATE->convertUnit($u); }
950 else {
951 0 return; } } }
952  
953 #======================================================================
954 # Mu Dimensions
955 #======================================================================
956 # <mudimen> = <optional signs><unsigned mudimem>
957 # <unsigned mudimen> = <normal mudimen> | <coerced mudimen>
958 # <normal mudimen> = <factor><mu unit>
959 # <mu unit> = <optional spaces><internal muglue> | mu <one optional space>
960 # <coerced mudimen> = <internal muglue>
961 0 ▶sub readMuDimension {
Subroutine readMuDimension: not called CC=4 SCAR=30.0
Pod documented
962 0 my ($self) = @_;
963 0 my $s = readOptionalSigns($self);
964 0 ▶ if (defined(my $m = readFactor($self))) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $m = readFactor($self))) { } 0 0 0
elsif (defined($m = readRegisterValue($self, 'MuDimension', $s, 1))) { } 0 0 0
965 0 my $munit = readMuUnit($self);
966 0 ▶ if (!defined $munit) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $munit) 0 0 0
967 0 Warn('expected', '<unit>', $self, "Illegal unit of measure (mu inserted)."); }
968 0 return MuDimension(fixpoint($s * $m, $munit)); }
969 elsif (defined($m = readRegisterValue($self, 'MuDimension', $s, 1))) {
970 0 return $m; }
971 else {
972 0 Warn('expected', '<mudimen>', $self, "Expecting mudimen; assuming 0");
973 0 return MuDimension(0); } }
974  
975 0 ▶sub readMuUnit {
Subroutine readMuUnit: not called CC=3 SCAR=24.8
Pod undocumented
976 0 my ($self) = @_;
977 0 ▶ if (my $m = readKeyword($self, 'mu')) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $m = readKeyword($self, 'mu')) { } 0 0 0
elsif ($m = readRegisterValue($self, 'MuGlue')) { } 0 0 0
978 0 skip1Space($self, 1);
979 0 return $UNITY; } # effectively, scaled mu
980 elsif ($m = readRegisterValue($self, 'MuGlue')) {
981 0 return $m->valueOf; }
982 else {
983 0 return; } }
984  
985 #======================================================================
986 # Glue
987 #======================================================================
988 # <glue> = <optional signs><internal glue> | <dimen><stretch><shrink>
989 # <stretch> = plus <dimen> | plus <fil dimen> | <optional spaces>
990 # <shrink> = minus <dimen> | minus <fil dimen> | <optional spaces>
991 0 ▶sub readGlue {
Subroutine readGlue: not called CC=6 SCAR=37.4
Pod documented
992 0 my ($self) = @_;
993 0 my $s = readOptionalSigns($self);
994 0 my $n;
995 0 ▶ if (defined($n = readRegisterValue($self, 'Glue', $s))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($n = readRegisterValue($self, 'Glue', $s))) { } 0 0 0
996 0 return $n; }
997 else {
998 0 my $d = readDimension($self);
999 0 ▶ if (!$d) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($d) 0 0 0
1000 0 Warn('expected', '<number>', $self, "Missing number (Glue), treated as zero.",
1001 "while processing " . ToString($LaTeXML::CURRENT_TOKEN), showUnexpected($self));
1002 0 return Glue(0); }
1003 0 ▶ $d = $d->negate if $s < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $s < 0 0 0 0
1004 0 my ($r1, $f1, $r2, $f2);
1005 0 ▶ ($r1, $f1) = readRubber($self) if readKeyword($self, 'plus');
Branch: 1 branch
BranchTrueFalseTotal
if readKeyword($self, "plus") 0 0 0
1006 0 ▶ ($r2, $f2) = readRubber($self) if readKeyword($self, 'minus');
Branch: 1 branch
BranchTrueFalseTotal
if readKeyword($self, "minus") 0 0 0
1007 0 return Glue($d->valueOf, $r1, $f1, $r2, $f2); } }
1008  
1009 5 my %FILLS = (fil => 1, fill => 2, filll => 3); # [CONSTANT]
1010  
1011 0 ▶sub readRubber {
Subroutine readRubber: not called CC=7 SCAR=40.3
Pod undocumented
1012 0 my ($self, $mu) = @_;
1013 0 my $s = readOptionalSigns($self);
1014 0 my $f = readFactor($self);
1015 0 ▶ if (!defined $f) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $f) { } 0 0 0
elsif (defined(my $fil = readKeyword($self, 'filll', 'fill', 'fil'))) { } 0 0 0
1016 0 ▶ $f = ($mu ? readMuDimension($self) : readDimension($self));
Branch: 1 branch
BranchTrueFalseTotal
$mu ? : 0 0 0
1017 0 return ($f->valueOf * $s, 0); }
1018 elsif (defined(my $fil = readKeyword($self, 'filll', 'fill', 'fil'))) {
1019 0 return (fixpoint($s * $f), $FILLS{$fil}); }
1020 else {
1021 0 ▶ my $u = ($mu ? readMuUnit($self) : readUnit($self));
Branch: 1 branch
BranchTrueFalseTotal
$mu ? : 0 0 0
1022 0 ▶ if (!defined $u) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $u) 0 0 0
1023 0 ▶ Warn('expected', '<unit>', $self,
Branch: 1 branch
BranchTrueFalseTotal
$mu ? : 0 0 0
1024 "Illegal unit of measure (" . ($mu ? 'mu' : 'pt') . " inserted)."); }
1025 0 return (fixpoint($s * $f, $u), 0); } }
1026  
1027 #======================================================================
1028 # Mu Glue
1029 #======================================================================
1030 # <muglue> = <optional signs><internal muglue> | <mudimen><mustretch><mushrink>
1031 # <mustretch> = plus <mudimen> | plus <fil dimen> | <optional spaces>
1032 # <mushrink> = minus <mudimen> | minus <fil dimen> | <optional spaces>
1033 0 ▶sub readMuGlue {
Subroutine readMuGlue: not called CC=7 SCAR=40.3
Pod documented
1034 0 my ($self) = @_;
1035 0 my $s = readOptionalSigns($self);
1036 0 my $n;
1037 0 ▶ if (defined($n = readRegisterValue($self, 'MuGlue'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($n = readRegisterValue($self, 'MuGlue'))) { } 0 0 0
1038 0 ▶ return ($s < 0 ? $n->negate : $n); }
Branch: 1 branch
BranchTrueFalseTotal
$s < 0 ? : 0 0 0
1039 else {
1040 0 my $d = readMuDimension($self);
1041 0 ▶ if (!$d) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($d) 0 0 0
1042 0 Warn('expected', '<number>', $self, "Missing number (MuGlue), treated as zero.",
1043 "while processing " . ToString($LaTeXML::CURRENT_TOKEN), showUnexpected($self));
1044 0 return MuGlue(0); }
1045 0 ▶ $d = $d->negate if $s < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $s < 0 0 0 0
1046 0 my ($r1, $f1, $r2, $f2);
1047 0 ▶ ($r1, $f1) = readRubber($self, 1) if readKeyword($self, 'plus');
Branch: 1 branch
BranchTrueFalseTotal
if readKeyword($self, "plus") 0 0 0
1048 0 ▶ ($r2, $f2) = readRubber($self, 1) if readKeyword($self, 'minus');
Branch: 1 branch
BranchTrueFalseTotal
if readKeyword($self, "minus") 0 0 0
1049 0 return MuGlue($d->valueOf, $r1, $f1, $r2, $f2); } }
1050  
1051 #======================================================================
1052 # See pp 272-275 for lists of the various registers.
1053 # These are implemented in Primitive.pm
1054  
1055 #**********************************************************************
1056 # Deprecated
1057 0 ▶sub readInternalInteger {
Subroutine readInternalInteger: not called CC=1 SCAR=6.9
Pod undocumented
1058 0 my ($self) = @_;
1059 0 Deprecated('readInternalInteger', '0.8.8',
1060 "Please use \$gullet->readRegisterValue('Number')");
1061 0 return readRegisterValue($self, 'Number'); }
1062  
1063 0 ▶sub readInternalDimension {
Subroutine readInternalDimension: not called CC=1 SCAR=6.9
Pod undocumented
1064 0 my ($self) = @_;
1065 0 Deprecated('readInternalDimension', '0.8.8',
1066 "Please use \$gullet->readRegisterValue('Dimension')");
1067 0 return readRegisterValue($self, 'Dimension'); }
1068  
1069 0 ▶sub readInternalGlue {
Subroutine readInternalGlue: not called CC=1 SCAR=6.9
Pod undocumented
1070 0 my ($self) = @_;
1071 0 Deprecated('readInternalGlue', '0.8.8',
1072 "Please use \$gullet->readRegisterValue('Glue')");
1073 0 return readRegisterValue($self, 'Glue'); }
1074  
1075 0 ▶sub readInternalMuGlue {
Subroutine readInternalMuGlue: not called CC=1 SCAR=6.9
Pod undocumented
1076 0 my ($self) = @_;
1077 0 Deprecated('readInternalMuGlue', '0.8.8',
1078 "Please use \$gullet->readRegisterValue('MuGlue')");
1079 0 return readRegisterValue($self, 'MuGlue'); }
1080  
1081 5 1;
1082  
1083 __END__
« lib/LaTeXML/Common/Glue.pm ↑ Summary lib/LaTeXML/Core/Rewrite.pm »