| 1 | # /=====================================================================\ # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # | LaTeXML::Core::Mouth | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | Analog of TeX's Mouth: Tokenizes strings & files | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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::Mouth; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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::Locator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use LaTeXML::Common::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use LaTeXML::Core::Token; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use LaTeXML::Core::Tokens; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use LaTeXML::Util::Pathname; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use Encode qw(decode); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | use base qw(LaTeXML::Common::Object); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Factory method; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # Create an appropriate Mouth | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # options are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # quiet, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # atletter, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | sub create { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my ($class, $source, %options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($options{content}) { # we've cached the content of this source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my ($dir, $name, $ext) = pathname_split($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $options{source} = $source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $options{shortsource} = "$name.$ext"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | return $class->new($options{content}, %options); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | elsif ($source =~ s/^literal://) { # we've supplied literal data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $options{source} = ''; # the source does not have a corresponding file name | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return $class->new($source, %options); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | elsif (!defined $source) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return $class->new('', %options); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $type = pathname_protocol($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $newclass = "LaTeXML::Core::Mouth::$type"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (!$newclass->can('new')) { # not already defined somewhere? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | require "LaTeXML/Core/Mouth/$type.pm"; } # Load it! | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return $newclass->new($source, %options); } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my ($class, $string, %options) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $string = q{} unless defined $string; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | #$options{source} = "Anonymous String" unless defined $options{source}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | #$options{shortsource} = "String" unless defined $options{shortsource}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | my $self = bless { source => $options{source}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | shortsource => $options{shortsource}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | fordefinitions => ($options{fordefinitions} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | notes => ($options{notes} ? 1 : 0), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $self->openString($string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $self->initialize; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $self; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | sub openString { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
openString: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # if (0){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if (utf8::is_utf8($string)) { } # If already utf7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | elsif (my $encoding = $STATE->lookupValue('PERL_INPUT_ENCODING')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | # Note that if chars in the input cannot be decoded, they are replaced by \x{FFFD} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # I _think_ that for TeX's behaviour we actually should turn such un-decodeable chars in to space(?). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $string = decode($encoding, $string, Encode::FB_DEFAULT); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if ($string =~ s/\x{FFFD}/ /g) { # Just remove the replacement chars, and warn (or Info?) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | Info('misdefined', $encoding, $self, "input isn't valid under encoding $encoding"); } } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $$self{string} = $string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $$self{buffer} = [(defined $string ? splitLines($string) : ())]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub initialize { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $$self{lineno} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $$self{colno} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $$self{chars} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $$self{nchars} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ($$self{notes}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | my $source = defined($$self{source}) ? ($$self{source} || 'Literal String') : 'Anonymous String'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$self->{"source"} or "Literal String"
MC/DC0%0/1
$self->{"source"} or "Literal String"
$self->{"source"}
Truth table0%0/2
A
A= $self->{"source"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $$self{note_message} = "Processing " . ($$self{fordefinitions} ? "definitions" : "content") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | . " " . $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | NoteBegin($$self{note_message}); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($$self{fordefinitions}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $$self{saved_at_cc} = $STATE->lookupCatcode('@'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $$self{SAVED_INCLUDE_COMMENTS} = $STATE->lookupValue('INCLUDE_COMMENTS'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $STATE->assignCatcode('@' => CC_LETTER); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $STATE->assignValue(INCLUDE_COMMENTS => 0); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | sub finish { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
finish: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $$self{buffer} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $$self{lineno} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $$self{colno} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $$self{chars} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $$self{nchars} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($$self{fordefinitions}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $STATE->assignCatcode('@' => $$self{saved_at_cc}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $STATE->assignValue(INCLUDE_COMMENTS => $$self{SAVED_INCLUDE_COMMENTS}); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($$self{notes}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | NoteEnd($$self{note_message}); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # This is (hopefully) a platform independent way of splitting a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # into "lines" ending with CRLF, CR or LF (DOS, Mac or Unix). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # Note that TeX considers newlines to be \r, ie CR, ie ^^M | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | sub splitLines { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | my ($string) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
splitLines: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $string =~ s/(?:\015\012|\015|\012)/\r/sg; # Normalize remaining | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return split("\r", $string); } # And split. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # This is (hopefully) a correct way to split a line into "chars", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | # or what is probably more desired is "Grapheme clusters" (even "extended") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # These are unicode characters that include any following combining chars, accents & such. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | # I am thinking that when we deal with unicode this may be the most correct way? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # If it's not the way XeTeX does it, perhaps, it must be that ALL combining chars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # have to be converted to the proper accent control sequences! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | sub splitChars { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my ($line) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
splitChars: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return [$line =~ m/\X/g]; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | sub getNextLine { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getNextLine: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | return unless scalar(@{ $$self{buffer} }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $line = shift(@{ $$self{buffer} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | return (scalar(@{ $$self{buffer} }) ? $line . "\r" : $line); } # No CR on last line! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | sub hasMoreInput { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hasMoreInput: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return ($$self{colno} < $$self{nchars}) || scalar(@{ $$self{buffer} }); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'colno'} < $self->{'nchars'} || scalar @{$self->{'buffer'};}
MC/DC0%0/1
$self->{'colno'} < $self->{'nchars'} || scalar @{$self->{'buffer'};}
$self->{'colno'} < $self->{'nchars'}
Truth table0%0/2
A
A= $self->{'colno'} < $self->{'nchars'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # Get the next character & it's catcode from the input, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # handling TeX's "^^" encoding. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Note that this is the only place where catcode lookup is done, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # and that it is somewhat `inlined'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub getNextChar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getNextChar: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ($$self{colno} < $$self{nchars}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $ch = $$self{chars}[$$self{colno}++]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $cc = $$STATE{catcode}{$ch}[0] // CC_OTHER; # $STATE->lookupCatcode($ch); OPEN CODED! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$LaTeXML::Core::Mouth::STATE->{"catcode"}{$ch}[0] // 12
MC/DC0%0/1
$LaTeXML::Core::Mouth::STATE->{"catcode"}{$ch}[0] // 12
$LaTeXML::Core::Mouth::STATE->{"catcode"}{$ch}[0]
Truth table0%0/2
A
A= $LaTeXML::Core::Mouth::STATE->{"catcode"}{$ch}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if (($cc == CC_SUPER) # Possible convert ^^x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$cc == 7 and $self->{"colno"} + 1 < $self->{"nchars"} and $ch eq $self->{"chars"}[$self->{"colno"}]
$cc == 7 and $self->{"colno"} + 1 < $self->{"nchars"}
MC/DC0%0/3
$cc == 7 and $self->{"colno"} + 1 < $self->{"nchars"} and $ch eq $self->{"chars"}[$self->{"colno"}]
$cc == 7
$self->{"colno"} + 1 < $self->{"nchars"}
$ch eq $self->{"chars"}[$self->{"colno"}]
Truth table0%0/4
A and B and C
A= $cc == 7B= $self->{"colno"} + 1 < $self->{"nchars"}C= $ch eq $self->{"chars"}[$self->{"colno"}]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | && ($$self{colno} + 1 < $$self{nchars}) && ($ch eq $$self{chars}[$$self{colno}])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my ($c1, $c2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | if (($$self{colno} + 2 < $$self{nchars}) # ^^ followed by TWO LOWERCASE Hex digits??? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$self->{"colno"} + 2 < $self->{"nchars"} and ($c1 = $self->{"chars"}[$self->{"colno"} + 1]) =~ /^[0-9a-f]$/ and ($c2 = $self->{"chars"}[$self->{"colno"} + 2]) =~ /^[0-9a-f]$/
$self->{"colno"} + 2 < $self->{"nchars"} and ($c1 = $self->{"chars"}[$self->{"colno"} + 1]) =~ /^[0-9a-f]$/
MC/DC0%0/3
$self->{"colno"} + 2 < $self->{"nchars"} and ($c1 = $self->{"chars"}[$self->{"colno"} + 1]) =~ /^[0-9a-f]$/ and ($c2 = $self->{"chars"}[$self->{"colno"} + 2]) =~ /^[0-9a-f]$/
$self->{"colno"} + 2 < $self->{"nchars"}
($c1 = $self->{"chars"}[$self->{"colno"} + 1]) =~ /^[0-9a-f]$/
($c2 = $self->{"chars"}[$self->{"colno"} + 2]) =~ /^[0-9a-f]$/
Truth table0%0/4
A and B and C
A= $self->{"colno"} + 2 < $self->{"nchars"}B= ($c1 = $self->{"chars"}[$self->{"colno"} + 1]) =~ /^[0-9a-f]$/C= ($c2 = $self->{"chars"}[$self->{"colno"} + 2]) =~ /^[0-9a-f]$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | && (($c1 = $$self{chars}[$$self{colno} + 1]) =~ /^[0-9a-f]$/) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | && (($c2 = $$self{chars}[$$self{colno} + 2]) =~ /^[0-9a-f]$/)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $ch = chr(hex($c1 . $c2)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | splice(@{ $$self{chars} }, $$self{colno} - 1, 4, $ch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $$self{nchars} -= 3; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | else { # OR ^^ followed by a SINGLE Control char type code??? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my $c = $$self{chars}[$$self{colno} + 1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $cn = ord($c); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $ch = chr($cn + ($cn > 64 ? -64 : 64)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | splice(@{ $$self{chars} }, $$self{colno} - 1, 3, $ch); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $$self{nchars} -= 2; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $cc = $STATE->lookupCatcode($ch) // CC_OTHER; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$LaTeXML::Core::Mouth::STATE->lookupCatcode($ch) // 12
MC/DC0%0/1
$LaTeXML::Core::Mouth::STATE->lookupCatcode($ch) // 12
$LaTeXML::Core::Mouth::STATE->lookupCatcode($ch)
Truth table0%0/2
A
A= $LaTeXML::Core::Mouth::STATE->lookupCatcode($ch)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | return ($ch, $cc); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | return (undef, undef); } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | sub stringify { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringify: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return "Mouth[<string>\@$$self{lineno}x$$self{colno}]"; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | sub getLocator { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getLocator: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my ($toLine, $toCol, $fromLine, $fromCol) = ($$self{lineno}, $$self{colno}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | my $maxCol = ($$self{nchars} ? $$self{nchars} - 1 : 0); #There is always a trailing EOL char | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ((defined $toCol) && ($toCol >= $maxCol)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $toCol and $toCol >= $maxCol
MC/DC0%0/2
defined $toCol and $toCol >= $maxCol
defined $toCol
$toCol >= $maxCol
Truth table0%0/3
A and B
A= defined $toColB= $toCol >= $maxCol
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $fromLine = $toLine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $fromCol = 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $fromLine = $toLine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $fromCol = $toCol; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | return LaTeXML::Common::Locator->new($$self{source}, $fromLine, $fromCol, $toLine, $toCol); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | sub getSource { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getSource: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | return $$self{source}; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # See The TeXBook, Chapter 8, The Characters You Type, pp.46--47. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | sub handle_escape { # Read control sequence | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_escape: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # NOTE: We're using control sequences WITH the \ prepended!!! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my ($ch, $cc) = getNextChar($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Knuth, p.46 says that Newlines are converted to spaces, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # Bit I believe that he does NOT mean within control sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $cs = "\\" . $ch; # I need this standardized to be able to lookup tokens (A better way???) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ((defined $cc) && ($cc == CC_LETTER)) { # For letter, read more letters for csname. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cc and $cc == 11
MC/DC0%0/2
defined $cc and $cc == 11
defined $cc
$cc == 11
Truth table0%0/3
A and B
A= defined $ccB= $cc == 11
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | while ((($ch, $cc) = getNextChar($self)) && $ch && ($cc == CC_LETTER)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
() = getNextChar($self) and $ch and $cc == 11
() = getNextChar($self) and $ch
MC/DC0%0/3
() = getNextChar($self) and $ch and $cc == 11
() = getNextChar($self)
$ch
$cc == 11
Truth table0%0/4
A and B and C
A= () = getNextChar($self)B= $chC= $cc == 11
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $cs .= $ch; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $$self{colno}--; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | if ((defined $cc) && ($cc == CC_SPACE)) { # We'll skip whitespace here. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cc and $cc == 10
MC/DC0%0/2
defined $cc and $cc == 10
defined $cc
$cc == 10
Truth table0%0/3
A and B
A= defined $ccB= $cc == 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | while ((($ch, $cc) = getNextChar($self)) && $ch && ($cc == CC_SPACE)) { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
() = getNextChar($self) and $ch and $cc == 10
() = getNextChar($self) and $ch
MC/DC0%0/3
() = getNextChar($self) and $ch and $cc == 10
() = getNextChar($self)
$ch
$cc == 10
Truth table0%0/4
A and B and C
A= () = getNextChar($self)B= $chC= $cc == 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | $$self{colno}-- if ($$self{colno} < $$self{nchars}); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ((defined $cc) && ($cc == CC_EOL)) { # If we've got an EOL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $cc and $cc == 5
MC/DC0%0/2
defined $cc and $cc == 5
defined $cc
$cc == 5
Truth table0%0/3
A and B
A= defined $ccB= $cc == 5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # if in \read mode, leave the EOL to be turned into a T_SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if (($STATE->lookupValue('PRESERVE_NEWLINES') || 0) > 1) { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$LaTeXML::Core::Mouth::STATE->lookupValue('PRESERVE_NEWLINES') || 0
MC/DC0%0/1
$LaTeXML::Core::Mouth::STATE->lookupValue('PRESERVE_NEWLINES') || 0
$LaTeXML::Core::Mouth::STATE->lookupValue('PRESERVE_NEWLINES')
Truth table0%0/2
A
A= $LaTeXML::Core::Mouth::STATE->lookupValue('PRESERVE_NEWLINES')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | else { # else skip it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | getNextChar($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $$self{colno}-- if ($$self{colno} < $$self{nchars}); } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | return T_CS($cs); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | sub handle_EOL { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_EOL: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # Note that newines should be converted to space (with " " for content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # but it makes nicer XML with occasional \n. Hopefully, this is harmless? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my $token = ($$self{colno} == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ? T_CS('\par') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | : ($STATE->lookupValue('PRESERVE_NEWLINES') ? Token("\n", CC_SPACE) : T_SPACE)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $$self{colno} = $$self{nchars}; # Ignore any remaining characters after EOL | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | return $token; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | sub handle_space { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_space: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my ($ch, $cc); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # Skip any following spaces! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | while ((($ch, $cc) = getNextChar($self)) && (defined $ch) && (($cc == CC_SPACE) || ($cc == CC_EOL))) { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
() = getNextChar($self) and defined $ch and $cc == 10 || $cc == 5
() = getNextChar($self) and defined $ch
$cc == 10 or $cc == 5
MC/DC0%0/4
() = getNextChar($self) and defined $ch and $cc == 10 || $cc == 5
() = getNextChar($self)
defined $ch
$cc == 10
$cc == 5
Truth table0%0/5
A and B and C or D
A= () = getNextChar($self)B= defined $chC= $cc == 10D= $cc == 5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $$self{colno}-- if ($$self{colno} < $$self{nchars}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return T_SPACE; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | sub handle_comment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_comment: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $n = $$self{colno}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $$self{colno} = $$self{nchars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $comment = join('', @{ $$self{chars} }[$n .. $$self{nchars} - 1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $comment =~ s/^\s+//; $comment =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | return ($comment && $STATE->lookupValue('INCLUDE_COMMENTS') ? T_COMMENT($comment) : undef); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$comment and $LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
MC/DC0%0/2
$comment and $LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
$comment
$LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
Truth table0%0/3
A and B
A= $commentB= $LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # These cache the (presumably small) set of distinct letters, etc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | # converted to Tokens. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # Note that this gets filled during runtime and carries over to through Daemon frames. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # However, since the values don't depend on any particular document, bindings, etc, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | # they should be safe. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | my %LETTER = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 4 | my %OTHER = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | my %ACTIVE = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | # # Dispatch table for catcodes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | # Possibly want to think about caching (common) letters, etc to keep from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | # creating tokens like crazy... or making them more compact... or ??? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | my @DISPATCH = ( # [CONSTANT] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | \&handle_escape, # T_ESCAPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | sub { ($_[1] eq '{' ? T_BEGIN : Token($_[1], CC_BEGIN)) }, # T_BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub { ($_[1] eq '}' ? T_END : Token($_[1], CC_END)) }, # T_END | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | sub { ($_[1] eq '$' ? T_MATH : Token($_[1], CC_MATH)) }, # T_MATH | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub { ($_[1] eq '&' ? T_ALIGN : Token($_[1], CC_ALIGN)) }, # T_ALIGN | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | \&handle_EOL, # T_EOL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | sub { ($_[1] eq '#' ? T_PARAM : Token($_[1], CC_PARAM)) }, # T_PARAM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub { ($_[1] eq '^' ? T_SUPER : Token($_[1], CC_SUPER)) }, # T_SUPER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | sub { ($_[1] eq '_' ? T_SUB : Token($_[1], CC_SUB)) }, # T_SUB | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub { undef; }, # T_IGNORE (we'll read next token) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | \&handle_space, # T_SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub { $LETTER{ $_[1] } || ($LETTER{ $_[1] } = T_LETTER($_[1])); }, # T_LETTER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | sub { $OTHER{ $_[1] } || ($OTHER{ $_[1] } = T_OTHER($_[1])); }, # T_OTHER | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub { $ACTIVE{ $_[1] } || ($ACTIVE{ $_[1] } = T_ACTIVE($_[1])); }, # T_ACTIVE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | \&handle_comment, # T_COMMENT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | sub { T_OTHER($_[1]); } # T_INVALID (we could get unicode!) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # Read the next token, or undef if exhausted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | # Note that this also returns COMMENT tokens containing source comments, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | # and also locator comments (file, line# info). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | # LaTeXML::Core::Gullet intercepts them and passes them on at appropriate times. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | sub readToken { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readToken: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | while (1) { # Iterate till we find a token, or run out. (use return) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # ===== Get next line, if we need to. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if ($$self{colno} >= $$self{nchars}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $$self{lineno}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $$self{colno} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $line = $self->getNextLine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if (!defined $line) { # Exhausted the input. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $$self{at_eof} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $$self{chars} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $$self{nchars} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # Remove trailing space, but NOT a control space! End with CR (not \n) since this gets tokenized! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $line =~ s/((\\ )*)\s*$/$1\r/s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $$self{chars} = splitChars($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $$self{nchars} = scalar(@{ $$self{chars} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | while (($$self{colno} < $$self{nchars}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$self->{"colno"} < $self->{"nchars"} and ($LaTeXML::Core::Mouth::STATE->{"catcode"}{$self->{"chars"}[$self->{"colno"}]}[0] || 12) == 10
$LaTeXML::Core::Mouth::STATE->{'catcode'}{$self->{'chars'}[$self->{'colno'}]}[0] || 12
MC/DC0%0/2
$self->{"colno"} < $self->{"nchars"} and ($LaTeXML::Core::Mouth::STATE->{"catcode"}{$self->{"chars"}[$self->{"colno"}]}[0] || 12) == 10
$self->{"colno"} < $self->{"nchars"}
$LaTeXML::Core::Mouth::STATE->{'catcode'}{$self->{'chars'}[$self->{'colno'}]}[0]
Truth table0%0/3
A and B
A= $self->{"colno"} < $self->{"nchars"}B= $LaTeXML::Core::Mouth::STATE->{'catcode'}{$self->{'chars'}[$self->{'colno'}]}[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # DIRECT ACCESS to $STATE's catcode table!!! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | && (($$STATE{catcode}{ $$self{chars}[$$self{colno}] }[0] || CC_OTHER) == CC_SPACE)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $$self{colno}++; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | # Sneak a comment out, every so often. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ((($$self{lineno} % 25) == 0) && $STATE->lookupValue('INCLUDE_COMMENTS')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"lineno"} % 25 == 0 and $LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
MC/DC0%0/2
$self->{"lineno"} % 25 == 0 and $LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
$self->{"lineno"} % 25 == 0
$LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
Truth table0%0/3
A and B
A= $self->{"lineno"} % 25 == 0B= $LaTeXML::Core::Mouth::STATE->lookupValue("INCLUDE_COMMENTS")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | ▶ | return T_COMMENT("**** " . ($$self{shortsource} || 'String') . " Line $$self{lineno} ****"); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'shortsource'} || 'String'
MC/DC0%0/1
$self->{'shortsource'} || 'String'
$self->{'shortsource'}
Truth table0%0/2
A
A= $self->{'shortsource'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | # ==== Extract next token from line. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my ($ch, $cc) = getNextChar($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | my $token = (defined $cc ? $DISPATCH[$cc] : undef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | $token = &$token($self, $ch) if ref $token eq 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | return $token if defined $token; # Else, repeat till we get something or run out. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | return; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | # Read all tokens until a token equal to $until (if given), or until exhausted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # Returns an empty Tokens list, if there is no input | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | sub readTokens { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | my ($self, $until) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readTokens: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my @tokens = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | while (defined(my $token = $self->readToken())) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | last if $until and $token->getString eq $until->getString; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$until and $token->getString eq $until->getString
MC/DC0%0/2
$until and $token->getString eq $until->getString
$until
$token->getString eq $until->getString
Truth table0%0/3
A and B
A= $untilB= $token->getString eq $until->getString
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | push(@tokens, $token); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | while (@tokens && $tokens[-1]->getCatcode == CC_SPACE) { # Remove trailing space | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@tokens and $tokens[-1]->getCatcode == 10
MC/DC0%0/2
@tokens and $tokens[-1]->getCatcode == 10
@tokens
$tokens[-1]->getCatcode == 10
Truth table0%0/3
A and B
A= @tokensB= $tokens[-1]->getCatcode == 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | pop(@tokens); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | return Tokens(@tokens); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | #********************************************************************** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # Read a raw line; there are so many variants of how it should end, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # that the Mouth API is left as simple as possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | # Alas: $noread true means NOT to read a new line, but only return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | # the remainder of the current line, if any. This is useful when combining | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # with previously peeked tokens from the Gullet. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | sub readRawLine { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | my ($self, $noread) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
readRawLine: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | my $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | if ($$self{colno} < $$self{nchars}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | $line = join('', @{ $$self{chars} }[$$self{colno} .. $$self{nchars} - 1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | # End lines with \n, not CR, since the result will be treated as strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $$self{colno} = $$self{nchars}; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | elsif ($noread) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $line = ''; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $line = $self->getNextLine; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | if (!defined $line) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $$self{at_eof} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $$self{chars} = []; $$self{nchars} = 0; $$self{colno} = 0; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $$self{lineno}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $$self{chars} = splitChars($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $$self{nchars} = scalar(@{ $$self{chars} }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $$self{colno} = $$self{nchars}; } } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | $line =~ s/\s*$//s if defined $line; # Is this right? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | return $line; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | sub isEOL { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isEOL: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | return $$self{colno} >= $$self{nchars}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | #====================================================================== | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||