diff options
author | Karl Berry <karl@freefriends.org> | 2017-02-24 22:07:42 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2017-02-24 22:07:42 +0000 |
commit | 990e60c6ed4437e5b632b7c9acf7f2237bbda871 (patch) | |
tree | 4dc9ea04f5fa46cc8ac59faa8dd62e4f8bc6835b /Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm | |
parent | 2e70942b44a972908c3180dd7a3c68be51afc466 (diff) |
latexindent (23feb17)
git-svn-id: svn://tug.org/texlive/trunk@43326 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm')
-rw-r--r-- | Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm b/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm new file mode 100644 index 00000000000..8a9a100dc26 --- /dev/null +++ b/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm @@ -0,0 +1,68 @@ +package LatexIndent::Tokens; +# 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 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See http://www.gnu.org/licenses/. +# +# Chris Hughes, 2017 +# +# For all communication, please visit: https://github.com/cmhughes/latexindent.pl +use strict; +use warnings; +use Exporter qw/import/; +use LatexIndent::Switches qw/$is_t_switch_active $is_tt_switch_active/; +our @EXPORT_OK = qw/token_check %tokens/; + +# each of the tokens begins the same way -- this is exploited during the hidden Children routine +my $beginningToken = "LTXIN-TK-"; +my $ifelsefiSpecial = "!-!"; + +# the %tokens hash is passed around many modules +our %tokens = ( + environment=>$beginningToken."ENVIRONMENT", + ifelsefiSpecial=>$ifelsefiSpecial, + ifelsefi=>$ifelsefiSpecial.$beginningToken."IFELSEFI", + item=>$beginningToken."ITEMS", + trailingComment=>"latexindenttrailingcomment", + blanklines=>$beginningToken."blank-line", + arguments=>$beginningToken."ARGUMENTS", + optionalArgument=>$beginningToken."OPTIONAL-ARGUMENT", + mandatoryArgument=>$beginningToken."MANDATORY-ARGUMENT", + roundBracket=>$beginningToken."ROUND-BRACKET", + verbatim=>$beginningToken."VERBATIM", + command=>$beginningToken."COMMAND", + key_equals_values_braces=>$beginningToken."KEY-VALUE-BRACES", + groupingBraces=>$beginningToken."GROUPING-BRACES", + unNamedgroupingBraces=>$beginningToken."UN-NAMED-GROUPING-BRACES", + special=>$beginningToken."SPECIAL", + heading=>$beginningToken."HEADING", + filecontents=>$beginningToken."FILECONTENTS", + preamble=>$beginningToken."preamble", + beginOfToken=>$beginningToken, + doubleBackSlash=>$beginningToken."DOUBLEBACKSLASH", + alignmentBlock=>$beginningToken."ALIGNMENTBLOCK", + endOfToken=>"-END", + ); + +sub token_check{ + my $self = shift; + + $self->logger("Token check",'heading') if $is_t_switch_active; + # we use tokens for trailing comments, environments, commands, etc, so check that they're not in the body + foreach( keys %tokens){ + while(${$self}{body} =~ m/$tokens{$_}/si){ + $self->logger("Found $tokens{$_} within body, updating replacement token to $tokens{$_}-LIN") if($is_t_switch_active); + $tokens{$_} .= "-LIN"; + } + } +} + + +1; |