nasm.sl 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. % This file defines a NASM editor mode for the JED editor.
  2. % JED's home page is http://space.mit.edu/~davis/jed.html.
  3. %
  4. % To install, copy this file into your JED_LIBRARY directory
  5. % (/usr/local/jed/lib or C:\JED\LIB or whatever), then add the
  6. % following lines to your .jedrc or jed.rc file:
  7. % autoload("nasm_mode", "nasm");
  8. % add_mode_for_extension("nasm", "asm");
  9. % (you can of course replace "asm" with whatever file extension
  10. % you like to use for your NASM source files).
  11. variable Nasm_Instruction_Indent = 10;
  12. variable Nasm_Comment_Column = 33;
  13. variable Nasm_Comment_Space = 1;
  14. variable nasm_kw_2 = strcat("ahalaxbhblbpbtbxchclcscxdbdddhdidldqdsdtdwdxes",
  15. "fsgsinjajbjcjejgjljojpjsjzorsispssto");
  16. variable nasm_kw_3 = strncat("a16a32aaaaadaamaasadcaddandbsfbsrbtcbtrbtscbw",
  17. "cdqclccldclicmccmpcr0cr2cr3cr4cwddaadasdecdiv",
  18. "dr0dr1dr2dr3dr6dr7eaxebpebxecxediedxequesiesp",
  19. "farfldfsthltincintjaejbejgejlejmpjnajnbjncjne",
  20. "jngjnljnojnpjnsjnzjpejpolarldslealeslfslgslsl",
  21. "lssltrmm0mm1mm2mm3mm4mm5mm6mm7movmulnegnopnot",
  22. "o16o32outpopporrclrcrrepretrolrorrsmsalsarsbb",
  23. "segshlshrsmist0st1st2st3st4st5st6st7stcstdsti",
  24. "strsubtr3tr4tr5tr6tr7wrtxor", 9);
  25. variable nasm_kw_4 = strncat("arplbytecallcltscwdeemmsfabsfaddfbldfchsfcom",
  26. "fcosfdivfenifildfistfld1fldzfmulfnopfsinfstp",
  27. "fsubftstfxamfxchibtsidivimulinsbinsdinswint1",
  28. "int3intoinvdiretjcxzjnaejnbejngejnlelahflgdt",
  29. "lidtlldtlmswlocklongloopmovdmovqnearpandpopa",
  30. "popfpushpxorreperepzresbresdresqrestreswretf",
  31. "retnsahfsalcsetasetbsetcsetesetgsetlsetosetp",
  32. "setssetzsgdtshldshrdsidtsldtsmswtestumovverr",
  33. "verwwaitwordxaddxbtsxchg", 9);
  34. variable nasm_kw_5 = strncat("boundbswapcmovacmovbcmovccmovecmovgcmovlcmovo",
  35. "cmovpcmovscmovzcmpsbcmpsdcmpswcpuiddwordenter",
  36. "f2xm1faddpfbstpfclexfcomifcompfdisifdivpfdivr",
  37. "ffreefiaddficomfidivfimulfinitfistpfisubfldcw",
  38. "fldpifmulpfpremfptanfsavefsqrtfstcwfstswfsubp",
  39. "fsubrfucomfyl2xicebpint01iretdiretwjecxzleave",
  40. "lodsblodsdlodswloopeloopzmovsbmovsdmovswmovsx",
  41. "movzxoutsboutsdoutswpaddbpadddpaddwpandnpopad",
  42. "popawpopfdpopfwpslldpsllqpsllwpsradpsrawpsrld",
  43. "psrlqpsrlwpsubbpsubdpsubwpushapushfqwordrdmsr",
  44. "rdpmcrdtscrepnerepnzscasbscasdscaswsetaesetbe",
  45. "setgesetlesetnasetnbsetncsetnesetngsetnlsetno",
  46. "setnpsetnssetnzsetpesetposhortstosbstosdstosw",
  47. "timestwordwrmsrxlatb", 14);
  48. variable nasm_kw_6 = strncat("cmovaecmovbecmovgecmovlecmovnacmovnbcmovnc",
  49. "cmovnecmovngcmovnlcmovnocmovnpcmovnscmovnz",
  50. "cmovpecmovpofcmovbfcmovefcmovufcomipfcompp",
  51. "fdivrpficompfidivrfisubrfldenvfldl2efldl2t",
  52. "fldlg2fldln2fpatanfprem1frstorfscalefsetpm",
  53. "fstenvfsubrpfucomifucompincbininvlpgloopne",
  54. "loopnzpaddsbpaddswpmulhwpmullwpsubsbpsubsw",
  55. "pushadpushawpushfdpushfwsetnaesetnbesetnge",
  56. "setnlewbinvd", 9);
  57. variable nasm_kw_7 = strncat("cmovnaecmovnbecmovngecmovnlecmpxchgfcmovbe",
  58. "fcmovnbfcmovnefcmovnufdecstpfincstpfrndint",
  59. "fsincosfucomipfucomppfxtractfyl2xp1loadall",
  60. "paddusbpadduswpcmpeqbpcmpeqdpcmpeqwpcmpgtb",
  61. "pcmpgtdpcmpgtwpmaddwdpsubusbpsubusw", 5);
  62. variable nasm_kw_8 = "fcmovnbepackssdwpacksswbpackuswb";
  63. variable nasm_kw_9 = strcat("cmpxchg8bpunpckhbwpunpckhdqpunpckhwdpunpcklbw",
  64. "punpckldqpunpcklwd");
  65. variable nasm_kw_10 = "cmpxchg486loadall286";
  66. define nasm_indent_line() {
  67. variable word, len, e, c;
  68. e = eolp();
  69. push_spot();
  70. EXIT_BLOCK {
  71. pop_spot();
  72. if (what_column() <= Nasm_Instruction_Indent)
  73. skip_white();
  74. }
  75. bol_skip_white();
  76. c = what_column();
  77. if (orelse
  78. {looking_at_char(';')}
  79. {looking_at_char('#')}
  80. {looking_at_char('[')}) {
  81. bol_trim();
  82. pop_spot();
  83. EXIT_BLOCK {
  84. }
  85. return;
  86. }
  87. if (looking_at_char('%')) {
  88. go_right_1();
  89. !if (orelse
  90. {looking_at_char('$')}
  91. {looking_at_char('%')}
  92. {looking_at_char('+')}
  93. {looking_at_char('-')}
  94. {looking_at_char('0')}
  95. {looking_at_char('1')}
  96. {looking_at_char('2')}
  97. {looking_at_char('3')}
  98. {looking_at_char('4')}
  99. {looking_at_char('5')}
  100. {looking_at_char('6')}
  101. {looking_at_char('7')}
  102. {looking_at_char('8')}
  103. {looking_at_char('9')}) {
  104. bol_trim();
  105. pop_spot();
  106. EXIT_BLOCK {
  107. }
  108. return;
  109. }
  110. go_left_1();
  111. }
  112. push_mark();
  113. skip_chars("%$+-");
  114. skip_chars("0-9a-zA-Z_.");
  115. word = bufsubstr();
  116. if (orelse
  117. {c == 1}
  118. {looking_at_char(':')}) {
  119. push_spot();
  120. bol_trim();
  121. pop_spot();
  122. len = strlen(word);
  123. if (looking_at_char(':')) {
  124. go_right_1();
  125. len++;
  126. }
  127. trim();
  128. if (e or not(eolp())) {
  129. if (len >= Nasm_Instruction_Indent) {
  130. pop();
  131. whitespace(1);
  132. } else
  133. whitespace(Nasm_Instruction_Indent - len);
  134. if (e) {
  135. pop_spot();
  136. eol();
  137. push_spot();
  138. }
  139. }
  140. } else {
  141. bol_trim();
  142. whitespace(Nasm_Instruction_Indent);
  143. }
  144. }
  145. define nasm_newline_indent() {
  146. push_spot();
  147. bol_skip_white();
  148. if (eolp())
  149. trim();
  150. pop_spot();
  151. newline();
  152. nasm_indent_line();
  153. }
  154. define nasm_bol_self_ins() {
  155. push_spot();
  156. bskip_white();
  157. bolp();
  158. pop_spot();
  159. call("self_insert_cmd");
  160. % Grotty: force immediate update of the syntax highlighting.
  161. insert_char('.');
  162. deln(left(1));
  163. if (())
  164. nasm_indent_line();
  165. }
  166. define nasm_self_ins_ind() {
  167. call("self_insert_cmd");
  168. % Grotty: force immediate update of the syntax highlighting.
  169. insert_char('.');
  170. deln(left(1));
  171. nasm_indent_line();
  172. }
  173. define nasm_insert_comment() {
  174. variable spc;
  175. bol_skip_white();
  176. if (looking_at_char(';')) {
  177. bol_trim();
  178. go_right(1);
  179. skip_white();
  180. return;
  181. } else if (eolp()) {
  182. bol_trim();
  183. insert("; ");
  184. return;
  185. }
  186. forever {
  187. skip_chars("^;\n'\"");
  188. if (looking_at_char('\'')) {
  189. go_right_1();
  190. skip_chars("^'\n");
  191. !if (eolp())
  192. go_right_1();
  193. } else if (looking_at_char('\"')) {
  194. go_right_1();
  195. skip_chars("^\"\n");
  196. !if (eolp())
  197. go_right_1();
  198. } else if (looking_at_char(';')) {
  199. !if (bolp()) {
  200. go_left_1();
  201. trim();
  202. !if (looking_at_char(';'))
  203. go_right_1();
  204. }
  205. break;
  206. } else {
  207. break;
  208. }
  209. }
  210. spc = Nasm_Comment_Column - what_column();
  211. if (spc < Nasm_Comment_Space)
  212. spc = Nasm_Comment_Space;
  213. whitespace(spc);
  214. if (eolp()) {
  215. insert("; ");
  216. } else {
  217. go_right_1();
  218. skip_white();
  219. }
  220. }
  221. $1 = "NASM";
  222. create_syntax_table($1);
  223. define_syntax (";", "", '%', $1);
  224. define_syntax ("([", ")]", '(', $1);
  225. define_syntax ('"', '"', $1);
  226. define_syntax ('\'', '\'', $1);
  227. define_syntax ("0-9a-zA-Z_.@#", 'w', $1);
  228. define_syntax ("-+0-9a-fA-F.xXL", '0', $1);
  229. define_syntax (",:", ',', $1);
  230. define_syntax ('%', '#', $1);
  231. define_syntax ("|^&<>+-*/%~", '+', $1);
  232. set_syntax_flags($1,1);
  233. #ifdef HAS_DFA_SYNTAX
  234. dfa_enable_highlight_cache("nasm.dfa", $1);
  235. dfa_define_highlight_rule(";.*$", "comment", $1);
  236. dfa_define_highlight_rule("[A-Za-z_\\.\\?][A-Za-z0-9_\\.\\?\\$#@~]*",
  237. "Knormal", $1);
  238. dfa_define_highlight_rule("$([A-Za-z_\\.\\?][A-Za-z0-9_\\.\\?\\$#@~]*)?",
  239. "normal", $1);
  240. dfa_define_highlight_rule("[0-9]+(\\.[0-9]*)?([Ee][\\+\\-]?[0-9]*)?",
  241. "number", $1);
  242. dfa_define_highlight_rule("[0-9]+[QqBb]", "number", $1);
  243. dfa_define_highlight_rule("(0x|\\$[0-9A-Fa-f])[0-9A-Fa-f]*", "number", $1);
  244. dfa_define_highlight_rule("[0-9A-Fa-f]+[Hh]", "number", $1);
  245. dfa_define_highlight_rule("\"[^\"]*\"", "string", $1);
  246. dfa_define_highlight_rule("\"[^\"]*$", "string", $1);
  247. dfa_define_highlight_rule("'[^']*'", "string", $1);
  248. dfa_define_highlight_rule("'[^']*$", "string", $1);
  249. dfa_define_highlight_rule("[\\(\\)\\[\\],:]*", "delimiter", $1);
  250. dfa_define_highlight_rule("^[ \t]*#", "PQpreprocess", $1);
  251. dfa_define_highlight_rule("^[ \t]*\\%{?[^%\\$\\+\\-0-9]", "PQpreprocess", $1);
  252. dfa_define_highlight_rule("^%$", "preprocess", $1);
  253. dfa_define_highlight_rule("[\\|\\^&<>\\+\\-\\*/%~]*", "operator", $1);
  254. dfa_define_highlight_rule("%([%\\$]?-?[0-9A-Za-z_\\.\\?\\$~@]+|{[^}]*}?)",
  255. "preprocess", $1);
  256. dfa_define_highlight_rule("[ \t]*", "normal", $1);
  257. dfa_define_highlight_rule(".", "normal", $1);
  258. dfa_build_highlight_table($1);
  259. #endif
  260. define_keywords_n($1, nasm_kw_2, 2, 0);
  261. define_keywords_n($1, nasm_kw_3, 3, 0);
  262. define_keywords_n($1, nasm_kw_4, 4, 0);
  263. define_keywords_n($1, nasm_kw_5, 5, 0);
  264. define_keywords_n($1, nasm_kw_6, 6, 0);
  265. define_keywords_n($1, nasm_kw_7, 7, 0);
  266. define_keywords_n($1, nasm_kw_8, 8, 0);
  267. define_keywords_n($1, nasm_kw_9, 9, 0);
  268. define_keywords_n($1, nasm_kw_10, 10, 0);
  269. define_keywords_n($1, "org", 3, 1);
  270. define_keywords_n($1, "bitsiend", 4, 1);
  271. define_keywords_n($1, "aligngroupstruc", 5, 1);
  272. define_keywords_n($1, "alignbcommonexternglobalistruc", 6, 1);
  273. define_keywords_n($1, "sectionsegmentlibrary", 7, 1);
  274. define_keywords_n($1, "absoluteendstruc", 8, 1);
  275. define_keywords_n($1, "uppercase", 9, 1);
  276. !if (keymap_p ($1)) make_keymap ($1);
  277. definekey("nasm_bol_self_ins", ";", $1);
  278. definekey("nasm_bol_self_ins", "#", $1);
  279. definekey("nasm_bol_self_ins", "%", $1);
  280. definekey("nasm_bol_self_ins", "[", $1);
  281. definekey("nasm_self_ins_ind", ":", $1);
  282. definekey("nasm_insert_comment", "^[;", $1);
  283. define nasm_mode() {
  284. set_mode("NASM", 4);
  285. use_keymap ("NASM");
  286. use_syntax_table ("NASM");
  287. set_buffer_hook ("indent_hook", "nasm_indent_line");
  288. set_buffer_hook ("newline_indent_hook", "nasm_newline_indent");
  289. runhooks("nasm_mode_hook");
  290. }