File: sml_simple.st

package info (click to toggle)
mlton 20100608-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 36,624 kB
  • sloc: ansic: 18,441; lisp: 2,879; makefile: 1,572; sh: 1,326; pascal: 256; asm: 97
file content (134 lines) | stat: -rw-r--r-- 2,390 bytes parent folder | download | duplicates (6)
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
124
125
126
127
128
129
130
131
132
133
134
/**
 * Name: sml_simple
 * Description: Standard ML programming language.
 * Author: Matthew Fluet <mfluet@acm.org>
 */

/*
builtin_face        --- 
comment_face        --- comments
function_name_face  --- 
highlight_face      --- 
keyword_face        --- keywords
reference_face      --- 
string_face         --- strings
type_face           --- 
variable_name_face  --- 
*/

sml_keywords_re =
/* Keywords:
(build-re '(; Core
            abstype  and  andalso  as  case  do  datatype  else
            end  exception  fn  fun  handle  if  in  infix
            infixr  let  local  nonfix  of  op  open  orelse
            raise  rec  then  type  val  with  withtype  while
            ; Modules
            eqtype  functor  include  sharing  sig
            signature  struct  structure  where)) ;'
*/
  /\b(a(bstype|nd(|also)|s)|case|d(atatype|o)|e(lse|nd|qtype|xception)|f(n|un(|ctor))|handle|i(f|n(|clude|fix(|r)))|l(et|ocal)|nonfix|o(f|p(|en)|relse)|r(aise|ec)|s(haring|ig(|nature)|truct(|ure))|t(hen|ype)|val|w(h(ere|ile)|ith(|type)))\b/;

state sml_simple extends HighlightEntry
{
  /*
   * Keywords
   */
  sml_keywords_re {
    keyword_face (true);
    language_print ($0);
    keyword_face (false);
  }

  /*
   * Special constants (strings)
   */
  /\"/ {
    string_face (true);
    language_print ($0);
    call (sml_string);
    string_face (false);
  }

  /*
   * Special constants (chars)
   */
  /(#)(\")/ {
    language_print ($1);
    string_face (true);
    language_print ($2);
    call (sml_string);
    string_face (false);
  }

  /*
   * Comments
   */
  /\(\*/ {
    comment_face (true);
    language_print ($0);
    call (sml_comment);
    comment_face (false);
  }
}

/*
 * Strings
 */
state sml_string extends Highlight
{
  /\\\\(\s|\n)/ {
    language_print ($0);
    call (sml_string_gap);
  }

  /\\\\./ {
    language_print ($0);
  }

  /\"/ {
    language_print ($0);
    return;
  }
}

state sml_string_gap extends Highlight
{
  /(\s|\n)/ {
    language_print ($0);
  }

  /\\\\/ {
    language_print ($0);
    return;
  }
}

/*
 * Nested comments
 */
state sml_comment extends Highlight 
{
  BEGIN {
    sml_comment_depth = 1;
  }

  /\(\*/ {
    sml_comment_depth += 1;
    language_print ($0);
  }

  /\*\)/ {
    sml_comment_depth -= 1;
    language_print ($0);
    if (sml_comment_depth == 0)
      return;
  }
}


/*
Local variables:
mode: c
End:
*/