lib/LaTeXML/Core/State.pm

filter: Statementstmt 5.0% 19 / 379 Branchbran 0.0% 0 / 162 Conditioncond 0.0% 0 / 118 MC/DCmcdc 0.0% 0 / 62 Subroutinesub 8.3% 5 / 60 Podpod 30.9% 17 / 55 totaltotal 4.9% 41 / 836 CC 129 SCAR 42.5
CC
129
Cov
3%
assign_internal
240.0
getStatusMessage
210.0
lookupDigestableDefinition
182.0
CRAP 70.0
« lib/LaTeXML/Core/KeyVals.pm ↑ Summary lib/LaTeXML/Core/Gullet.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Core::State | #
3 # | Maintains state: bindings, values, grouping | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12 package LaTeXML::Core::State;
13 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 29 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 29 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 29 ▶use LaTeXML::Core::Token; # To get CatCodes
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Naming scheme for keys (such as it is)
20 # binding:<cs> : the definition associated with <cs>
21 # value:<name> : some data stored under <name>
22 # With TeX Registers/Parameters, the name begins with "\"
23 # internal:<name> : Some internally interesting state.
24  
25 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26 # The State efficiently maintain the bindings in a TeX-like fashion.
27 # bindings associate data with keys (eg definitions with macro names)
28 # and respect TeX grouping; that is, an assignment is only in effect
29 # until the current group (opened by \bgroup) is closed (by \egroup).
30 #----------------------------------------------------------------------
31 # The objective is to make the following, most-common, operations FAST:
32 # begin & end a group (ie. push/pop a stack frame)
33 # lookup & assignment of values
34 # With the more obvious approach, a "stack of frames", either lookup would involve
35 # checking a sequence of frames until the current value is found;
36 # or, starting a new frame would involve copying bindings for all values
37 # I never quite studied how Knuth does it;
38 # The following structures allow these to be constant operations (usually),
39 # except for endgroup (which is linear in # of changed values in that frame).
40  
41 # There are 2 main structures used here.
42 # For each of several $table's (being "value", "meaning", "catcode" or other space of names),
43 # each table maintains the bound values, and "undo" defines the stack frames:
44 # $$self{$table}{$key} = [$current_value, $previous_value, ...]
45 # $$self{undo}[$frame]{$table}{$key} = (undef | $n)
46 # such that the "current value" associated with $key is the 0th element of the table array;
47 # the $previous_value's (if any) are values that had been assigned within previous groups.
48 # The undo list indicates how many values have been assigned for $key in
49 # the $frame'th frame (usually 0 is the one of interest).
50 # [Would be simpler to store boolean in undo, but see deactivateScope]
51 # [All keys fo $$self{undo}[$frame} are table names, EXCEPT "_FRAME_LOCK_"!!]
52 #
53 # So, in handwaving form, the algorithms are as follows:
54 # push-frame == bgroup == begingroup:
55 # push an empty hash {} onto the undo stack;
56 # pop-frame == egroup == endgroup:
57 # for the $n associated with every key in the topmost hash in the undo stack
58 # pop $n values from the table
59 # then remove the hash from the undo stack.
60 # Lookup value:
61 # we simply fetch the 0th element from the table
62 # Assign a value:
63 # local scope (the normal way):
64 # we push a new value into the table described above,
65 # and also increment the associated value in the undo stack
66 # global scope:
67 # remove any locally scoped values, and undo entries for the key
68 # then set the 0th (only remaining) value to the given one.
69 # named-scope $scope:
70 # push an entry [$table,$key,$value] globally to the 'stash' table's value.
71 # And assign locally, if the $scope is active (has non-zero value in stash_active table),
72 #
73 # There are tables for
74 # catcode: keys are char;
75 # Also, "math:$char" =1 when $char is active in math.
76 # mathcode, sfcode, lccode, uccode, delcode : are similar to catcode but store
77 # additional kinds codes per char (see TeX)
78 # value: keys are anything (typically a string, though) and value is the value associated with it
79 # meaning: The definition assocated with $key, usually a control-sequence.
80 # stash & stash_active: support named scopes
81 # (see also activateScope & deactivateScope)
82 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83  
84 # options:
85 # catcodes => (standard|style|none)
86 # stomach => a Stomach object.
87 # model => a Mod el object.
88 sub new {
89 0 ▶ my ($class, %options) = @_;
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
90 my $self = bless { # table => {},
91 value => {}, meaning => {}, stash => {}, stash_active => {},
92 catcode => {}, mathcode => {}, sfcode => {}, lccode => {}, uccode => {}, delcode => {},
93 undo => [{ _FRAME_LOCK_ => 1 }], prefixes => {}, status => {},
94 0 stomach => $options{stomach}, model => $options{model} }, $class;
95 # Note that "100" is hardwired into TeX, The Program!!!
96 0 $$self{value}{MAX_ERRORS} = [100];
97 0 $$self{value}{VERBOSITY} = [0];
98 # Standard TeX units, in scaled points
99 $$self{value}{UNITS} = [{
100 0 pt => 65536, pc => 12 * 65536, in => 72.27 * 65536, bp => 72.27 * 65536 / 72,
101 cm => 72.27 * 65536 / 2.54, mm => 72.27 * 65536 / 2.54 / 10, dd => 1238 * 65536 / 1157,
102 cc => 12 * 1238 * 65536 / 1157, sp => 1 }];
103  
104 0 ▶ $options{catcodes} = 'standard' unless defined $options{catcodes};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $options{"catcodes"} 0 0 0
105 0 ▶ if ($options{catcodes} =~ /^(standard|style)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"catcodes"} =~ /^(standard|style)/) 0 0 0
106 # Setup default catcodes.
107 0 my %std = ("\\" => CC_ESCAPE, "{" => CC_BEGIN, "}" => CC_END, "\$" => CC_MATH,
108 "\&" => CC_ALIGN, "\r" => CC_EOL, "#" => CC_PARAM, "^" => CC_SUPER,
109 "_" => CC_SUB, " " => CC_SPACE, "\t" => CC_SPACE, "%" => CC_COMMENT,
110 "~" => CC_ACTIVE, chr(0) => CC_IGNORE, "\f" => CC_ACTIVE);
111 0 map { $$self{catcode}{$_} = [$std{$_}] } keys %std;
112 0 ▶ for (my $c = ord('A') ; $c <= ord('Z') ; $c++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c <= 90) 0 0 0
113 0 $$self{catcode}{ chr($c) } = [CC_LETTER];
114 0 $$self{catcode}{ chr($c + ord('a') - ord('A')) } = [CC_LETTER]; }
115 }
116 0 $$self{value}{SPECIALS} = [['^', '_', '@', '~', '&', '$', '#', "'"]];
117 0 ▶ if ($options{catcodes} eq 'style') {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"catcodes"} eq "style") 0 0 0
118 0 $$self{catcode}{'@'} = [CC_LETTER]; }
119 0 $$self{mathcode} = {};
120 0 $$self{sfcode} = {};
121 0 $$self{lccode} = {};
122 0 $$self{uccode} = {};
123 0 $$self{delcode} = {};
124 0 $$self{tracing_definitions} = {};
125 0 return $self; }
126  
127 sub assign_internal {
128 0 ▶ my ($self, $table, $key, $value, $scope) = @_;
Subroutine assign_internal: not called CC=15 SCAR=54.8
Pod undocumented
129 0 ▶ $scope = ($$self{prefixes}{global} ? 'global' : 'local') unless defined $scope;
Branch: 2 branches
BranchTrueFalseTotal
unless defined $scope 0 0 0
$self->{'prefixes'}{'global'} ? : 0 0 0
130 0 ▶ if (exists $$self{tracing_definitions}{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"tracing_definitions"}{$key}) 0 0 0
131 0 ▶ print STDERR "ASSIGN $key in $table " . ($scope ? "($scope)" : '') . " => " .
Branch: 2 branches
BranchTrueFalseTotal
$scope ? : 0 0 0
ref $value ? : 0 0 0
132 (ref $value ? $value->stringify : $value) . "\n"; }
133 0 ▶ if ($scope eq 'global') {
Branch: 2 branches
BranchTrueFalseTotal
if ($scope eq 'global') { } 0 0 0
elsif ($scope eq 'local') { } 0 0 0
134 # Remove bindings made in all frames down-to & including the next lower locked frame
135 0 my $frame;
136 0 my @frames = @{ $$self{undo} };
137 0 ▶ while (@frames) {
Branch: 1 branch
BranchTrueFalseTotal
if (@frames) 0 0 0
138 0 $frame = shift(@frames);
139 0 ▶ if (my $n = $$frame{$table}{$key}) { # Undo the bindings, if $key was bound in this frame
Branch: 1 branch
BranchTrueFalseTotal
if (my $n = $frame->{$table}{$key}) 0 0 0
140 0 ▶ map { shift(@{ $$self{$table}{$key} }) } 1 .. $n if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 0 0 0
141 0 delete $$frame{$table}{$key}; }
142 0 ▶ last if $$frame{_FRAME_LOCK_}; }
Branch: 1 branch
BranchTrueFalseTotal
if $frame->{"_FRAME_LOCK_"} 0 0 0
143 # whatever is left -- if anything -- should be bindings below the locked frame.
144 0 $$frame{$table}{$key} = 1; # Note that there's only one value in the stack, now
145 0 unshift(@{ $$self{$table}{$key} }, $value); }
146 elsif ($scope eq 'local') {
147 0 ▶ if ($$self{undo}[0]{$table}{$key}) { # If the value was previously assigned in this frame
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'undo'}[0]{$table}{$key}) { } 0 0 0
148 0 $$self{$table}{$key}[0] = $value; } # Simply replace the value
149 else { # Otherwise, push new value & set 1 to be undone
150 0 $$self{undo}[0]{$table}{$key} = 1;
151 0 unshift(@{ $$self{$table}{$key} }, $value); } } # And push new binding.
152 else {
153 # print STDERR "Assigning $key in stash $stash\n";
154 0 ▶ assign_internal($self, 'stash', $scope, [], 'global') unless $$self{stash}{$scope}[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"stash"}{$scope}[0] 0 0 0
155 0 push(@{ $$self{stash}{$scope}[0] }, [$table, $key, $value]);
156 assign_internal($self, $table, $key, $value, 'local')
157 0 ▶ if $$self{stash_active}{$scope}[0]; }
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"stash_active"}{$scope}[0] 0 0 0
158 0 return; }
159  
160 #======================================================================
161 sub getStomach {
162 0 ▶ my ($self) = @_;
Subroutine getStomach: not called CC=1 SCAR=6.9
Pod documented
163 0 return $$self{stomach}; }
164  
165 sub getModel {
166 0 ▶ my ($self) = @_;
Subroutine getModel: not called CC=1 SCAR=6.9
Pod documented
167 0 return $$self{model}; }
168  
169 #======================================================================
170  
171 # Lookup & assign a general Value
172 # [Note that the more direct $$self{value}{$_[1]}[0]; works, but creates entries
173 # this could concievably cause space issues, but timing doesn't show improvements this way]
174 sub lookupValue {
175 0 ▶ my ($self, $key) = @_;
Subroutine lookupValue: not called CC=2 SCAR=17.9
Pod documented
176 0 my $e = $$self{value}{$key};
177 0 ▶ return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
178  
179 sub assignValue {
180 0 ▶ my ($self, $key, $value, $scope) = @_;
Subroutine assignValue: not called CC=1 SCAR=6.9
Pod documented
181 0 assign_internal($self, 'value', $key, $value, $scope);
182 0 return; }
183  
184 # manage a (global) list of values
185 sub pushValue {
186 0 ▶ my ($self, $key, @values) = @_;
Subroutine pushValue: not called CC=2 SCAR=17.9
Pod documented
187 0 my $vtable = $$self{value};
188 0 ▶ assign_internal($self, 'value', $key, [], 'global') unless $$vtable{$key}[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $vtable->{$key}[0] 0 0 0
189 0 push(@{ $$vtable{$key}[0] }, @values);
190 0 return; }
191  
192 sub popValue {
193 0 ▶ my ($self, $key) = @_;
Subroutine popValue: not called CC=2 SCAR=17.9
Pod undocumented
194 0 my $vtable = $$self{value};
195 0 ▶ assign_internal($self, 'value', $key, [], 'global') unless $$vtable{$key}[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $vtable->{$key}[0] 0 0 0
196 0 return pop(@{ $$vtable{$key}[0] }); }
197  
198 sub unshiftValue {
199 0 ▶ my ($self, $key, @values) = @_;
Subroutine unshiftValue: not called CC=2 SCAR=17.9
Pod undocumented
200 0 my $vtable = $$self{value};
201 0 ▶ assign_internal($self, 'value', $key, [], 'global') unless $$vtable{$key}[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $vtable->{$key}[0] 0 0 0
202 0 unshift(@{ $$vtable{$key}[0] }, @values);
203 0 return; }
204  
205 sub shiftValue {
206 0 ▶ my ($self, $key) = @_;
Subroutine shiftValue: not called CC=2 SCAR=17.9
Pod undocumented
207 0 my $vtable = $$self{value};
208 0 ▶ assign_internal($self, 'value', $key, [], 'global') unless $$vtable{$key}[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $vtable->{$key}[0] 0 0 0
209 0 return shift(@{ $$vtable{$key}[0] }); }
210  
211 # manage a (global) hash of values
212 sub lookupMapping {
213 0 ▶ my ($self, $map, $key) = @_;
Subroutine lookupMapping: not called CC=2 SCAR=17.9
Pod undocumented
214 0 my $vtable = $$self{value};
215 0 my $mapping = $$vtable{$map}[0];
216 0 ▶ return ($mapping ? $$mapping{$key} : undef); }
Branch: 1 branch
BranchTrueFalseTotal
$mapping ? : 0 0 0
217  
218 sub assignMapping {
219 0 ▶ my ($self, $map, $key, $value) = @_;
Subroutine assignMapping: not called CC=3 SCAR=24.8
Pod undocumented
220 0 my $vtable = $$self{value};
221 0 ▶ assign_internal($self, 'value', $map, {}, 'global') unless $$vtable{$map}[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $vtable->{$map}[0] 0 0 0
222 0 ▶ if (!defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $value) { } 0 0 0
223 0 delete $$vtable{$map}[0]{$key}; }
224 else {
225 0 $$vtable{$map}[0]{$key} = $value; }
226 0 return; }
227  
228 sub lookupMappingKeys {
229 0 ▶ my ($self, $map) = @_;
Subroutine lookupMappingKeys: not called CC=2 SCAR=17.9
Pod undocumented
230 0 my $vtable = $$self{value};
231 0 my $mapping = $$vtable{$map}[0];
232 0 ▶ return ($mapping ? sort keys %$mapping : ()); }
Branch: 1 branch
BranchTrueFalseTotal
$mapping ? : 0 0 0
233  
234 sub lookupStackedValues {
235 0 ▶ my ($self, $key) = @_;
Subroutine lookupStackedValues: not called CC=2 SCAR=17.9
Pod undocumented
236 0 my $stack = $$self{value}{$key};
237 0 ▶ return ($stack ? @$stack : ()); }
Branch: 1 branch
BranchTrueFalseTotal
$stack ? : 0 0 0
238  
239 #======================================================================
240 # Was $name bound? If $frame is given, check only whether it is bound in
241 # that frame (0 is the topmost).
242 sub isValueBound {
243 0 ▶ my ($self, $key, $frame) = @_;
Subroutine isValueBound: not called CC=2 SCAR=17.9
Pod undocumented
244 return (defined $frame ? $$self{undo}[$frame]{value}{$key}
245 0 ▶ : defined $$self{value}{$key}[0]); }
Branch: 1 branch
BranchTrueFalseTotal
defined $frame ? : 0 0 0
246  
247 sub valueInFrame {
248 0 ▶ my ($self, $key, $frame) = @_;
Subroutine valueInFrame: not called CC=4 SCAR=30.0
Pod undocumented
249 0 ▶ $frame = 0 unless defined $frame;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $frame 0 0 0
250 0 my $p = 0;
251 0 ▶ for (my $f = 0 ; $f < $frame ; $f++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f < $frame) 0 0 0
252 0 ▶ $p += $$self{undo}[$f]{value}{$key} || 0; }
Condition0%0/2
$self->{'undo'}[$f]{'value'}{$key} || 0
l!l
00
MC/DC0%0/1
$self->{'undo'}[$f]{'value'}{$key} || 0
$self->{'undo'}[$f]{'value'}{$key}
Truth table0%0/2
A
A= $self->{'undo'}[$f]{'value'}{$key}
Aresult
11
00
253 0 return $$self{value}{$key}[$p]; }
254  
255 #======================================================================
256 # Lookup & assign a character's Catcode
257 sub lookupCatcode {
258 0 ▶ my ($self, $key) = @_;
Subroutine lookupCatcode: not called CC=2 SCAR=17.9
Pod documented
259 0 my $e = $$self{catcode}{$key};
260 0 ▶ return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
261  
262 sub assignCatcode {
263 0 ▶ my ($self, $key, $value, $scope) = @_;
Subroutine assignCatcode: not called CC=1 SCAR=6.9
Pod documented
264 0 assign_internal($self, 'catcode', $key, $value, $scope);
265 0 return; }
266  
267 # The following rarely used.
268 sub lookupMathcode {
269 0 ▶ my ($self, $key) = @_;
Subroutine lookupMathcode: not called CC=2 SCAR=17.9
Pod undocumented
270 0 my $e = $$self{mathcode}{$key};
271 0 ▶ return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
272  
273 sub assignMathcode {
274 0 ▶ my ($self, $key, $value, $scope) = @_;
Subroutine assignMathcode: not called CC=1 SCAR=6.9
Pod undocumented
275 0 assign_internal($self, 'mathcode', $key, $value, $scope);
276 0 return; }
277  
278 sub lookupSFcode {
279 0 ▶ my ($self, $key) = @_;
Subroutine lookupSFcode: not called CC=2 SCAR=17.9
Pod undocumented
280 0 my $e = $$self{sfcode}{$key};
281 0 ▶ return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
282  
283 sub assignSFcode {
284 0 ▶ my ($self, $key, $value, $scope) = @_;
Subroutine assignSFcode: not called CC=1 SCAR=6.9
Pod undocumented
285 0 assign_internal($self, 'sfcode', $key, $value, $scope);
286 0 return; }
287  
288 sub lookupLCcode {
289 0 ▶ my ($self, $key) = @_;
Subroutine lookupLCcode: not called CC=2 SCAR=17.9
Pod undocumented
290 0 my $e = $$self{lccode}{$key};
291 0 ▶ return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
292  
293 sub assignLCcode {
294 0 ▶ my ($self, $key, $value, $scope) = @_;
Subroutine assignLCcode: not called CC=1 SCAR=6.9
Pod undocumented
295 0 assign_internal($self, 'lccode', $key, $value, $scope);
296 0 return; }
297  
298 sub lookupUCcode {
299 0 ▶ my ($self, $key) = @_;
Subroutine lookupUCcode: not called CC=2 SCAR=17.9
Pod undocumented
300 0 my $e = $$self{uccode}{$key};
301 0 ▶ return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
302  
303 sub assignUCcode {
304 0 ▶ my ($self, $key, $value, $scope) = @_;
Subroutine assignUCcode: not called CC=1 SCAR=6.9
Pod undocumented
305 0 assign_internal($self, 'uccode', $key, $value, $scope);
306 0 return; }
307  
308 sub lookupDelcode {
309 0 ▶ my ($self, $key) = @_;
Subroutine lookupDelcode: not called CC=2 SCAR=17.9
Pod undocumented
310 0 my $e = $$self{delcode}{$key};
311 0 ▶ return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
312  
313 sub assignDelcode {
314 0 ▶ my ($self, $key, $value, $scope) = @_;
Subroutine assignDelcode: not called CC=1 SCAR=6.9
Pod undocumented
315 0 assign_internal($self, 'delcode', $key, $value, $scope);
316 0 return; }
317  
318 #======================================================================
319 # Specialized versions of lookup & assign for dealing with definitions
320  
321 29 our @active_or_cs = (
322 0, 0, 0, 0,
323 0, 0, 0, 0,
324 0, 0, 0, 0,
325 0, 1, 0, 0,
326 1, 0);
327 29 our @letter_or_other = (
328 0, 0, 0, 0,
329 0, 0, 0, 0,
330 0, 0, 0, 1,
331 1, 0, 0, 0,
332 0, 0);
333  
334 # Get the `Meaning' of a token. For active control sequence's
335 # this may give the definition object (if defined) or another token (if \let) or undef
336 # Any other token is returned as is.
337 sub lookupMeaning {
338 0 ▶ my ($self, $token) = @_;
Subroutine lookupMeaning: not called CC=5 SCAR=34.0
Pod documented
339 0 my $e;
340 0 ▶ if (my $cs = $token
Branch: 1 branch
BranchTrueFalseTotal
if (my $cs = $token && $LaTeXML::Core::State::active_or_cs[$token->[1]] && $token->[0]) { } 0 0 0
Condition0%0/6
$token && $LaTeXML::Core::State::active_or_cs[$token->[1]] && $token->[0]
!ll&&!rl&&r
000
$token and $LaTeXML::Core::State::active_or_cs[$token->[1]]
!ll&&!rl&&r
000
MC/DC0%0/3
$token && $LaTeXML::Core::State::active_or_cs[$token->[1]] && $token->[0]
$token $LaTeXML::Core::State::active_or_cs[$token->[1]] $token->[0]
Truth table0%0/4
A and B && C
A= $tokenB= $LaTeXML::Core::State::active_or_cs[$token->[1]]C= $token->[0]
ABCresult
0XX0
10X0
1100
1111
341 && $active_or_cs[$$token[1]]
342 && $$token[0]) {
343 0 ▶ my $e = $$self{meaning}{$cs}; return $e && $$e[0]; }
Condition0%0/3
$e && $e->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
$e && $e->[0]
$e $e->[0]
Truth table0%0/3
A && B
A= $eB= $e->[0]
ABresult
0X0
100
111
344 0 else { return $token; } }
345  
346 # $meaning should be a definition (for defining active control sequences)
347 # or another token, for \let
348 sub assignMeaning {
349 0 ▶ my ($self, $token, $meaning, $scope) = @_;
Subroutine assignMeaning: not called CC=2 SCAR=17.9
Pod documented
350 0 ▶ return if $token->equals($meaning); # HACK!!!????
Branch: 1 branch
BranchTrueFalseTotal
if $token->equals($meaning) 0 0 0
351 0 assign_internal($self, 'meaning', $token->getCSName => $meaning, $scope);
352 0 return; }
353  
354 # used for expansion & various queries
355 # Since we're not doing digestion here, we don't need to handle mathactive,
356 # nor cs let to executable tokens
357 # This returns a definition object, or undef
358  
359 # merge of @executable_catcode & @PRIMITIVE_NAME
360 29 our @executable_primitive_name = ( # [CONSTANT]
361 undef, 'Begin', 'End', 'Math',
362 'Align', undef, undef, 'Superscript',
363 'Subscript', undef, undef, undef,
364 undef, undef, undef, undef,
365 undef, undef);
366  
367 sub lookupDefinition {
368 0 ▶ my ($self, $token) = @_;
Subroutine lookupDefinition: not called CC=7 SCAR=40.3
Pod undocumented
369 0 ▶ return unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
370 0 my $defn;
371 my $entry;
372 # my $inmath = $self->lookupValue('IN_MATH');
373 0 my $cc = $$token[1];
374 0 ▶ my $lookupname =
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::Core::State::active_or_cs[$cc] ? : 0 0 0
375 ($active_or_cs[$cc]
376 ? $$token[0]
377 : $executable_primitive_name[$cc]);
378 0 ▶ if ($lookupname
Branch: 1 branch
BranchTrueFalseTotal
if ($lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token") 0 0 0
Condition0%0/9
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token"
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0]
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname}
!ll&&!rl&&r
000
MC/DC0%0/4
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token"
$lookupname $entry = $self->{"meaning"}{$lookupname} $defn = $entry->[0] ref $defn ne "LaTeXML::Core::Token"
Truth table0%0/5
A and B and C and D
A= $lookupnameB= $entry = $self->{"meaning"}{$lookupname}C= $defn = $entry->[0]D= ref $defn ne "LaTeXML::Core::Token"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
379 && ($entry = $$self{meaning}{$lookupname})
380 && ($defn = $$entry[0])
381 # Can only be a token or definition; we want defns!
382 && ((ref $defn) ne 'LaTeXML::Core::Token')) {
383 0 return $defn; }
384 0 return; }
385  
386 # identical, but for return test; used by skipConditionalBody
387 sub lookupConditional {
388 0 ▶ my ($self, $token) = @_;
Subroutine lookupConditional: not called CC=7 SCAR=40.3
Pod undocumented
389 0 ▶ return unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
390 0 my $defn;
391 my $entry;
392 # my $inmath = $self->lookupValue('IN_MATH');
393 0 my $cc = $$token[1];
394 0 ▶ my $lookupname =
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::Core::State::active_or_cs[$cc] ? : 0 0 0
395 ($active_or_cs[$cc]
396 ? $$token[0]
397 : $executable_primitive_name[$cc]);
398 0 ▶ if ($lookupname
Branch: 1 branch
BranchTrueFalseTotal
if ($lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token") 0 0 0
Condition0%0/9
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token"
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0]
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname}
!ll&&!rl&&r
000
MC/DC0%0/4
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token"
$lookupname $entry = $self->{"meaning"}{$lookupname} $defn = $entry->[0] ref $defn ne "LaTeXML::Core::Token"
Truth table0%0/5
A and B and C and D
A= $lookupnameB= $entry = $self->{"meaning"}{$lookupname}C= $defn = $entry->[0]D= ref $defn ne "LaTeXML::Core::Token"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
399 && ($entry = $$self{meaning}{$lookupname})
400 && ($defn = $$entry[0])
401 # Can only be a token or definition; we only want defns that have conditional_type
402 && ((ref $defn) ne 'LaTeXML::Core::Token')) {
403 0 return $$defn{conditional_type}; }
404 0 return; }
405  
406 # Identical but inlined return tests for efficiency; used by readXToken
407 sub lookupExpandable {
408 0 ▶ my ($self, $token, $toplevel) = @_;
Subroutine lookupExpandable: not called CC=10 SCAR=47.0
Pod undocumented
409 0 ▶ return unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
410 0 my $defn;
411 my $entry;
412 # my $inmath = $self->lookupValue('IN_MATH');
413 0 my $cc = $$token[1];
414 0 ▶ my $lookupname =
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::Core::State::active_or_cs[$cc] ? : 0 0 0
415 ($active_or_cs[$cc]
416 ? $$token[0]
417 : $executable_primitive_name[$cc]);
418 0 ▶ if ($lookupname
Branch: 1 branch
BranchTrueFalseTotal
if ($lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token" and $defn->{"isExpandable"} and $toplevel || !$defn->{"isProtected"}) 0 0 0
Condition0%0/18
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token" and $defn->{"isExpandable"} and $toplevel || !$defn->{"isProtected"}
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token" and $defn->{"isExpandable"}
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token"
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0]
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname}
!ll&&!rl&&r
000
$toplevel or not $defn->{"isProtected"}
l!l&&r!l&&!r
000
MC/DC0%0/7
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0] and ref $defn ne "LaTeXML::Core::Token" and $defn->{"isExpandable"} and $toplevel || !$defn->{"isProtected"}
$lookupname $entry = $self->{"meaning"}{$lookupname} $defn = $entry->[0] ref $defn ne "LaTeXML::Core::Token" $defn->{"isExpandable"} $toplevel not $defn->{"isProtected"}
Truth table0%0/8
A and B and C and D and E and F or not(G)
A= $lookupnameB= $entry = $self->{"meaning"}{$lookupname}C= $defn = $entry->[0]D= ref $defn ne "LaTeXML::Core::Token"E= $defn->{"isExpandable"}F= $toplevelG= not $defn->{"isProtected"}
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
11110XX0
11111000
111111X1
11111011
419 && ($entry = $$self{meaning}{$lookupname})
420 && ($defn = $$entry[0])
421 # Can only be a token or definition; we want defns!
422 && ((ref $defn) ne 'LaTeXML::Core::Token')
423 && $$defn{isExpandable}
424 && ($toplevel || !$$defn{isProtected})) { # is this the right logic here? don't expand unless digesting?
425 0 return $defn; }
426 0 return; }
427  
428 # used for digestion
429 # This recognizes mathactive tokens in math mode
430 # and also looks for cs that have been let to other `executable' tokens
431 # This returns a definition object,
432 # or a "self inserting" token.
433 sub lookupDigestableDefinition {
434 0 ▶ my ($self, $token) = @_;
Subroutine lookupDigestableDefinition: not called CC=13 SCAR=52.0
Pod undocumented
435 0 ▶ return unless $token;
Branch: 1 branch
BranchTrueFalseTotal
unless $token 0 0 0
436 0 my $defn;
437 my $entry;
438 # my $inmath = $self->lookupValue('IN_MATH');
439 0 my $cc = $$token[1];
440 0 my $name = $$token[0];
441 0 ▶ my $lookupname =
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::Core::State::active_or_cs[$cc] || $LaTeXML::Core::State::letter_or_other[$cc] && $self->lookupValue('IN_MATH') && ($self->lookupMathcode($name) || 0) == 32768 ? : 0 0 0
Condition0%0/11
$LaTeXML::Core::State::active_or_cs[$cc] or $LaTeXML::Core::State::letter_or_other[$cc] and $self->lookupValue("IN_MATH") and ($self->lookupMathcode($name) || 0) == 32768
l!l&&r!l&&!r
000
$LaTeXML::Core::State::letter_or_other[$cc] and $self->lookupValue("IN_MATH") and ($self->lookupMathcode($name) || 0) == 32768
!ll&&!rl&&r
000
$LaTeXML::Core::State::letter_or_other[$cc] and $self->lookupValue("IN_MATH")
!ll&&!rl&&r
000
$self->lookupMathcode($name) || 0
l!l
00
MC/DC0%0/4
$LaTeXML::Core::State::active_or_cs[$cc] or $LaTeXML::Core::State::letter_or_other[$cc] and $self->lookupValue("IN_MATH") and ($self->lookupMathcode($name) || 0) == 32768
$LaTeXML::Core::State::active_or_cs[$cc] $LaTeXML::Core::State::letter_or_other[$cc] $self->lookupValue("IN_MATH") $self->lookupMathcode($name)
Truth table0%0/5
A or B and C and D
A= $LaTeXML::Core::State::active_or_cs[$cc]B= $LaTeXML::Core::State::letter_or_other[$cc]C= $self->lookupValue("IN_MATH")D= $self->lookupMathcode($name)
ABCDresult
1XXX1
01111
00XX0
010X0
01100
442 (($active_or_cs[$cc]
443 || ($letter_or_other[$cc] && $self->lookupValue('IN_MATH')
444 && (($self->lookupMathcode($name) || 0) == 0x8000)))
445 ? $name
446 : $executable_primitive_name[$cc]);
447 0 ▶ if ($lookupname && ($entry = $$self{meaning}{$lookupname})
Branch: 1 branch
BranchTrueFalseTotal
if ($lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0]) 0 0 0
Condition0%0/6
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0]
!ll&&!rl&&r
000
$lookupname and $entry = $self->{"meaning"}{$lookupname}
!ll&&!rl&&r
000
MC/DC0%0/3
$lookupname and $entry = $self->{"meaning"}{$lookupname} and $defn = $entry->[0]
$lookupname $entry = $self->{"meaning"}{$lookupname} $defn = $entry->[0]
Truth table0%0/4
A and B and C
A= $lookupnameB= $entry = $self->{"meaning"}{$lookupname}C= $defn = $entry->[0]
ABCresult
0XX0
10X0
1100
1111
448 && ($defn = $$entry[0])) {
449 # If a cs has been let to an executable token, lookup ITS defn.
450 0 ▶ if (((ref $defn) eq 'LaTeXML::Core::Token')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $defn eq "LaTeXML::Core::Token" and $lookupname = $LaTeXML::Core::State::executable_primitive_name[$defn->[1]] and $entry = $self->{"meaning"}{$lookupname}) 0 0 0
Condition0%0/6
ref $defn eq "LaTeXML::Core::Token" and $lookupname = $LaTeXML::Core::State::executable_primitive_name[$defn->[1]] and $entry = $self->{"meaning"}{$lookupname}
!ll&&!rl&&r
000
ref $defn eq "LaTeXML::Core::Token" and $lookupname = $LaTeXML::Core::State::executable_primitive_name[$defn->[1]]
!ll&&!rl&&r
000
MC/DC0%0/3
ref $defn eq "LaTeXML::Core::Token" and $lookupname = $LaTeXML::Core::State::executable_primitive_name[$defn->[1]] and $entry = $self->{"meaning"}{$lookupname}
ref $defn eq "LaTeXML::Core::Token" $lookupname = $LaTeXML::Core::State::executable_primitive_name[$defn->[1]] $entry = $self->{"meaning"}{$lookupname}
Truth table0%0/4
A and B and C
A= ref $defn eq "LaTeXML::Core::Token"B= $lookupname = $LaTeXML::Core::State::executable_primitive_name[$defn->[1]]C= $entry = $self->{"meaning"}{$lookupname}
ABCresult
0XX0
10X0
1100
1111
451 && ($lookupname = $executable_primitive_name[$$defn[1]])
452 && ($entry = $$self{meaning}{$lookupname})) {
453 0 $defn = $$entry[0]; }
454 0 return $defn; }
455 0 return $token; }
456  
457 # And a shorthand for installing definitions
458 sub installDefinition {
459 0 ▶ my ($self, $definition, $scope) = @_;
Subroutine installDefinition: not called CC=7 SCAR=40.3
Pod documented
460 # Locked definitions!!! (or should this test be in assignMeaning?)
461 # Ignore attempts to (re)define $cs from tex sources
462 # my $cs = $definition->getCS->getCSName;
463 0 my $token = $definition->getCS;
464 0 ▶ my $cs = ($LaTeXML::Core::Token::PRIMITIVE_NAME[$$token[1]] || $$token[0]);
Condition0%0/3
$LaTeXML::Core::Token::PRIMITIVE_NAME[$token->[1]] || $token->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$LaTeXML::Core::Token::PRIMITIVE_NAME[$token->[1]] || $token->[0]
$LaTeXML::Core::Token::PRIMITIVE_NAME[$token->[1]] $token->[0]
Truth table0%0/3
A || B
A= $LaTeXML::Core::Token::PRIMITIVE_NAME[$token->[1]]B= $token->[0]
ABresult
1X1
011
000
465 0 ▶ if ($self->lookupValue("$cs:locked") && !$LaTeXML::Core::State::UNLOCKED) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->lookupValue("${cs}:locked") and not $LaTeXML::Core::State::UNLOCKED) 0 0 0
Condition0%0/3
$self->lookupValue("${cs}:locked") and not $LaTeXML::Core::State::UNLOCKED
!ll&&!rl&&r
000
MC/DC0%0/2
$self->lookupValue("${cs}:locked") and not $LaTeXML::Core::State::UNLOCKED
$self->lookupValue("${cs}:locked") not $LaTeXML::Core::State::UNLOCKED
Truth table0%0/3
A and not(B)
A= $self->lookupValue("${cs}:locked")B= not $LaTeXML::Core::State::UNLOCKED
ABresult
0X0
100
111
466 0 my $s = $self->getStomach->getGullet->getSource;
467 # report if the redefinition seems to come from document source
468 0 ▶ if (((!defined($s)) || ($s =~ /\.(tex|bib)$/))
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($s) || $s =~ /\.(tex|bib)$/ and not $s =~ /\.code\.tex$/) 0 0 0
Condition0%0/6
!defined($s) || $s =~ /\.(tex|bib)$/ and not $s =~ /\.code\.tex$/
!ll&&!rl&&r
000
not defined $s or $s =~ /\.(tex|bib)$/
l!l&&r!l&&!r
000
MC/DC0%0/3
!defined($s) || $s =~ /\.(tex|bib)$/ and not $s =~ /\.code\.tex$/
not defined $s $s =~ /\.(tex|bib)$/ not $s =~ /\.code\.tex$/
Truth table0%0/5
not(A) or B and not(C)
A= not defined $sB= $s =~ /\.(tex|bib)$/C= not $s =~ /\.code\.tex$/
ABCresult
00X0
1X00
0100
1X11
0111
469 && ($s !~ /\.code\.tex$/)) {
470 0 Info('ignore', $cs, $self->getStomach, "Ignoring redefinition of $cs"); }
471 0 return; }
472 0 assign_internal($self, 'meaning', $cs => $definition, $scope);
473 0 return; }
474  
475 # NOTE: Common usage patterns seem to be to lookup
476 # expandable definitions
477 # register values
478 # conditionals
479 # digestibles
480 # or just variants on testing defined-ness
481 # May be will introduce more clarity (possibly efficiency)
482 # to collect those more uniformly and implement here, or in Package
483  
484 #======================================================================
485  
486 sub pushFrame {
487 0 ▶ my ($self, $nobox) = @_;
Subroutine pushFrame: not called CC=1 SCAR=6.9
Pod documented
488 # Easy: just push a new undo hash.
489 0 unshift(@{ $$self{undo} }, {});
490 0 return; }
491  
492 sub popFrame {
493 0 ▶ my ($self) = @_;
Subroutine popFrame: not called CC=4 SCAR=30.0
Pod documented
494 0 ▶ if ($$self{undo}[0]{_FRAME_LOCK_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'undo'}[0]{'_FRAME_LOCK_'}) { } 0 0 0
495 0 Fatal('unexpected', '<endgroup>', $self->getStomach,
496 "Attempt to pop last locked stack frame"); }
497 else {
498 0 my $undo = shift(@{ $$self{undo} });
499 0 foreach my $table (keys %$undo) {
500 0 my $undotable = $$undo{$table};
501 0 foreach my $name (keys %$undotable) {
502 # Typically only 1 value to shift off the table, unless scopes have been activated.
503 0 map { shift(@{ $$self{$table}{$name} }) } 1 .. $$undotable{$name}; } } }
504 0 return; }
505  
506 # Determine depth of group nesting created by {,},\bgroup,\egroup,\begingroup,\endgroup
507 # by counting all frames which are not Daemon frames (and thus don't possess _FRAME_LOCK_).
508 # This may give incorrect results for some special environments (e.g. minipage)
509 sub getFrameDepth {
510 0 ▶ my ($self) = @_;
Subroutine getFrameDepth: not called CC=1 SCAR=6.9
Pod undocumented
511 0 return scalar(grep { not defined $$_{_FRAME_LOCK_} } @{ $$self{undo} }) - 1; }
512  
513 #======================================================================
514 # This is primarily about catcodes, but a bit more...
515  
516 sub beginSemiverbatim {
517 0 ▶ my ($self, @extraspecials) = @_;
Subroutine beginSemiverbatim: not called CC=1 SCAR=6.9
Pod undocumented
518 # Is this a good/safe enough shorthand, or should we really be doing beginMode?
519 0 $self->pushFrame;
520 0 $self->assignValue(MODE => 'text');
521 0 $self->assignValue(IN_MATH => 0);
522 0 map { $self->assignCatcode($_ => CC_OTHER, 'local') }
523 0 @{ $self->lookupValue('SPECIALS') }, @extraspecials;
524 0 $self->assignMathcode('\'' => 0x8000, 'local');
525 # try to stay as ASCII as possible
526 0 $self->assignValue(font => $self->lookupValue('font')->merge(encoding => 'ASCII'), 'local');
527 0 return; }
528  
529 sub endSemiverbatim {
530 0 ▶ my ($self) = @_;
Subroutine endSemiverbatim: not called CC=1 SCAR=6.9
Pod undocumented
531 0 $self->popFrame;
532 0 return; }
533  
534 #======================================================================
535  
536 sub pushDaemonFrame {
537 0 ▶ my ($self) = @_;
Subroutine pushDaemonFrame: not called CC=6 SCAR=37.4
Pod undocumented
538 0 my $frame = {};
539 0 unshift(@{ $$self{undo} }, $frame);
540 # Push copys of data for any data that is mutable;
541 # Only the value & stash tables need to be to be checked.
542 # NOTE ??? No...
543 0 foreach my $table (qw(value stash)) {
544 0 ▶ if (my $hash = $$self{$table}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $hash = $self->{$table}) 0 0 0
545 0 foreach my $key (keys %$hash) {
546 0 my $value = $$hash{$key}[0];
547 0 my $type = ref $value;
548 0 ▶ if (($type eq 'HASH') || ($type eq 'ARRAY')) { # Only concerned with mutable perl data?
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "HASH" or $type eq "ARRAY") 0 0 0
Condition0%0/3
$type eq "HASH" or $type eq "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "HASH" or $type eq "ARRAY"
$type eq "HASH" $type eq "ARRAY"
Truth table0%0/3
A or B
A= $type eq "HASH"B= $type eq "ARRAY"
ABresult
1X1
011
000
549 # Local assignment
550 0 $$frame{$table}{$key} = 1; # Note new value in this frame.
551 0 unshift(@{ $$hash{$key} }, daemon_copy($value)); } } } } # And push new binding.
552 # Record the contents of LaTeXML::Package::Pool as preloaded
553 0 my $pool_preloaded_hash = { map { $_ => 1 } keys %LaTeXML::Package::Pool:: };
554 0 $self->assignValue('_PRELOADED_POOL_', $pool_preloaded_hash, 'global');
555 # Now mark the top frame as LOCKED!!!
556 0 $$frame{_FRAME_LOCK_} = 1;
557 0 return; }
558  
559 sub daemon_copy {
560 0 ▶ my ($ob) = @_;
Subroutine daemon_copy: not called CC=3 SCAR=24.8
Pod undocumented
561 0 ▶ if (ref $ob eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ob eq 'HASH') { } 0 0 0
elsif (ref $ob eq 'ARRAY') { } 0 0 0
562 0 my %hash = map { ($_ => daemon_copy($$ob{$_})) } keys %$ob;
563 0 return \%hash; }
564 elsif (ref $ob eq 'ARRAY') {
565 0 return [map { daemon_copy($_) } @$ob]; }
566 else {
567 0 return $ob; } }
568  
569 sub popDaemonFrame {
570 0 ▶ my ($self) = @_;
Subroutine popDaemonFrame: not called CC=5 SCAR=34.0
Pod undocumented
571 0 ▶ while (!$$self{undo}[0]{_FRAME_LOCK_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"undo"}[0]{"_FRAME_LOCK_"}) 0 0 0
572 0 $self->popFrame; }
573 0 ▶ if (scalar(@{ $$self{undo} } > 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar(@{$self->{'undo'};} > 1)) { } 0 0 0
574 0 delete $$self{undo}[0]{_FRAME_LOCK_};
575 # Any non-preloaded Pool routines should be wiped away, as we
576 # might want to reuse the Pool namespaces for the next run.
577 0 my $pool_preloaded_hash = $self->lookupValue('_PRELOADED_POOL_');
578 0 $self->assignValue('_PRELOADED_POOL_', undef, 'global');
579 0 foreach my $subname (keys %LaTeXML::Package::Pool::) {
580 0 ▶ unless (exists $$pool_preloaded_hash{$subname}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $pool_preloaded_hash->{$subname}) 0 0 0
581 0 undef $LaTeXML::Package::Pool::{$subname};
582 0 delete $LaTeXML::Package::Pool::{$subname};
583 } }
584 # Finally, pop the frame
585 0 $self->popFrame; }
586 else {
587 0 Fatal('unexpected', '<endgroup>', $self->getStomach,
588 "Daemon Attempt to pop last stack frame"); }
589 0 return; }
590  
591 #======================================================================
592 # Set one of the definition prefixes global, etc (only global matters!)
593 sub setPrefix {
594 0 ▶ my ($self, $prefix) = @_;
Subroutine setPrefix: not called CC=1 SCAR=6.9
Pod documented
595 0 $$self{prefixes}{$prefix} = 1;
596 0 return; }
597  
598 sub getPrefix {
599 0 ▶ my ($self, $prefix) = @_;
Subroutine getPrefix: not called CC=1 SCAR=6.9
Pod undocumented
600 0 return $$self{prefixes}{$prefix}; }
601  
602 sub clearPrefixes {
603 0 ▶ my ($self) = @_;
Subroutine clearPrefixes: not called CC=1 SCAR=6.9
Pod documented
604 0 $$self{prefixes} = {};
605 0 return; }
606  
607 #======================================================================
608  
609 sub activateScope {
610 0 ▶ my ($self, $scope) = @_;
Subroutine activateScope: not called CC=4 SCAR=30.0
Pod documented
611 0 ▶ if (!$$self{stash_active}{$scope}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"stash_active"}{$scope}[0]) 0 0 0
612 0 assign_internal($self, 'stash_active', $scope, 1, 'local');
613 0 ▶ if (defined(my $defns = $$self{stash}{$scope}[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $defns = $self->{"stash"}{$scope}[0])) 0 0 0
614 # Now make local assignments for all those in the stash.
615 0 my $frame = $$self{undo}[0];
616 0 foreach my $entry (@$defns) {
617 # Here we ALWAYS push the stashed values into the table
618 # since they may be popped off by deactivateScope
619 0 my ($table, $key, $value) = @$entry;
620 0 $$frame{$table}{$key}++; # Note that this many values must be undone
621 0 unshift(@{ $$self{$table}{$key} }, $value); } } } # And push new binding.
622 0 return; }
623  
624 # Probably, in most cases, the assignments made by activateScope
625 # will be undone by egroup or popping frames.
626 # But they can also be undone explicitly
627 sub deactivateScope {
628 0 ▶ my ($self, $scope) = @_;
Subroutine deactivateScope: not called CC=5 SCAR=34.0
Pod documented
629 0 ▶ if ($$self{stash_active}{$scope}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"stash_active"}{$scope}[0]) 0 0 0
630 0 assign_internal($self, 'stash_active', $scope, 0, 'global');
631 0 ▶ if (defined(my $defns = $$self{stash}{$scope}[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $defns = $self->{"stash"}{$scope}[0])) 0 0 0
632 0 my $frame = $$self{undo}[0];
633 0 foreach my $entry (@$defns) {
634 0 my ($table, $key, $value) = @$entry;
635 0 ▶ if ($$self{$table}{$key}[0] eq $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{$table}{$key}[0] eq $value) { } 0 0 0
636 # Here we're popping off the values pushed by activateScope
637 # to (possibly) reveal a local assignment in the same frame, preceding activateScope.
638 0 shift(@{ $$self{$table}{$key} });
639 0 $$frame{$table}{$key}--; }
640 else {
641 Warn('internal', $key, $self->getStomach,
642 "Unassigning wrong value for $key from table $table in deactivateScope",
643 0 "value is $value but stack is " . join(', ', @{ $$self{$table}{$key} })); } } } }
644 0 return; }
645  
646 sub getKnownScopes {
647 0 ▶ my ($self) = @_;
Subroutine getKnownScopes: not called CC=1 SCAR=6.9
Pod undocumented
648 0 my @scopes = sort keys %{ $$self{stash} };
649 0 return @scopes; }
650  
651 sub getActiveScopes {
652 0 ▶ my ($self) = @_;
Subroutine getActiveScopes: not called CC=1 SCAR=6.9
Pod undocumented
653 0 my @scopes = sort keys %{ $$self{stash_active} };
654 0 return @scopes; }
655  
656 #======================================================================
657 # Units.
658  
659 sub convertUnit {
660 0 ▶ my ($self, $unit) = @_;
Subroutine convertUnit: not called CC=5 SCAR=34.0
Pod documented
661 0 $unit = lc($unit);
662 # Put here since it could concievably evolve to depend on the current font.
663 # Eventually try to track font size?
664 0 ▶ if ($unit eq 'em') { return 10.0 * 65536; }
Branch: 3 branches
BranchTrueFalseTotal
if ($unit eq 'em') { } 0 0 0
elsif ($unit eq 'ex') { } 0 0 0
elsif ($unit eq 'mu') { } 0 0 0
665 0 elsif ($unit eq 'ex') { return 4.3 * 65536; }
666 0 elsif ($unit eq 'mu') { return 10.0 * 65536 / 18; }
667 else {
668 0 my $units = $self->lookupValue('UNITS');
669 0 my $sp = $$units{$unit};
670 0 ▶ if (!$sp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sp) 0 0 0
671 0 Warn('expected', '<unit>', undef, "Illegal unit of measure '$unit', assuming pt.");
672 0 $sp = $$units{'pt'}; }
673 0 return $sp; } }
674  
675 #======================================================================
676  
677 sub noteStatus {
678 0 ▶ my ($self, $type, @data) = @_;
Subroutine noteStatus: not called CC=3 SCAR=24.8
Pod undocumented
679 0 ▶ if ($type eq 'undefined') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'undefined') { } 0 0 0
elsif ($type eq 'missing') { } 0 0 0
680 0 map { $$self{status}{undefined}{$_}++ } @data; }
681 elsif ($type eq 'missing') {
682 0 map { $$self{status}{missing}{$_}++ } @data; }
683 else {
684 0 $$self{status}{$type}++; }
685 0 return; }
686  
687 sub getStatus {
688 0 ▶ my ($self, $type) = @_;
Subroutine getStatus: not called CC=1 SCAR=6.9
Pod undocumented
689 0 return $$self{status}{$type}; }
690  
691 sub getStatusMessage {
692 0 ▶ my ($self) = @_;
Subroutine getStatusMessage: not called CC=14 SCAR=53.5
Pod undocumented
693 0 my $status = $$self{status};
694 0 my @report = ();
695 push(@report, colorizeString("$$status{warning} warning" . ($$status{warning} > 1 ? 's' : ''), 'warning'))
696 0 ▶ if $$status{warning};
Branch: 2 branches
BranchTrueFalseTotal
if $status->{"warning"} 0 0 0
$status->{'warning'} > 1 ? : 0 0 0
697 push(@report, colorizeString("$$status{error} error" . ($$status{error} > 1 ? 's' : ''), 'error'))
698 0 ▶ if $$status{error};
Branch: 2 branches
BranchTrueFalseTotal
if $status->{"error"} 0 0 0
$status->{'error'} > 1 ? : 0 0 0
699 push(@report, "$$status{fatal} fatal error" . ($$status{fatal} > 1 ? 's' : ''))
700  
701 0 ▶ if $$status{fatal};
Branch: 2 branches
BranchTrueFalseTotal
if $status->{"fatal"} 0 0 0
$status->{'fatal'} > 1 ? : 0 0 0
702 0 ▶ my @undef = ($$status{undefined} ? keys %{ $$status{undefined} } : ());
Branch: 1 branch
BranchTrueFalseTotal
$status->{'undefined'} ? : 0 0 0
703 0 ▶ push(@report, colorizeString(scalar(@undef) . " undefined macro" . (@undef > 1 ? 's' : '')
Branch: 2 branches
BranchTrueFalseTotal
if @undef 0 0 0
@undef > 1 ? : 0 0 0
704 . "[" . join(', ', @undef) . "]", 'details'))
705 if @undef;
706 0 ▶ my @miss = ($$status{missing} ? keys %{ $$status{missing} } : ());
Branch: 1 branch
BranchTrueFalseTotal
$status->{'missing'} ? : 0 0 0
707 0 ▶ push(@report, colorizeString(scalar(@miss) . " missing file" . (@miss > 1 ? 's' : '')
Branch: 2 branches
BranchTrueFalseTotal
if @miss 0 0 0
@miss > 1 ? : 0 0 0
708 . "[" . join(', ', @miss) . "]", 'details'))
709 if @miss;
710 0 ▶ return join('; ', @report) || colorizeString('No obvious problems', 'success'); }
Condition0%0/3
join('; ', @report) || colorizeString('No obvious problems', 'success')
l!l&&r!l&&!r
000
MC/DC0%0/2
join('; ', @report) || colorizeString('No obvious problems', 'success')
join('; ', @report) colorizeString('No obvious problems', 'success')
Truth table0%0/3
A || B
A= join('; ', @report)B= colorizeString('No obvious problems', 'success')
ABresult
1X1
011
000
711  
712 sub getStatusCode {
713 0 ▶ my ($self) = @_;
Subroutine getStatusCode: not called CC=7 SCAR=40.3
Pod undocumented
714 0 my $status = $$self{status};
715 0 my $code;
716 0 ▶ if ($$status{fatal} && $$status{fatal} > 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($status->{'fatal'} and $status->{'fatal'} > 0) { } 0 0 0
elsif ($status->{'error'} and $status->{'error'} > 0) { } 0 0 0
elsif ($status->{'warning'} and $status->{'warning'} > 0) { } 0 0 0
Condition0%0/3
$status->{"fatal"} and $status->{"fatal"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$status->{"fatal"} and $status->{"fatal"} > 0
$status->{"fatal"} $status->{"fatal"} > 0
Truth table0%0/3
A and B
A= $status->{"fatal"}B= $status->{"fatal"} > 0
ABresult
0X0
100
111
717 0 $code = 3; }
718 ▶ elsif ($$status{error} && $$status{error} > 0) {
Condition0%0/3
$status->{"error"} and $status->{"error"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$status->{"error"} and $status->{"error"} > 0
$status->{"error"} $status->{"error"} > 0
Truth table0%0/3
A and B
A= $status->{"error"}B= $status->{"error"} > 0
ABresult
0X0
100
111
719 0 $code = 2; }
720 ▶ elsif ($$status{warning} && $$status{warning} > 0) {
Condition0%0/3
$status->{"warning"} and $status->{"warning"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$status->{"warning"} and $status->{"warning"} > 0
$status->{"warning"} $status->{"warning"} > 0
Truth table0%0/3
A and B
A= $status->{"warning"}B= $status->{"warning"} > 0
ABresult
0X0
100
111
721 0 $code = 1; }
722 else {
723 0 $code = 0; }
724 0 return $code; }
725 #======================================================================
726 29 1;
727  
728 __END__
« lib/LaTeXML/Core/KeyVals.pm ↑ Summary lib/LaTeXML/Core/Gullet.pm »