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.
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).
12 variable Nasm_Instruction_Indent = 10;
13 variable Nasm_Comment_Column = 33;
14 variable Nasm_Comment_Space = 1;
16 variable nasm_kw_2 = strcat("ahalaxbhblbpbtbxchclcscxdbdddhdidldqdsdtdwdxes",
17 "fsgsinjajbjcjejgjljojpjsjzorsispssto");
18 variable nasm_kw_3 = strncat("a16a32aaaaadaamaasadcaddandbsfbsrbtcbtrbtscbw",
19 "cdqclccldclicmccmpcr0cr2cr3cr4cwddaadasdecdiv",
20 "dr0dr1dr2dr3dr6dr7eaxebpebxecxediedxequesiesp",
21 "farfldfsthltincintjaejbejgejlejmpjnajnbjncjne",
22 "jngjnljnojnpjnsjnzjpejpolarldslealeslfslgslsl",
23 "lssltrmm0mm1mm2mm3mm4mm5mm6mm7movmulnegnopnot",
24 "o16o32outpopporrclrcrrepretrolrorrsmsalsarsbb",
25 "segshlshrst0st1st2st3st4st5st6st7stcstdstistr",
26 "subtr3tr4tr5tr6tr7wrtxor", 9);
27 variable nasm_kw_4 = strncat("arplbytecallcltscwdeemmsfabsfaddfbldfchsfcom",
28 "fcosfdivfenifildfistfld1fldzfmulfnopfsinfstp",
29 "fsubftstfxamfxchidivimulinsbinsdinswint3into",
30 "invdiretjcxzjnaejnbejngejnlelahflgdtlidtlldt",
31 "lmswlocklongloopmovdmovqnearpandpopapopfpush",
32 "pxorreperepzresbresdreswretfretnsahfsetasetb",
33 "setcsetesetgsetlsetosetpsetssetzsgdtshldshrd",
34 "sidtsldtsmswtestverrverwwaitwordxaddxchg", 8);
35 variable nasm_kw_5 = strncat("boundbswapcmpsbcmpsdcmpswcpuiddwordenterf2xm1",
36 "faddpfbstpfclexfcompfdisifdivpfdivrffreefiadd",
37 "ficomfidivfimulfinitfistpfisubfldcwfldpifmulp",
38 "fpremfptanfsavefsqrtfstcwfstswfsubpfsubrfucom",
39 "fyl2xiretdiretwjecxzleavelodsblodsdlodswloope",
40 "loopzmovsbmovsdmovswmovsxmovzxoutsboutsdoutsw",
41 "paddbpadddpaddwpandnpopadpopawpopfdpopfwpslld",
42 "psllqpsllwpsradpsrawpsrldpsrlqpsrlwpsubbpsubd",
43 "psubwpushapushfqwordrdmsrrdtscrepnerepnzscasb",
44 "scasdscaswsetaesetbesetgesetlesetnasetnbsetnc",
45 "setnesetngsetnlsetnosetnpsetnssetnzsetpesetpo",
46 "shortstosbstosdstoswtimestwordwrmsrxlatb", 12);
47 variable nasm_kw_6 = strncat("fcomppfdivrpficompfidivrfisubrfldenvfldl2e",
48 "fldl2tfldlg2fldln2fpatanfprem1frstorfscale",
49 "fsetpmfstenvfsubrpfucompinvlpgloopneloopnz",
50 "paddsbpaddswpmulhwpmullwpsubsbpsubswpushad",
51 "pushawpushfdpushfwsetnaesetnbesetngesetnle",
53 variable nasm_kw_7 = strncat("cmpxchgfdecstpfincstpfrndintfsincosfucompp",
54 "fxtractfyl2xp1paddusbpadduswpcmpeqbpcmpeqd",
55 "pcmpeqwpcmpgtbpcmpgtdpcmpgtwpmaddwdpsubusb",
57 variable nasm_kw_8 = "packssdwpacksswbpackuswb";
58 variable nasm_kw_9 = strcat("cmpxchg8bpunpckhbwpunpckhdqpunpckhwdpunpcklbw",
59 "punpckldqpunpcklwd");
64 variable list, min, max, pos, cmp;
71 { case 2: list = nasm_kw_2; }
72 { case 3: list = nasm_kw_3; }
73 { case 4: list = nasm_kw_4; }
74 { case 5: list = nasm_kw_5; }
75 { case 6: list = nasm_kw_6; }
76 { case 7: list = nasm_kw_7; }
77 { case 8: list = nasm_kw_8; }
78 { case 9: list = nasm_kw_9; }
82 max = strlen(list) / len;
83 while (max - min >= 2) {
84 pos = (max + min) / 2;
85 cmp = strcmp(word, substr(list, pos * len + 1, len));
87 return 1; % it's a keyword
89 max = pos; % bottom half
96 define nasm_indent_line() {
97 variable word, len, e;
104 if (what_column() <= Nasm_Instruction_Indent)
111 {looking_at_char(';')}
112 {looking_at_char('#')}
113 {looking_at_char('[')}) {
122 skip_chars("0-9a-zA-Z_.");
125 if (nasm_is_kw(word)) {
127 whitespace(Nasm_Instruction_Indent);
133 if (looking_at_char(':')) {
138 if (e or not(eolp())) {
139 if (len >= Nasm_Instruction_Indent) {
143 whitespace(Nasm_Instruction_Indent - len);
153 define nasm_newline_indent {
163 define nasm_bol_self_ins {
169 call("self_insert_cmd");
171 % Grotty: force immediate update of the syntax highlighting.
179 define nasm_self_ins_ind {
180 call("self_insert_cmd");
182 % Grotty: force immediate update of the syntax highlighting.
189 define nasm_insert_comment {
193 if (looking_at_char(';')) {
205 skip_chars("^;\n'\"");
206 if (looking_at_char('\'')) {
211 } else if (looking_at_char('\"')) {
216 } else if (looking_at_char(';')) {
220 !if (looking_at_char(';'))
228 spc = Nasm_Comment_Column - what_column();
229 if (spc < Nasm_Comment_Space)
230 spc = Nasm_Comment_Space;
241 create_syntax_table($1);
243 define_syntax (";", "", '%', $1);
244 define_syntax ("([", ")]", '(', $1);
245 define_syntax ('"', '"', $1);
246 define_syntax ('\'', '\'', $1);
247 define_syntax ("0-9a-zA-Z_.@#", 'w', $1);
248 define_syntax ("-+0-9a-fA-F.xXL", '0', $1);
249 define_syntax (",:", ',', $1);
250 define_syntax ('#', '#', $1);
251 define_syntax ("|^&<>+-*/%~", '+', $1);
253 set_syntax_flags($1,1);
255 #ifdef HAS_DFA_SYNTAX
257 enable_highlight_cache("nasm.dfa", $1);
258 define_highlight_rule(";.*$", "comment", $1);
259 define_highlight_rule("[A-Za-z_\\.\\?][A-Za-z0-9_\\.\\?\\$#@~]*",
261 define_highlight_rule("$([A-Za-z_\\.\\?][A-Za-z0-9_\\.\\?\\$#@~]*)?",
263 define_highlight_rule("[0-9]+(\\.[0-9]*)?([Ee][\\+\\-]?[0-9]*)?",
265 define_highlight_rule("[0-9]+[QqBb]", "number", $1);
266 define_highlight_rule("(0x|\\$[0-9A-Fa-f])[0-9A-Fa-f]*", "number", $1);
267 define_highlight_rule("[0-9A-Fa-f]+[Hh]", "number", $1);
268 define_highlight_rule("\"[^\"]*\"", "string", $1);
269 define_highlight_rule("\"[^\"]*$", "string", $1);
270 define_highlight_rule("'[^']*'", "string", $1);
271 define_highlight_rule("'[^']*$", "string", $1);
272 define_highlight_rule("[\\(\\)\\[\\],:]*", "delimiter", $1);
273 define_highlight_rule("[\\|\\^&<>\\+\\-\\*/%~]*", "operator", $1);
274 define_highlight_rule("^[ \t]*#", "PQpreprocess", $1);
275 define_highlight_rule("@[0-9A-Za-z_\\.]*", "keyword1", $1);
276 define_highlight_rule("[ \t]*", "normal", $1);
277 define_highlight_rule(".", "normal", $1);
278 build_highlight_table($1);
282 define_keywords_n($1, nasm_kw_2, 2, 0);
283 define_keywords_n($1, nasm_kw_3, 3, 0);
284 define_keywords_n($1, nasm_kw_4, 4, 0);
285 define_keywords_n($1, nasm_kw_5, 5, 0);
286 define_keywords_n($1, nasm_kw_6, 6, 0);
287 define_keywords_n($1, nasm_kw_7, 7, 0);
288 define_keywords_n($1, nasm_kw_8, 8, 0);
289 define_keywords_n($1, nasm_kw_9, 9, 0);
291 !if (keymap_p ($1)) make_keymap ($1);
292 definekey("nasm_bol_self_ins", ";", $1);
293 definekey("nasm_bol_self_ins", "#", $1);
294 definekey("nasm_bol_self_ins", "[", $1);
295 definekey("nasm_self_ins_ind", ":", $1);
296 definekey("nasm_insert_comment", "^[;", $1);
301 use_syntax_table ("NASM");
302 set_buffer_hook ("indent_hook", "nasm_indent_line");
303 set_buffer_hook ("newline_indent_hook", "nasm_newline_indent");
304 runhooks("nasm_mode_hook");