~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/System/Language/mathemagix_language.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2009-04-26 19:35:14 UTC
  • mfrom: (1.1.10 upstream) (4.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090426193514-9yo3oggdslgdls4b
Tags: 1:1.0.7.2-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* texmacs crashes if /usr/share/texmacs/TeXmacs/misc/pixmaps/unknown.ps
  is not present. Do not remove it. (Closes: #484073, #497021)
* update patches 03_mupad.dpatch, 04_axiom.dpatch, 11-desktop-file.dpatch
* fix the mime problem in gnome. Thanks to Andrea Gamba for the fix.
[kohda]
* Refined a fix for the mime problem in gnome a bit.
* Try to fix /bin/sh problem (debian/fixsh) but it is not complete fix yet.
* Try to fix hard coded settings for ipa fonts(patches/09_ipa.dpatch), 
  especially for Debian where no ipa fonts exist yet.
* Fixed obsolete Build-Depends: changed libltdl3-dev to 
  libltdl-dev | libltdl7-dev (the latter for Ubuntu?)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : mathemagix_language.cpp
 
4
* DESCRIPTION: the "mathemagix" language
 
5
* COPYRIGHT  : (C) 2008  Francis Jamet
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license version 3 or later.
 
8
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
 
9
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
 
10
******************************************************************************/
 
11
 
 
12
#include "analyze.hpp"
 
13
#include "impl_language.hpp"
 
14
#include "Scheme/object.hpp"
 
15
 
 
16
static void parse_number (string s, int& pos);
 
17
static void parse_string (string s, int& pos);
 
18
static void parse_alpha (string s, int& pos);
 
19
 
 
20
mathemagix_language_rep::mathemagix_language_rep (string name):
 
21
  language_rep (name), colored ("")
 
22
 
23
  eval ("(use-modules (utils misc tm-keywords))");
 
24
  list<string> l= as_list_string (eval ("(map symbol->string highlight-any)"));
 
25
  while (!is_nil (l)) {
 
26
    colored (l->item)= "blue";
 
27
    l= l->next;
 
28
  }
 
29
}
 
30
 
 
31
text_property
 
32
mathemagix_language_rep::advance (string s, int& pos) {
 
33
  if (pos==N(s)) return &tp_normal_rep;
 
34
  char c= s[pos];
 
35
  if (c == ' ') {
 
36
    pos++; return &tp_space_rep; }
 
37
  if (c >= '0' && c <= '9') {
 
38
    parse_number (s, pos); return &tp_normal_rep; }
 
39
  if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
 
40
      (c == '_') || (c == '$')) {
 
41
    parse_alpha (s, pos); return &tp_normal_rep; }
 
42
  tm_char_forwards (s, pos);
 
43
  return &tp_normal_rep;
 
44
}
 
45
 
 
46
array<int>
 
47
mathemagix_language_rep::get_hyphens (string s) {
 
48
  int i;
 
49
  array<int> penalty (N(s)+1);
 
50
  penalty[0]= HYPH_INVALID;
 
51
  for (i=1; i<N(s); i++)
 
52
    if (s[i-1] == '-' && is_alpha (s[i]))
 
53
      penalty[i]= HYPH_STD;
 
54
    else penalty[i]= HYPH_INVALID;
 
55
  penalty[i]= HYPH_INVALID;
 
56
  return penalty;
 
57
}
 
58
 
 
59
void
 
60
mathemagix_language_rep::hyphenate (
 
61
  string s, int after, string& left, string& right)
 
62
 
63
  left = s(0, after);
 
64
  right= s(after, N(s));
 
65
}
 
66
 
 
67
static void
 
68
mathemagix_color_setup_constants (hashmap<string, string> & t) {
 
69
  string c= "#2060c0";
 
70
  t ("cpp_flags")= c;
 
71
  t ("cpp_libs")= c;
 
72
  t ("cpp_preamble")= c;
 
73
  t ("true")= c;
 
74
  t ("false")= c;
 
75
  t ("mmout")= c;
 
76
  t ("mmin")= c;
 
77
  t ("mmerr")= c;
 
78
  t ("nil")= c;
 
79
}
 
