xyntax -- Header-only library for syntax highlighting control.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
Ognjen Milan Robovic ef2cf04a3e Read me not and ignore me please... il y a 2 mois
.gitignore Read me not and ignore me please... il y a 2 mois
LICENSE Initial commit il y a 8 mois
README.md Read me not and ignore me please... il y a 2 mois
compile.sh A lot of stuff changed, might even delete some in the future... il y a 6 mois
install.sh A lot of stuff changed, might even delete some in the future... il y a 6 mois
xyntax.c Changed naming to redo standard... il y a 4 mois
xyntax.h Changed naming to redo standard... il y a 4 mois

README.md

xyntax

xyntax -- Xolatile-style “header-only” library for syntax definition control.

  • Primary focus of this library is for syntax highlighting, hence the name, but it can do more...
  • Important note: Regular expressions are more robust, this is simple solution for simple problems.
  • Everything related to my libraries is clean of all warning options on Clang, GCC and Valgrind.

Compile:

sh compile.sh

Install:

$ sudo sh install.sh

Usage:

#include <xolatile/xyntax.h> /* Or: */
#include <xolatile/xyntax.c> /* Instead of '#define BLA_BLA_IMPLEMENTATION' if you want to compile it all together. */
...
int symbols = syntax_define (true, false, ".,:;<=>+-*/%!&~^?|()[]{}", "", '\0', 0, 0);
/* Variable 'symbols' will become the index of current 'syntax_count', and you can use it to count elements or select them without null-termination. */
...
int select = syntax_select (& buffer [offset], & length);
/* Variable 'select' will become the index of syntax rule you defined previously, or 'syntax_count' if there is no match. */
/* It's important to note that for performance reasons I'm not returning a string or structure, but index and length of the token. */

It can be used for:

  • syntax highlighting in terminal or graphical text editors...
  • source code processing, parsing, tokenization...
  • counting source code elements such as keywords, literals, brackets...

For example, your can define simple ANSI C syntax highlight like this:

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

char * keywords [] = {
	"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"
};

int word;

syntax_define (false, false, "/*", "*/", '\0', colour_grey,   effect_bold);
syntax_define (false, false, "//", "\n", '\0', colour_grey,   effect_bold);
syntax_define (false, false, "#",  "\n", '\\', colour_yellow, effect_italic);
syntax_define (false, false, "'",  "'",  '\\', colour_pink,   effect_bold);
syntax_define (false, false, "\"", "\"", '\\', colour_pink,   effect_normal);

for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
	syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
}

syntax_define (true, false, "()[]{}",             "", '\0', colour_blue, effect_normal);
syntax_define (true, false, ".,:;<=>+*-/%!&~^?|", "", '\0', colour_cyan, effect_normal);

syntax_define (true, true, "0123456789",                 separators, '\0', colour_pink,  effect_bold);
syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
syntax_define (true, true, "_",                          separators, '\0', colour_white, effect_italic);

If you want to do parsing, counting, tokenization, you can use return value of ‘syntax_define’...