mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-23 21:40:19 +00:00
d0d45d4043
We test here, if any \end_{somethig} matches \begin_{something}. Exeptions are \end_index and \end_branch ATM, they should match \index and \branch respectively. Also added new testfile.
42 lines
842 B
Perl
Executable File
42 lines
842 B
Perl
Executable File
#! /usr/bin/env perl
|
|
# -*- mode: perl; -*-
|
|
|
|
use strict;
|
|
|
|
my @stack = ();
|
|
my $depth = 0;
|
|
my $input = $ARGV[0];
|
|
my $line = 0;
|
|
if (open(FI, $input)) {
|
|
while (my $l = <FI>) {
|
|
chomp($l);
|
|
$line++;
|
|
if ($l =~ /^\s*\\begin_([a-z]+)/) {
|
|
$stack[$depth] = $1;
|
|
$depth++;
|
|
}
|
|
elsif ($l =~ /^\s*\\(index|branch)\s/) {
|
|
# does not start with e.g. \begin_index, but ends with \end_index!!
|
|
$stack[$depth] = $1;
|
|
$depth++;
|
|
}
|
|
elsif ($l =~ /^\s*\\end_([a-z]+)/) {
|
|
my $expect = $1;
|
|
if ($depth > 0) {
|
|
if ($stack[$depth-1] eq $expect) {
|
|
$depth--;
|
|
}
|
|
else {
|
|
print "expected \\end_$stack[$depth-1], got \\end_$expect instead at $input:$line\n";
|
|
exit(-1);
|
|
}
|
|
}
|
|
else {
|
|
print "got \\end_$expect, but depth is already 0 at $input:$line\n";
|
|
exit(-2);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
exit(0);
|