% Mercury mode with syntax, highlighting and simple indentation. % Put something like this into your .jedrc: % % add_mode_for_extension ("mercury", "m"); % autoload ("mercury_mode","/home/andre/lib/src/s-lang/mercury.sl"); % % by: Andre Rognes % % Copyright (c) 2003, Andre Rognes % All rights reserved. % % This program is free software; you can redistribute it and/or modify it % under the terms of the GNU General Public License as published by the Free % Software Foundation; either version 2 of the License, or (at your option) % any later version. % % This program is distributed in the hope that it will be useful, but WITHOUT % ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or % FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for % more details. % % You should have received a copy of the GNU General Public License along % with this program; if not, write to the Free Software Foundation, Inc., 675 % Mass Ave, Cambridge, MA 02139, USA. message ("Reading Mercury Syntax_table"); $1 = "Mercury"; !if (keymap_p ($1)) make_keymap ($1); create_syntax_table ("Mercury"); define_syntax ("%", "", '%', "Mercury"); % comments define_syntax ("/*", "*/", '%', "Mercury"); % comments define_syntax ("([{", ")]}", '(', "Mercury");% delimiters %define_syntax (":-", ".",'<', "Mercury"); % clause %define_syntax ("-->", ".", '<', "Mercury"); % clause %define_syntax ("--->", ".", '<', "Mercury"); % clause define_syntax ('"', '"', "Mercury"); % Mercury strings define_syntax ('\'', '\'', "Mercury"); % Mercury atoms or 0'x: No! define_syntax ('\\', '\\', "Mercury"); define_syntax ("a-zA-Z0-9_", 'w', "Mercury"); % words define_syntax ("-+0-9", '0', "Mercury"); % Numbers define_syntax (".!", ',', "Mercury"); % define_syntax (",;:^*/<>=-+@\\", '+', "Mercury"); % operators and keywords1 set_syntax_flags ("Mercury", 0); () = define_keywords_n ("Mercury","diifinuiuo",2,0); () = define_keywords_n ("Mercury","alldetmdimuimuonotout",3,0); () = define_keywords_n ("Mercury","elsefailfuncinstmodepredsomethentruetypeuniv",4,0); () = define_keywords_n ("Mercury","boundfloatmultiwhere",5,0); () = define_keywords_n ("Mercury","groundmodulenondetpragmastring",6,0); () = define_keywords_n ("Mercury","failuresemidet",7,0); () = define_keywords_n ("Mercury","cc_multiequalityexternalinstance",8,0); () = define_keywords_n ("Mercury","cc_nondeterroneousinterfaceio__statetypeclass",9,0); () = define_keywords_n ("Mercury","end_module",10,0); () = define_keywords_n ("Mercury","import_module",13,0); () = define_keywords_n ("Mercury","implementationinclude_module",14,0); define lp_reset_point () { push_mark (); bskip_white (); if (bolp ()) { skip_white (); pop_mark_0 (); } else pop_mark_1 (); } define lp_column_line_arr(lines) { variable i,str,col; col = 0; foreach (lines) { str = (); str = strcompress(str," \t\f\r\n"); if (str == ".") continue; % the initial . if (string_match(str,"^%",1)) continue; %this line is a comment if (string_match(str,":-$",1)) col += TAB; if (string_match(str,"-->$",1)) col += TAB; %also covers ---> if (string_match(str,"($",1)) col += TAB; if (string_match(str,")$",1)) col -= TAB; if (string_match(str,"{$",1)) col += TAB; if (string_match(str,"}$",1)) col -= TAB; if (string_match(str,"\\\[$",1)) col += TAB; if (string_match(str,"\\\]$",1)) col -= TAB; } return col; } define lp_column() { variable val,str,lines; bol(); push_spot(); push_mark(); if (re_bsearch("\\\.[ \t\f\r]*$") == 0) bob(); str = bufsubstr(); lines = strchop(str,'\n',0); pop_mark_0(); pop_spot(); return lp_column_line_arr(lines); } define lp_indent_line () { variable col; push_spot (); col = lp_column(); bol_skip_white (); bol_trim (); whitespace (col); pop_spot (); lp_reset_point(); } define mercury_mode () { variable mode = "Mercury"; set_mode (mode, 0x4); set_buffer_hook("indent_hook","lp_indent_line"); use_keymap (mode); use_syntax_table (mode); mode_set_mode_info (mode, "fold_info", "%{{{\r%}}}\r\r"); run_mode_hooks("mercury_mode_hook"); }