80
 
 
81
static void
 
82
mathemagix_color_setup_keywords (hashmap<string, string> & t)  {
 
83
  string c= "#8020c0"; string d= "modifier"; string e= "class";
 
84
  t ("abstract")= c;
 
85
  t ("alias")= c;
 
86
  t ("and")= c;
 
87
  t ("assume")= d;
 
88
  t ("begin")= c;
 
89
  t ("break")= c;
 
90
  t ("case")= c;
 
91
  t ("cast")= c;
 
92
  t ("catch")= c;
 
93
  t ("category")= e;
 
94
  t ("class")= e;
 
95
  t ("concrete")= c;
 
96
  t ("constant")= c;
 
97
  t ("constructor")= c;
 
98
  t ("continue")= c;
 
99
  t ("convert")= c;
 
100
  t ("destructor")= c;
 
101
  t ("direct")= c;
 
102
  t ("div")= c;
 
103
  t ("do")= c;
 
104
  t ("downto")= c;
 
105
  t ("downgrade")= c;
 
106
  t ("else")= c;
 
107
  t ("evolutive")= c;
 
108
  t ("exists")= d;
 
109
  t ("explode")= c;
 
110
  t ("export")= d;
 
111
  t ("extend")= c;
 
112
  t ("extern")= c;
 
113
  t ("for")= c;
 
114
  t ("forall")= d;
 
115
  t ("foreach")= c;
 
116
  t ("foreign")= c;
 
117
  t ("from")= c;
 
118
  t ("fuse")= c;
 
119
  t ("generate")= c;
 
120
  t ("has")= c;
 
121
  t ("hidden")= c;
 
122
  t ("holds")= c;
 
123
  t ("if")= c;
 
124
  t ("import")= c;
 
125
  t ("in")= c;
 
126
  t ("include")= c;
 
127
  t ("indirect")= c;
 
128
  t ("infix")= c;
 
129
  t ("inherit")= c;
 
130
  t ("inline")= d;
 
131
  t ("interactive")= c;
 
132
  t ("intern")= c;
 
133
  t ("join")= c;
 
134
  t ("keyword")= c;
 
135
  t ("literal")= c;
 
136
  t ("lambda")= c;
 
137
  t ("literal_integer")= c;
 
138
  t ("literal_floating")= c;
 
139
  t ("literal_string")= c;
 
140
  t ("locked")= c;
 
141
  t ("loop")= c;
 
142
  t ("macro")= c;
 
143
  t ("map")= c;
 
144
  t ("melt")= c;
 
145
  t ("method")= c;
 
146
  t ("mod")= c;
 
147
  t ("module")= e;
 
148
  t ("mutable")= c;
 
149
  t ("operator")= c;
 
150
  t ("or")= c;
 
151
  t ("packed")= c;
 
152
  t ("postfix")= "postfix";
 
153
  t ("prefix")= c;
 
154
  t ("private")= c;
 
155
  t ("protected")= c;
 
156
  t ("public")= c;
 
157
  t ("outline")= c;
 
158
  t ("quit")= c;
 
159
  t ("raise")= c;
 
160
  t ("require")= c;
 
161
  t ("return")= c ;
 
162
  t ("split")= c;
 
163
  t ("step")= c;
 
164
  t ("supports?")= c;
 
165
  t ("then")= c;
 
166
  t ("this")= c;
 
167
  t ("to")= c;
 
168
  t ("try")= c;
 
169
  t ("type")= c;
 
170
  t ("unpacked")= c;
 
171
  t ("until")= c;
 
172
  t ("upgrade")= c;
 
173
  t ("use")= c;
 
174
  t ("value")= c;
 
175
  t ("while")= c;
 
176
  t ("with")= c;
 
177
  t ("xor")= c;
 
178
}
 
179
 
 
180
static void
 
