aboutsummaryrefslogtreecommitdiffhomepage
path: root/coq/coqtags
blob: b6c72c784f944f0c9f313d3af04ed45e76761627 (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
#!/usr/local/bin/perl4
$/=0777;

if($#ARGV<$[) {die "No Files\n";}
open(tagfile,">TAGS") || die "Couldn't open TAGS: $!\n";

while(<>)	
{ 
  print "Tagging $ARGV\n";
  $a=$_;
  $cp=1;
  $lp=1;
  $tagstring="";

  while(1) 
  { 

#   ---- Get the next statement starting on a newline ---- 

    if($a=~/^[ \t\n]*\(\*/)
    { while($a=~/^\s*\(\*/) 
      { $d=1; $a=$'; $cp+=length $&; $lp+=($&=~tr/\n/\n/);
        while($d>0 && $a=~/\(\*|\*\)/)
        { $a=$'; $cp+=2+length $`; $lp+=($`=~tr/\n/\n/);
          if($& eq "(*") {$d++} else {$d--};
        }
        if($d!=0) {die "Unbalanced Comment?";}
      }
    }

    if($cp>1 && $a=~/.*\n/) {$a=$'; $cp+=length $&; $lp++;}
    while($a=~/^\n/) {$cp++;$lp++;$a=$'}

    if($a=~/^[^\.]*\./) 
    { $stmt=$&; $newa=$'; $newcp=$cp+length $&; $newlp=$lp+($&=~tr/\n/\n/); }
    else { last;}

# ---- The above embarrasses itself if there are semicolons inside comments 
# ---- inside commands. Could do better.

#  print "----- (",$lp,",",$cp,")\n", $stmt, "\n";

    if($stmt=~/^([ \t]*((Fact)|(Goal)|(Lemma)|(Remark)|(Theorem))\s+([\w\']+))\s*:/)
       { $tagstring.=$1."\177".$8."\001".$lp.",".$cp."\n"; }

    elsif($stmt=~/^([ \t]*((Axiom)|(Hypothesis)|(Parameter)|(Variable))\s+([\w\']+))\s*:/)
       { $tagstring.=$1."\177".$7."\001".$lp.",".$cp."\n"; }

    elsif($stmt=~/^([ \t]*((Definition)|(Fixpoint)|(Inductive))\s+([\w\']+))\s*[:[]/)
       { $tagstring.=$1."\177".$6."\001".$lp.",".$cp."\n"; }

    $cp=$newcp; $lp=$newlp; $a=$newa;
  }  
  print tagfile "\f\n".$ARGV.",".(length $tagstring)."\n".$tagstring;
}
close tagfile;