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 "segshlshrsmist0st1st2st3st4st5st6st7stcstdsti",
26 "strsubtr3tr4tr5tr6tr7wrtxor", 9);
27 variable nasm_kw_4 = strncat("arplbytecallcltscwdeemmsfabsfaddfbldfchsfcom",
28 "fcosfdivfenifildfistfld1fldzfmulfnopfsinfstp",
29 "fsubftstfxamfxchibtsidivimulinsbinsdinswint1",
30 "int3intoinvdiretjcxzjnaejnbejngejnlelahflgdt",
31 "lidtlldtlmswlocklongloopmovdmovqnearpandpopa",
32 "popfpushpxorreperepzresbresdresqrestreswretf",
33 "retnsahfsalcsetasetbsetcsetesetgsetlsetosetp",
34 "setssetzsgdtshldshrdsidtsldtsmswtestumovverr",
35 "verwwaitwordxaddxbtsxchg", 9);
36 variable nasm_kw_5 = strncat("boundbswapcmovacmovbcmovccmovecmovgcmovlcmovo",
37 "cmovpcmovscmovzcmpsbcmpsdcmpswcpuiddwordenter",
38 "f2xm1faddpfbstpfclexfcomifcompfdisifdivpfdivr",
39 "ffreefiaddficomfidivfimulfinitfistpfisubfldcw",
40 "fldpifmulpfpremfptanfsavefsqrtfstcwfstswfsubp",
41 "fsubrfucomfyl2xicebpint01iretdiretwjecxzleave",
42 "lodsblodsdlodswloopeloopzmovsbmovsdmovswmovsx",
43 "movzxoutsboutsdoutswpaddbpadddpaddwpandnpopad",
44 "popawpopfdpopfwpslldpsllqpsllwpsradpsrawpsrld",
45 "psrlqpsrlwpsubbpsubdpsubwpushapushfqwordrdmsr",
46 "rdpmcrdtscrepnerepnzscasbscasdscaswsetaesetbe",
47 "setgesetlesetnasetnbsetncsetnesetngsetnlsetno",
48 "setnpsetnssetnzsetpesetposhortstosbstosdstosw",
49 "timestwordwrmsrxlatb", 14);
50 variable nasm_kw_6 = strncat("cmovaecmovbecmovgecmovlecmovnacmovnbcmovnc",
51 "cmovnecmovngcmovnlcmovnocmovnpcmovnscmovnz",
52 "cmovpecmovpofcmovbfcmovefcmovufcomipfcompp",
53 "fdivrpficompfidivrfisubrfldenvfldl2efldl2t",
54 "fldlg2fldln2fpatanfprem1frstorfscalefsetpm",
55 "fstenvfsubrpfucomifucompincbininvlpgloopne",
56 "loopnzpaddsbpaddswpmulhwpmullwpsubsbpsubsw",
57 "pushadpushawpushfdpushfwsetnaesetnbesetnge",
59 variable nasm_kw_7 = strncat("cmovnaecmovnbecmovngecmovnlecmpxchgfcmovbe",
60 "fcmovnbfcmovnefcmovnufdecstpfincstpfrndint",
61 "fsincosfucomipfucomppfxtractfyl2xp1loadall",
62 "paddusbpadduswpcmpeqbpcmpeqdpcmpeqwpcmpgtb",
63 "pcmpgtdpcmpgtwpmaddwdpsubusbpsubusw", 5);
64 variable nasm_kw_8 = "fcmovnbepackssdwpacksswbpackuswb";
65 variable nasm_kw_9 = strcat("cmpxchg8bpunpckhbwpunpckhdqpunpckhwdpunpcklbw",
66 "punpckldqpunpcklwd");
67 variable nasm_kw_10 = "cmpxchg486loadall286";
69 define nasm_indent_line() {
70 variable word, len, e, c;
77 if (what_column() <= Nasm_Instruction_Indent)
85 {looking_at_char(';')}
86 {looking_at_char('#')}
87 {looking_at_char('[')}) {
95 if (looking_at_char('%')) {
98 {looking_at_char('$')}
99 {looking_at_char('%')}
100 {looking_at_char('+')}
101 {looking_at_char('-')}
102 {looking_at_char('0')}
103 {looking_at_char('1')}
104 {looking_at_char('2')}
105 {looking_at_char('3')}
106 {looking_at_char('4')}
107 {looking_at_char('5')}
108 {looking_at_char('6')}
109 {looking_at_char('7')}
110 {looking_at_char('8')}
111 {looking_at_char('9')}) {
123 skip_chars("0-9a-zA-Z_.");
128 {looking_at_char(':')}) {
133 if (looking_at_char(':')) {
138 if (e or not(eolp())) {
139 if (len >= Nasm_Instruction_Indent) {
143 whitespace(Nasm_Instruction_Indent - len);
152 whitespace(Nasm_Instruction_Indent);
156 define nasm_newline_indent() {
166 define nasm_bol_self_ins() {
172 call("self_insert_cmd");
174 % Grotty: force immediate update of the syntax highlighting.
182 define nasm_self_ins_ind() {
183 call("self_insert_cmd");
185 % Grotty: force immediate update of the syntax highlighting.
192 define nasm_insert_comment() {
196 if (looking_at_char(';')) {
208 skip_chars("^;\n'\"");
209 if (looking_at_char('\'')) {
214 } else if (looking_at_char('\"')) {
219 } else if (looking_at_char(';')) {
223 !if (looking_at_char(';'))
231 spc = Nasm_Comment_Column - what_column();
232 if (spc < Nasm_Comment_Space)
233 spc = Nasm_Comment_Space;
244 create_syntax_table($1);
246 define_syntax (";", "", '%', $1);
247 define_syntax ("([", ")]", '(', $1);
248 define_syntax ('"', '"', $1);
249 define_syntax ('\'', '\'', $1);
250 define_syntax ("0-9a-zA-Z_.@#", 'w', $1);
251 define_syntax ("-+0-9a-fA-F.xXL", '0', $1);
252 define_syntax (",:", ',', $1);
253 define_syntax ('%', '#', $1);
254 define_syntax ("|^&<>+-*/%~", '+', $1);
256 set_syntax_flags($1,1);
258 #ifdef HAS_DFA_SYNTAX
260 dfa_enable_highlight_cache("nasm.dfa", $1);
261 dfa_define_highlight_rule(";.*$", "comment", $1);
262 dfa_define_highlight_rule("[A-Za-z_\\.\\?][A-Za-z0-9_\\.\\?\\$#@~]*",
264 dfa_define_highlight_rule("$([A-Za-z_\\.\\?][A-Za-z0-9_\\.\\?\\$#@~]*)?",
266 dfa_define_highlight_rule("[0-9]+(\\.[0-9]*)?([Ee][\\+\\-]?[0-9]*)?",
268 dfa_define_highlight_rule("[0-9]+[QqBb]", "number", $1);
269 dfa_define_highlight_rule("(0x|\\$[0-9A-Fa-f])[0-9A-Fa-f]*", "number", $1);
270 dfa_define_highlight_rule("[0-9A-Fa-f]+[Hh]", "number", $1);
271 dfa_define_highlight_rule("\"[^\"]*\"", "string", $1);
272 dfa_define_highlight_rule("\"[^\"]*$", "string", $1);
273 dfa_define_highlight_rule("'[^']*'", "string", $1);
274 dfa_define_highlight_rule("'[^']*$", "string", $1);
275 dfa_define_highlight_rule("[\\(\\)\\[\\],:]*", "delimiter", $1);
276 dfa_define_highlight_rule("^[ \t]*#", "PQpreprocess", $1);
277 dfa_define_highlight_rule("^[ \t]*\\%{?[^%\\$\\+\\-0-9]", "PQpreprocess", $1);
278 dfa_define_highlight_rule("^%$", "preprocess", $1);
279 dfa_define_highlight_rule("[\\|\\^&<>\\+\\-\\*/%~]*", "operator", $1);
280 dfa_define_highlight_rule("%([%\\$]?-?[0-9A-Za-z_\\.\\?\\$~@]+|{[^}]*}?)",
282 dfa_define_highlight_rule("[ \t]*", "normal", $1);
283 dfa_define_highlight_rule(".", "normal", $1);
284 dfa_build_highlight_table($1);
287 define_keywords_n($1, nasm_kw_2, 2, 0);
288 define_keywords_n($1, nasm_kw_3, 3, 0);
289 define_keywords_n($1, nasm_kw_4, 4, 0);
290 define_keywords_n($1, nasm_kw_5, 5, 0);
291 define_keywords_n($1, nasm_kw_6, 6, 0);
292 define_keywords_n($1, nasm_kw_7, 7, 0);
293 define_keywords_n($1, nasm_kw_8, 8, 0);
294 define_keywords_n($1, nasm_kw_9, 9, 0);
295 define_keywords_n($1, nasm_kw_10, 10, 0);
297 define_keywords_n($1, "org", 3, 1);
298 define_keywords_n($1, "bitsiend", 4, 1);
299 define_keywords_n($1, "aligngroupstruc", 5, 1);
300 define_keywords_n($1, "alignbcommonexternglobalistruc", 6, 1);
301 define_keywords_n($1, "sectionsegmentlibrary", 7, 1);
302 define_keywords_n($1, "absoluteendstruc", 8, 1);
303 define_keywords_n($1, "uppercase", 9, 1);
305 !if (keymap_p ($1)) make_keymap ($1);
306 definekey("nasm_bol_self_ins", ";", $1);
307 definekey("nasm_bol_self_ins", "#", $1);
308 definekey("nasm_bol_self_ins", "%", $1);
309 definekey("nasm_bol_self_ins", "[", $1);
310 definekey("nasm_self_ins_ind", ":", $1);
311 definekey("nasm_insert_comment", "^[;", $1);
316 use_syntax_table ("NASM");
317 set_buffer_hook ("indent_hook", "nasm_indent_line");
318 set_buffer_hook ("newline_indent_hook", "nasm_newline_indent");
319 runhooks("nasm_mode_hook");