181
mathemagix_color_setup_otherlexeme (hashmap<string, string>& t) {
 
182
  string c= "black";
 
183
  t ("==<gtr>")= c; 
 
184
  t ("==")= c;
 
185
  t (":=")= c;
 
186
  t ("+=")= c;
 
187
  t ("-=")= c; 
 
188
  t ("*=")= c;
 
189
  t ("/=")= c;
 
190
  t (":=<gtr>")= c;
 
191
  t (":-<gtr>")= c;
 
192
  t ("yield")= c;   
 
193
  t (",")= c;
 
194
  t (";")= c;
 
195
  t (")")= c;
 
196
  t ("[")= c;
 
197
  t ("]")= c;
 
198
  t ("{")= c;
 
199
  t ("}")= c;
 
200
  t ("<less><less>")= c;
 
201
  t ("<less><less>*")= c;
 
202
  t ("<less><less>%")= c;
 
203
  t ("<gtr><gtr>")= c;
 
204
}
 
205
 
 
206
static inline bool
 
207
belongs_to_identifier (char c) {
 
208
  return ((c<='9' && c>='0') ||
 
209
         (c<='Z' && c>='A') ||
 
210
         (c<='z' && c>='a') ||
 
211
          c=='_' || c=='$'  || c=='?');
 
212
}
 
213
 
 
214
static inline bool
 
215
is_number (char c) {
 
216
  return (c>='0' && c<='9');
 
217
}
 
218
 
 
219
static void
 
220
parse_identifier (hashmap<string, string>& t,
 
221
                  string s, int& pos, bool postfix) {
 
222
  int i=pos;
 
223
  if (pos>=N(s)) return;
 
224
  if (is_number (s[i])) return;
 
225
  if (postfix && s[i]=='.') i++;
 
226
  while (i<N(s) && belongs_to_identifier (s[i])) i++;
 
227
  if (!(t->contains (s (pos, i)))) pos= i;
 
228
}
 
229
 
 
230
static void
 
231
parse_alpha (string s, int& pos) {
 
232
  static hashmap<string,string> empty;
 
233
  parse_identifier (empty, s, pos, false);
 
234
}
 
235
 
 
236
static void
 
237
parse_blanks (string s, int& pos) {
 
238
  while (pos<N(s) && (s[pos]==' ' || s[pos]=='\t')) pos++;
 
239
}
 
240
 
 
241
static void
 
242
parse_string (string s, int& pos) {
 
243
  if (pos>=N(s)) return;
 
244
  switch (s[pos])  {
 
245
  case '\042':
 
246
    do pos++;
 
247
    while((pos<N(s)) &&
 
248
          ((s[pos-1]=='\\' && s[pos]=='\042') || s[pos]!='\042'));
 
249
    if (s[pos]=='\042') pos++;
 
250
    return;
 
251
  case '/':
 
252
    if (pos+1<N(s) && s[pos+1]=='\042') {
 
253
      pos=pos+2;
 
254
      do {
 
255
        if (pos+1<N(s) && s[pos]=='\042' && s[pos+1]=='/') {
 
256
          pos=pos+2; return; }
 
257
        pos++;
 
258
      } while (pos<N(s));
 
259
    }
 
260
  }
 
261
}
 
262
  
 
263
static void
 
264
parse_keyword (hashmap<string,string>& t, string s, int& pos) {
 
265
  int i= pos;
 
266
  if (pos>=N(s)) return;
 
267
  if (is_number (s[i])) return;
 
268
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
 
269
  string r= s (pos, i);
 
270
  if (t->contains (r) && t(r)=="#8020c0") { pos=i; return; }
 
271
}
 
272
 
 
273
static void
 
274
parse_modifier (hashmap<string,string>& t, string s, int& pos) {
 
275
  int i= pos;
 
276
  if (pos>=N(s)) return;
 
277
  if (is_number (s[i])) return;
 
278
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
 
279
  string r= s (pos, i);
 
280
  if (t->contains (r) && t(r)=="modifier") { pos=i; return; }
 
281
}
 
282
 
 
283
static void
 
284
parse_class (hashmap<string,string>& t, string s, int& pos) {
 
285
  int i= pos;
 
286
  if (pos>=N(s)) return;
 
287
  if (is_number (s[i])) return;
 
288
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
 
289
  string r= s (pos, i);
 
290
  if (t->contains (r) && t(r)=="class") { pos=i; return; }
 
291
}
 
