ruby.st 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /**
  2. * Name: ruby
  3. * Description: Ruby programming language.
  4. * Author: Mike Wilson <m.v.wilson@home.com>
  5. */
  6. state ruby_comment
  7. {
  8. /\*\\\// {
  9. language_print ($0);
  10. return;
  11. }
  12. LANGUAGE_SPECIALS {
  13. language_print ($0);
  14. }
  15. }
  16. state ruby_dquot_string
  17. {
  18. /\\\\./ {
  19. language_print ($0);
  20. }
  21. /\"/ {
  22. language_print ($0);
  23. return;
  24. }
  25. LANGUAGE_SPECIALS {
  26. language_print ($0);
  27. }
  28. }
  29. state ruby_quot_string
  30. {
  31. /\\\\./ {
  32. language_print ($0);
  33. }
  34. /[\']/ {
  35. language_print ($0);
  36. return;
  37. }
  38. LANGUAGE_SPECIALS {
  39. language_print ($0);
  40. }
  41. }
  42. state ruby_bquot_string
  43. {
  44. /\\\\./ {
  45. language_print ($0);
  46. }
  47. /`/ {
  48. language_print ($0);
  49. return;
  50. }
  51. LANGUAGE_SPECIALS {
  52. language_print ($0);
  53. }
  54. }
  55. state ruby
  56. {
  57. BEGIN {
  58. header ();
  59. }
  60. END {
  61. trailer ();
  62. }
  63. /* Comments. */
  64. /#[^{].*$/ {
  65. comment_face (true);
  66. language_print ($0);
  67. comment_face (false);
  68. }
  69. /* Ignore escaped quote marks */
  70. /\\\"/ {
  71. language_print ($0);
  72. }
  73. /\\\'/ {
  74. language_print ($0);
  75. }
  76. /\\\`/ {
  77. language_print ($0);
  78. }
  79. /* In cgi files, JavaScript might be imbedded, so we need to look out
  80. * for the JavaScript comments, because they might contain something
  81. * we don't like, like a contraction (don't, won't, etc.)
  82. * We won't put them in comment face, because they are not ruby
  83. * comments.
  84. */
  85. /\/\// {
  86. language_print ($0);
  87. call (eat_one_line);
  88. }
  89. /* String constants. */
  90. /\"/ {
  91. string_face (true);
  92. language_print ($0);
  93. call (ruby_dquot_string);
  94. string_face (false);
  95. }
  96. /[\']/ {
  97. string_face (true);
  98. language_print ($0);
  99. call (ruby_quot_string);
  100. string_face (false);
  101. }
  102. /* Backquoted command string */
  103. /`/ {
  104. string_face (true);
  105. language_print ($0);
  106. call (ruby_bquot_string);
  107. string_face (false);
  108. }
  109. /* Variables globals and instance */
  110. /[$@]\w+/ {
  111. variable_name_face (true);
  112. language_print ($0);
  113. variable_name_face (false);
  114. }
  115. /* Variables class variable */
  116. /@@\w+/ {
  117. variable_name_face (true);
  118. language_print ($0);
  119. variable_name_face (false);
  120. }
  121. /([ \t]*)(def)([ \t]+)([^(]*)/ {
  122. /* indentation */
  123. language_print ($1);
  124. /* def */
  125. keyword_face (true);
  126. language_print ($2);
  127. keyword_face (false);
  128. /* middle */
  129. language_print ($3);
  130. /* Function name. */
  131. function_name_face (true);
  132. language_print ($4);
  133. function_name_face (false);
  134. }
  135. /\$[!@&`'+~=\/\\,;.<>_*$?:"]/ {
  136. variable_name_face (true);
  137. language_print ($0);
  138. variable_name_face (false);
  139. }
  140. /* Highlighting
  141. --Type face
  142. private protected public
  143. --Builtin face (I consider these to be somewhat special)
  144. alias alias_method attr attr_accessor attr_reader attr_writer
  145. module_alias module_function self super
  146. --Reference face
  147. require include
  148. --Keyword face
  149. and begin break case class def defined? do else elsif end
  150. ensure eval extend false for if in method module next nil not
  151. or redo rescue retry return then true undef unless until when
  152. while yield
  153. */
  154. /\\b(private|protected|public)\\b/ {
  155. type_face (true);
  156. language_print ($0);
  157. type_face (false);
  158. }
  159. /\\b(alias|alias_method|attr|attr_accessor|attr_reader|attr_writer\\
  160. |module_alias|module_function|self|super)\\b/ {
  161. builtin_face (true);
  162. language_print ($0);
  163. builtin_face (false);
  164. }
  165. /\\b(include|require)\\b/ {
  166. reference_face (true);
  167. language_print ($0);
  168. reference_face (false);
  169. }
  170. /\\b(and|begin|break|case|class|def|defined?|do|else|elsif|end|ensure|eval\\
  171. |extend|false|for|if|in|method|module|next|nil|not|or|raise|redo|rescue|retry\\
  172. |return|then|true|undef|unless|until|when|while|yield)\\b/ {
  173. keyword_face (true);
  174. language_print ($0);
  175. keyword_face (false);
  176. }
  177. LANGUAGE_SPECIALS {
  178. language_print ($0);
  179. }
  180. }
  181. /*
  182. Local variables:
  183. mode: c
  184. End:
  185. */