lib/LaTeXML/Core/Token.pm

filter: Statementstmt 54.8% 113 / 206 Branchbran 0.0% 0 / 50 Conditioncond 0.0% 0 / 58 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 58.6% 34 / 58 Podpod 58.3% 14 / 24 totaltotal 37.9% 161 / 424 CC 46 SCAR 53.1
CC
46
Cov
36%
UnTeX
756.0
equals
30.0
ExplodeText
20.0
CRAP 202.9
« lib/LaTeXML/Common/Glue.pm ↑ Summary lib/LaTeXML/Util/Pathname.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Core::Token, LaTeXML::Core::Tokens | #
3 # | Representation 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  
13 #**********************************************************************
14 # A Token represented as a pair: [string,catcode]
15 # string is a character or control sequence.
16 # Yes, a bit inefficient, but code is clearer...
17 #**********************************************************************
18 package LaTeXML::Core::Token;
19 29 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 29 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 29 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 29 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 29 ▶use base qw(LaTeXML::Common::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 29 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 29 our @EXPORT = (
26 # Catcode constants
27 qw( CC_ESCAPE CC_BEGIN CC_END CC_MATH
28 CC_ALIGN CC_EOL CC_PARAM CC_SUPER
29 CC_SUB CC_IGNORE CC_SPACE CC_LETTER
30 CC_OTHER CC_ACTIVE CC_COMMENT CC_INVALID
31 CC_CS CC_NOTEXPANDED CC_MARKER),
32 # Token constructors
33 qw( T_BEGIN T_END T_MATH T_ALIGN T_PARAM T_SUB T_SUPER T_SPACE
34 &T_LETTER &T_OTHER &T_ACTIVE &T_COMMENT &T_CS
35 T_CR &T_MARKER
36 &Token),
37 # String exploders
38 qw(&Explode &ExplodeText &UnTeX)
39 );
40  
41 #======================================================================
42 # Constructors.
43  
44 29 ▶use constant CC_ESCAPE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 29 ▶use constant CC_BEGIN => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 29 ▶use constant CC_END => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 29 ▶use constant CC_MATH => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 29 ▶use constant CC_ALIGN => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 29 ▶use constant CC_EOL => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 29 ▶use constant CC_PARAM => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 29 ▶use constant CC_SUPER => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 29 ▶use constant CC_SUB => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 29 ▶use constant CC_IGNORE => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 29 ▶use constant CC_SPACE => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 29 ▶use constant CC_LETTER => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 29 ▶use constant CC_OTHER => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 29 ▶use constant CC_ACTIVE => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 29 ▶use constant CC_COMMENT => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 29 ▶use constant CC_INVALID => 15;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 # Extended Catcodes for expanded output.
61 29 ▶use constant CC_CS => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 29 ▶use constant CC_NOTEXPANDED => 17;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 29 ▶use constant CC_MARKER => 18; # non TeX extension!
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 # [The documentation for constant is a bit confusing about subs,
66 # but these apparently DO generate constants; you always get the same one]
67 # These are immutable
68 29 ▶use constant T_BEGIN => bless ['{', 1], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
69 29 ▶use constant T_END => bless ['}', 2], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
70 29 ▶use constant T_MATH => bless ['$', 3], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 29 ▶use constant T_ALIGN => bless ['&', 4], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
72 29 ▶use constant T_PARAM => bless ['#', 6], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
73 29 ▶use constant T_SUPER => bless ['^', 7], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 29 ▶use constant T_SUB => bless ['_', 8], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 29 ▶use constant T_SPACE => bless [' ', 10], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
76 29 ▶use constant T_CR => bless ["\n", 10], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
77 0 ▶sub T_LETTER { my ($c) = @_; return bless [$c, 11], 'LaTeXML::Core::Token'; }
Subroutine T_LETTER: not called CC=1 SCAR=6.9
Pod undocumented
78 0 ▶sub T_OTHER { my ($c) = @_; return bless [$c, 12], 'LaTeXML::Core::Token'; }
Subroutine T_OTHER: not called CC=1 SCAR=6.9
Pod undocumented
79 0 ▶sub T_ACTIVE { my ($c) = @_; return bless [$c, 13], 'LaTeXML::Core::Token'; }
Subroutine T_ACTIVE: not called CC=1 SCAR=6.9
Pod undocumented
80 0 ▶sub T_COMMENT { my ($c) = @_; return bless ['%' . ($c || ''), 14], 'LaTeXML::Core::Token'; }
Subroutine T_COMMENT: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$c || ''
l!l
00
MC/DC0%0/1
$c || ''
$c
Truth table0%0/2
A
A= $c
Aresult
11
00
81 0 ▶sub T_CS { my ($c) = @_; return bless [$c, 16], 'LaTeXML::Core::Token'; }
Subroutine T_CS: not called CC=1 SCAR=6.9
Pod undocumented
82 # Illegal: don't use unless you know...
83 0 ▶sub T_MARKER { my ($t) = @_; return bless [$t, 18], 'LaTeXML::Core::Token'; }
Subroutine T_MARKER: not called CC=1 SCAR=6.9
Pod undocumented
84  
85 sub Token {
86 0 ▶ my ($string, $cc) = @_;
Subroutine Token: not called CC=2 SCAR=17.9
Pod documented
87 0 ▶ return bless [$string, (defined $cc ? $cc : CC_OTHER)], 'LaTeXML::Core::Token'; }
Branch: 1 branch
BranchTrueFalseTotal
defined $cc ? : 0 0 0
88  
89 # Explode a string into a list of tokens, all w/catcode OTHER (except space).
90 sub Explode {
91 0 ▶ my ($string) = @_;
Subroutine Explode: not called CC=3 SCAR=24.8
Pod documented
92 return (defined $string
93 0 ▶ ? map { ($_ eq ' ' ? T_SPACE() : T_OTHER($_)) } split('', $string)
Branch: 2 branches
BranchTrueFalseTotal
defined $string ? : 0 0 0
$_ eq ' ' ? : 0 0 0
94 : ()); }
95  
96 # Similar to Explode, but convert letters to catcode LETTER and others to OTHER
97 # Hopefully, this is essentially correct WITHOUT resorting to catcode lookup?
98 sub ExplodeText {
99 0 ▶ my ($string) = @_;
Subroutine ExplodeText: not called CC=4 SCAR=30.0
Pod documented
100 return (defined $string
101 0 ▶ ? map { ($_ eq ' ' ? T_SPACE() : (/[a-zA-Z]/ ? T_LETTER($_) : T_OTHER($_))) }
Branch: 3 branches
BranchTrueFalseTotal
defined $string ? : 0 0 0
$_ eq ' ' ? : 0 0 0
/[a-zA-Z]/ ? : 0 0 0
102 split('', $string)
103 : ()); }
104  
105 29 my $UNTEX_LINELENGTH = 78; # [CONSTANT]
106  
107 sub UnTeX {
108 0 ▶ my ($thing) = @_;
Subroutine UnTeX: not called CC=27 SCAR=66.3
Pod documented
109 0 ▶ return unless defined $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 0 0
110 0 ▶ my @tokens = (ref $thing ? $thing->revert : Explode($thing));
Branch: 1 branch
BranchTrueFalseTotal
ref $thing ? : 0 0 0
111 0 my $string = '';
112 0 my $length = 0;
113 0 my $level = 0;
114 0 my ($prevs, $prevcc) = ('', CC_COMMENT);
115 0 ▶ while (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 0 0 0
116 0 my $token = shift(@tokens);
117 0 my $cc = $token->getCatcode;
118 0 ▶ next if $cc == CC_COMMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $cc == 14 0 0 0
119 0 my $s = $token->getString();
120 0 ▶ if ($cc == CC_LETTER) { # keep "words" together, just for aesthetics
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 11) 0 0 0
121 0 ▶ while (@tokens && ($tokens[0]->getCatcode == CC_LETTER)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens and $tokens[0]->getCatcode == 11) 0 0 0
Condition0%0/3
@tokens and $tokens[0]->getCatcode == 11
!ll&&!rl&&r
000
MC/DC0%0/2
@tokens and $tokens[0]->getCatcode == 11
@tokens $tokens[0]->getCatcode == 11
Truth table0%0/3
A and B
A= @tokensB= $tokens[0]->getCatcode == 11
ABresult
0X0
100
111
122 0 $s .= shift(@tokens)->getString; } }
123 0 my $l = length($s);
124 0 ▶ if ($cc == CC_BEGIN) { $level++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 1) 0 0 0
125 # Seems a reasonable & safe time to line break, for readability, etc.
126 0 ▶ if (($cc == CC_SPACE) && ($s eq "\n")) { # preserve newlines already present
Branch: 3 branches
BranchTrueFalseTotal
if ($cc == 10 and $s eq "\n") { } 0 0 0
elsif ($cc == 11 || $cc == 12 && $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/ and $prevcc == 16 and $prevs =~ /(.)$/ and ($LaTeXML::Core::Token::STATE->lookupCatcode($1) || 14) == 11) { } 0 0 0
elsif ($length > 0 and $length + $l > $UNTEX_LINELENGTH and scalar @tokens > 1) { } 0 0 0
Condition0%0/3
$cc == 10 and $s eq "\n"
!ll&&!rl&&r
000
MC/DC0%0/2
$cc == 10 and $s eq "\n"
$cc == 10 $s eq "\n"
Truth table0%0/3
A and B
A= $cc == 10B= $s eq "\n"
ABresult
0X0
100
111
127 0 ▶ if ($length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 0) 0 0 0
128 0 $string .= $s; $length = 0; } }
129 # If this token is a letter (or otherwise starts with a letter or digit): space or linebreak
130 ▶ elsif ((($cc == CC_LETTER) || (($cc == CC_OTHER) && ($s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/)))
Condition0%0/17
$cc == 11 || $cc == 12 && $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/ and $prevcc == 16 and $prevs =~ /(.)$/ and ($LaTeXML::Core::Token::STATE->lookupCatcode($1) || 14) == 11
!ll&&!rl&&r
000
$cc == 11 || $cc == 12 && $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/ and $prevcc == 16 and $prevs =~ /(.)$/
!ll&&!rl&&r
000
$cc == 11 || $cc == 12 && $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/ and $prevcc == 16
!ll&&!rl&&r
000
$cc == 11 or $cc == 12 and $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/
l!l&&r!l&&!r
000
$cc == 12 and $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/
!ll&&!rl&&r
000
$LaTeXML::Core::Token::STATE->lookupCatcode($1) || 14
l!l
00
MC/DC0%0/6
$cc == 11 || $cc == 12 && $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/ and $prevcc == 16 and $prevs =~ /(.)$/ and ($LaTeXML::Core::Token::STATE->lookupCatcode($1) || 14) == 11
$cc == 11 $cc == 12 $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/ $prevcc == 16 $prevs =~ /(.)$/ $LaTeXML::Core::Token::STATE->lookupCatcode($1)
Truth table0%0/10
A or B and C and D and E and F
A= $cc == 11B= $cc == 12C= $s =~ /^(?:\p{IsAlpha}|\p{IsDigit})/D= $prevcc == 16E= $prevs =~ /(.)$/F= $LaTeXML::Core::Token::STATE->lookupCatcode($1)
ABCDEFresult
00XXXX0
010XXX0
1XX0XX0
0110XX0
1XX10X0
01110X0
1XX1100
0111100
1XX1111
0111111
131 && ($prevcc == CC_CS) && ($prevs =~ /(.)$/)
132 && (($STATE->lookupCatcode($1) || CC_COMMENT) == CC_LETTER)) {
133 # Insert a (virtual) space before a letter if previous token was a CS w/letters
134 # This is required for letters, but just aesthetic for digits (to me?)
135 # Of course, use a newline if we're already at end
136 0 ▶ my $space = (($length > 0) && ($length + $l > $UNTEX_LINELENGTH) ? "\n" : ' ');
Branch: 1 branch
BranchTrueFalseTotal
$length > 0 && $length + $l > $UNTEX_LINELENGTH ? : 0 0 0
Condition0%0/3
$length > 0 and $length + $l > $UNTEX_LINELENGTH
!ll&&!rl&&r
000
MC/DC0%0/2
$length > 0 and $length + $l > $UNTEX_LINELENGTH
$length > 0 $length + $l > $UNTEX_LINELENGTH
Truth table0%0/3
A and B
A= $length > 0B= $length + $l > $UNTEX_LINELENGTH
ABresult
0X0
100
111
137 0 $string .= $space . $s; $length += 1 + $l; }
138 ▶ elsif (($length > 0) && ($length + $l > $UNTEX_LINELENGTH) # linebreak before this token?
Condition0%0/6
$length > 0 and $length + $l > $UNTEX_LINELENGTH and scalar @tokens > 1
!ll&&!rl&&r
000
$length > 0 and $length + $l > $UNTEX_LINELENGTH
!ll&&!rl&&r
000
MC/DC0%0/3
$length > 0 and $length + $l > $UNTEX_LINELENGTH and scalar @tokens > 1
$length > 0 $length + $l > $UNTEX_LINELENGTH scalar @tokens > 1
Truth table0%0/4
A and B and C
A= $length > 0B= $length + $l > $UNTEX_LINELENGTHC= scalar @tokens > 1
ABCresult
0XX0
10X0
1100
1111
139 && (scalar(@tokens) > 1) # and not at end!
140 ) { # Or even within an arg!
141 0 $string .= "%\n" . $s; $length = $l; } # with %, so that it "disappears"
142 else {
143 0 $string .= $s; $length += $l; }
144 0 ▶ if ($cc == CC_END) { $level--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 2) 0 0 0
145 0 $prevs = $s; $prevcc = $cc; }
146 # Patch up nesting for valid TeX !!!
147 0 ▶ if ($level > 0) { $string = $string . ('}' x $level); }
Branch: 2 branches
BranchTrueFalseTotal
if ($level > 0) { } 0 0 0
elsif ($level < 0) { } 0 0 0
148 0 elsif ($level < 0) { $string = ('{' x -$level) . $string; }
149 0 return $string; }
150  
151 #======================================================================
152 # Categories of Category codes.
153 # For Tokens with these catcodes, only the catcode is relevant for comparison.
154 # (if they even make it to a stage where they get compared)
155 29 our @primitive_catcode = ( # [CONSTANT]
156 1, 1, 1, 1,
157 1, 1, 1, 1,
158 1, 0, 1, 0,
159 0, 0, 0, 0,
160 0, 1);
161 29 our @executable_catcode = ( # [CONSTANT]
162 0, 1, 1, 1,
163 1, 0, 0, 1,
164 1, 0, 0, 0,
165 0, 1, 0, 0,
166 1, 0);
167  
168 29 our @standardchar = ( # [CONSTANT]
169 "\\", '{', '}', q{$},
170 q{&}, "\n", q{#}, q{^},
171 q{_}, undef, undef, undef,
172 undef, undef, q{%}, undef);
173  
174 29 our @CC_NAME = #[CONSTANT]
175 qw(Escape Begin End Math
176 Align EOL Parameter Superscript
177 Subscript Ignore Space Letter
178 Other Active Comment Invalid
179 ControlSequence NotExpanded);
180 29 our @PRIMITIVE_NAME = ( # [CONSTANT]
181 'Escape', 'Begin', 'End', 'Math',
182 'Align', 'EOL', 'Parameter', 'Superscript',
183 'Subscript', undef, 'Space', undef,
184 undef, undef, undef, undef,
185 undef, 'NotExpanded');
186 29 our @CC_SHORT_NAME = #[CONSTANT]
187 qw(T_ESCAPE T_BEGIN T_END T_MATH
188 T_ALIGN T_EOL T_PARAM T_SUPER
189 T_SUB T_IGNORE T_SPACE T_LETTER
190 T_OTHER T_ACTIVE T_COMMENT T_INVALID
191 T_CS T_NOTEXPANDED
192 );
193  
194 #======================================================================
195 # Accessors.
196  
197 0 ▶sub isaToken { return 1; }
Subroutine isaToken: not called CC=1 SCAR=6.9
Pod documented
198  
199 # Get the CS Name of the token. This is the name that definitions will be
200 # stored under; It's the same for various `different' BEGIN tokens, eg.
201 sub getCSName {
202 0 ▶ my ($token) = @_;
Subroutine getCSName: not called CC=2 SCAR=17.9
Pod documented
203 0 ▶ return $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
204  
205 # Get the CSName only if the catcode is executable!
206 sub getExecutableName {
207 0 ▶ my ($self) = @_;
Subroutine getExecutableName: not called CC=3 SCAR=24.8
Pod undocumented
208 0 my ($cs, $cc) = @$self;
209 0 ▶ return $executable_catcode[$cc] && ($PRIMITIVE_NAME[$cc] || $cs); }
Condition0%0/6
$LaTeXML::Core::Token::executable_catcode[$cc] && ($LaTeXML::Core::Token::PRIMITIVE_NAME[$cc] || $cs)
!ll&&!rl&&r
000
$LaTeXML::Core::Token::PRIMITIVE_NAME[$cc] or $cs
l!l&&r!l&&!r
000
MC/DC0%0/3
$LaTeXML::Core::Token::executable_catcode[$cc] && ($LaTeXML::Core::Token::PRIMITIVE_NAME[$cc] || $cs)
$LaTeXML::Core::Token::executable_catcode[$cc] $LaTeXML::Core::Token::PRIMITIVE_NAME[$cc] $cs
Truth table0%0/4
A && B or C
A= $LaTeXML::Core::Token::executable_catcode[$cc]B= $LaTeXML::Core::Token::PRIMITIVE_NAME[$cc]C= $cs
ABCresult
0XX0
1000
11X1
1011
210  
211 # Return the string or character part of the token
212 sub getString {
213 0 ▶ my ($self) = @_;
Subroutine getString: not called CC=1 SCAR=6.9
Pod documented
214 0 return $$self[0]; }
215  
216 # Return the character code of character part of the token, or 256 if it is a control sequence
217 sub getCharcode {
218 0 ▶ my ($self) = @_;
Subroutine getCharcode: not called CC=2 SCAR=17.9
Pod documented
219 0 ▶ return ($$self[1] == CC_CS ? 256 : ord($$self[0])); }
Branch: 1 branch
BranchTrueFalseTotal
$self->[1] == 16 ? : 0 0 0
220  
221 # Return the catcode of the token.
222 sub getCatcode {
223 0 ▶ my ($self) = @_;
Subroutine getCatcode: not called CC=1 SCAR=6.9
Pod documented
224 0 return $$self[1]; }
225  
226 sub isExecutable {
227 0 ▶ my ($self) = @_;
Subroutine isExecutable: not called CC=1 SCAR=6.9
Pod undocumented
228 0 return $executable_catcode[$$self[1]]; }
229  
230 # Defined so a Token or Tokens can be used interchangeably.
231 sub unlist {
232 0 ▶ my ($self) = @_;
Subroutine unlist: not called CC=1 SCAR=6.9
Pod documented
233 0 return ($self); }
234  
235 29 my @NEUTRALIZABLE = ( # [CONSTANT]
236 0, 0, 0, 1,
237 1, 0, 1, 1,
238 1, 0, 0, 0,
239 0, 1, 0, 0,
240 0, 0);
241  
242 # neutralize really should only retroactively imitate what Semiverbatim would have done.
243 # So, it needs to neutralize those in SPECIALS
244 # NOTE that although '%' gets it's catcode changed in Semiverbatim,
245 # I'm pretty sure we do NOT want to neutralize comments (turn them into CC_OTHER)
246 # here, since if comments do get into the Tokens, that will introduce weird crap into the stream.
247 sub neutralize {
248 0 ▶ my ($self, @extraspecials) = @_;
Subroutine neutralize: not called CC=3 SCAR=24.8
Pod undocumented
249 0 my ($ch, $cc) = @$self;
250 0 ▶ return ($NEUTRALIZABLE[$cc] && (grep { $ch } @{ $STATE->lookupValue('SPECIALS') }, @extraspecials)
Branch: 1 branch
BranchTrueFalseTotal
$NEUTRALIZABLE[$cc] && grep({$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue('SPECIALS');}, @extraspecials) ? : 0 0 0
Condition0%0/3
$NEUTRALIZABLE[$cc] and grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
!ll&&!rl&&r
000
MC/DC0%0/2
$NEUTRALIZABLE[$cc] and grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
$NEUTRALIZABLE[$cc] grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
Truth table0%0/3
A and B
A= $NEUTRALIZABLE[$cc]B= grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
ABresult
0X0
100
111
251 ? T_OTHER($ch) : $self); }
252  
253 #======================================================================
254 # Note that this converts the string to a more `user readable' form using `standard' chars for catcodes.
255 # We'll need to be careful about using string instead of reverting for internal purposes where the
256 # actual character is needed.
257  
258 # Should revert do something with this???
259 # ($standardchar[$$self[1]] || $$self[0]); }
260  
261 sub revert {
262 0 ▶ my ($self) = @_;
Subroutine revert: not called CC=1 SCAR=6.9
Pod undocumented
263 0 return $self; }
264  
265 sub toString {
266 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=1 SCAR=6.9
Pod documented
267 0 return $$self[0]; }
268  
269 sub beDigested {
270 0 ▶ my ($self, $stomach) = @_;
Subroutine beDigested: not called CC=1 SCAR=6.9
Pod documented
271 0 return $stomach->digest($self); }
272  
273 #======================================================================
274 # Methods for overloaded ops.
275  
276 # Compare two tokens; They are equal if they both have same catcode & string
277 # [We pretend all SPACE's are the same, since we'd like to hide newline's in there!]
278 # NOTE: That another popular equality checks whether the "meaning" (defn) are the same.
279 # That is NOT done here; see Equals(x,y) and XEquals(x,y)
280 sub equals {
281 0 ▶ my ($a, $b) = @_;
Subroutine equals: not called CC=5 SCAR=34.0
Pod documented
282 return
283 0 ▶ (defined $b
Condition0%0/12
defined $b && ref $a eq ref $b && $a->[1] == $b->[1] && ($a->[1] == 10 || $a->[0] eq $b->[0])
!ll&&!rl&&r
000
defined $b and ref $a eq ref $b and $a->[1] == $b->[1]
!ll&&!rl&&r
000
defined $b and ref $a eq ref $b
!ll&&!rl&&r
000
$a->[1] == 10 or $a->[0] eq $b->[0]
l!l&&r!l&&!r
000
MC/DC0%0/5
defined $b && ref $a eq ref $b && $a->[1] == $b->[1] && ($a->[1] == 10 || $a->[0] eq $b->[0])
defined $b ref $a eq ref $b $a->[1] == $b->[1] $a->[1] == 10 $a->[0] eq $b->[0]
Truth table0%0/6
A and B and C && D or E
A= defined $bB= ref $a eq ref $bC= $a->[1] == $b->[1]D= $a->[1] == 10E= $a->[0] eq $b->[0]
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
284 && (ref $a) eq (ref $b))
285 && ($$a[1] == $$b[1])
286 && (($$a[1] == CC_SPACE) || ($$a[0] eq $$b[0])); }
287  
288 29 my @CONTROLNAME = ( #[CONSTANT]
289 qw( NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
290 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US));
291 # Primarily for error reporting.
292 sub stringify {
293 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=3 SCAR=24.8
Pod documented
294 0 my $string = $$self[0];
295 # Make the token's char content more printable, since this is for error messages.
296 0 ▶ if (length($string) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string == 1) 0 0 0
297 0 my $c = ord($string);
298 0 ▶ if ($c < 0x020) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c < 32) 0 0 0
299 0 $string = 'U+' . sprintf("%04x", $c) . '/' . $CONTROLNAME[$c]; } }
300 0 return $CC_SHORT_NAME[$$self[1]] . '[' . $string . ']'; }
301  
302 #======================================================================
303  
304 29 1;
305  
306 __END__
« lib/LaTeXML/Common/Glue.pm ↑ Summary lib/LaTeXML/Util/Pathname.pm »