lib/LaTeXML/Core/Token.pm

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