diff -Nru liblatex-tom-perl-1.00/Build.PL liblatex-tom-perl-1.03/Build.PL --- liblatex-tom-perl-1.00/Build.PL 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/Build.PL 2011-12-23 21:16:43.000000000 +0000 @@ -10,6 +10,10 @@ module_name => 'LaTeX::TOM', dist_author => 'Steven Schubiger ', dist_version_from => 'lib/LaTeX/TOM.pm', + requires => { + 'Carp' => 0, + 'File::Basename' => 0, + }, build_requires => { 'Test::More' => 0 }, license => 'perl', create_readme => 1, diff -Nru liblatex-tom-perl-1.00/Changes liblatex-tom-perl-1.03/Changes --- liblatex-tom-perl-1.00/Changes 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/Changes 2011-12-23 21:16:43.000000000 +0000 @@ -1,5 +1,125 @@ Revision history for Perl extension LaTeX::TOM. +1.03 2011-12-23 + + - Merged development version to stable. + +1.02_01 2011-11-24 + + - Change commented debug statements in ::Parser to be invokable. + + - Alter _debug() to print filename and line number. + +1.02 2011-11-13 + + - Merged development version to stable. + +1.01_01 2011-10-09 + + - Refactor new(), copy() and split() Node methods. + + - Adjust setNodeText(). + + - Replace Node's boolean values with true/false. + + - Enable warnings for the Node class. + + - Remove obsoleted LICENSE file. + +1.01 2011-08-19 + + - Merged development version to stable. + +1.00_08 2011-08-18 + + - Test getCommandNodesByName(), getEnvironmentsByName() and + getNodesByCondition(). + +1.00_07 2011-08-15 + + - Fix parsing user-defined mappings and add a test. + [rt #48540 - Jesse S. Bangs] + + - Don't pass the parser object to the Tree constructor. + + - Adjust some code indentation. + +1.00_06 2011-08-03 + + - Fix setting instance config data for the main constructor. + + - Introduce error handlers to minimize code repetition. + + - Change commented debug statements in parse() to be invokable. + + - Rename print() to _debug_tree() and wrap it twice in order to + emit output to STDOUT/STDERR. + + - Alter _debug_tree() further to use the output handler being + passed in and enhance the code layout. + + - Be less verbose for variable names when assigning user options. + +1.00_05 2011-07-29 + + - Refactor _getTextAndCommentNodes(), which includes: + + - Move creating a comment or text node to a lexical subroutine. + + - Store the type as string and adjust comments accordingly. + + - Append line to string directly instead of pushing to an array. + + - (Re)set initialization variables with short-circuit operators. + + - Use underscores within variable names where appropriate. + + - Reformat visually the regular expressions used. + +1.00_04 2011-07-27 + + - Strengthen the check for a \input file filename extension. + + - Add File::Basename as dependency. + +1.00_03 2011-07-26 + + - Fix an error when dereferencing the nodes of a subtree. + + - Improve the \bibliography handling code and add a test. + + - Make reading a \input file more strict. + + - Test that empty \input files are not skipped. + + - Bless into current package for the Node/Tree constructors. + + - Adjust some code indentation. + +1.00_02 2011-07-24 + + - Improve the \input handling code and add tests. + + - Raise error in _readFile() when a file cannot be opened. + + - Use lexical filehandle and slurp file in _readFile(). + + - Substitute warn with carp in _addInputs(). + +1.00_01 2011-07-20 + + - Use true as boolean value when initializing config data. + + - Change the mention of the primary contact. + + - Reword the documentation a bit. + + - Remove broken website link and according text. + + - Update broken license link. + + - Skip documentation tests for non-release testing. + 1.00 Wed Oct 7 10:56:12 CEST 2009 - Merged development version to stable. diff -Nru liblatex-tom-perl-1.00/debian/changelog liblatex-tom-perl-1.03/debian/changelog --- liblatex-tom-perl-1.00/debian/changelog 2017-11-02 22:57:13.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/changelog 2017-09-09 18:14:12.000000000 +0000 @@ -1,3 +1,28 @@ +liblatex-tom-perl (1.03-1) unstable; urgency=medium + + * Take over for the Debian Perl Group; Closes: #867754 -- RFA/ITA + * debian/control: Added: Vcs-Git field (source stanza); Vcs-Browser + field (source stanza). Changed: Homepage field changed to + metacpan.org URL; Maintainer set to Debian Perl Group (was: Patrick Winnertz + ). + * debian/watch: use metacpan-based URL. + * Mark package as autopkgtest-able. + * Declare compliance with Debian Policy 4.1.0. + * Drop version from perl build dependency. + * Switch to source format "3.0 (quilt)". + * Bump debhelper compatibility level to 9. + * Use dh(1). + * debian/copyright: switch formatting to Copyright-Format 1.0. + * Add /me to Uploaders. + * Update short and long description. + * Cleanup build dependencies. + + * New upstream release. + * Add a spelling patch. + + -- gregor herrmann Sat, 09 Sep 2017 20:14:12 +0200 + liblatex-tom-perl (1.00-1) unstable; urgency=low * New upstream release (Closes: #531336) diff -Nru liblatex-tom-perl-1.00/debian/compat liblatex-tom-perl-1.03/debian/compat --- liblatex-tom-perl-1.00/debian/compat 2017-11-02 22:57:13.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/compat 2017-09-09 18:14:12.000000000 +0000 @@ -1 +1 @@ -5 +9 diff -Nru liblatex-tom-perl-1.00/debian/control liblatex-tom-perl-1.03/debian/control --- liblatex-tom-perl-1.00/debian/control 2017-11-02 22:57:13.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/control 2017-09-09 18:14:12.000000000 +0000 @@ -1,22 +1,28 @@ Source: liblatex-tom-perl +Maintainer: Debian Perl Group +Uploaders: gregor herrmann Section: perl +Testsuite: autopkgtest-pkg-perl Priority: optional -Build-Depends: debhelper (>= 5.0.0) -Build-Depends-Indep: perl (>= 5.8.0-7), libmodule-build-perl, libtest-pod-coverage-perl, libtest-pod-perl -Maintainer: Patrick Winnertz -Standards-Version: 3.8.3 -Homepage: http://search.cpan.org/~schubiger/LaTeX-TOM-1.00/lib/LaTeX/TOM.pm +Build-Depends: debhelper (>= 9), + libmodule-build-perl, + perl +Standards-Version: 4.1.0 +Vcs-Browser: https://anonscm.debian.org/cgit/pkg-perl/packages/liblatex-tom-perl.git +Vcs-Git: https://anonscm.debian.org/git/pkg-perl/packages/liblatex-tom-perl.git +Homepage: https://metacpan.org/release/LaTeX-TOM Package: liblatex-tom-perl Architecture: all -Depends: ${perl:Depends}, ${misc:Depends} -Description: A module for parsing, analyzing and manipulating latex documents - This module provides a parser which parses and interprets (though not fully) - LaTeX documents and returns a tree-based representation of what it finds. - This tree is a LaTeX::TOM::Tree. The tree contains LaTeX::TOM::Node nodes. +Depends: ${perl:Depends}, + ${misc:Depends} +Description: module for parsing, analyzing and manipulating LaTeX documents + The LaTeX::TOM module provides a parser which parses and interprets (though + not fully) LaTeX documents and returns a tree-based representation of what it + finds. This tree is a LaTeX::TOM::Tree. The tree contains LaTeX::TOM::Node + nodes. . This module should be especially useful to anyone who wants to do processing of LaTeX documents that requires extraction of plain-text information, or altering of the plain-text components (or alternatively, the math-text components). - diff -Nru liblatex-tom-perl-1.00/debian/copyright liblatex-tom-perl-1.03/debian/copyright --- liblatex-tom-perl-1.00/debian/copyright 2017-11-02 22:57:13.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/copyright 2017-09-09 18:14:12.000000000 +0000 @@ -1,13 +1,29 @@ -This is the debian package for the LaTeX-TOM module. -It was created by Patrick Winnertz using dh-make-perl. +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Source: https://metacpan.org/release/LaTeX-TOM +Upstream-Contact: Steven Schubiger +Upstream-Name: LaTeX-TOM -The upstream author is: Aaron Krowne . -Copyright (c) 2002 Aaron Krowne +Files: * +Copyright: 2002, Aaron Krowne +License: Artistic or GPL-1+ -The sourcecode is downloaded from: http://search.cpan.org/~schubiger/LaTeX-TOM-0.6/lib/LaTeX/TOM.pm +Files: debian/* +Copyright: 2007, 2010, Patrick Winnertz + 2017, gregor herrmann +License: Artistic or GPL-1+ -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +License: Artistic + This program is free software; you can redistribute it and/or modify + it under the terms of the Artistic License, which comes with Perl. + . + On Debian systems, the complete text of the Artistic License can be + found in `/usr/share/common-licenses/Artistic'. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +License: GPL-1+ + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 1, or (at your option) + any later version. + . + On Debian systems, the complete text of version 1 of the GNU General + Public License can be found in `/usr/share/common-licenses/GPL-1'. diff -Nru liblatex-tom-perl-1.00/debian/docs liblatex-tom-perl-1.03/debian/docs --- liblatex-tom-perl-1.00/debian/docs 2017-11-02 22:57:13.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/docs 1970-01-01 00:00:00.000000000 +0000 @@ -1 +0,0 @@ -TODO diff -Nru liblatex-tom-perl-1.00/debian/liblatex-tom-perl.docs liblatex-tom-perl-1.03/debian/liblatex-tom-perl.docs --- liblatex-tom-perl-1.00/debian/liblatex-tom-perl.docs 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/liblatex-tom-perl.docs 2017-09-09 18:14:12.000000000 +0000 @@ -0,0 +1 @@ +TODO diff -Nru liblatex-tom-perl-1.00/debian/patches/series liblatex-tom-perl-1.03/debian/patches/series --- liblatex-tom-perl-1.00/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/patches/series 2017-09-09 18:14:12.000000000 +0000 @@ -0,0 +1 @@ +spelling.patch diff -Nru liblatex-tom-perl-1.00/debian/patches/spelling.patch liblatex-tom-perl-1.03/debian/patches/spelling.patch --- liblatex-tom-perl-1.00/debian/patches/spelling.patch 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/patches/spelling.patch 2017-09-09 18:14:12.000000000 +0000 @@ -0,0 +1,45 @@ +Description: spelling fix +Origin: vendor +Author: gregor herrmann +Last-Update: 2017-09-09 +Forwarded: https://rt.cpan.org/Ticket/Display.html?id=122996 +Bug: https://rt.cpan.org/Ticket/Display.html?id=122996 + +--- a/lib/LaTeX/TOM.pm ++++ b/lib/LaTeX/TOM.pm +@@ -346,7 +346,7 @@ + =item COMMENT + + A C node is very similar to a C node, except it is specifically for +-lines beginning with C<``%''> (the TeX comment delimeter) or the right-hand ++lines beginning with C<``%''> (the TeX comment delimiter) or the right-hand + portion of a line that has C<``%''> at some internal point. + + =back +--- a/lib/LaTeX/TOM/Parser.pm ++++ b/lib/LaTeX/TOM/Parser.pm +@@ -620,7 +620,7 @@ + } + } + +-# This is the "math" stage: here we grab simple-delimeter math modes from ++# This is the "math" stage: here we grab simple-delimiter math modes from + # the text they are embedded in, and turn those into new groupings, with the + # "math" flag set. + # +@@ -716,13 +716,13 @@ + _debug("splitacross: found (right) $right in [$node->{content}]", undef); + + # create new set of 4 smaller text nodes from the original two +- # that contain the left and right delimeters ++ # that contain the left and right delimiters + # + my ($textnode1, $textnode2) = $tree->{nodes}[$leftidx]->split($leftpos, $leftpos + length($left) - 1); + my ($textnode3, $textnode4) = $tree->{nodes}[$i]->split($rightpos, $rightpos + length($right) - 1); + + # nodes to remove "from the middle" (between the left and right +- # text nodes which contain the delimeters) ++ # text nodes which contain the delimiters) + # + my @remnodes = splice @{$tree->{nodes}}, $leftidx+1, $i - $leftidx - 1; + diff -Nru liblatex-tom-perl-1.00/debian/rules liblatex-tom-perl-1.03/debian/rules --- liblatex-tom-perl-1.00/debian/rules 2017-11-02 22:57:13.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/rules 2017-09-09 18:14:12.000000000 +0000 @@ -1,56 +1,4 @@ #!/usr/bin/make -f -export PERL_MM_USE_DEFAULT=1 -PACKAGE=$(shell dh_listpackages) - -ifndef PERL -PERL = /usr/bin/perl -endif - -TMP =$(CURDIR)/debian/$(PACKAGE) - -build: build-stamp -build-stamp: - dh_testdir - $(PERL) Build.PL installdirs=vendor - OPTIMIZE="-Wall -O2 -g" $(PERL) Build - touch build-stamp - -clean: - dh_testdir - dh_testroot - -$(PERL) Build distclean - rm -rf Makefile.old - dh_clean build-stamp install-stamp - -install: build install-stamp -install-stamp: - dh_testdir - dh_testroot - dh_clean -k - $(PERL) Build test - $(PERL) Build install destdir=$(TMP) - find $(TMP) -type f -name .packlist | xargs rm -f - #Delete automatically empty dirs. - find $(TMP) -depth -type d -empty -exec rmdir {} \; - touch install-stamp - -binary-arch: - -binary-indep: build install - dh_testdir - dh_testroot - dh_installdocs - dh_installchangelogs Changes - dh_perl - dh_link - dh_strip - dh_compress - dh_fixperms - dh_installdeb - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary +%: + dh $@ diff -Nru liblatex-tom-perl-1.00/debian/source/format liblatex-tom-perl-1.03/debian/source/format --- liblatex-tom-perl-1.00/debian/source/format 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/source/format 2017-09-09 18:14:12.000000000 +0000 @@ -0,0 +1 @@ +3.0 (quilt) diff -Nru liblatex-tom-perl-1.00/debian/watch liblatex-tom-perl-1.03/debian/watch --- liblatex-tom-perl-1.00/debian/watch 2017-11-02 22:57:13.000000000 +0000 +++ liblatex-tom-perl-1.03/debian/watch 2017-09-09 18:14:12.000000000 +0000 @@ -1,2 +1,2 @@ version=3 -http://search.cpan.org/CPAN/authors/id/S/SC/SCHUBIGER/LaTeX-TOM-([\d\.]*).tar.gz \ No newline at end of file +https://metacpan.org/release/LaTeX-TOM .*/LaTeX-TOM-v?(\d[\d.-]+)\.(?:tar(?:\.gz|\.bz2)?|tgz|zip)$ \ No newline at end of file diff -Nru liblatex-tom-perl-1.00/lib/LaTeX/TOM/Node.pm liblatex-tom-perl-1.03/lib/LaTeX/TOM/Node.pm --- liblatex-tom-perl-1.00/lib/LaTeX/TOM/Node.pm 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/lib/LaTeX/TOM/Node.pm 2011-12-23 21:16:43.000000000 +0000 @@ -10,16 +10,19 @@ package LaTeX::TOM::Node; use strict; +use warnings; +use constant true => 1; +use constant false => 0; -our $VERSION = '0.01'; +our $VERSION = '0.03'; # Make a new Node: turn input hash into object. # sub new { my $class = shift; - my $node = shift || {}; + my ($node) = @_; - return bless $node, ref($class) || $class; + return bless $node || {}; } # "copy constructor" @@ -27,9 +30,7 @@ sub copy { my $node = shift; - my $copynode = {%$node}; # copy the memory contents and get a pointer - - return bless $copynode; + return bless $node; } # Split a text node into two text nodes, with the first ending before point a, @@ -44,27 +45,28 @@ # sub split { my $node = shift; - my $a = shift; - my $b = shift; + my ($a, $b) = @_; - return (undef, undef) if ($node->{type} ne 'TEXT'); + return (undef) x 2 unless $node->{type} eq 'TEXT'; - my $lefttext = substr $node->{content}, 0, $a; - my $righttext = substr $node->{content}, $b + 1, length($node->{content}) - $b; + my $left_text = substr $node->{content}, 0, $a; + my $right_text = substr $node->{content}, $b + 1, length($node->{content}) - $b; - my $leftnode = LaTeX::TOM::Node->new( - {type => 'TEXT', - start => $node->{start}, - end => $node->{start} + $a -1, - content => $lefttext}); - - my $rightnode = LaTeX::TOM::Node->new( - {type => 'TEXT', - start => $node->{start} + $b + 1, - end => $node->{start} + length($node->{content}), - content => $righttext}); + my $left_node = LaTeX::TOM::Node->new({ + type => 'TEXT', + start => $node->{start}, + end => $node->{start} + $a - 1, + content => $left_text, + }); + + my $right_node = LaTeX::TOM::Node->new({ + type => 'TEXT', + start => $node->{start} + $b + 1, + end => $node->{start} + length $node->{content}, + content => $right_text, + }); - return ($leftnode, $rightnode); + return ($left_node, $right_node); } # @@ -85,7 +87,7 @@ sub setNodeText { my $node = shift; - my $text = shift; + my ($text) = @_; $node->{content} = $text; } @@ -105,13 +107,13 @@ sub getNodeMathFlag { my $node = shift; - return $node->{math} ? 1 : 0; + return $node->{math} ? true : false; } sub getNodePlainTextFlag { my $node = shift; - return $node->{plaintext} ? 1 : 0; + return $node->{plaintext} ? true : false; } sub getNodeOuterStartingPosition { diff -Nru liblatex-tom-perl-1.00/lib/LaTeX/TOM/Parser.pm liblatex-tom-perl-1.03/lib/LaTeX/TOM/Parser.pm --- liblatex-tom-perl-1.00/lib/LaTeX/TOM/Parser.pm 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/lib/LaTeX/TOM/Parser.pm 2011-12-23 21:16:43.000000000 +0000 @@ -13,17 +13,37 @@ LaTeX::TOM::Node LaTeX::TOM::Tree ); +use constant true => 1; +use constant false => 0; -our $VERSION = '0.01'; +use Carp qw(carp croak); +use File::Basename qw(fileparse); + +our $VERSION = '0.07'; + +my %error_handlers = ( + 0 => sub { warn "parse error: $_[0].\n" }, + 1 => sub { die "parse error: $_[0].\n" }, + 2 => sub {}, +); # Constructor # sub new { my $class = shift; - my $self = {}; + no strict 'refs'; - bless $self, ref($class) || $class; + my $self = bless { + config => { + BRACELESS => \%{"${class}::BRACELESS"}, + INNERCMDS => \%{"${class}::INNERCMDS"}, + MATHENVS => \%{"${class}::MATHENVS"}, + MATHBRACKETS => \%{"${class}::MATHBRACKETS"}, + PARSE_ERRORS_FATAL => ${"${class}::PARSE_ERRORS_FATAL"}, + TEXTENVS => \%{"${class}::TEXTENVS"}, + }, + }; $self->_init(@_); @@ -36,7 +56,7 @@ my $parser = shift; my ($parse_errors_fatal, $readinputs, $applymappings) = @_; - my $retrieve_opt_with_default = sub + my $retrieve_opt_default = sub { my ($opt, $default) = @_; return $opt if defined $opt; @@ -45,9 +65,9 @@ # set user options # - $parser->{readinputs} = $retrieve_opt_with_default->($readinputs, 0); - $parser->{applymappings} = $retrieve_opt_with_default->($applymappings, 0); - $parser->{PARSE_ERRORS_FATAL} = $retrieve_opt_with_default->($parse_errors_fatal, $parser->{config}{PARSE_ERRORS_FATAL}); + $parser->{readinputs} = $retrieve_opt_default->($readinputs, 0); + $parser->{applymappings} = $retrieve_opt_default->($applymappings, 0); + $parser->{PARSE_ERRORS_FATAL} = $retrieve_opt_default->($parse_errors_fatal, $parser->{config}{PARSE_ERRORS_FATAL}); # init internal stuff # @@ -75,17 +95,13 @@ $parser->{file} = $filename; # file name member data my $tree = {}; # init output tree - # read in text from file + # read in text from file or bomb out # - my $text = _readFile($filename); + my $text = _readFile($filename, true); - # do the parse or bomb out + # do the parse # - if ($text) { - $tree = $parser->parse($text); - } else { - die "Could not read file $filename !"; - } + $tree = $parser->parse($text); return $tree; } @@ -94,36 +110,39 @@ # sub parse { my $parser = shift; - - my $text = shift; + my ($text) = @_; # first half of parsing (goes up to finding commands, reading inputs) # my ($tree, $bracehash) = $parser->_parseA($text); - - #print "done with _parseA\n"; - #$tree->print(); + _debug( + 'done with _parseA', + sub { $tree->_warn() }, + ); # handle mappings # $parser->_applyMappings($tree) if $parser->{applymappings}; - - #print "done with _applyMappings\n"; - #$tree->print(); + _debug( + 'done with _applyMappings', + sub { $tree->_warn() }, + ); # second half of parsing (environments) # $parser->_parseB($tree); - - #print "done with _parseB\n"; - #$tree->print(); + _debug( + 'done with _parseB', + sub { $tree->_warn() }, + ); # once all the above is done we can propegate math/plaintext modes down # $parser->_propegateModes($tree, 0, 0); # math = 0, plaintext = 0 - - #print "done with _propegateModes\n"; - #$tree->print(); + _debug( + 'done with _propegateModes', + sub { $tree->_warn() }, + ); # handle kooky \[ \] math mode # @@ -134,8 +153,10 @@ $parser->{MATHBRACKETS}->{'\\['} = '\\]'; # put back in brackets list for $parser->{MATHBRACKETS}->{'\\('} = '\\)'; # printing purposes. } - - #$tree->print(); + _debug( + undef, + sub { $tree->_warn() }, + ); $tree->listify; # add linked-list stuff @@ -169,7 +190,7 @@ my @nodes = _getTextAndCommentNodes($text, 0, length($text)); - return LaTeX::TOM::Tree->new([@nodes], $parser); + return LaTeX::TOM::Tree->new([@nodes]); } # this stage parses the braces ({}) and adds the corresponding structure to @@ -203,7 +224,8 @@ if ($node->{type} eq 'TEXT') { - #warn "parseStage2: looking at text node: [$node->{content}]"; + _debug("parseStage2: looking at text node: [$node->{content}]", undef); + my ($nextpos, $brace) = _findbrace($node->{content}, $pos); while ($nextpos != -1) { @@ -211,7 +233,7 @@ # handle left brace if ($brace eq '{') { - #warn "found '{' at position $nextpos, leftcount is $leftcount"; + _debug("found '{' at position $nextpos, leftcount is $leftcount", undef); if ($leftcount == 0) { $leftpos = $nextpos; $leftidx = $i @@ -222,7 +244,7 @@ # handle right brance elsif ($brace eq '}') { - #warn "found '}' at position $nextpos , leftcount is $leftcount"; + _debug("found '}' at position $nextpos, leftcount is $leftcount", undef); my $rightpos = $nextpos; $leftcount--; @@ -241,7 +263,7 @@ {type => 'GROUP', start => $textnode2->{start} - 1, end => $textnode2->{end} + 1, - children => LaTeX::TOM::Tree->new([$textnode2], $parser), + children => LaTeX::TOM::Tree->new([$textnode2]), }); # splice the new subtree into the old location @@ -280,8 +302,7 @@ children => LaTeX::TOM::Tree->new( [$textnode2, @removed, - $textnode3], - $parser), + $textnode3]), }); # replace the two original text nodes with the leftover left and @@ -309,13 +330,8 @@ # check for '}'-based error # if ($leftcount < 0) { - if ($parser->{PARSE_ERRORS_FATAL} == 1) { - die "parse error: '}' before '{' at ".($spos+$rightpos)."."; - } elsif ($parser->{PARSE_ERRORS_FATAL} == 0) { - warn "parse error: '}' before '{' at ".($spos+$rightpos)."."; - } - # reset and continue - $leftcount = 0; + $error_handlers{$parser->{PARSE_ERRORS_FATAL}}->("'}' before '{' at " . ($spos + $rightpos)); + $leftcount = 0; # reset and continue } } # right brace @@ -330,12 +346,9 @@ # check for extra '{' parse error # if ($leftcount > 0) { - my $spos = $tree->{nodes}[$leftidx]->{start}; # get text start position - if ($parser->{PARSE_ERRORS_FATAL} == 1) { - die "parse error: unmatched '{' at ".($spos+$leftpos)."."; - } elsif ($parser->{PARSE_ERRORS_FATAL} == 0) { - warn "parse error: unmatched '{' at ".($spos+$leftpos)."."; - } + my $spos = $tree->{nodes}[$leftidx]->{start}; # get text start position + $error_handlers{$parser->{PARSE_ERRORS_FATAL}}->("unmatched '{' at " . ($spos + $leftpos)); + # try to continue on, after the offending brace $parser->_stage2($tree, $bracehash, $leftidx, $leftpos + 1); } @@ -383,7 +396,7 @@ children => $parent->{children} }); # point parent to it - $parent->{children} = LaTeX::TOM::Tree->new([$newnode], $parser); + $parent->{children} = LaTeX::TOM::Tree->new([$newnode]); # start over at this level (get additional inner commands) $parent = $newnode; @@ -418,7 +431,7 @@ my $tag = $1; - #print "found text node [$text] with command tag [$tag]\n"; + _debug("found text node [$text] with command tag [$tag]", undef); # remove the text $node->{content} =~ s/\\\w+\*?\s*(?:\[.*?\])?\s*$//os; @@ -474,7 +487,7 @@ command => $command, start => $node->{start} + $a, end => $node->{start} + $b, - children => LaTeX::TOM::Tree->new([$newchild], $parser), + children => LaTeX::TOM::Tree->new([$newchild]), }); $parser->{USED_COMMANDS}->{$commandnode->{command}} = 1; @@ -526,20 +539,20 @@ # see if this is a "\begin" command node if ($node->{type} eq 'COMMAND' && $node->{command} eq 'begin') { - #warn "parseStage4: found a begin COMMAND node, ".$node->{children}->{nodes}[0]->{content}." @ $node->{start}"; + _debug("parseStage4: found a begin COMMAND node, $node->{children}->{nodes}[0]->{content} @ $node->{start}", undef); # start a new "stack" if ($bcount == 0) { $bidx = $i; $bcount++; $class = $node->{children}->{nodes}->[0]->{content}; - #warn "parseStage4: opening environment tag found, class = $class"; + _debug("parseStage4: opening environment tag found, class = $class", undef); } # add to the "stack" elsif ($node->{children}->{nodes}->[0]->{content} eq $class) { $bcount++; - #warn "parseStage4: incrementing tag count for $class"; + _debug("parseStage4: incrementing tag count for $class", undef); } } @@ -549,14 +562,14 @@ $node->{children}->{nodes}->[0]->{content} eq $class) { $bcount--; - #warn "parseStage4: decrementing tag count for $class"; + _debug("parseStage4: decrementing tag count for $class", undef); # we found our closing "\end" tag. replace everything with the proper # ENVIRONMENT tag and subtree. # if ($bcount == 0) { - #warn "parseStage4: closing environment $class"; + _debug("parseStage4: closing environment $class", undef); # first we must take everything between the "\begin" and "\end" # nodes and put them in a new array, removing them from the old one @@ -572,7 +585,7 @@ end => $end, ostart => $start - length('begin') - length($class) - 2, oend => $end + length('end') + length($class) + 2, - children => LaTeX::TOM::Tree->new([@newarray], $parser), + children => LaTeX::TOM::Tree->new([@newarray]), }); if ($parser->{config}{MATHENVS}->{$envnode->{class}}) { @@ -601,11 +614,9 @@ # parse error if we're missing an "\end" tag. if ($bcount > 0) { - if ($parser->{PARSE_ERRORS_FATAL} == 1) { - die "parse error: missing \\end{$class} for \\begin{$class} at position ".$tree->{nodes}[$bidx]->{end}." !"; - } elsif ($parser->{PARSE_ERRORS_FATAL} == 0) { - warn "parse error: missing \\end{$class} for \\begin{$class} at position ".$tree->{nodes}[$bidx]->{end}." !"; - } + $error_handlers{$parser->{PARSE_ERRORS_FATAL}}->( + "missing \\end{$class} for \\begin{$class} at position $tree->{nodes}[$bidx]->{end}" + ); } } @@ -660,7 +671,7 @@ $leftpos = _findsymbol($node->{content}, $left, $pos); if ($leftpos != -1) { - #print "found (left) $left in [$node->{content}]\n"; + _debug("found (left) $left in [$node->{content}]", undef); $leftidx = $i; $pos = $leftpos + 1; # next pos to search from } @@ -675,7 +686,7 @@ # we have to split the text node into 3 parts if ($leftidx == $i) { - #print "splitwithin: found (right) $right in [$node->{content}]\n"; + _debug("splitwithin: found (right) $right in [$node->{content}]", undef); my ($leftnode, $textnode3) = $node->split($rightpos, $rightpos + length($right) - 1); my ($textnode1, $textnode2) = $leftnode->split($leftpos, $leftpos + length($left) - 1); @@ -691,7 +702,7 @@ ostart => $startpos + $leftpos - length($left) + 1, end => $startpos + $rightpos, oend => $startpos + $rightpos + length($right) - 1, - children => LaTeX::TOM::Tree->new([$textnode2], $parser), + children => LaTeX::TOM::Tree->new([$textnode2]), }); splice @{$tree->{nodes}}, $i, 1, $textnode1, $mathnode, $textnode3; @@ -702,7 +713,7 @@ # split across nodes else { - #print "splitacross: found (right) $right in [$node->{content}]\n"; + _debug("splitacross: found (right) $right in [$node->{content}]", undef); # create new set of 4 smaller text nodes from the original two # that contain the left and right delimeters @@ -730,7 +741,7 @@ children => LaTeX::TOM::Tree->new( [$textnode2, @remnodes, - $textnode3], $parser), + $textnode3]), }); # replace (TEXT_A, ... , TEXT_B) with the mathnode created above @@ -750,12 +761,8 @@ my $rightpos = _findsymbol($node->{content}, $right, $pos); if ($rightpos != -1) { - my $startpos = $node->{start}; # get text start position - if ($parser->{PARSE_ERRORS_FATAL} == 1) { - die "parse error: unmatched '$right' at ".($startpos+$rightpos)."."; - } elsif ($parser->{PARSE_ERRORS_FATAL} == 0) { - warn "parse error: unmatched '$right' at ".($startpos+$rightpos)."."; - } + my $startpos = $node->{start}; # get text start position + $error_handlers{$parser->{PARSE_ERRORS_FATAL}}->("unmatched '$right' at " . ($startpos + $rightpos)); } } } # if TEXT @@ -767,10 +774,12 @@ ($node->{type} eq 'COMMAND' && $node->{command} =~ /^verb/) || ($node->{type} eq 'ENVIRONMENT' && $node->{class} =~ /^verbatim/))) { - #print "Recurring into $node->{type} node "; - #print "$node->{command}" if ($node->{type} eq 'COMMAND'); - #print "$node->{class}" if ($node->{type} eq 'ENVIRONMENT'); - #print "\n"; + if ($LaTeX::TOM::DEBUG) { + my $message = "Recurring into $node->{type} node "; + $message .= $node->{command} if ($node->{type} eq 'COMMAND'); + $message .= $node->{class} if ($node->{type} eq 'ENVIRONMENT'); + _debug($message, undef); + } $parser->_stage5_r($node->{children}, $left, $right, $caremath); } @@ -779,11 +788,7 @@ if ($leftpos != -1) { my $startpos = $tree->{nodes}[$leftidx]->{start}; # get text start position - if ($parser->{PARSE_ERRORS_FATAL} == 1) { - die "parse error: unmatched '$left' at ".($startpos+$leftpos)."."; - } elsif ($parser->{PARSE_ERRORS_FATAL} == 0) { - warn "parse error: unmatched '$left' at ".($startpos+$leftpos)."."; - } + $error_handlers{$parser->{PARSE_ERRORS_FATAL}}->("unmatched '$left' at " . ($startpos + $leftpos)); } } @@ -887,10 +892,10 @@ # begin environment nodes # - if ($node->{type} eq 'COMMAND' && - $node->{command} eq 'begin' && - $node->{children}->{nodes}[0]->{content} eq $mapping->{name}) { - + if ($node->{type} eq 'COMMAND' + && $node->{command} eq 'begin' + && $node->{children}->{nodes}[0]->{content} eq $mapping->{name} + ) { # grab the nparams next group nodes as parameters # my @params = (); @@ -917,36 +922,36 @@ my $applied = _applyParamsToTemplate($mapping->{btemplate}, @params); # splice in the result - splice @{$tree->{nodes}}, $i, $j, @$applied; + splice @{$tree->{nodes}}, $i, $j, @{$applied->{nodes}}; # skip past all the new stuff - $i += scalar @$applied - 1; + $i += scalar @{$applied->{nodes}} - 1; } # end environment nodes # - elsif ($node->{type} eq 'COMMAND' && - $node->{command} eq 'end' && - $node->{children}->{nodes}[0]->{content} eq $mapping->{name}) { - + elsif ($node->{type} eq 'COMMAND' + && $node->{command} eq 'end' + && $node->{children}->{nodes}[0]->{content} eq $mapping->{name} + ) { # make new subtree (no params) my $applied = $mapping->{etemplate}->copy(); # splice in the result - splice @{$tree->{nodes}}, $i, 1, @$applied; + splice @{$tree->{nodes}}, $i, 1, @{$applied->{nodes}}; # skip past all the new stuff - $i += scalar @$applied - 1; + $i += scalar @{$applied->{nodes}} - 1; $applications++; # only count end environment nodes } # newcommand nodes # - elsif ($node->{type} eq 'COMMAND' && - $node->{command} eq $mapping->{name} && - $mapping->{nparams}) { - + elsif ($node->{type} eq 'COMMAND' + && $node->{command} eq $mapping->{name} + && $mapping->{nparams} + ) { my @params = (); # children of COMMAND node will be first parameter @@ -975,10 +980,10 @@ my $applied = _applyParamsToTemplate($mapping->{template}, @params); # splice in the result - splice @{$tree->{nodes}}, $i, $j, @$applied; + splice @{$tree->{nodes}}, $i, $j, @{$applied->{nodes}}; # skip past all the new stuff - $i += scalar @$applied - 1; + $i += scalar @{$applied->{nodes}} - 1; $applications++; } @@ -995,7 +1000,7 @@ while (($wordend && $text =~ /\\\Q$command\E(\W|$)/g) || (!$wordend && $text =~ /\\\Q$command\E/g)) { - #warn "found occurrence of mapping $command"; + _debug("found occurrence of mapping $command", undef); my $idx = index $node->{content}, '\\' . $command, 0; @@ -1006,10 +1011,10 @@ my $applied = $mapping->{template}->copy(); # splice the new nodes in - splice @{$tree->{nodes}}, $i, 1, $leftnode, @$applied, $rightnode; + splice @{$tree->{nodes}}, $i, 1, $leftnode, @{$applied->{nodes}}, $rightnode; # adjust i so we end up on rightnode when we're done - $i += scalar @$applied + 1; + $i += scalar @{$applied->{nodes}} + 1; # get the next node $node = $tree->{$node}[$i]; @@ -1051,9 +1056,9 @@ next if (!$mapping->{name}); # skip fragged commands if ($parser->{USED_COMMANDS}->{$mapping->{name}}) { - #print "applying (nc) mapping $mapping->{name}\n"; + _debug("applying (nc) mapping $mapping->{name}", undef); } else { - #print "NOT applying (nc) mapping $mapping->{name}\n"; + _debug("NOT applying (nc) mapping $mapping->{name}", undef); next; } @@ -1061,7 +1066,7 @@ # $parser->{MAPPEDCMDS}->{"\\$mapping->{name}"} = 1; - #print "found a mapping with name $mapping->{name}, $mapping->{nparams} params\n"; + _debug("found a mapping with name $mapping->{name}, $mapping->{nparams} params", undef); # remove the mapping declaration # @@ -1070,10 +1075,9 @@ # apply the mapping my $count = $parser->_applyMapping($tree, $mapping, $i); - #if ($count > 0) { - # print "printing altered subtree\n"; - # $tree->print(); - #} + if ($count > 0) { + _debug("printing altered subtree", sub { $tree->_warn() }); + } $i--; # since we removed the cmd node, check this index again } @@ -1087,7 +1091,7 @@ my $mapping = $parser->_makeEnvMapping($tree, $i); next if (!$mapping->{name}); # skip fragged commands. - #print "applying (ne) mapping $mapping->{name}\n"; + _debug("applying (ne) mapping $mapping->{name}", undef); # remove the mapping declaration # @@ -1104,7 +1108,7 @@ $prev->{type} eq 'TEXT' && $prev->{content} =~ /\\def\s*$/o) { - #print "found def style mapping $node->{command}\n"; + _debug("found def style mapping $node->{command}", undef); # remove the \def $prev->{content} =~ s/\\def\s*$//o; @@ -1118,9 +1122,9 @@ next if (!$mapping->{name}); # skip fragged commands if ($parser->{USED_COMMANDS}->{$mapping->{name}}) { - #print "applying (def) mapping $mapping->{name}\n"; + _debug("applying (def) mapping $mapping->{name}", undef); } else { - #print "NOT applying (def) mapping $mapping->{name}\n"; + _debug("NOT applying (def) mapping $mapping->{name}", undef); next; } @@ -1128,8 +1132,7 @@ # $parser->{MAPPEDCMDS}->{"\\$mapping->{name}"} = 1; - #print "template is \n"; - #$mapping->{template}->print(); + _debug("template is", sub { $mapping->{template}->_warn() }); # remove the command node splice @{$tree->{nodes}}, $i, 1; @@ -1161,32 +1164,40 @@ my $node = $tree->{nodes}[$i]; - if ($node->{type} eq 'COMMAND' && - $node->{command} eq 'input') { - + if ($node->{type} eq 'COMMAND' + && $node->{command} eq 'input' + ) { my $file = $node->{children}->{nodes}[0]->{content}; - next if ($file =~ /pstex/); # ignore pstex images + next if $file =~ /pstex/; # ignore pstex images + + _debug("reading input file $file", undef); - #print "reading input file $file\n"; + my $contents; + my $filename = fileparse($file); + my $has_extension = qr/\.\S+$/; # read in contents of file - my $contents = _readFile($file); - if ($contents eq '' && not $file =~ /\.tex$/) { + if (-e $file && $filename =~ $has_extension) { + $contents = _readFile($file); + } + elsif ($filename !~ $has_extension) { $file = "$file.tex"; - $contents = _readFile($file); + $contents = _readFile($file) if -e $file; } # dump Psfig/TeX files, they aren't useful to us and have # nonconforming syntax. Use declaration line as our heuristic. # - if ($contents =~ /^\%\s*Psfig\/TeX\s*$/m) { - $contents = ''; - warn "ignoring Psfig input '$file'"; + if (defined $contents + && $contents =~ m!^ \% \s*? Psfig/TeX \s* $!mx + ) { + undef $contents; + carp "ignoring Psfig input `$file'"; } # actually do the parse of the sub-content # - if ($contents) { + if (defined $contents) { # parse into a tree my ($subtree,) = $parser->_basicparse($contents, $parser->{PARSE_ERRORS_FATAL}); @@ -1197,23 +1208,20 @@ $i--; } } - elsif ($node->{type} eq 'COMMAND' && - $node->{command} eq 'bibliography') { - + elsif ($node->{type} eq 'COMMAND' + && $node->{command} eq 'bibliography' + ) { # try to find a .bbl file # - my @FILES = <*>; - foreach my $file (@FILES) { - if ($file =~ /\.bbl$/) { - - my $contents = _readFile($file); - - if ($contents) { - - my ($subtree,) = $parser->_basicparse($contents, $parser->{PARSE_ERRORS_FATAL}); - splice @{$tree->{nodes}}, $i, 1, @$subtree; - $i--; - } + foreach my $file (<*.bbl>) { + + my $contents = _readFile($file); + + if (defined $contents) { + + my ($subtree,) = $parser->_basicparse($contents, $parser->{PARSE_ERRORS_FATAL}); + splice @{$tree->{nodes}}, $i, 1, @{$subtree->{nodes}}; + $i--; } } } @@ -1249,11 +1257,11 @@ $parser->_stage4($tree); - #print "done with parseStage4\n"; + _debug("done with parseStage4", undef); $parser->_stage5($tree, 0); - #print "done with parseStage5\n"; + _debug("done with parseStage5", undef); } ############################################################################### @@ -1442,7 +1450,7 @@ $nodecopy->{children} = $subtree; # set the child pointer to new subtree # return a new tree with the new node (subtree) as its only element - return LaTeX::TOM::Tree->new([$nodecopy], $parser); + return LaTeX::TOM::Tree->new([$nodecopy]); } return undef; @@ -1595,9 +1603,9 @@ my $template = shift; my @params = @_; - for (my $i = 0; $i < @$template; $i++) { + for (my $i = 0; $i < @{$template->{nodes}}; $i++) { - my $node = $template->[$i]; + my $node = $template->{nodes}[$i]; if ($node->{type} eq 'TEXT') { @@ -1625,11 +1633,11 @@ # splice the new text nodes, along with the parameter subtree, into # the old location # - splice @$template, $i, 1, $leftnode, @$param, $rightnode; + splice @{$template->{nodes}}, $i, 1, $leftnode, @{$param->{nodes}}, $rightnode; # skip forward to where $rightnode is in $template on next iteration # - $i += scalar @$param; + $i += scalar @{$param->{nodes}}; } } @@ -1647,76 +1655,71 @@ # '%' prefixed LaTeX comment lines # sub _getTextAndCommentNodes { - my $text = shift; - my $begins = shift; - my $ends = shift; + my ($text, $begins, $ends) = @_; - my $nodetext = substr $text, $begins, $ends - $begins; + my $node_text = substr $text, $begins, $ends - $begins; - #warn "getTextAndCommentNodes: looking at [$nodetext]"; + _debug("getTextAndCommentNodes: looking at [$node_text]", undef); - my @lines = split (/((?: *(?new({ + type => uc $mode_type, + start => $begins + $start_pos, + end => $begins + $start_pos + length($output) - 1, + content => $output, + }); + }; - my $startpos = 0; - my @out = (); - my $comment = 0; # comment mode - my $first = 1; + my @lines = split (/( + (?:\s* # whitespace + (?new( - {type => $comment ? 'COMMENT' : 'TEXT', - start => $begins + $startpos, - end => $begins + $startpos + length($output) - 1, - content => $output}); - - push @nodes, $newnode; + push @nodes, $make_node->($mode_type, $begins, $start_pos, $output); - $startpos += length($output); # update start position - @out = ($line); + $start_pos += length($output); # update start position + $output = $line; - $comment = $mode; + $mode_type = $line_type; } } - # make node from last chunk - my $output = join('', @out); - - my $newnode = LaTeX::TOM::Node->new( - {type => $comment ? 'COMMENT' : 'TEXT', - start => $begins + $startpos, - end => $begins + $startpos + length($output) - 1, - content => $output}); - - push @nodes, $newnode; + push @nodes, $make_node->($mode_type, $begins, $start_pos, $output) if defined $output; return @nodes; } @@ -1724,19 +1727,35 @@ # Read in the contents of a text file on disk. Return in string scalar. # sub _readFile { - my $file = shift || '/dev/stdin'; + my ($file, $raise_error) = @_; - my $contents = ""; + $raise_error ||= false; - open INFILE, $file or return ""; + my $opened = open(my $fh, '<', $file); - while (my $line = ) { - $contents .= $line; + unless ($opened) { + croak "Cannot open $file: $!" if $raise_error; + return undef; } - close INFILE; + my $contents = do { local $/; <$fh> }; + close($fh); return $contents; } +sub _debug { + my ($message, $code) = @_; + + my $DEBUG = $LaTeX::TOM::DEBUG; + + return unless $DEBUG >= 1 && $DEBUG <= 2; + + my ($filename, $line) = (caller)[1,2]; + my $caller = join ':', (fileparse($filename))[0], $line; + + warn "$caller: $message\n" if $DEBUG >= 1 && defined $message; + $code->() if $DEBUG == 2 && defined $code; +} + 1; diff -Nru liblatex-tom-perl-1.00/lib/LaTeX/TOM/Tree.pm liblatex-tom-perl-1.03/lib/LaTeX/TOM/Tree.pm --- liblatex-tom-perl-1.00/lib/LaTeX/TOM/Tree.pm 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/lib/LaTeX/TOM/Tree.pm 2011-12-23 21:16:43.000000000 +0000 @@ -12,23 +12,19 @@ use Carp qw(croak); -our $VERSION = '0.01'; +our $VERSION = '0.04'; # "constructor" # sub new { - my $class = shift; - my $nodes = shift || []; # empty array for tree structure - my $parser = shift; - - my $opts = $parser->{config}{MATHBRACKETS}; + my $class = shift; + my $nodes = shift || []; # empty array for tree structure my $self = { - config => { MATHBRACKETS => $opts }, - nodes => $nodes, + nodes => $nodes, }; - return bless $self, ref($class) || $class; + return bless $self; } # make a copy of a tree, recursively @@ -56,59 +52,71 @@ } # each subtree is a tree - return bless [@output]; + return __PACKAGE__->new([@output]); +} + +sub print { + shift->_debug_tree(@_, sub { print STDOUT $_[0] }); +} +sub _warn { + shift->_debug_tree(@_, sub { print STDERR $_[0] }); } # Print out the LaTeX "TOM" tree. Good for debugging our parser. # -sub print { +sub _debug_tree { my $tree = shift; - my $level = shift || 0; + my $output_handler = pop; + my ($level) = @_; + + $level ||= 0; foreach my $node (@{$tree->{nodes}}) { - my $spacer = ' ' x ($level*2); + my $spacer = ' ' x ($level * 2); - print $spacer; + $output_handler->($spacer); # print grouping/command info if ($node->{type} eq 'COMMAND') { - if ($node->{opts}) { - print "(COMMAND) \\$node->{command} [$node->{opts}] @ [$node->{start}, $node->{end}]"; - } else { - print "(COMMAND) \\$node->{command} @ [$node->{start}, $node->{end}]"; - } + $output_handler->(sprintf + "($node->{type}) \\$node->{command} %s @ [$node->{start}, $node->{end}]", + $node->{opts} ? "[$node->{opts}]" : "\b", + ); } elsif ($node->{type} eq 'GROUP') { - print "(GROUP) [$node->{start}, $node->{end}]"; + $output_handler->("($node->{type}) [$node->{start}, $node->{end}]"); } elsif ($node->{type} eq 'ENVIRONMENT') { - print "(ENVIRONMENT) $node->{class} @ inner [$node->{start}, $node->{end}] outer [$node->{ostart}, $node->{oend}]"; + $output_handler->("($node->{type}) $node->{class} @ inner [$node->{start}, $node->{end}] outer [$node->{ostart}, $node->{oend}]"); } - elsif ($node->{type} eq 'TEXT' || $node->{type} eq 'COMMENT') { - my $spaceout = "$spacer $node->{type} |"; - $spaceout =~ s/[A-Z]/ /go; - my $printtext = $node->{content}; - my $maxlen = 80 - length($spaceout); - $printtext =~ s/^(.{0,$maxlen}).*$/$1/gm; - $printtext =~ s/\n/\n$spaceout/gs; - print "(".$node->{type}.") |$printtext\""; + elsif ($node->{type} =~ /^(?:TEXT|COMMENT)$/) { + my $space_out = do { + local $_ = "$spacer $node->{type} |"; + s/[A-Z]/ /go; + $_; + }; + my $max_len = 80 - length($space_out); + my $print_text = do { + local $_ = $node->{content}; + s/^(.{0,$max_len}).*$/$1/gm; + s/\n/\n$space_out/gs; + $_; + }; + $output_handler->("($node->{type}) |$print_text\""); } - if ($node->{math}) { - print " ** math mode **"; - } - if ($node->{plaintext}) { - print " ** plaintext **"; - } + $output_handler->(' ** math mode **') if $node->{math}; + $output_handler->(' ** plaintext **') if $node->{plaintext}; - print "\n"; + $output_handler->("\n"); # recur if (defined $node->{children}) { - $node->{children}->print($level+1); + my ($wrapper) = (caller(1))[3] =~ /.+::(.+)$/; + $node->{children}->$wrapper($level + 1); } } } @@ -208,9 +216,10 @@ elsif ($node->{type} eq 'ENVIRONMENT') { # handle special math mode envs - if (defined $tree->{config}{MATHBRACKETS}->{$node->{class}}) { + my $MATHBRACKETS = \%LaTeX::TOM::MATHBRACKETS; + if (defined $MATHBRACKETS->{$node->{class}}) { # print with left and lookup right brace. - $str .= $node->{class} . $node->{children}->toLaTeX($node) . $tree->{config}{MATHBRACKETS}->{$node->{class}}; + $str .= $node->{class} . $node->{children}->toLaTeX($node) . $MATHBRACKETS->{$node->{class}}; } # standard \begin/\end envs diff -Nru liblatex-tom-perl-1.00/lib/LaTeX/TOM.pm liblatex-tom-perl-1.03/lib/LaTeX/TOM.pm --- liblatex-tom-perl-1.00/lib/LaTeX/TOM.pm 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/lib/LaTeX/TOM.pm 2011-12-23 21:16:43.000000000 +0000 @@ -2,7 +2,7 @@ # # LaTeX::TOM (TeX Object Model) # -# Version 1.00 +# Version 1.03 # # ---------------------------------------------------------------------------- # @@ -31,11 +31,13 @@ use strict; use base qw(LaTeX::TOM::Parser); +use constant true => 1; -our $VERSION = '1.00'; +our $VERSION = '1.03'; our (%INNERCMDS, %MATHENVS, %MATHBRACKETS, - %BRACELESS, %TEXTENVS, $PARSE_ERRORS_FATAL); + %BRACELESS, %TEXTENVS, $PARSE_ERRORS_FATAL, + $DEBUG); # BEGIN CONFIG SECTION ######################################################## @@ -43,7 +45,7 @@ # environment of that grouping. For instance {\bf text}. Without listing the # command names here, the parser will treat such sequences as plain text. # -%INNERCMDS = map { $_ => 1 } ( +%INNERCMDS = map { $_ => true } ( 'bf', 'md', 'em', @@ -72,7 +74,7 @@ # these commands put their environments into math mode # -%MATHENVS = map { $_ => 1 } ( +%MATHENVS = map { $_ => true } ( 'align', 'equation', 'eqnarray', @@ -87,7 +89,7 @@ # these commands/environments put their children in text (non-math) mode # -%TEXTENVS = map { $_ => 1 } ( +%TEXTENVS = map { $_ => true } ( 'tiny', 'scriptsize', 'footnotesize', @@ -169,7 +171,7 @@ # these commands require no braces, and their parameters are simply the # "word" following the command declaration # -%BRACELESS = map { $_ => 1 } ( +%BRACELESS = map { $_ => true } ( 'oddsidemargin', 'evensidemargin', 'topmargin', @@ -186,22 +188,18 @@ # $PARSE_ERRORS_FATAL = 0; +# debugging mode (internal use) +# +# 0 = off, 1 = messages, 2 = messages and code +# +$DEBUG = 0; + # END CONFIG SECTION ########################################################## sub new { - my $self = shift; - my $obj = LaTeX::TOM::Parser->new(@_); + my $class = shift; - $obj->{config} = { - BRACELESS => \%BRACELESS, - INNERCMDS => \%INNERCMDS, - MATHENVS => \%MATHENVS, - MATHBRACKETS => \%MATHBRACKETS, - PARSE_ERRORS_FATAL => $PARSE_ERRORS_FATAL, - TEXTENVS => \%TEXTENVS, - }; - - return $obj; + return __PACKAGE__->SUPER::new(@_); } 1; @@ -763,11 +761,11 @@ ~1000 research publications from the Computing Research Repository, so I deemed it ``good enough'' to use for purposes similar to mine. -Please let the authors know of parser errors if you discover any. +Please let the maintainer know of parser errors if you discover any. =head1 CREDITS -Thanks to (in order of appearance) who have contributed valuable suggestions & patches: +Thanks to (in order of appearance) who have contributed valuable suggestions and patches: Otakar Smrz Moritz Lenz @@ -780,16 +778,11 @@ Maintained by Steven Schubiger -=head1 WEB SITE - -Please see http://br.endernet.org/~akrowne/elaine/latex_tom/ for this -module's home on the WWW. - =head1 LICENSE This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. -See L +See L =cut diff -Nru liblatex-tom-perl-1.00/LICENSE liblatex-tom-perl-1.03/LICENSE --- liblatex-tom-perl-1.00/LICENSE 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/LICENSE 1970-01-01 00:00:00.000000000 +0000 @@ -1,7 +0,0 @@ -Copyright (c) 2002 Aaron Krowne - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff -Nru liblatex-tom-perl-1.00/Makefile.PL liblatex-tom-perl-1.03/Makefile.PL --- liblatex-tom-perl-1.00/Makefile.PL 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/Makefile.PL 2011-12-23 21:16:43.000000000 +0000 @@ -1,4 +1,4 @@ -# Note: this file was auto-generated by Module::Build::Compat version 0.34 +# Note: this file was auto-generated by Module::Build::Compat version 0.3800 use ExtUtils::MakeMaker; WriteMakefile ( @@ -8,7 +8,9 @@ 'EXE_FILES' => [], 'VERSION_FROM' => 'lib/LaTeX/TOM.pm', 'PREREQ_PM' => { - 'Test::More' => 0 + 'Test::More' => 0, + 'File::Basename' => 0, + 'Carp' => 0 } ) ; diff -Nru liblatex-tom-perl-1.00/MANIFEST liblatex-tom-perl-1.03/MANIFEST --- liblatex-tom-perl-1.00/MANIFEST 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/MANIFEST 2011-12-23 21:16:43.000000000 +0000 @@ -5,9 +5,9 @@ lib/LaTeX/TOM/Node.pm lib/LaTeX/TOM/Parser.pm lib/LaTeX/TOM/Tree.pm -LICENSE Makefile.PL MANIFEST This list of files +META.json META.yml README t/00-load.t @@ -15,8 +15,24 @@ t/02-parser.t t/03-tree.t t/04-node.t +t/bibliography.t +t/by_condition.t +t/by_name.t +t/data/bibliography.t/sample.bbl +t/data/bibliography.t/sample.in +t/data/input.t/00-image_skip.pstex_t +t/data/input.t/01-basic.in +t/data/input.t/01-basic.tex +t/data/input.t/02-guess.in +t/data/input.t/02-guess.tex +t/data/input.t/03-empty.in +t/data/input.t/03-empty.tex +t/data/input.t/04-psfig_ignore.tex t/data/input.tex +t/data/mapping.t/mapping.in t/data/tex.in +t/input.t +t/mapping.t t/pod-coverage.t t/pod.t TODO diff -Nru liblatex-tom-perl-1.00/META.json liblatex-tom-perl-1.03/META.json --- liblatex-tom-perl-1.00/META.json 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/META.json 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,59 @@ +{ + "abstract" : "A module for parsing, analyzing, and manipulating LaTeX documents.", + "author" : [ + "Steven Schubiger " + ], + "dynamic_config" : 1, + "generated_by" : "Module::Build version 0.38, CPAN::Meta::Converter version 2.110930", + "license" : [ + "perl_5" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : "2" + }, + "name" : "LaTeX-TOM", + "prereqs" : { + "build" : { + "requires" : { + "Test::More" : 0 + } + }, + "configure" : { + "requires" : { + "Module::Build" : "0.38" + } + }, + "runtime" : { + "requires" : { + "Carp" : 0, + "File::Basename" : 0 + } + } + }, + "provides" : { + "LaTeX::TOM" : { + "file" : "lib/LaTeX/TOM.pm", + "version" : "1.03" + }, + "LaTeX::TOM::Node" : { + "file" : "lib/LaTeX/TOM/Node.pm", + "version" : "0.03" + }, + "LaTeX::TOM::Parser" : { + "file" : "lib/LaTeX/TOM/Parser.pm", + "version" : "0.07" + }, + "LaTeX::TOM::Tree" : { + "file" : "lib/LaTeX/TOM/Tree.pm", + "version" : "0.04" + } + }, + "release_status" : "stable", + "resources" : { + "license" : [ + "http://dev.perl.org/licenses/" + ] + }, + "version" : "1.03" +} diff -Nru liblatex-tom-perl-1.00/META.yml liblatex-tom-perl-1.03/META.yml --- liblatex-tom-perl-1.00/META.yml 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/META.yml 2011-12-23 21:16:43.000000000 +0000 @@ -1,30 +1,34 @@ --- -name: LaTeX-TOM -version: 1.00 +abstract: 'A module for parsing, analyzing, and manipulating LaTeX documents.' author: - 'Steven Schubiger ' -abstract: 'A module for parsing, analyzing, and manipulating LaTeX documents.' -license: perl -resources: - license: http://dev.perl.org/licenses/ build_requires: Test::More: 0 configure_requires: - Module::Build: 0.34 + Module::Build: 0.38 +dynamic_config: 1 +generated_by: 'Module::Build version 0.38, CPAN::Meta::Converter version 2.110930' +license: perl +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: 1.4 +name: LaTeX-TOM provides: LaTeX::TOM: file: lib/LaTeX/TOM.pm - version: 1.00 + version: 1.03 LaTeX::TOM::Node: file: lib/LaTeX/TOM/Node.pm - version: 0.01 + version: 0.03 LaTeX::TOM::Parser: file: lib/LaTeX/TOM/Parser.pm - version: 0.01 + version: 0.07 LaTeX::TOM::Tree: file: lib/LaTeX/TOM/Tree.pm - version: 0.01 -generated_by: Module::Build version 0.34 -meta-spec: - url: http://module-build.sourceforge.net/META-spec-v1.4.html - version: 1.4 + version: 0.04 +requires: + Carp: 0 + File::Basename: 0 +resources: + license: http://dev.perl.org/licenses/ +version: 1.03 diff -Nru liblatex-tom-perl-1.00/README liblatex-tom-perl-1.03/README --- liblatex-tom-perl-1.00/README 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/README 2011-12-23 21:16:43.000000000 +0000 @@ -44,7 +44,6 @@ COMPONENTS LaTeX::TOM::Parser - The parser recognizes 3 parameters upon creation. The parameters, in order, are @@ -74,7 +73,6 @@ The parser returns a `LaTeX::TOM::Tree' ($document in the SYNOPSIS). LaTeX::TOM::Node - Nodes may be of the following types: TEXT @@ -135,7 +133,6 @@ some internal point. LaTeX::TOM::Trees - As mentioned before, the Tree is the return result of a parse. The tree is nothing more than an arrayref of Nodes, some of which may @@ -146,7 +143,6 @@ METHODS LaTeX::TOM - new Instantiate a new parser object. @@ -154,7 +150,6 @@ and described. LaTeX::TOM::Parser - The methods for the parser (aside from the constructor, discussed above) are : @@ -166,7 +161,6 @@ Parse the string *string* and return a `LaTeX::TOM::Tree'. LaTeX::TOM::Tree - This section contains methods for the Trees returned by the parser. copy @@ -219,7 +213,6 @@ walk the tree yourself, starting with the first node. LaTeX::TOM::Node - This section contains the methods for nodes of the parsed Trees. getNodeType @@ -332,11 +325,11 @@ of ~1000 research publications from the Computing Research Repository, so I deemed it ``good enough'' to use for purposes similar to mine. - Please let the authors know of parser errors if you discover any. + Please let the maintainer know of parser errors if you discover any. CREDITS Thanks to (in order of appearance) who have contributed valuable - suggestions & patches: + suggestions and patches: Otakar Smrz Moritz Lenz @@ -348,13 +341,9 @@ Maintained by Steven Schubiger -WEB SITE - Please see http://br.endernet.org/~akrowne/elaine/latex_tom/ for this - module's home on the WWW. - LICENSE This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. - See http://www.perl.com/perl/misc/Artistic.html + See http://dev.perl.org/licenses/ diff -Nru liblatex-tom-perl-1.00/t/bibliography.t liblatex-tom-perl-1.03/t/bibliography.t --- liblatex-tom-perl-1.00/t/bibliography.t 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/bibliography.t 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use File::Spec; +use FindBin qw($Bin); +use LaTeX::TOM; +use Test::More tests => 1; + +my $abs_path = File::Spec->catfile($Bin, 'data', 'bibliography.t'); + +my $parser = LaTeX::TOM->new(0,1,0); + +my $tex = do { local $/; }; + +chdir $abs_path; + +my $tree_string = $parser->parse($tex); +my $tree_file = $parser->parseFile(File::Spec->catfile($abs_path, 'sample.in')); + +is_deeply( + [ grep /\S/, split /\n/, $tree_string->toLaTeX ], + [ grep /\S/, split /\n/, $tree_file->toLaTeX ], +'sample'); + +__DATA__ +\documentclass[10pt]{article} +\begin{document} +\bibliography{sample} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/by_condition.t liblatex-tom-perl-1.03/t/by_condition.t --- liblatex-tom-perl-1.00/t/by_condition.t 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/by_condition.t 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,39 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use LaTeX::TOM; +use Test::More tests => 1; + +my $parser = LaTeX::TOM->new; + +my $tex = do { local $/; }; + +my $tree = $parser->parse($tex); + +my $nodes = $tree->getNodesByCondition(sub { + my $node = shift; + return ( + $node->getNodeType eq 'COMMAND' + && $node->getCommandName =~ /section$/ + ); +}); + +my $count = 3; + +my $ok = ( + @$nodes == $count + && (grep { $_->getNodeType eq 'COMMAND' } @$nodes) == $count + && (grep { $_->getCommandName =~ /section$/ } @$nodes) == $count +); + +ok($ok, 'getNodesByCondition'); + +__DATA__ +\documentclass[10pt]{article} +\begin{document} +\section{abc} +\subsection{def} +\subsubsection{ghi} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/by_name.t liblatex-tom-perl-1.03/t/by_name.t --- liblatex-tom-perl-1.00/t/by_name.t 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/by_name.t 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,41 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use LaTeX::TOM; +use Test::More tests => 2; + +my $parser = LaTeX::TOM->new; + +my $tex = do { local $/; }; + +my $tree = $parser->parse($tex); + +{ + my $nodes = $tree->getCommandNodesByName('section'); + + my $ok = (@$nodes == 1 + && $nodes->[0]->getNodeType eq 'COMMAND' + && $nodes->[0]->getCommandName eq 'section' + ); + + ok($ok, 'getCommandNodesByName'); +} + +{ + my $nodes = $tree->getEnvironmentsByName('document'); + + my $ok = (@$nodes == 1 + && $nodes->[0]->getNodeType eq 'ENVIRONMENT' + && $nodes->[0]->getEnvironmentClass eq 'document' + ); + + ok($ok, 'getEnvironmentsByName'); +} + +__DATA__ +\documentclass[10pt]{article} +\begin{document} +\section{abc} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/data/bibliography.t/sample.bbl liblatex-tom-perl-1.03/t/data/bibliography.t/sample.bbl --- liblatex-tom-perl-1.00/t/data/bibliography.t/sample.bbl 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/bibliography.t/sample.bbl 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,3 @@ +\begin{thebibliography}{99} +\bibitem{reference} text +\end{thebibliography} diff -Nru liblatex-tom-perl-1.00/t/data/bibliography.t/sample.in liblatex-tom-perl-1.03/t/data/bibliography.t/sample.in --- liblatex-tom-perl-1.00/t/data/bibliography.t/sample.in 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/bibliography.t/sample.in 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,6 @@ +\documentclass[10pt]{article} +\begin{document} +\begin{thebibliography}{99} +\bibitem{reference} text +\end{thebibliography} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/data/input.t/00-image_skip.pstex_t liblatex-tom-perl-1.03/t/data/input.t/00-image_skip.pstex_t --- liblatex-tom-perl-1.00/t/data/input.t/00-image_skip.pstex_t 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/input.t/00-image_skip.pstex_t 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1 @@ +skipped diff -Nru liblatex-tom-perl-1.00/t/data/input.t/01-basic.in liblatex-tom-perl-1.03/t/data/input.t/01-basic.in --- liblatex-tom-perl-1.00/t/data/input.t/01-basic.in 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/input.t/01-basic.in 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,7 @@ +\documentclass[10pt]{article} +\begin{document} +\begin{verbatim} +Tade kuu mushi mo sukizuki + -- japanese proverb +\end{verbatim} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/data/input.t/01-basic.tex liblatex-tom-perl-1.03/t/data/input.t/01-basic.tex --- liblatex-tom-perl-1.00/t/data/input.t/01-basic.tex 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/input.t/01-basic.tex 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,4 @@ +\begin{verbatim} +Tade kuu mushi mo sukizuki + -- japanese proverb +\end{verbatim} diff -Nru liblatex-tom-perl-1.00/t/data/input.t/02-guess.in liblatex-tom-perl-1.03/t/data/input.t/02-guess.in --- liblatex-tom-perl-1.00/t/data/input.t/02-guess.in 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/input.t/02-guess.in 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,4 @@ +\documentclass[10pt]{article} +\begin{document} +No great discovery was ever made without a bold guess +\end{document} diff -Nru liblatex-tom-perl-1.00/t/data/input.t/02-guess.tex liblatex-tom-perl-1.03/t/data/input.t/02-guess.tex --- liblatex-tom-perl-1.00/t/data/input.t/02-guess.tex 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/input.t/02-guess.tex 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1 @@ +No great discovery was ever made without a bold guess diff -Nru liblatex-tom-perl-1.00/t/data/input.t/03-empty.in liblatex-tom-perl-1.03/t/data/input.t/03-empty.in --- liblatex-tom-perl-1.00/t/data/input.t/03-empty.in 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/input.t/03-empty.in 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,3 @@ +\documentclass[10pt]{article} +\begin{document} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/data/input.t/04-psfig_ignore.tex liblatex-tom-perl-1.03/t/data/input.t/04-psfig_ignore.tex --- liblatex-tom-perl-1.00/t/data/input.t/04-psfig_ignore.tex 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/input.t/04-psfig_ignore.tex 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1 @@ +% Psfig/TeX diff -Nru liblatex-tom-perl-1.00/t/data/mapping.t/mapping.in liblatex-tom-perl-1.03/t/data/mapping.t/mapping.in --- liblatex-tom-perl-1.00/t/data/mapping.t/mapping.in 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/data/mapping.t/mapping.in 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,6 @@ +\documentclass[10pt]{article} +\begin{document} +\begin{center} +foo {\bf bar} baz +\end{center} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/input.t liblatex-tom-perl-1.03/t/input.t --- liblatex-tom-perl-1.00/t/input.t 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/input.t 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,106 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use constant true => 1; +use constant false => 0; + +use File::Spec; +use FindBin qw($Bin); +use LaTeX::TOM; +use Test::More tests => 6; + +my $set_input = sub { ${$_[0]} =~ s/\$INPUT/\\input{$_[1]}/ }; + +my $abs_path = File::Spec->catfile($Bin, 'data', 'input.t'); +my $rel_path = File::Spec->abs2rel($abs_path); + +my $parser = LaTeX::TOM->new(0,1,0); + +my $data = do { local $/; }; + +my @tests = ( + # input file # tex file # message # input file must exist + [ '00-image_skip.pstex_t', undef, 'skip pstex' , true ], + [ '01-basic.tex', '01-basic.in', 'basic' , true ], + [ '02-guess', '02-guess.in', 'guess' , false ], # file extension for '02-guess' missing on purpose + [ '03-empty.tex', '03-empty.in', 'empty', true ], + [ '04-psfig_ignore.tex', undef, 'ignore Psfig', true ], +); + +SKIP: +{ + skip 'test for release testing', 1 unless $ENV{RELEASE_TESTING}; + + # Check that all input files exist or bogus results may ensue. + my $exist = true; + foreach my $test (@tests) { + my ($input_file, $must_exist) = @$test[0,3]; + if ($must_exist) { + $exist &= -e File::Spec->catfile($abs_path, $input_file) ? true : false; + } + } + ok($exist, '\input test files exist'); +} + +sub check_unaltered_tex +{ + my $input_file = $_[0]->[0]; + + $input_file = File::Spec->catfile($rel_path, $input_file); + + my $tex = $data; + $set_input->(\$tex, $input_file); + + my $tree = $parser->parse($tex); + + return scalar grep /\\input\{\Q$input_file\E\}/, split /\n/, $tree->toLaTeX; +} + +{ + my $skipped = check_unaltered_tex($tests[0]); + my $message = $tests[0]->[2]; + + ok($skipped, $message); +} + +{ + foreach my $test (@tests[1..3]) { + my ($input_file, $tex_file, $message) = @$test; + + $input_file = File::Spec->catfile($rel_path, $input_file); + $tex_file = File::Spec->catfile($abs_path, $tex_file); + + my $tex = $data; + $set_input->(\$tex, $input_file); + + my $tree_string = $parser->parse($tex); + my $tree_file = $parser->parseFile($tex_file); + + is_deeply( + [ grep /\S/, split /\n/, $tree_string->toLaTeX ], + [ grep /\S/, split /\n/, $tree_file->toLaTeX ], + $message); + } +} + +{ + my $seen_warning = false; + + local $SIG{__WARN__} = sub + { + warn $_[0] and return unless $_[0] =~ /^ignoring Psfig/; + $seen_warning = true; + }; + + my $ignored = check_unaltered_tex($tests[4]); + my $message = $tests[4]->[2]; + + ok($ignored && $seen_warning, $message); +} + +__DATA__ +\documentclass[10pt]{article} +\begin{document} +$INPUT +\end{document} diff -Nru liblatex-tom-perl-1.00/t/mapping.t liblatex-tom-perl-1.03/t/mapping.t --- liblatex-tom-perl-1.00/t/mapping.t 1970-01-01 00:00:00.000000000 +0000 +++ liblatex-tom-perl-1.03/t/mapping.t 2011-12-23 21:16:43.000000000 +0000 @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use File::Spec; +use FindBin qw($Bin); +use LaTeX::TOM; +use Test::More tests => 1; + +my $abs_path = File::Spec->catfile($Bin, 'data', 'mapping.t'); + +my $parser = LaTeX::TOM->new(0,0,1); + +my $tex = do { local $/; }; + +my $tree_string = $parser->parse($tex); +my $tree_file = $parser->parseFile(File::Spec->catfile($abs_path, 'mapping.in')); + +is_deeply( + [ grep /\S/, split /\n/, $tree_string->toLaTeX ], + [ grep /\S/, split /\n/, $tree_file->toLaTeX ], +'mapping'); + +__DATA__ +\documentclass[10pt]{article} +\newenvironment{centered}{\begin{center}}{\end{center}} +\newcommand{\bold}[1]{{\bf #1}} +\begin{document} +\begin{centered} +foo \bold{bar} baz +\end{centered} +\end{document} diff -Nru liblatex-tom-perl-1.00/t/pod-coverage.t liblatex-tom-perl-1.03/t/pod-coverage.t --- liblatex-tom-perl-1.00/t/pod-coverage.t 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/t/pod-coverage.t 2011-12-23 21:16:43.000000000 +0000 @@ -5,6 +5,7 @@ use Test::More; +plan skip_all => 'tests for release testing' unless $ENV{RELEASE_TESTING}; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; diff -Nru liblatex-tom-perl-1.00/t/pod.t liblatex-tom-perl-1.03/t/pod.t --- liblatex-tom-perl-1.00/t/pod.t 2009-10-07 09:42:18.000000000 +0000 +++ liblatex-tom-perl-1.03/t/pod.t 2011-12-23 21:16:43.000000000 +0000 @@ -5,6 +5,7 @@ use Test::More; +plan skip_all => 'tests for release testing' unless $ENV{RELEASE_TESTING}; eval "use Test::Pod 1.14"; plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;