292
 
 
293
 
 
294
static void
 
295
parse_postfix (hashmap<string,string>& t, string s, int& pos) {
 
296
  int i= pos;
 
297
  if (pos>=N(s)) return;
 
298
  if (is_number (s[i])) return;
 
299
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
 
300
  string r= s (pos, i);
 
301
  if (t->contains (r) && t(r)=="postfix") { pos=i; return; }
 
302
}
 
303
 
 
304
static void
 
305
parse_constant (hashmap<string,string>& t, string s, int& pos) {
 
306
  int i=pos;
 
307
  if (pos>=N(s)) return;
 
308
  if (is_number (s[i])) return;
 
309
  while ((i<N(s)) && belongs_to_identifier (s[i])) i++;
 
310
  string r= s (pos, i);
 
311
  if (t->contains (r) && t(r)=="#2060c0") { pos=i; return; }
 
312
}
 
313
 
 
314
static void
 
315
parse_other_lexeme (hashmap<string,string>& t, string s, int& pos) {
 
316
  int i;
 
317
  for (i=12; i>=1; i--) {
 
318
    string r=s(pos,pos+i);
 
319
    if (t->contains(r) && t(r)=="black") {
 
320
      pos=pos+i; return; }
 
321
  }
 
322
}
 
323
 
 
324
static void
 
325
parse_number (string s, int& pos) {
 
326
  int i= pos;
 
327
  if (pos>=N(s)) return;
 
328
  if (s[i] == '.') return;
 
329
  while (i<N(s) && 
 
330
         (is_number (s[i]) ||
 
331
          (s[i] == '.' && (i+1<N(s)) &&
 
332
           (is_number (s[i+1]) ||
 
333
            s[i+1] == 'e' || s[i+1] == 'E')))) i++;
 
334
  if (i == pos) return;
 
335
  if (i<N(s) && (s[i] == 'e' || s[i] == 'E')) {
 
336
    i++;
 
337
    if (i<N(s) && s[i] == '-') i++;
 
338
    while (i<N(s) && (is_number (s[i]))) i++;
 
339
  }
 
340
  pos= i;
 
341
}
 
342
 
 
343
static void
 
344
parse_no_declare_type (string s, int& pos) {
 
345
  if (pos+1<N(s) && s[pos]==':' && s[pos+1]==':') pos=pos+2;
 
346
}
 
347
 
 
348
static void
 
349
parse_declare_type (string s, int& pos) {
 
350
  if (pos>=N(s)) return;
 
351
  if (s[pos]!=':') return;
 
352
  if (pos+1<N(s) && s[pos+1]=='=') return;
 
353
  pos++;
 
354
  if (!test (s, pos, "<gtr>")) return;
 
355
  pos+=5;
 
356
}
 
357
 
 
358
static void
 
359
parse_comment (string s, int& pos) {
 
360
  if (pos>=N(s)) return;
 
361
  if (s[pos]!='/') return;
 
362
  if (pos+1<N(s) && s[pos+1]=='/') {pos=N(s);return;}
 
363
  if (pos+1<N(s) && s[pos+1]=='{') {
 
364
    pos= pos+2;
 
365
    while ((pos<N(s) && s[pos]!='}') || (pos+1<N(s) && s[pos+1]!='/')) pos++;
 
366
    pos= min(pos+2,N(s));
 
367
  }
 
368
}
 
369
 
 
370
static void
 
371
parse_end_comment (string s, int& pos) {
 
372
  if (pos+1<N(s) && s[pos]=='}' && s[pos+1]=='/') pos=pos+2; 
 
373
}
 
374
  
 
375
 
 
376
static void
 
