Переглянути джерело

Added Ada highlighting, changed bunch of simple stuff...

master
Ognjen Milan Robovic 8 місяці тому
джерело
коміт
98aaf77c38
1 змінених файлів з 61 додано та 24 видалено
  1. +61
    -24
      xighlight.c

+ 61
- 24
xighlight.c Переглянути файл

@@ -9,38 +9,75 @@
#include <xolatile/xyntax.h>
#include <xolatile/xyntax.c>

int main (void) {
int offset = 0;
int word = 0;
int select = 0;
int length = 0;
char * buffer = NULL;
static void highlight_c (void) {
char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";

char * separator = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";

char * c_keywords [32] = {
char * keywords [32] = {
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
"do", "while", "for", "continue", "switch", "case", "default", "break",
"enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
};

(void) syntax_define (1, 0, " \t\r\n", "", '\0', COLOUR_WHITE, EFFECT_NORMAL);
(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);
syntax_define_separators (separators);

for (word = 0; word != 32; ++word) {
(void) syntax_define (0, 1, c_keywords [word], separator, '\0', COLOUR_BLUE, EFFECT_BOLD);
}
syntax_define_default (COLOUR_RED, EFFECT_NORMAL, COLOUR_CYAN, 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);

(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);
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 ();
}

buffer = record ();

@@ -48,7 +85,7 @@ int main (void) {
select = syntax_select (& buffer [offset], & length);

if (select >= syntax_count) {
terminal_style (EFFECT_NORMAL, COLOUR_WHITE);
terminal_style (EFFECT_REVERSE, COLOUR_RED);
} else {
terminal_style (syntax_effect [select], syntax_colour [select]);
}


Завантаження…
Відмінити
Зберегти