File: syntax.sl

package info (click to toggle)
jed 0.99.16-5
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,312 kB
  • ctags: 4,736
  • sloc: ansic: 36,879; sh: 8,660; makefile: 379
file content (123 lines) | stat: -rw-r--r-- 2,942 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
% syntax.sl		-*- SLang -*-
% The functions here are used to manipulate the syntax keyword tables

static define add_hash_to_syntax_table (tbl, hash, len, n)
{
   variable i;
   hash = assoc_get_keys (hash);
   i = array_sort (hash);
   hash = strjoin (hash[i], "");
   () = define_keywords_n (tbl, hash, len, n);
   hash;
}


%!%+
%\function{add_keywords}
%\synopsis{add_keywords}
%\usage{String add_keywords (String tbl, String kws, Int len, Int n);}
%\description
% 
% Adds a set of keywords `kws', each of length `len', to the already
% existing syntax table `tbl'.  For convenience of the user, the function
% does alphabetical sorting and removes duplicate entries.
% 
% The previous list of keywords is returned.
%\seealso{define_keywords_n, create_syntax_table, add_keyword_n}
%!%-
define add_keywords (tbl, kws, len, n)
{
   variable okws, a, i, j, num, idx;
   variable hash;

   % add old keywords
   kws += define_keywords_n (tbl, "", len, n);

   num = strlen (kws) / len;
   !if (num) return "";

   hash = Assoc_Type[Int_Type];

   _for (0, num-1, 1)
     {
	i = ();
	hash [substr (kws, 1 + i * len, len)] = 1;
     }
   
   add_hash_to_syntax_table (tbl, hash, len, n);
}

%!%+
%\function{add_keyword_n}
%\synopsis{add_keyword_n}
%\usage{Void add_keyword_n (String tbl, String kw, Int n);}
%\description
% 
% Adds a single keyword `kw' to the already existing syntax table `tbl'.
%\seealso{define_keywords_n, create_syntax_table, add_keywords}
%!%-
define add_keyword_n (tbl, kw, n)
{
   variable len = strlen (kw);
   !if (len) return;
   () = add_keywords (tbl, kw, len, n);
}

%!%+
%\function{add_keyword}
%\synopsis{add_keyword}
%\usage{Void add_keyword (String_Type tbl, String_Type kw);}
%\description
% 
% Adds a single keyword `kw' to the already existing syntax table `tbl'.
%\seealso{define_keywords_n, create_syntax_table, add_keyword_n}
%!%-
define add_keyword ()
{
   add_keyword_n (0);
}

%!%+
%\function{remove_keywords}
%\synopsis{remove_keywords}
%\usage{String remove_keywords (String tbl, String kws, Int len, Int n);}
%\description
% Removes a set of keywords `kws', each of length `len', from the already
% existing syntax table `tbl'.
%
% The previous list of keywords is returned.
%\seealso{add_keywords, define_keywords_n, create_syntax_table, add_keyword_n}
%!%-
define remove_keywords (tbl, kws, len, n)
{
   variable okws, num, nrem, i, rm;
   variable hash;

   % the old keywords
   okws = define_keywords_n (tbl, "", len, n);
   num = strlen (okws) / len;

   nrem = strlen (kws) / len;
   !if (nrem)
     {
	() = define_keywords_n (tbl, okws, len, n);
	return okws;
     }

   hash = Assoc_Type[Int_Type];
   _for (0, num-1, 1)
     {
	i = ();
	hash [substr (okws, 1 + i * len, len)] = 1;
     }

   % remove unwanted entries
   _for (0, nrem-1, 1)
     {
	i = ();
	assoc_delete_key (hash, substr (kws, 1 + i * len, len));
     }

   () = add_hash_to_syntax_table (tbl, hash, len, n);
   okws;
}