Added Ada highlighting, changed bunch of simple stuff...
This commit is contained in:
parent
73288f6b0b
commit
98aaf77c38
85
xighlight.c
85
xighlight.c
@ -9,46 +9,83 @@
|
|||||||
#include <xolatile/xyntax.h>
|
#include <xolatile/xyntax.h>
|
||||||
#include <xolatile/xyntax.c>
|
#include <xolatile/xyntax.c>
|
||||||
|
|
||||||
int main (void) {
|
static void highlight_c (void) {
|
||||||
int offset = 0;
|
char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
|
||||||
int word = 0;
|
|
||||||
int select = 0;
|
|
||||||
int length = 0;
|
|
||||||
char * buffer = NULL;
|
|
||||||
|
|
||||||
char * separator = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
|
char * keywords [32] = {
|
||||||
|
|
||||||
char * c_keywords [32] = {
|
|
||||||
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
|
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
|
||||||
"do", "while", "for", "continue", "switch", "case", "default", "break",
|
"do", "while", "for", "continue", "switch", "case", "default", "break",
|
||||||
"enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
|
"enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
|
||||||
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
||||||
};
|
};
|
||||||
|
|
||||||
(void) syntax_define (1, 0, " \t\r\n", "", '\0', COLOUR_WHITE, EFFECT_NORMAL);
|
syntax_define_separators (separators);
|
||||||
(void) syntax_define (0, 0, "#", "\n", '\\', COLOUR_PINK, EFFECT_BOLD);
|
|
||||||
(void) syntax_define (0, 0, "//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
|
||||||
(void) syntax_define (0, 0, "/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
|
|
||||||
(void) syntax_define (0, 0, "'", "'", '\\', COLOUR_RED, EFFECT_NORMAL);
|
|
||||||
(void) syntax_define (0, 0, "\"", "\"", '\\', COLOUR_RED, EFFECT_BOLD);
|
|
||||||
(void) syntax_define (1, 0, ".,:;<=>+-*/%!&~^?|()[]{}", "", '\0', COLOUR_CYAN, EFFECT_NORMAL);
|
|
||||||
|
|
||||||
for (word = 0; word != 32; ++word) {
|
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
||||||
(void) syntax_define (0, 1, c_keywords [word], separator, '\0', COLOUR_BLUE, EFFECT_BOLD);
|
|
||||||
|
syntax_define_range ("/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
|
syntax_define_range ("//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
|
syntax_define_range ("#", "\n", '\\', COLOUR_PINK, EFFECT_NORMAL);
|
||||||
|
syntax_define_range ("'", "'", '\\', COLOUR_PINK, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_operators (".,:;<=>+*-/%!&~^?|()[]{}", COLOUR_BLUE, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_words (keywords, 32, COLOUR_BLUE, EFFECT_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void highlight_ada (void) {
|
||||||
|
char * separators = ".,:;<=>+-*/&|()\" \t\r\n";
|
||||||
|
|
||||||
|
char * keywords [73] = {
|
||||||
|
"abort", "else", "new", "return", "abs", "elsif", "not", "reverse",
|
||||||
|
"abstract", "end", "null", "accept", "entry", "select", "access", "of",
|
||||||
|
"separate", "aliased", "exit", "or", "some", "all", "others", "subtype",
|
||||||
|
"and", "for", "out", "array", "function", "at", "tagged", "generic",
|
||||||
|
"package", "task", "begin", "goto", "pragma", "body", "private", "then",
|
||||||
|
"type", "case", "in", "constant", "until", "is", "raise", "use",
|
||||||
|
"if", "declare", "range", "delay", "limited", "record", "when", "delta",
|
||||||
|
"loop", "rem", "while", "digits", "renames", "with", "do", "mod",
|
||||||
|
"requeue", "xor", "procedure", "protected", "interface",
|
||||||
|
"synchronized", "exception", "overriding", "terminate"
|
||||||
|
};
|
||||||
|
|
||||||
|
syntax_define_separators (separators);
|
||||||
|
|
||||||
|
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_range ("--", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
|
||||||
|
syntax_define_range ("'", "'", '\0', COLOUR_PINK, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_operators (".,:;<=>+-*/&|()'", COLOUR_BLUE, EFFECT_BOLD);
|
||||||
|
|
||||||
|
syntax_define_words (keywords, 73, COLOUR_BLUE, EFFECT_NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main (int argc, char * * argv) {
|
||||||
|
int offset = 0;
|
||||||
|
int select = 0;
|
||||||
|
int length = 0;
|
||||||
|
char * buffer = NULL;
|
||||||
|
|
||||||
|
if (argc != 1) {
|
||||||
|
if (string_compare (argv [1], "c") != 0) {
|
||||||
|
highlight_c ();
|
||||||
|
} else if (string_compare (argv [1], "ada") != 0) {
|
||||||
|
highlight_ada ();
|
||||||
|
} else {
|
||||||
|
highlight_c ();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
highlight_c ();
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) syntax_define (1, 1, "_", separator, '\0', COLOUR_GREY, EFFECT_BOLD);
|
|
||||||
(void) syntax_define (1, 1, "0123456789", separator, '\0', COLOUR_CYAN, EFFECT_BOLD);
|
|
||||||
(void) syntax_define (1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', COLOUR_PINK, EFFECT_ITALIC);
|
|
||||||
(void) syntax_define (1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', COLOUR_WHITE, EFFECT_ITALIC);
|
|
||||||
|
|
||||||
buffer = record ();
|
buffer = record ();
|
||||||
|
|
||||||
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
for (offset = 0; buffer [offset] != '\0'; offset += length) {
|
||||||
select = syntax_select (& buffer [offset], & length);
|
select = syntax_select (& buffer [offset], & length);
|
||||||
|
|
||||||
if (select >= syntax_count) {
|
if (select >= syntax_count) {
|
||||||
terminal_style (EFFECT_NORMAL, COLOUR_WHITE);
|
terminal_style (EFFECT_REVERSE, COLOUR_RED);
|
||||||
} else {
|
} else {
|
||||||
terminal_style (syntax_effect [select], syntax_colour [select]);
|
terminal_style (syntax_effect [select], syntax_colour [select]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user