(file) Return to c.st CVS log (file) (dir) Up to [RizwankCVS] / testProject / source / states / hl

  1 rizwank 1.1 /**
  2              * Name: c
  3              * Description: C programming language.
  4              * Author: Markku Rossi <mtr@iki.fi>
  5              */
  6             
  7             c_type_re =
  8             /* Types.
  9                (build-re '(auto char const double enum extern float int long
 10                register short signed static struct typedef union unsigned void
 11                volatile))
 12              */
 13               /\b(auto|c(har|onst)|double|e(num|xtern)|float|int|long|register\
 14             |s(hort|igned|t(atic|ruct))|typedef|un(ion|signed)|vo(id|latile))\b/;
 15             
 16             /* The super state of all C highlightings. */
 17             state CHighlight extends Highlight
 18             {
 19               BEGIN {
 20                 if (verbose_highlighting)
 21                   verbose_re = /(->|<=|>=|==|!=|\&\&|\|\||!)/;
 22 rizwank 1.1     else
 23                   verbose_re = 0;
 24               }
 25             
 26               verbose_re {
 27                 match = $0;
 28                 if (strcmp (match, "->") == 0)
 29                   str = "rightarrow";
 30                 else if (strcmp (match, "<=") == 0)
 31                   str = "le";
 32                 else if (strcmp (match, ">=") == 0)
 33                   str = "ge";
 34                 else if (strcmp (match, "==") == 0)
 35                   str = "equiv";
 36                 else if (strcmp (match, "&&") == 0)
 37                   str = "land";
 38                 else if (strcmp (match, "||") == 0)
 39                   str = "lor";
 40                 else if (strcmp (match, "!") == 0)
 41                   str = "lnot";
 42                 else if (strcmp (match, "!=") == 0)
 43 rizwank 1.1       str = "ne";
 44                 else
 45                   str = 0;
 46             
 47                 if (!str || !language_symbol (str))
 48                   language_print ($0);
 49               }
 50             }
 51             
 52             /*
 53              * The highlight entry for C highlightings.  It is a bit ugly to
 54              * re-implement the BEGIN and END because they must be kept in sync
 55              * with the code in the `HighlightEntry'.  But, since we don't support
 56              * multiple heritance, we have no choice.
 57              */
 58             state CHighlightEntry extends CHighlight
 59             {
 60               BEGIN {
 61                 if (highlight_entry_nesting++ == 0)
 62                   header ();
 63               }
 64 rizwank 1.1   END {
 65                 if (--highlight_entry_nesting == 0)
 66                   trailer ();
 67               }
 68             }
 69             
 70             state c extends CHighlightEntry
 71             {
 72               BEGIN {
 73                 /*
 74                  * Set the regular expression that is used to highlight types from
 75                  * the beginning of the on-line function definition.  This
 76                  * variable should be overwritten by each state that extends the
 77                  * `c' state.
 78                  */
 79                 type_re = c_type_re;
 80               }
 81             
 82               /* Comments. */
 83               /\/\*/ {
 84                 comment_face (true);
 85 rizwank 1.1     language_print ($0);
 86                 call (c_comment);
 87                 comment_face (false);
 88               }
 89               /\/\// {
 90                 comment_face (true);
 91                 language_print ($0);
 92                 call (eat_one_line);
 93                 comment_face (false);
 94               }
 95             
 96               /* String constants. */
 97               /\"/ {
 98                 string_face (true);
 99                 language_print ($0);
100                 call (c_string);
101                 string_face (false);
102               }
103             
104               /* Pre-processor lines. */
105               /^#/ {
106 rizwank 1.1     language_print ($0);
107                 call (c_ppline);
108               }
109             
110               /* Character constants. */
111               /'.'|'\\\\.'/ {
112                 string_face (true);
113                 language_print ($0);
114                 string_face (false);
115               }
116             
117               /* Keywords, but not types, goto, or case.
118                  (build-re '(break continue default do else for if return sizeof
119                  switch while))
120               */
121               /\b(break|continue|d(efault|o)|else|for|if|return|s(izeof|witch)|while)\b/ {
122                 keyword_face (true);
123                 language_print ($0);
124                 keyword_face (false);
125               }
126             
127 rizwank 1.1   /* Types. */
128               c_type_re {
129                 type_face (true);
130                 language_print ($0);
131                 type_face (false);
132               }
133             
134               /* Labels.  Emacs accepts also bare numbers. */
135               /^([ \t]*)([a-zA-Z0-9_]+)(:)/ {
136                 language_print ($1);
137             
138                 reference_face (true);
139                 language_print ($2);
140                 reference_face (false);
141             
142                 language_print ($3);
143               }
144             
145               /* Goto, case and the target. */
146               /\<(goto|case)\>([ \t]+)(-?[A-Za-z_0-9]+)?/ {
147                 keyword_face (true);
148 rizwank 1.1     language_print ($1);
149                 keyword_face (false);
150             
151                 language_print ($2);
152             
153                 if (length ($3) > 0)
154                   {
155             	reference_face (true);
156             	language_print ($3);
157             	reference_face (false);
158                   }
159               }
160             
161               /*
162                * Function definitions, but only if you code with the one and only
163                * usable indentation style (GNU).
164                */
165               /^([a-zA-Z_][a-zA-Z_0-9]*)([ \t]*\()/ {
166                 function_name_face (true);
167                 language_print ($1);
168                 function_name_face (false);
169 rizwank 1.1 
170                 language_print ($2);
171               }
172             
173               /* Function definitions and prototypes for other (loser) coding styles. */
174               /^([A-Za-z][a-zA-Z0-9_\* ]+)([ \*])([a-zA-Z_][a-zA-Z_0-9]*)([ \t]*\()/ {
175                 garbage = $1;
176                 middle_garbage = $2;
177                 function_name = $3;
178                 tail_garbage = $4;
179             
180                 highlight_types (garbage, type_re);
181             
182                 language_print (middle_garbage);
183             
184                 function_name_face (true);
185                 language_print (function_name);
186                 function_name_face (false);
187             
188                 language_print (tail_garbage);
189               }
190 rizwank 1.1 }
191             
192             
193             /*
194             Local variables:
195             mode: c
196             End:
197             */

Rizwan Kassim
Powered by
ViewCVS 0.9.2