]> git.lyx.org Git - lyx.git/blob - development/autotests/beginEndStructureCheck.pl
Improve format specification for 616.
[lyx.git] / development / autotests / beginEndStructureCheck.pl
1 #! /usr/bin/env perl
2 # -*- mode: perl; -*-
3
4 use strict;
5
6 my @stack = ();
7 my $depth = 0;
8 my $input = $ARGV[0];
9 my $line = 0;
10 if (open(FI, $input)) {
11   while (my $l = <FI>) {
12     chomp($l);
13     $line++;
14     if ($l =~ /^\s*\\begin_([a-z]+)/) {
15       $stack[$depth] = $1;
16       $depth++;
17     }
18     elsif ($l =~ /^\s*\\(index|branch)\s/) {
19       # does not start with e.g. \begin_index, but ends with \end_index!!
20       $stack[$depth] = $1;
21       $depth++;
22     }
23     elsif ($l =~ /^\s*\\end_([a-z]+)/) {
24       my $expect = $1;
25       if ($depth > 0) {
26         if ($stack[$depth-1] eq $expect) {
27           $depth--;
28         }
29         else {
30           print "expected \\end_$stack[$depth-1], got \\end_$expect instead at $input:$line\n";
31           exit(-1);
32         }
33       }
34       else {
35         print "got \\end_$expect, but depth is already 0 at $input:$line\n";
36         exit(-2);
37       }
38     }
39   }
40 }
41 exit(0);