summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/latexindent/LatexIndent/Tokens.pm
blob: 8a9a100dc260654c2dca9ba50e33bfd74882a7cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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;