Add an error check for correct formatting in Deflate uncompressed
[sgt/halibut] / misc / halibut.sl
1 % Halibut mode for Jed.
2
3 $1 = "Halibut";
4 create_syntax_table ($1);
5
6 define_syntax ("\#", "", '%', $1); % Comment Syntax
7 define_syntax ('\\', '\\', $1); % Quote character
8 define_syntax ("{", "}", '(', $1); % are all these needed?
9 define_syntax ("a-zA-Z0-9", 'w', $1);
10 set_syntax_flags ($1, 8);
11
12 #ifdef HAS_DFA_SYNTAX
13 %enable_highlight_cache ("halibut.dfa", $1);
14
15 % A braced comment in Halibut is \#{ ... }, where ... may contain
16 % any correctly nested sequence of braces. Of course we can't match
17 % that in a DFA rule, so we'll go down to a reasonable depth of 3
18 % instead.
19 #ifexists dfa_define_highlight_rule
20 dfa_define_highlight_rule ("\\\\#{[^{}]*({[^{}]*({[^}]*}[^{}]*)*}[^{}]*)*}",
21 "Qcomment", $1);
22
23 dfa_define_highlight_rule ("\\\\#.*$", "comment", $1);
24 dfa_define_highlight_rule ("^\\\\c([ \t].*)?$", "string", $1);
25 dfa_define_highlight_rule ("\\\\[\\\\{}\\-_]", "keyword0", $1);
26 dfa_define_highlight_rule ("\\\\[A-Za-tv-z][A-Za-z0-9]*", "keyword0", $1);
27 dfa_define_highlight_rule ("\\\\u[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]",
28 "keyword0", $1);
29 dfa_define_highlight_rule ("\\\\u[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]",
30 "keyword1", $1);
31 dfa_define_highlight_rule ("[{}]", "delimiter", $1);
32 dfa_define_highlight_rule (".", "normal", $1);
33 dfa_build_highlight_table ($1);
34 #else
35 define_highlight_rule ("\\\\#{[^{}]*({[^{}]*({[^}]*}[^{}]*)*}[^{}]*)*}",
36 "Qcomment", $1);
37
38 define_highlight_rule ("\\\\#.*$", "comment", $1);
39 define_highlight_rule ("^\\\\c([ \t].*)?$", "string", $1);
40 define_highlight_rule ("\\\\[\\\\{}\\-_]", "keyword0", $1);
41 define_highlight_rule ("\\\\[A-Za-tv-z][A-Za-z0-9]*", "keyword0", $1);
42 define_highlight_rule ("\\\\u[A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9][A-Fa-f0-9]",
43 "keyword0", $1);
44 define_highlight_rule ("\\\\u[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]?[A-Fa-f0-9]",
45 "keyword1", $1);
46 define_highlight_rule ("[{}]", "delimiter", $1);
47 define_highlight_rule (".", "normal", $1);
48 build_highlight_table ($1);
49 #endif
50 #endif
51
52 % This hook identifies lines containing comments as paragraph separator
53 define halibut_is_comment() {
54 bol ();
55 while (ffind ("\\\\#")) go_right (3);
56 ffind ("\\#"); % return value on stack
57 }
58
59 variable Halibut_Ignore_Comment = 0; % if true, line containing a comment
60 % does not delimit a paragraph
61
62 define halibut_paragraph_separator() {
63 bol();
64 skip_white();
65 if (eolp())
66 return 1;
67 if (looking_at("\\c ") or looking_at("\\c\t") or
68 looking_at("\\c\n"))
69 return 1;
70 return not (Halibut_Ignore_Comment) and halibut_is_comment();
71 }
72
73 define halibut_wrap_hook() {
74 variable yep;
75 push_spot ();
76 yep = up_1 () and halibut_is_comment ();
77 pop_spot ();
78 if (yep) {
79 push_spot ();
80 bol_skip_white ();
81 insert ("\\# ");
82 pop_spot ();
83 }
84 }
85
86 #ifexists mode_set_mode_info
87 mode_set_mode_info("Halibut", "fold_info", "\\# {{{\r\\# }}}\r\r");
88 #endif
89
90 define halibut_mode() {
91 variable mode = "Halibut";
92 % use_keymap (mode);
93 set_mode (mode, 0x1 | 0x20);
94 set_buffer_hook ("par_sep", "halibut_paragraph_separator");
95 set_buffer_hook ("wrap_hook", "halibut_wrap_hook");
96 use_syntax_table (mode);
97 runhooks ("halibut_mode_hook");
98 }