377
parse_parenthesized (string s, int& pos) {
 
378
  int i=pos;
 
379
  if (pos>=N(s)) return;
 
380
  if (s[i]!='(') return;
 
381
  int nbpar=0;
 
382
  while(i<N(s)) {
 
383
    switch (s[i]) {
 
384
    case '(':
 
385
      nbpar++;break;
 
386
    case ')':if (nbpar>0) nbpar--;
 
387
      if (nbpar==0) {i++;pos=i;return;}
 
388
      break;
 
389
    case '/':
 
390
      if (i+1<N(s) && 
 
391
          (s[i+1]=='\042' || s[i+1]=='{' || s[i+1]=='/')) {
 
392
        pos= i; return; }
 
393
      break;
 
394
    case '\042':
 
395
      pos=i;
 
396
      return;
 
397
    }
 
398
    i++;
 
399
  }
 
400
  pos=i;
 
401
}
 
402
 
 
403
static void
 
404
parse_backquote (string s, int & pos) {
 
405
  if (pos>=N(s)) return;
 
406
  if (s[pos]=='\047') pos++;
 
407
}
 
408
 
 
409
static void
 
410
parse_declare_function (string s, int& pos) {
 
411
  if (pos+1>=N(s)) return;
 
412
  if (s[pos]==':' && s[pos+1]=='=') { pos=pos+2; return; }
 
413
  if (s[pos]=='=' && s[pos+1]=='=') { pos=pos+2; return; }
 
414
}
 
415
 
 
416
static void
 
417
parse_declare_macro (string s, int& pos) {
 
418
  if (test(s,pos,"==<gtr>")) { pos=pos+7; return; }
 
419
  if (test(s,pos,":=<gtr>")) { pos=pos+7; return; }
 
420
}
 
421
 
 
422
string
 
