summaryrefslogtreecommitdiff
path: root/web/noweb/src/icon/smldefs.nw
blob: 1a715ced4aa19589b106cd8b540d1d0429fcbee5 (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
% -*- mode: Noweb; noweb-code-mode: icon-mode -*-
\section{Finding definitions in Standard ML}
<<*>>=
procedure rcsinfo () 
  return "$Id: smldefs.nw,v 1.19 2008/10/06 01:03:05 nr Exp nr $" ||
         "$Name: v2_12 $"
end
procedure main(args)
  go()
end
<<*>>=
procedure postpass(name, arg)
  static kind, definers, id1, id2, reserved
  initial { kind := "bogus"
            definers := ["fun", "val", "structure", "signature", "and", "functor",
			 "type", "eqtype", "datatype", "withtype", "exception"]
	    id1 := &letters ++ &digits ++ '\'_'
            id2 := '!%&$+-/:<=>?@\\~^|#*`'
            reserved := set()
            every insert(reserved, !"*|:=#_" | "->" | "=>")
          }
  case name of {
    "begin" : arg ? kind := tab(upto(' ')|0)
    "text" : if kind == "code" then arg ?
        if =(""|" "|"  ") & =!definers & tab(many(' ')) then {
            skiptyvars(); optwhite()
            writedefn(1(id := tab(many(id1 | id2)), not member(reserved, id)))
        }
  }
  return
end

procedure prepass(name, arg)
  if name == "end" then writedefn(&null) # force newline
end

procedure skiptyvars()
  suspend ="'" || tab(many(&letters ++ &digits ++ '\'_')) |
          ="(" || tab(bal(')', '(', ')')) || =")"
end       

procedure optwhite()
 suspend tab(many(' \t')) | ""
end