xyntax -- Header-only library for syntax highlighting control.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

преди 9 месеца
преди 8 месеца
преди 2 месеца
преди 8 месеца
преди 6 месеца
преди 8 месеца
преди 6 месеца
преди 8 месеца
преди 2 месеца
преди 6 месеца
преди 8 месеца
преди 2 месеца
преди 6 месеца
преди 8 месеца
преди 2 месеца
преди 8 месеца
преди 2 месеца
преди 8 месеца
преди 8 месеца
преди 6 месеца
преди 2 месеца
преди 8 месеца
преди 6 месеца
преди 2 месеца
преди 8 месеца
преди 6 месеца
преди 2 месеца
преди 8 месеца
преди 2 месеца
преди 8 месеца
преди 6 месеца
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # xyntax
  2. xyntax -- Xolatile-style "header-only" library for syntax definition control.
  3. - Primary focus of this library is for syntax highlighting, hence the name, but it can do more...
  4. - Important note: Regular expressions are more robust, this is simple solution for simple problems.
  5. - Everything related to my libraries is clean of all warning options on Clang, GCC and Valgrind.
  6. Compile:
  7. ```bash
  8. sh compile.sh
  9. ```
  10. Install:
  11. ```bash
  12. $ sudo sh install.sh
  13. ```
  14. Usage:
  15. ```c
  16. #include <xolatile/xyntax.h> /* Or: */
  17. #include <xolatile/xyntax.c> /* Instead of '#define BLA_BLA_IMPLEMENTATION' if you want to compile it all together. */
  18. ...
  19. int symbols = syntax_define (true, false, ".,:;<=>+-*/%!&~^?|()[]{}", "", '\0', 0, 0);
  20. /* Variable 'symbols' will become the index of current 'syntax_count', and you can use it to count elements or select them without null-termination. */
  21. ...
  22. int select = syntax_select (& buffer [offset], & length);
  23. /* Variable 'select' will become the index of syntax rule you defined previously, or 'syntax_count' if there is no match. */
  24. /* It's important to note that for performance reasons I'm not returning a string or structure, but index and length of the token. */
  25. ```
  26. It can be used for:
  27. - syntax highlighting in terminal or graphical text editors...
  28. - source code processing, parsing, tokenization...
  29. - counting source code elements such as keywords, literals, brackets...
  30. For example, your can define simple ANSI C syntax highlight like this:
  31. ```c
  32. char * separators = ".,:;<=>+-*/%!&~^?|()[]{}'\" \t\r\n";
  33. char * keywords [] = {
  34. "register", "volatile", "auto", "const",
  35. "static", "extern", "if", "else",
  36. "do", "while", "for", "continue",
  37. "switch", "case", "default", "break",
  38. "enum", "union", "struct", "typedef",
  39. "goto", "void", "return", "sizeof",
  40. "char", "short", "int", "long",
  41. "signed", "unsigned", "float", "double"
  42. };
  43. int word;
  44. syntax_define (false, false, "/*", "*/", '\0', colour_grey, effect_bold);
  45. syntax_define (false, false, "//", "\n", '\0', colour_grey, effect_bold);
  46. syntax_define (false, false, "#", "\n", '\\', colour_yellow, effect_italic);
  47. syntax_define (false, false, "'", "'", '\\', colour_pink, effect_bold);
  48. syntax_define (false, false, "\"", "\"", '\\', colour_pink, effect_normal);
  49. for (word = 0; word != (int) (sizeof (keywords) / sizeof (keywords [0])); ++word) {
  50. syntax_define (false, true, keywords [word], separators, '\0', colour_yellow, effect_bold);
  51. }
  52. syntax_define (true, false, "()[]{}", "", '\0', colour_blue, effect_normal);
  53. syntax_define (true, false, ".,:;<=>+*-/%!&~^?|", "", '\0', colour_cyan, effect_normal);
  54. syntax_define (true, true, "0123456789", separators, '\0', colour_pink, effect_bold);
  55. syntax_define (true, true, "abcdefghijklmnopqrstuvwxyz", separators, '\0', colour_white, effect_normal);
  56. syntax_define (true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separators, '\0', colour_white, effect_bold);
  57. syntax_define (true, true, "_", separators, '\0', colour_white, effect_italic);
  58. ```
  59. If you want to do parsing, counting, tokenization, you can use return value of 'syntax_define'...