lib/LaTeXML/Core/Token.pm

filter: Statementstmt 49.4% 123 / 249 Branchbran 0.0% 0 / 74 Conditioncond 0.0% 0 / 79 MC/DCmcdc 0.0% 0 / 38 Subroutinesub 54.4% 37 / 68 Podpod 43.7% 14 / 32 totaltotal 32.2% 174 / 540 CC 65 SCAR 53.9
CC
65
Cov
31%
UnTeX
930.0
equals
42.0
with_dont_expand
30.0
CRAP 219.2
« lib/LaTeXML/Post/LaTeXImages.pm ↑ Summary lib/LaTeXML/Common/Glue.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 32 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 32 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 32 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 32 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 32 ▶use base qw(LaTeXML::Common::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 32 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 32 our @EXPORT = (
27 # Catcode constants
28 qw( CC_ESCAPE CC_BEGIN CC_END CC_MATH
29 CC_ALIGN CC_EOL CC_PARAM CC_SUPER
30 CC_SUB CC_IGNORE CC_SPACE CC_LETTER
31 CC_OTHER CC_ACTIVE CC_COMMENT CC_INVALID
32 CC_CS CC_MARKER CC_ARG CC_SMUGGLE_THE),
33 # Token constructors
34 qw( T_BEGIN T_END T_MATH T_ALIGN T_PARAM T_SUB T_SUPER T_SPACE
35 &T_LETTER &T_OTHER &T_ACTIVE &T_COMMENT &T_CS
36 T_CR &T_MARKER T_ARG T_SMUGGLE_THE
37 &Token),
38 # String exploders
39 qw(&Explode &ExplodeText &UnTeX)
40 );
41  
42 #======================================================================
43 # Constructors.
44  
45 32 ▶use constant CC_ESCAPE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 32 ▶use constant CC_BEGIN => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 32 ▶use constant CC_END => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 32 ▶use constant CC_MATH => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 32 ▶use constant CC_ALIGN => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 32 ▶use constant CC_EOL => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 32 ▶use constant CC_PARAM => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 32 ▶use constant CC_SUPER => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 32 ▶use constant CC_SUB => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 32 ▶use constant CC_IGNORE => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
55 32 ▶use constant CC_SPACE => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 32 ▶use constant CC_LETTER => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
57 32 ▶use constant CC_OTHER => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 32 ▶use constant CC_ACTIVE => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
59 32 ▶use constant CC_COMMENT => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 32 ▶use constant CC_INVALID => 15;
Subroutine BEGIN: called CC=1 SCAR=0.0
61 # Extended Catcodes for expanded output.
62 32 ▶use constant CC_CS => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 32 ▶use constant CC_MARKER => 17; # non TeX extension!
Subroutine BEGIN: called CC=1 SCAR=0.0
64 32 ▶use constant CC_ARG => 18; # "out_param" in B Book
Subroutine BEGIN: called CC=1 SCAR=0.0
65 32 ▶use constant CC_SMUGGLE_THE => 19; # defered expansion once
Subroutine BEGIN: called CC=1 SCAR=0.0
66  
67 # [The documentation for constant is a bit confusing about subs,
68 # but these apparently DO generate constants; you always get the same one]
69 # These are immutable
70 32 ▶use constant T_BEGIN => bless ['{', CC_BEGIN], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
71 32 ▶use constant T_END => bless ['}', CC_END], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
72 32 ▶use constant T_MATH => bless ['$', CC_MATH], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
73 32 ▶use constant T_ALIGN => bless ['&', CC_ALIGN], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
74 32 ▶use constant T_PARAM => bless ['#', CC_PARAM], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
75 32 ▶use constant T_SUPER => bless ['^', CC_SUPER], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
76 32 ▶use constant T_SUB => bless ['_', CC_SUB], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
77 32 ▶use constant T_SPACE => bless [' ', CC_SPACE], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
78 32 ▶use constant T_CR => bless ["\n", CC_SPACE], 'LaTeXML::Core::Token';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 0 ▶sub T_LETTER { my ($c) = @_; return bless [$c, CC_LETTER], 'LaTeXML::Core::Token'; }
Subroutine T_LETTER: not called CC=1 SCAR=6.9
Pod undocumented
80 0 ▶sub T_OTHER { my ($c) = @_; return bless [$c, CC_OTHER], 'LaTeXML::Core::Token'; }
Subroutine T_OTHER: not called CC=1 SCAR=6.9
Pod undocumented
81 0 ▶sub T_ACTIVE { my ($c) = @_; return bless [$c, CC_ACTIVE], 'LaTeXML::Core::Token'; }
Subroutine T_ACTIVE: not called CC=1 SCAR=6.9
Pod undocumented
82 0 ▶sub T_COMMENT { my ($c) = @_; return bless ['%' . ($c || ''), CC_COMMENT], '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
83 30 ▶sub T_CS { my ($c) = @_; return bless [$c, CC_CS], 'LaTeXML::Core::Token'; }
Subroutine T_CS: called CC=1 SCAR=0.0
Pod undocumented
84 # Illegal: don't use unless you know...
85 0 ▶sub T_MARKER { my ($t) = @_; return bless [$t, CC_MARKER], 'LaTeXML::Core::Token'; }
Subroutine T_MARKER: not called CC=1 SCAR=6.9
Pod undocumented
86  
87 sub T_ARG {
88 0 ▶ my ($v) = @_;
Subroutine T_ARG: not called CC=4 SCAR=30.0
Pod undocumented
89 0 my $int = $v;
90 # get the integer value from the token
91 0 ▶ if (ref $v eq 'LaTeXML::Core::Token') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq "LaTeXML::Core::Token") 0 0 0
92 0 my $v_str = $$v[0];
93 0 $int = int($$v[0]);
94 0 ▶ if ($int < 1 || $int > 9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int < 1 or $int > 9) 0 0 0
Condition0%0/3
$int < 1 or $int > 9
l!l&&r!l&&!r
000
MC/DC0%0/2
$int < 1 or $int > 9
$int < 1 $int > 9
Truth table0%0/3
A or B
A= $int < 1B= $int > 9
ABresult
1X1
011
000
95 0 Fatal('malformed', 'T_ARG', 'value should be #1-#9', "Illegal: " . $v->stringify); } }
96 0 return bless ["$int", CC_ARG], 'LaTeXML::Core::Token'; }
97  
98 # This hides tokens coming from \the (-like) primitives from expansion; CC_CS,CC_ACTIVE, but also CC_PARAM and CC_ARG
99 32 our @CATCODE_CAN_SMUGGLE_THE = (
100 0, 0, 0, 0,
101 0, 0, 1, 0,
102 0, 0, 0, 0,
103 0, 1, 0, 0,
104 1, 0, 1, 0);
105  
106 sub T_SMUGGLE_THE {
107 0 ▶ my ($t) = @_;
Subroutine T_SMUGGLE_THE: not called CC=3 SCAR=24.8
Pod undocumented
108 0 my $cc = $$t[1];
109 0 ▶ if ($cc == CC_SMUGGLE_THE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 19) 0 0 0
110 # LaTeXML Bug, we haven't correctly emulated scan_toks! Offending token was:
111 0 Fatal('unexpected', 'CC_SMUGGLE_THE', 'We are masking a \the-produced token twice, this must Never happen.', "Illegal: " . $t->stringify); }
112 0 ▶ return ($CATCODE_CAN_SMUGGLE_THE[$cc] ? bless ["SMUGGLE_THE", CC_SMUGGLE_THE, $t], 'LaTeXML::Core::Token' : $t); }
Branch: 1 branch
BranchTrueFalseTotal
$LaTeXML::Core::Token::CATCODE_CAN_SMUGGLE_THE[$cc] ? : 0 0 0
113  
114 sub Token {
115 0 ▶ my ($string, $cc) = @_;
Subroutine Token: not called CC=2 SCAR=17.9
Pod documented
116 0 ▶ return bless [$string, (defined $cc ? $cc : CC_OTHER)], 'LaTeXML::Core::Token'; }
Branch: 1 branch
BranchTrueFalseTotal
defined $cc ? : 0 0 0
117  
118 # Explode a string into a list of tokens, all w/catcode OTHER (except space).
119 sub Explode {
120 0 ▶ my ($string) = @_;
Subroutine Explode: not called CC=3 SCAR=24.8
Pod documented
121 return (defined $string
122 0 ▶ ? map { ($_ eq ' ' ? T_SPACE() : T_OTHER($_)) } split('', $string)
Branch: 2 branches
BranchTrueFalseTotal
defined $string ? : 0 0 0
$_ eq ' ' ? : 0 0 0
123 : ()); }
124  
125 # Similar to Explode, but convert letters to catcode LETTER and others to OTHER
126 # Hopefully, this is essentially correct WITHOUT resorting to catcode lookup?
127 sub ExplodeText {
128 0 ▶ my ($string) = @_;
Subroutine ExplodeText: not called CC=4 SCAR=30.0
Pod documented
129 return (defined $string
130 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
131 split('', $string)
132 : ()); }
133  
134 32 my $UNTEX_LINELENGTH = 78; # [CONSTANT]
135  
136 sub UnTeX {
137 0 ▶ my ($thing, $suppress_linebreak) = @_;
Subroutine UnTeX: not called CC=30 SCAR=68.4
Pod documented
138 0 ▶ return unless defined $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $thing 0 0 0
139 my @tokens = ref $thing ?
140 0 ▶ map { ref $_ eq 'LaTeXML::Core::Tokens' ? $_->unlist : $_ } $thing->revert :
Branch: 2 branches
BranchTrueFalseTotal
ref $thing ? : 0 0 0
ref $_ eq 'LaTeXML::Core::Tokens' ? : 0 0 0
141 Explode($thing);
142 0 my $string = '';
143 0 my $length = 0;
144 0 my $level = 0;
145 0 my ($prevs, $prevcc) = ('', CC_COMMENT);
146  
147 0 ▶ while (@tokens) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 0 0 0
148 0 my $token = shift(@tokens);
149 0 my $cc = $token->getCatcode;
150 0 ▶ next if $cc == CC_COMMENT;
Branch: 1 branch
BranchTrueFalseTotal
if $cc == 14 0 0 0
151 0 my $s = $token->toString();
152 0 ▶ if ($cc == CC_LETTER) { # keep "words" together, just for aesthetics
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 11) 0 0 0
153 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
154 0 $s .= shift(@tokens)->toString; } }
155 0 my $l = length($s);
156 0 ▶ if ($cc == CC_BEGIN) { $level++; }
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 1) 0 0 0
157 # Seems a reasonable & safe time to line break, for readability, etc.
158 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 (not $suppress_linebreak and $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
159 0 ▶ if ($length > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 0) 0 0 0
160 0 $string .= $s; $length = 0; } }
161 # If this token is a letter (or otherwise starts with a letter or digit): space or linebreak
162 ▶ 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
163 && ($prevcc == CC_CS) && ($prevs =~ /(.)$/)
164 && (($STATE->lookupCatcode($1) || CC_COMMENT) == CC_LETTER)) {
165 # Insert a (virtual) space before a letter if previous token was a CS w/letters
166 # This is required for letters, but just aesthetic for digits (to me?)
167 # Of course, use a newline if we're already at end
168 0 ▶ my $space = (!$suppress_linebreak && ($length > 0) && ($length + $l > $UNTEX_LINELENGTH) ? "\n" : ' ');
Branch: 1 branch
BranchTrueFalseTotal
!$suppress_linebreak && $length > 0 && $length + $l > $UNTEX_LINELENGTH ? : 0 0 0
Condition0%0/6
not $suppress_linebreak and $length > 0 and $length + $l > $UNTEX_LINELENGTH
!ll&&!rl&&r
000
not $suppress_linebreak and $length > 0
!ll&&!rl&&r
000
MC/DC0%0/3
not $suppress_linebreak and $length > 0 and $length + $l > $UNTEX_LINELENGTH
not $suppress_linebreak $length > 0 $length + $l > $UNTEX_LINELENGTH
Truth table0%0/4
not(A) and B and C
A= not $suppress_linebreakB= $length > 0C= $length + $l > $UNTEX_LINELENGTH
ABCresult
0XX0
10X0
1100
1111
169 0 $string .= $space . $s; $length += 1 + $l; }
170 ▶ elsif (!$suppress_linebreak && ($length > 0) && ($length + $l > $UNTEX_LINELENGTH) # linebreak before this token?
Condition0%0/9
not $suppress_linebreak and $length > 0 and $length + $l > $UNTEX_LINELENGTH and scalar @tokens > 1
!ll&&!rl&&r
000
not $suppress_linebreak and $length > 0 and $length + $l > $UNTEX_LINELENGTH
!ll&&!rl&&r
000
not $suppress_linebreak and $length > 0
!ll&&!rl&&r
000
MC/DC0%0/4
not $suppress_linebreak and $length > 0 and $length + $l > $UNTEX_LINELENGTH and scalar @tokens > 1
not $suppress_linebreak $length > 0 $length + $l > $UNTEX_LINELENGTH scalar @tokens > 1
Truth table0%0/5
not(A) and B and C and D
A= not $suppress_linebreakB= $length > 0C= $length + $l > $UNTEX_LINELENGTHD= scalar @tokens > 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
171 && (scalar(@tokens) > 1) # and not at end!
172 ) { # Or even within an arg!
173 0 $string .= "%\n" . $s; $length = $l; } # with %, so that it "disappears"
174 else {
175 0 $string .= $s; $length += $l; }
176 0 ▶ if ($cc == CC_END) { $level--; }
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 2) 0 0 0
177 0 $prevs = $s; $prevcc = $cc; }
178 # Patch up nesting for valid TeX !!!
179 0 ▶ if ($level > 0) { $string = $string . ('}' x $level); }
Branch: 2 branches
BranchTrueFalseTotal
if ($level > 0) { } 0 0 0
elsif ($level < 0) { } 0 0 0
180 0 elsif ($level < 0) { $string = ('{' x -$level) . $string; }
181 0 return $string; }
182  
183 #======================================================================
184 # Categories of Category codes.
185 # For Tokens with these catcodes, only the catcode is relevant for comparison.
186 # (if they even make it to a stage where they get compared)
187 32 our @CATCODE_PRIMITIVE = ( # [CONSTANT]
188 1, 1, 1, 1,
189 1, 1, 1, 1,
190 1, 0, 1, 0,
191 0, 0, 0, 0,
192 0, 0, 0, 0);
193 32 our @CATCODE_EXECUTABLE = ( # [CONSTANT]
194 0, 1, 1, 1,
195 1, 0, 0, 1,
196 1, 0, 0, 0,
197 0, 1, 0, 0,
198 1, 0, 0, 0);
199  
200 32 our @CATCODE_STANDARDCHAR = ( # [CONSTANT]
201 "\\", '{', '}', q{$},
202 q{&}, "\n", q{#}, q{^},
203 q{_}, undef, undef, undef,
204 undef, undef, q{%}, undef,
205 undef, undef, undef, undef);
206  
207 32 our @CATCODE_NAME = #[CONSTANT]
208 qw(Escape Begin End Math
209 Align EOL Parameter Superscript
210 Subscript Ignore Space Letter
211 Other Active Comment Invalid
212 ControlSequence Marker Arg NoExpand1);
213 32 our @CATCODE_PRIMITIVE_NAME = ( # [CONSTANT]
214 'Escape', 'Begin', 'End', 'Math',
215 'Align', 'EOL', 'Parameter', 'Superscript',
216 'Subscript', undef, 'Space', undef,
217 undef, undef, undef, undef,
218 undef, undef, undef, undef);
219 32 our @CATCODE_SHORT_NAME = #[CONSTANT]
220 qw(T_ESCAPE T_BEGIN T_END T_MATH
221 T_ALIGN T_EOL T_PARAM T_SUPER
222 T_SUB T_IGNORE T_SPACE T_LETTER
223 T_OTHER T_ACTIVE T_COMMENT T_INVALID
224 T_CS T_MARKER T_ARG T_SMUGGLE_THE
225 );
226  
227 32 our $SMUGGLE_THE_COMMANDS = {
228 '\the' => 1,
229 '\showthe' => 1,
230 '\unexpanded' => 1,
231 '\detokenize' => 1
232 };
233  
234 #======================================================================
235 # Accessors.
236  
237 0 ▶sub isaToken { return 1; }
Subroutine isaToken: not called CC=1 SCAR=6.9
Pod documented
238  
239 # Get the CS Name of the token. This is the name that definitions will be
240 # stored under; It's the same for various `different' BEGIN tokens, eg.
241 sub getCSName {
242 0 ▶ my ($token) = @_;
Subroutine getCSName: not called CC=2 SCAR=17.9
Pod documented
243 0 ▶ return $CATCODE_PRIMITIVE_NAME[$$token[1]] || $$token[0]; }
Condition0%0/3
$LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$token->[1]] || $token->[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$token->[1]] || $token->[0]
$LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$token->[1]] $token->[0]
Truth table0%0/3
A || B
A= $LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$token->[1]]B= $token->[0]
ABresult
1X1
011
000
244  
245 # Get the CSName only if the catcode is executable!
246 sub getExecutableName {
247 0 ▶ my ($self) = @_;
Subroutine getExecutableName: not called CC=3 SCAR=24.8
Pod undocumented
248 0 my ($cs, $cc) = @$self;
249 0 ▶ return $CATCODE_EXECUTABLE[$cc] && ($CATCODE_PRIMITIVE_NAME[$cc] || $cs); }
Condition0%0/6
$LaTeXML::Core::Token::CATCODE_EXECUTABLE[$cc] && ($LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$cc] || $cs)
!ll&&!rl&&r
000
$LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$cc] or $cs
l!l&&r!l&&!r
000
MC/DC0%0/3
$LaTeXML::Core::Token::CATCODE_EXECUTABLE[$cc] && ($LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$cc] || $cs)
$LaTeXML::Core::Token::CATCODE_EXECUTABLE[$cc] $LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$cc] $cs
Truth table0%0/4
A && B or C
A= $LaTeXML::Core::Token::CATCODE_EXECUTABLE[$cc]B= $LaTeXML::Core::Token::CATCODE_PRIMITIVE_NAME[$cc]C= $cs
ABCresult
0XX0
1000
11X1
1011
250  
251 # Return the string or character part of the token
252 sub getString {
253 0 ▶ my ($self) = @_;
Subroutine getString: not called CC=1 SCAR=6.9
Pod documented
254 0 return $$self[0]; }
255  
256 # Return the character code of character part of the token, or 256 if it is a control sequence
257 sub getCharcode {
258 0 ▶ my ($self) = @_;
Subroutine getCharcode: not called CC=2 SCAR=17.9
Pod documented
259 0 ▶ return ($$self[1] == CC_CS ? 256 : ord($$self[0])); }
Branch: 1 branch
BranchTrueFalseTotal
$self->[1] == 16 ? : 0 0 0
260  
261 # Return the catcode of the token.
262 sub getCatcode {
263 0 ▶ my ($self) = @_;
Subroutine getCatcode: not called CC=1 SCAR=6.9
Pod documented
264 0 return $$self[1]; }
265  
266 sub isExecutable {
267 0 ▶ my ($self) = @_;
Subroutine isExecutable: not called CC=1 SCAR=6.9
Pod undocumented
268 0 return $CATCODE_EXECUTABLE[$$self[1]]; }
269  
270 # Defined so a Token or Tokens can be used interchangeably.
271 sub unlist {
272 0 ▶ my ($self) = @_;
Subroutine unlist: not called CC=1 SCAR=6.9
Pod documented
273 0 return ($self); }
274  
275 sub stripBraces {
276 0 ▶ my ($self) = @_;
Subroutine stripBraces: not called CC=1 SCAR=6.9
Pod undocumented
277 0 return ($self); }
278  
279 32 our @CATCODE_NEUTRALIZABLE = ( # [CONSTANT]
280 0, 0, 0, 1,
281 1, 0, 1, 1,
282 1, 0, 0, 0,
283 0, 1, 0, 0,
284 0, 0, 0, 0);
285  
286 # neutralize really should only retroactively imitate what Semiverbatim would have done.
287 # So, it needs to neutralize those in SPECIALS
288 # NOTE that although '%' gets it's catcode changed in Semiverbatim,
289 # I'm pretty sure we do NOT want to neutralize comments (turn them into CC_OTHER)
290 # here, since if comments do get into the Tokens, that will introduce weird crap into the stream.
291 sub neutralize {
292 0 ▶ my ($self, @extraspecials) = @_;
Subroutine neutralize: not called CC=3 SCAR=24.8
Pod undocumented
293 0 my ($ch, $cc) = @$self;
294 0 ▶ if ($CATCODE_NEUTRALIZABLE[$cc] && (grep { $ch } @{ $STATE->lookupValue('SPECIALS') }, @extraspecials)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LaTeXML::Core::Token::CATCODE_NEUTRALIZABLE[$cc] and grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue('SPECIALS');}, @extraspecials) { } 0 0 0
Condition0%0/3
$LaTeXML::Core::Token::CATCODE_NEUTRALIZABLE[$cc] and grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
!ll&&!rl&&r
000
MC/DC0%0/2
$LaTeXML::Core::Token::CATCODE_NEUTRALIZABLE[$cc] and grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
$LaTeXML::Core::Token::CATCODE_NEUTRALIZABLE[$cc] grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
Truth table0%0/3
A and B
A= $LaTeXML::Core::Token::CATCODE_NEUTRALIZABLE[$cc]B= grep {$ch;} @{$LaTeXML::Core::Token::STATE->lookupValue("SPECIALS");}, @extraspecials
ABresult
0X0
100
111
295 0 return T_OTHER($ch); }
296 else {
297 0 return $self; } }
298  
299 sub substituteParameters {
300 0 ▶ my ($self, @args) = @_;
Subroutine substituteParameters: not called CC=2 SCAR=17.9
Pod undocumented
301 0 ▶ if ($$self[1] == CC_ARG) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1] == 18) { } 0 0 0
302 0 return $args[ord($$self[0]) - ord("0") - 1]; }
303 else {
304 0 return $self; } }
305  
306 0 ▶sub packParameters { return $_[0]; }
Subroutine packParameters: not called CC=1 SCAR=6.9
Pod undocumented
307  
308 # Mark a token as not to be expanded (\noexpand) by hiding itself as the 3rd element of a new token.
309 # Wonder if this should only have effect on expandable tokens?
310 sub with_dont_expand {
311 0 ▶ my ($self) = @_;
Subroutine with_dont_expand: not called CC=5 SCAR=34.0
Pod undocumented
312 0 my $cc = $$self[1];
313 0 ▶ if ($cc == CC_SMUGGLE_THE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cc == 19) 0 0 0
314 # LaTeXML Bug, we haven't correctly emulated scan_toks! Offending token was:
315 0 Fatal('unexpected', 'CC_SMUGGLE_THE', 'We are marking as \noexpand a masked \the-produced token, this must Never happen.', "Illegal: " . $self->stringify); }
316 0 ▶ return ((($cc == CC_CS) || ($cc == CC_ACTIVE)) && $STATE->isDontExpandable($self))
Branch: 1 branch
BranchTrueFalseTotal
($cc == 16 || $cc == 13) && $LaTeXML::Core::Token::STATE->isDontExpandable($self) ? : 0 0 0
Condition0%0/6
$cc == 16 || $cc == 13 and $LaTeXML::Core::Token::STATE->isDontExpandable($self)
!ll&&!rl&&r
000
$cc == 16 or $cc == 13
l!l&&r!l&&!r
000
MC/DC0%0/3
$cc == 16 || $cc == 13 and $LaTeXML::Core::Token::STATE->isDontExpandable($self)
$cc == 16 $cc == 13 $LaTeXML::Core::Token::STATE->isDontExpandable($self)
Truth table0%0/5
A or B and C
A= $cc == 16B= $cc == 13C= $LaTeXML::Core::Token::STATE->isDontExpandable($self)
ABCresult
00X0
1X00
0100
1X11
0111
317 ? bless ['\relax', CC_CS, $self], 'LaTeXML::Core::Token'
318 : $self; }
319  
320 # Return the original token of a not-expanded token,
321 # or undef if it isn't marked as such.
322 sub get_dont_expand {
323 0 ▶ my ($self) = @_;
Subroutine get_dont_expand: not called CC=1 SCAR=6.9
Pod undocumented
324 0 return $$self[2]; }
325  
326 sub without_dont_expand {
327 0 ▶ my ($self) = @_;
Subroutine without_dont_expand: not called CC=3 SCAR=24.8
Pod undocumented
328 # Remove dont_expand flag, remove SMUGGLE_THE wrapper
329 0 my $inner = $$self[2];
330 0 ▶ return $inner ? ($$inner[2] || $inner) : $self; }
Branch: 1 branch
BranchTrueFalseTotal
$inner ? : 0 0 0
Condition0%0/3
$inner->[2] or $inner
l!l&&r!l&&!r
000
MC/DC0%0/2
$inner->[2] or $inner
$inner->[2] $inner
Truth table0%0/3
A or B
A= $inner->[2]B= $inner
ABresult
1X1
011
000
331  
332 #======================================================================
333 # Note that this converts the string to a more `user readable' form using `standard' chars for catcodes.
334 # We'll need to be careful about using string instead of reverting for internal purposes where the
335 # actual character is needed.
336  
337 # Should revert do something with this???
338 # ($CATCODE_STANDARDCHAR[$$self[1]] || $$self[0]); }
339  
340 sub revert {
341 0 ▶ my ($self) = @_;
Subroutine revert: not called CC=1 SCAR=6.9
Pod undocumented
342 0 return $self; }
343  
344 sub toString {
345 0 ▶ my ($self) = @_;
Subroutine toString: not called CC=2 SCAR=17.9
Pod documented
346 0 ▶ return $$self[1] == CC_ARG ? ("#" . $$self[0]) : $$self[0]; }
Branch: 1 branch
BranchTrueFalseTotal
$self->[1] == 18 ? : 0 0 0
347  
348 sub beDigested {
349 0 ▶ my ($self, $stomach) = @_;
Subroutine beDigested: not called CC=1 SCAR=6.9
Pod documented
350 0 return $stomach->digest($self); }
351  
352 #======================================================================
353 # Methods for overloaded ops.
354  
355 # Compare two tokens; They are equal if they both have same catcode & string
356 # [We pretend all SPACE's are the same, since we'd like to hide newline's in there!]
357 # NOTE: That another popular equality checks whether the "meaning" (defn) are the same.
358 # That is NOT done here; see Equals(x,y) and XEquals(x,y)
359 sub equals {
360 0 ▶ my ($a, $b) = @_;
Subroutine equals: not called CC=6 SCAR=37.4
Pod documented
361 return
362 0 ▶ (defined $b
Condition0%0/15
defined $b && ref $a eq ref $b && $a->[1] == $b->[1] && ($a->[1] == 10 || $a->[0] eq $b->[0]) && (!$a->[2]) == !$b->[2]
!ll&&!rl&&r
000
defined $b and ref $a eq ref $b and $a->[1] == $b->[1] and $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/6
defined $b && ref $a eq ref $b && $a->[1] == $b->[1] && ($a->[1] == 10 || $a->[0] eq $b->[0]) && (!$a->[2]) == !$b->[2]
defined $b ref $a eq ref $b $a->[1] == $b->[1] $a->[1] == 10 $a->[0] eq $b->[0] (!$a->[2]) == !$b->[2]
Truth table0%0/8
A and B and C and D or E && not(F)
A= defined $bB= ref $a eq ref $bC= $a->[1] == $b->[1]D= $a->[1] == 10E= $a->[0] eq $b->[0]F= (!$a->[2]) == !$b->[2]
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
11100X0
1111X00
1110100
1111X11
1110111
363 && (ref $a) eq (ref $b))
364 && ($$a[1] == $$b[1])
365 && (($$a[1] == CC_SPACE) || ($$a[0] eq $$b[0]))
366 && ((!$$a[2]) == (!$$b[2])) # must have same dont-expand-edness
367 ; }
368  
369 32 my @CONTROLNAME = ( #[CONSTANT]
370 qw( NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
371 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US));
372 # Primarily for error reporting.
373 sub stringify {
374 0 ▶ my ($self) = @_;
Subroutine stringify: not called CC=5 SCAR=34.0
Pod documented
375 0 ▶ if ($$self[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[2]) 0 0 0
376 0 ▶ return $$self[2]->stringify() . ($$self[1] == CC_SMUGGLE_THE ? " (defer expand once)" : " (dont expand)"); }
Branch: 1 branch
BranchTrueFalseTotal
$self->[1] == 19 ? : 0 0 0
377 0 my $string = $self->toString;
378 # Make the token's char content more printable, since this is for error messages.
379 0 ▶ if (length($string) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $string == 1) 0 0 0
380 0 my $c = ord($string);
381 0 ▶ if ($c < 0x020) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c < 32) 0 0 0
382 0 $string = 'U+' . sprintf("%04x", $c) . '/' . $CONTROLNAME[$c]; } }
383 0 return $CATCODE_SHORT_NAME[$$self[1]] . '[' . $string . ']'; }
384  
385 #======================================================================
386  
387 32 1;
388  
389 __END__
« lib/LaTeXML/Post/LaTeXImages.pm ↑ Summary lib/LaTeXML/Common/Glue.pm »