% A mode for Inform ().
%
% 2002-07-21 / Juho Snellman
% * First public release.
% inform mode
create_syntax_table ("inform");
define_syntax ("([{", ")]}", '(', "inform");
define_syntax ("!", "", '%', "inform");
define_syntax ('"', '"', "inform");
define_syntax ('\\', '\\', "inform");
define_syntax (",.;:", ',', "inform");
define_syntax ("0-9a-zA-Z_", 'w', "inform"); % words
define_syntax ("-+0-9", '0', "inform"); % Numbers
define_syntax ("=+-<>/*", '+', "inform");
#ifdef HAS_DFA_SYNTAX
%%% DFA_CACHE_BEGIN %%%
static define setup_dfa_callback (name)
{
% dfa_enable_highlight_cache ("inform.dfa", name);
dfa_define_highlight_rule ("!.*$", "comment", name);
dfa_define_highlight_rule ("\"([^\\\\\"]|\\\\.)*\"", "string", name);
dfa_define_highlight_rule ("\"([^\\\\\"]|\\\\.)*$", "string", name);
dfa_define_highlight_rule ("'[^'][a-zA-Z]+", "string", name);
dfa_define_highlight_rule ("[\\(\\)\\[\\]\\{\\}]", "Qdelimiter", name);
dfa_define_highlight_rule ("[0-9A-Za-z_\\-]+|->",
"Knormal", name);
dfa_define_highlight_rule ("[,\\.;:]", "delimiter", name);
dfa_define_highlight_rule ("[\\+\\-<>\\*/]+", "operator", name);
dfa_define_highlight_rule (".", "normal", name);
dfa_build_highlight_table (name);
}
dfa_set_init_callback (&setup_dfa_callback, "inform");
%%% DFA_CACHE_END %%%
#endif
() = define_keywords("inform", "doifonto", 2);
() = define_keywords("inform", "boxforhasoff", 3);
() = define_keywords("inform", "boldelsefontgivejumpmovequitreadsavewith", 4);
() = define_keywords("inform", "arraybreakclassfixedhasntnotinprintromanrtruestyleuntilwhile", 5);
() = define_keywords("inform", "globalnearbyobjectremovereturnrfalsespacesstringswitch", 6);
() = define_keywords("inform", "ofclassrestorereverse", 7);
() = define_keywords("inform", "constantcontinuenew_lineproperty", 8);
() = define_keywords("inform", "attributeinversionlowstringprint_retunderline", 9);
() = define_keywords("inform", "objectloop", 10);
() = define_keywords("inform", "fake_action", 11);
() = define_keywords_n("inform", "Endend", 3, 1);
() = define_keywords_n("inform", "Ifv3Ifv5LinkStubVerbifv3ifv5linkstubverb", 4, 1);
() = define_keywords_n("inform", "ArrayClassEndifIfdefTracearrayclassendififdeftrace", 5, 1);
() = define_keywords_n("inform", "BtraceEtraceExtendGlobalIfndefIftrueImportLtraceNearbyObjectSerialbtraceetraceextendglobalifndefiftrueimportltracenearbyobjectserial", 6, 1);
() = define_keywords_n("inform", "DefaultIffalseIncludeMessageNotraceReleaseReplacedefaultiffalseincludemessagenotracereleasereplace", 7, 1);
() = define_keywords_n("inform", "ConstantListdictNobtraceNoetraceNoltracePropertySwitchesconstantlistdictnobtracenoetracenoltracepropertyswitches", 8, 1);
() = define_keywords_n("inform", "AttributeListverbsLowstringattributelistverbslowstring", 9, 1);
() = define_keywords_n("inform", "AbbreviateDictionaryStatuslineZcharacterabbreviatedictionarystatuslinezcharacter", 10, 1);
() = define_keywords_n("inform", "Fake_actionListsymbolsSystem_filefake_actionlistsymbolssystem_file", 11, 1);
variable INFORM_INDENT = 4;
static define xlooking_at(word) {
variable s;
s = sprintf("%s ", word);
if (looking_at(s)) { return 1; }
s = sprintf("%s\n", word);
if (looking_at(s)) { return 1; }
s = sprintf("%s\t", word);
if (looking_at(s)) { return 1; }
return 0;
}
static define last_non_empty () {
do {
() = up(1);
eol();
} while (bolp() and (not bobp()));
}
static define last_line_ends_with_comma () {
push_spot();
EXIT_BLOCK {
pop_spot();
}
last_non_empty();
eol(); bskip_white();
return blooking_at(",");
}
static define last_line_starts_with_with () {
push_spot();
EXIT_BLOCK {
pop_spot();
}
last_non_empty();
bol_skip_white();
return looking_at("with\n");
}
static define inside_brackets() {
push_spot();
EXIT_BLOCK {
pop_spot();
}
return find_matching_delimiter(']');
}
static define inside_kw () {
push_spot();
EXIT_BLOCK {
pop_spot();
}
while (not bobp()) {
up(1);
bol_skip_white();
if (parse_to_point() == 0 and
inside_brackets() == 0) {
switch (0)
{ looking_at(";") : return 0; }
{ xlooking_at("object") : return 1; }
{ xlooking_at("class") : return 1; }
{ xlooking_at("has") : return 1; }
{ xlooking_at("with") : return 1; }
}
}
return 0;
}
define inform_indent_line () {
variable col = 0;
push_spot();
EXIT_BLOCK {
col--;
pop_spot();
bol_trim();
whitespace(col);
bol_skip_white();
}
eol(); bskip_white();
if (blooking_at(":")) {
col -= 2;
}
bol_skip_white();
if (parse_to_point() == -2) {
() = up(1);
bol_skip_white();
col = what_column();
return;
}
if (parse_to_point() == -1) {
do {
() = up(1);
bol_skip_white();
} while (parse_to_point() == -1 and not bobp());
while (not (looking_at("\"") or looking_at("'"))) {
() = right(1);
}
col = 1 + what_column();
return;
}
if (looking_at("]")) {
col -= INFORM_INDENT;
}
if (looking_at("}")) {
col -= INFORM_INDENT;
}
% [ 1 2 3 ;
% foo;
% bar;
% ]
push_spot();
if (find_matching_delimiter(']') == 1) {
bol_skip_white();
col += what_column() + INFORM_INDENT;
pop_spot();
return;
}
% if (foo) {
% foo;
% bar;
% }
pop_spot(); push_spot();
if (find_matching_delimiter('}') == 1) {
bskip_chars(" \n\t");
if (blooking_at(")")) {
() = left(1);
find_matching_delimiter(')');
}
bol_skip_white();
col += what_column() + INFORM_INDENT;
pop_spot();
return;
}
% if (foo (bar
% baz)
% blah)
% ...
pop_spot(); push_spot();
if (find_matching_delimiter(')') == 1) {
col += 1 + what_column();
pop_spot();
return;
}
pop_spot();
switch (0)
{ looking_at(";") : col = 0; }
{ xlooking_at("class") : col = 0; }
{ xlooking_at("object") : col = 0; }
{ xlooking_at("with") : col = INFORM_INDENT; }
{ xlooking_at("has") : col = INFORM_INDENT; }
{ 1 :
if (inside_kw()) {
col = 3 * INFORM_INDENT;
} else {
col = 0;
}
if (last_line_ends_with_comma() or
last_line_starts_with_with()) {
col -= INFORM_INDENT;
}
}
}
!if (keymap_p ("inform")) make_keymap ("inform");
define inform_mode () {
set_mode("inform", 4);
set_buffer_hook ("indent_hook", "inform_indent_line");
use_syntax_table ("inform");
use_keymap ("inform");
set_comment_info ("inform", "!", "", 0);
run_mode_hooks ("inform_mode_hook");
}