lib/LaTeXML/Core/Tokens.pm

filter: Statementstmt 34.2% 26 / 76 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 40.0% 8 / 20 Podpod 50.0% 6 / 12 totaltotal 26.8% 40 / 149 CC 17 SCAR 30.8
CC
17
Cov
24%
equals
56.0
substituteParameters
42.0
isBalanced
20.0
CRAP 21.8
« lib/LaTeXML/Post/MathML/Presentation.pm ↑ Summary lib/LaTeXML/Util/ObjectDB/Entry.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Core::Tokens | #
3 # | A list of Token(s) | #
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::Tokens;
13 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use LaTeXML::Core::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use base qw(LaTeXML::Common::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 our @EXPORT = ( # Global STATE; This gets bound by LaTeXML.pm
22 qw(&Tokens)
23 );
24  
25 #======================================================================
26 # Token List constructors.
27  
28 # Return a LaTeXML::Core::Tokens made from the arguments (tokens)
29 sub Tokens {
30 0 ▶ my (@tokens) = @_;
Subroutine Tokens: not called CC=1 SCAR=6.9
Pod documented
31 0 return LaTeXML::Core::Tokens->new(@tokens); }
32  
33 #======================================================================
34  
35 # Form a Tokens list of Token's
36 # Flatten the arguments Token's and Tokens's into plain Token's
37 # .... Efficiently! since this seems to be called MANY times.
38 sub new {
39 0 ▶ my ($class, @tokens) = @_;
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
40 0 my $r;
41 0 ▶ return bless [map { (($r = ref $_) eq 'LaTeXML::Core::Token' ? $_
Branch: 2 branches
BranchTrueFalseTotal
($r = ref $_) eq 'LaTeXML::Core::Token' ? : 0 0 0
$r eq 'LaTeXML::Core::Tokens' ? : 0 0 0
42 : ($r eq 'LaTeXML::Core::Tokens' ? @$_
43 : Fatal('misdefined', $r, undef, "Expected a Token, got " . Stringify($_)))) }
44 @tokens], $class; }
45  
46 # Return a list of the tokens making up this Tokens
47 sub unlist {
48 0 ▶ my ($self) = @_;
Subroutine unlist: not called CC=1 SCAR=6.9
Pod undocumented
49 0 return @$self; }
50  
51 # Return a shallow copy of the Tokens
52 sub clone {
53 0 ▶ my ($self) = @_;
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
54 0 return bless [@$self], ref $self; }
55  
56 # Return a string containing the TeX form of the Tokens
57 sub revert {
58 0 ▶ my ($self) = @_;
Subroutine revert: not called CC=1 SCAR=6.9
Pod undocumented
59 0 return @$self; }
60  
61 # toString is used often, and for more keyword-like reasons,
62 # NOT for creating valid TeX (use revert or UnTeX for that!)
63 sub toString {
64 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
65 0 return join('', map { $$_[0] } @$self); }
66  
67 # Methods for overloaded ops.
68 sub equals {
69 0 ▶ my ($a, $b) = @_;
Subroutine equals: not called CC=7 SCAR=40.3
Pod documented
70 0 ▶ return 0 unless defined $b && (ref $a) eq (ref $b);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $b and ref $a eq ref $b 0 0 0
Condition0%0/3
defined $b and ref $a eq ref $b
!ll&&!rl&&r
000
MC/DC0%0/2
defined $b and ref $a eq ref $b
defined $b ref $a eq ref $b
Truth table0%0/3
A and B
A= defined $bB= ref $a eq ref $b
ABresult
0X0
100
111
71 0 my @a = @$a;
72 0 my @b = @$b;
73 0 ▶ while (@a && @b && ($a[0]->equals($b[0]))) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a and @b and $a[0]->equals($b[0])) 0 0 0
Condition0%0/6
@a and @b and $a[0]->equals($b[0])
!ll&&!rl&&r
000
@a and @b
!ll&&!rl&&r
000
MC/DC0%0/3
@a and @b and $a[0]->equals($b[0])
@a @b $a[0]->equals($b[0])
Truth table0%0/4
A and B and C
A= @aB= @bC= $a[0]->equals($b[0])
ABCresult
0XX0
10X0
1100
1111
74 0 shift(@a); shift(@b); }
75 0 ▶ return !(@a || @b); }
Condition0%0/3
@a || @b
l!l&&r!l&&!r
000
MC/DC0%0/2
@a || @b
@a @b
Truth table0%0/3
A || B
A= @aB= @b
ABresult
1X1
011
000
76  
77 sub stringify {
78 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=1 SCAR=6.9
Pod documented
79 0 return "Tokens[" . join(',', map { $_->toString } @$self) . "]"; }
80  
81 sub beDigested {
82 0 ▶ my ($self, $stomach) = @_;
Subroutine beDigested: not called CC=1 SCAR=6.9
Pod documented
83 0 return $stomach->digest($self); }
84  
85 sub neutralize {
86 0 ▶ my ($self, @extraspecials) = @_;
Subroutine neutralize: not called CC=1 SCAR=6.9
Pod undocumented
87 0 return Tokens(map { $_->neutralize(@extraspecials) } $self->unlist); }
88  
89 sub isBalanced {
90 0 ▶ my ($self) = @_;
Subroutine isBalanced: not called CC=4 SCAR=30.0
Pod undocumented
91 0 my $level = 0;
92 0 foreach my $t (@$self) {
93 0 my $cc = $$t[1]; # INLINE
94 0 ▶ $level++ if $cc == CC_BEGIN;
Branch: 1 branch
BranchTrueFalseTotal
if $cc == 1 0 0 0
95 0 ▶ $level-- if $cc == CC_END; }
Branch: 1 branch
BranchTrueFalseTotal
if $cc == 2 0 0 0
96 0 return $level == 0; }
97  
98 # NOTE: Assumes each arg either undef or also Tokens
99 # Using inline accessors on those assumptions
100 sub substituteParameters {
101 0 ▶ my ($self, @args) = @_;
Subroutine substituteParameters: not called CC=6 SCAR=37.4
Pod undocumented
102 0 my @in = @{$self}; # ->unlist
103 0 my @result = ();
104 0 ▶ while (@in) {
Branch: 1 branch
BranchTrueFalseTotal
if (@in) 0 0 0
105 0 my $token;
106 0 ▶ if (($token = shift(@in))->[1] != CC_PARAM) { # Non '#'; copy it
Branch: 2 branches
BranchTrueFalseTotal
if (+($token = shift @in)->[1] != 6) { } 0 0 0
elsif (+($token = shift @in)->[1] != 6) { } 0 0 0
107 0 push(@result, $token); }
108 elsif (($token = shift(@in))->[1] != CC_PARAM) { # Not multiple '#'; read arg.
109 0 ▶ if (my $arg = $args[ord($$token[0]) - ord('0') - 1]) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $arg = $args[ord($token->[0]) - 48 - 1]) 0 0 0
110 0 ▶ push(@result, (ref $arg eq 'LaTeXML::Core::Token' ? $arg : @$arg)); } } # ->unlist
Branch: 1 branch
BranchTrueFalseTotal
ref $arg eq 'LaTeXML::Core::Token' ? : 0 0 0
111 else { # Duplicated '#', copy 2nd '#'
112 0 push(@result, $token); } }
113 0 return LaTeXML::Core::Tokens->new(@result); }
114  
115 #======================================================================
116  
117 4 1;
118  
119 __END__
« lib/LaTeXML/Post/MathML/Presentation.pm ↑ Summary lib/LaTeXML/Util/ObjectDB/Entry.pm »