423
mathemagix_language_rep::get_color (tree t, int start, int end) {
 
424
  static bool setup_done= false;
 
425
  if (!setup_done) {
 
426
    mathemagix_color_setup_constants (colored);
 
427
    mathemagix_color_setup_keywords (colored);
 
428
    mathemagix_color_setup_otherlexeme (colored);
 
429
    setup_done= true;
 
430
  }
 
431
 
 
432
  static string none= "";
 
433
  if (start >= end) return none;
 
434
  string s= t->label;
 
435
  int pos=0;int opos;
 
436
  bool backquote= false;
 
437
  bool after_backquote;
 
438
  bool postfix= false;
 
439
  bool possible_function= true;
 
440
  bool possible_type= false;
 
441
  bool possible_class= false;
 
442
  bool possible_future_type= false;
 
443
  bool possible_future_function= true;
 
444
  bool possible_future_class= false;
 
445
  string type;
 
446
  do {
 
447
    do {
 
448
      opos=pos;
 
449
      parse_string (s, pos);
 
450
      if (opos<pos) break;
 
451
      parse_comment (s, pos);
 
452
      if (opos<pos) break;
 
453
      parse_end_comment (s, pos);
 
454
      if (opos<pos) { 
 
455
        if (pos>start) {return "brown";} 
 
456
        else break;
 
457
      }
 
458
      pos++;
 
459
    }
 
460
    while(false);
 
461
  }
 
462
  while(pos<N(s));
 
463
  pos=0;
 
464
  do {
 
465
    type= none;
 
466
    do {
 
467
      after_backquote= backquote;
 
468
      possible_function= possible_future_function;
 
469
      possible_type= possible_future_type;
 
470
      possible_class= possible_future_class;
 
471
      opos= pos;
 
472
      parse_blanks (s, pos);
 
473
      if (opos<pos) break;
 
474
      parse_string (s, pos);
 
475
      if (opos<pos) {
 
476
        type= "string";
 
477
        backquote= false;
 
478
        postfix= false;
 
479
        possible_future_function= false;
 
480
        possible_future_type= false;
 
481
        possible_future_class= false;
 
482
        possible_type= false;
 
483
        break;
 
484
      }
 
485
      parse_comment (s, pos);
 
486
      if (opos<pos) {
 
487
        type= "comment";
 
488
        backquote= false;
 
489
        postfix= false;
 
490
        possible_future_type= false;
 
491
        possible_type= false;
 
492
        break;
 
493
      }
 
494
      parse_modifier (colored, s, pos);
 
495
      if (opos<pos) {
 
496
        type="keyword";
 
497
        backquote= false;
 
498
        postfix= false;
 
499
        possible_future_type= false;
 
500
        possible_type= false;
 
501
        possible_function= false;
 
502
        break;
 
503
          }
 
504
      parse_postfix (colored, s, pos);
 
505
      if (opos<pos) {
 
506
        type="keyword";
 
507
        backquote= false;
 
508
        postfix= true;
 
509
        possible_future_type= false;
 
510
        possible_future_class= false;
 
511
        possible_type= false;
 
512
        possible_function= false;
 
513
        possible_future_class= false;
 
514
        break;
 
515
      }
 
516
      parse_class (colored, s, pos);
 
517
      if (opos<pos) {
 
518
        type= "keyword";
 
519
        backquote=false;
 
520
        postfix=false;
 
521
        possible_future_type= false;
 
522
        possible_type= false;
 
523
        possible_future_class=true;
 
524
        possible_future_function= false;
 
525
        break;
 
526
      }
 
527
      parse_keyword (colored, s, pos);
 
528
      if (opos<pos) {
 
529
        type= "keyword";
 
530
        backquote= false;
 
531
        postfix= false;
 
532
        possible_future_type= false;
 
533
        possible_type= false;
 
534
        possible_function= false;
 
535
        possible_future_function= false;
 
536
        possible_future_class= false;
 
537
        break;
 
538
      }
 
539
      parse_other_lexeme (colored, s, pos);  //not left parenthesis
 
540
      if (opos<pos) {
 
541
        type= "other_lexeme";
 
542
        backquote= false;
 
543
        postfix= false;
 
544
        possible_function= false;
 
545
        possible_future_function= true;
 
546
        possible_future_type= false;
 
547
        possible_future_class= false;
 
548
        possible_type= false;
 
549
        break;
 
550
      }
 
551
      parse_constant (colored, s, pos);
 
552
      if (opos<pos) {
 
553
        type= "constant";
 
554
        backquote= false;
 
555
        postfix= false;
 
556
        possible_future_function= false;
 
557
        possible_future_class= false;
 
558
        break;
 
559
      }
 
560
      parse_number (s, pos);
 
561
      if (opos<pos) {
 
562
        type= "number";
 
563
        backquote= false;
 
564
        postfix= false;
 
565
        possible_future_function= false;
 
566
        possible_future_class= false;
 
567
        break;
 
568
      }
 
569
      parse_no_declare_type (s, pos); // :: 
 
570
      if (opos<pos) {
 
571
        type= "no_declare_type";
 
572
        possible_type= false;
 
573
        possible_future_type= false;
 
574
        possible_function= false;
 
575
        possible_future_function= false;
 
576
        possible_future_class= false;
 
577
        break;
 
578
      }  
 
579
      parse_backquote (s, pos);
 
580
      if (opos<pos) {
 
581
        backquote= true;
 
582
        postfix= false;
 
583
        possible_future_function= false;
 
584
        possible_future_class= false;
 
585
        break;
 
586
      }
 
587
      parse_declare_type (s, pos); // : and :>
 
588
      if (opos<pos) {
 
589
        type= "declare_type";
 
590
        backquote= false;
 
591
        postfix= false;
 
592
        if (!after_backquote) possible_future_type=true; 
 
593
        possible_function= false;
 
594
        possible_future_function= false;
 
595
        possible_future_class= false;
 
596
        break;
 
597
      }
 
598
      parse_identifier (colored, s, pos, postfix);
 
599
      if (opos<pos) {
 
600
        type="identifier";
 
601
        backquote= false;
 
602
        postfix= false;
 
603
        possible_future_function=false;
 
604
        possible_future_class= false;
 
605
        break;
 
606
      }
 
607
      parse_parenthesized (s, pos);
 
608
      // stops after well parenthesized ) or before  // or /{ or " or /"
 
609
      if (opos<pos && pos<=start) {
 
610
        type="left_parenthesis";
 
611
        backquote= false;
 
612
        postfix= false;
 
613
        possible_function= false;
 
614
        possible_future_function= true;
 
615
        possible_future_class= false;
 
616
        break;
 
617
      }
 
618
      if (opos<pos && possible_type==true)
 
619
        return "dark green";
 
620
      if (opos<pos && after_backquote)  
 
621
        return none;
 
622
      backquote= false;
 
623
      postfix= false;
 
624
      pos= opos;
 
625
      pos++;
 
626
    }
 
627
    while (false);
 
628
  }
 
629
  while (pos<=start);
 
630
  if (possible_type) return "dark green";
 
631
  if (type=="string") return "#a06040";
 
632
  if (type=="comment") return "brown";
 
633
  if (type=="keyword" && !after_backquote) return "#8020c0";
 
634
  if (type=="other_lexeme") return none;
 
635
  if (type=="constant") return "#2060c0";
 
636
  if (type=="number") return "#2060c0";
 
637
  if (type=="no_declare_type") return none;
 
638
  if (type=="declare_type") return none;
 
639
  if (type=="left_parenthesis") return none;
 
640
  if (type=="identifier" && possible_function==false && possible_class==false) 
 
641
    return none;
 
642
  if (type=="identifier" && possible_function) {
 
643
    possible_function= false;
 
644
    do {
 
645
      do {
 
646
        opos=pos;
 
647
        parse_blanks (s, pos);
 
648
        if (opos<pos) break;
 
649
        parse_identifier (colored, s, pos,false);
 
650
        if (opos<pos) { possible_function= true; break; }
 
651
        parse_number (s, pos);
 
652
        if (opos<pos) { possible_function= true; break; }
 
653
        parse_constant (colored, s, pos);
 
654
        if (opos<pos) { possible_function= true; break; }
 
655
        parse_comment (s, pos);
 
656
        if (opos<pos) break;
 
657
        parse_parenthesized (s, pos);
 
658
        if (opos<pos) { possible_function= true; break; }
 
659
      }
 
660
      while (false);
 
661
    }
 
662
    while (opos!=pos);
 
663
    if (!possible_function) return none;
 
664
    do {
 
665
      do {
 
666
        opos=pos;
 
667
        parse_blanks (s, pos);
 
668
        if (opos<pos) break;
 
669
        parse_identifier (colored, s, pos,false);
 
670
        if (opos<pos) break;
 
671
        parse_number(s,pos);
 
672
        if (opos<pos) break;
 
673
        parse_constant (colored, s, pos);
 
674
        if (opos<pos) break;
 
675
        parse_comment(s,pos);
 
676
        if (opos<pos) break;
 
677
        parse_parenthesized (s, pos);
 
678
        if (opos<pos) break;
 
679
        parse_no_declare_type (s, pos);
 
680
        if (opos<pos) break;
 
681
        parse_declare_type (s, pos);
 
682
        if (opos<pos) break;
 
683
        parse_declare_macro(s,pos);
 
684
        if (opos<pos) return "#00d000";
 
685
        parse_declare_function (s, pos);
 
686
        if (opos<pos) return "#0000e0";
 
687
        return none;
 
688
      }
 
689
      while (false);
 
690
    }
 
691
    while (pos<N(s));
 
692
  }
 
693
  if (type=="identifier" && possible_class) {
 
694
  do {
 
695
    do {
 
696
      opos=pos;
 
697
      parse_blanks (s, pos);
 
698
      if (opos<pos) break;
 
699
      parse_identifier (colored, s, pos,false);
 
700
      if (opos<pos) break;
 
701
      parse_number(s,pos);
 
702
      if (opos<pos) break;
 
703
      parse_constant (colored, s, pos);
 
704
      if (opos<pos) break;
 
705
      parse_comment(s,pos);
 
706
      if (opos<pos) break;
 
707
      parse_parenthesized (s, pos);
 
708
      if (opos<pos) break;
 
709
      parse_no_declare_type (s, pos);
 
710
      if (opos<pos) break;
 
711
      parse_declare_type (s, pos);
 
712
      if (opos<pos) break;
 
713
      parse_declare_function (s, pos);
 
714
      if (opos<pos) return "#0000e0";
 
715
      return none;
 
716
    }
 
717
    while (false);
 
718
  }
 
719
  while (pos<N(s));
 
720
  }
 
721
  return none;
 
722
}