Highlight things
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

9ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
9ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
9ヶ月前
8ヶ月前
8ヶ月前
9ヶ月前
8ヶ月前
9ヶ月前
8ヶ月前
8ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
8ヶ月前
9ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
9ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
9ヶ月前
9ヶ月前
8ヶ月前
8ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
8ヶ月前
8ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # libhl
  2. ## API
  3. ```C
  4. int hl_init(void);
  5. int hl_deinit(void);
  6. ```
  7. These functions are responsible for the library's "life time".
  8. `hl_init()` must be called before any other library function.
  9. `hl_deinit()` will ensure all occupied memory is freed.
  10. ```C
  11. #define HLPATH ~/.local/hl/:~/.vim/syntax/
  12. ```
  13. Coma separated list of directories to be searched for syntax scripts. `#undef` to disable it entirely.
  14. ```C
  15. void render_string(const char * const string, const char * const mode); //XXX: rename
  16. ```
  17. This function matches _string_ against all known highlighting rules and dispatches the appropriate callback depending on _mode_.
  18. ```C
  19. int token_fits(const token_t * const token, const char * const to, const int string_offset, const bool is_start_of_line, int * match_offset);
  20. ```
  21. Fit a specific token against a string. `render_string()` uses this function internally.
  22. ```C
  23. typedef void (*attribute_callback_t)(const char * const string, const int length, void * const attributes);
  24. ```
  25. The type used for defining appropriate callbacks for render\_string().
  26. + string - string to be processed (probably printed)
  27. + length - number of characters to be processed from _string_
  28. + attributes - arbitrary data associated with the matched token; intended to hold color/font information for example; if no token was matched NULL will be passed
  29. ```C
  30. struct token_table_t;
  31. ```
  32. Holds a group of tokens belonging to the same language.
  33. ```C
  34. typedef struct {
  35. char * key;
  36. attribute_callback_t callback;
  37. } display_t;
  38. ```
  39. The type for defining display modes.
  40. ```C
  41. void new_display_mode(display_t * mode);
  42. ```
  43. This is how you append a display mode that render\_string() will search based on _.key_.
  44. ```C
  45. typedef enum {
  46. KEYSYMBOL,
  47. KEYWORD,
  48. MATCH,
  49. REGION
  50. } token_type_t;
  51. ```
  52. These are the valid type of distinct token types.
  53. + KEYSYMBOL - a string which is contextless, the surounding text is ignored
  54. "mysymbol" will match inside all of these:
  55. "something mysymbol something"
  56. "somethingmysymbolsomething"
  57. it is intended to match such thing as programming language operators
  58. + KEYWORD - a string which is recognized when surounded by word bundaries such as ' ' or '\t'
  59. + MATCH - a regular expression to be recognized
  60. + REGION - a regular expression where the starting and ending patters are to be distinguished from the contents
  61. The universal way to add a new pattern to be recognized is with:
  62. ```C
  63. token * new_token(const char * const syntax, const token_type_t t, const hl_group_t * const g);
  64. ```
  65. There are also convinience functions:
  66. ```C
  67. // NOTE: the return value is the number tokens successfully inserted
  68. int new_keyword_tokens(const char * const * words, hl_group_t * const g); // _words_ must be NULL terminated
  69. int new_syntax_char_tokens(const char * const chars, hl_group_t * const g);
  70. token_t * new_symbol_token(const char * const c, hl_group_t * const g);
  71. int new_symbol_tokens(const char * const * symbols, hl_group_t * const g);
  72. int new_char_tokens(const char * str, hl_group_t * const g);
  73. token_t * new_keyword_token(const char * const word, hl_group_t * const g);
  74. token_t * new_region_token(const char * start, const char * end, hl_group_t * g);
  75. ```
  76. The regex engine used for MATCH-es is Jeger by default, emulating Vim regex.
  77. However the regex engine can be overridden:
  78. ```C
  79. // ?!
  80. ```
  81. ### Default
  82. There are default of most anything defined for convenience. They can be disable with `#undef`-ing the following macro:
  83. ```C
  84. #define HL_DEFAULTS
  85. ```
  86. ```C
  87. hl_group_t * normal_hl
  88. hl_group_t * error_hl
  89. hl_group_t * warning_hl
  90. hl_group_t * search_hl
  91. hl_group_t * underlined_hl
  92. hl_group_t * bold_hl
  93. hl_group_t * italics_hl
  94. hl_group_t * comment_hl
  95. hl_group_t * block_hl
  96. hl_group_t * operator_hl
  97. hl_group_t * constant_hl
  98. hl_group_t * special_hl
  99. hl_group_t * identifier_hl
  100. hl_group_t * type_hl
  101. // ---
  102. token_table_t std_token_table;
  103. ```
  104. ---
  105. # hl
  106. General purpose highlighter (and demo program for libhl).
  107. ## Usage
  108. hl will read from stdin and write to stdout.
  109. ```bash
  110. hl < source/main.c
  111. ```
  112. ### Cli Options
  113. ```bash
  114. -h : display help message
  115. -I <dir> : syntax file look up directory
  116. -s <syntax> : specify syntax to load
  117. ```
  118. ### Environment variables
  119. ```bash
  120. $HLPATH : colon separated list of directories searched for syntax script files;
  121. overriddes the value of the HLPATH macro
  122. ```
  123. ---
  124. # Scripting
  125. hl can parse a small subset of VimScript: the few instructions related to highlighing, and it ignores everything else.
  126. All Vim highlighing scripts should be valid hl scripts.
  127. The instrunctions in particular are:
  128. ```vimscript
  129. sy[ntax] keyword <hl_group> <word>+
  130. sy[ntax] match <hl_group> <regex>
  131. sy[ntax] region <hl_group> start=<string|match> end=<string|match>
  132. hi[ghtlight] link <from_group> <to_group>
  133. hi[ghtlight] def <group> <display_t>=<data>+
  134. ```
  135. Additionally hl recognizes:
  136. ```vimscript
  137. syn[ntax] keysymbol <char>+
  138. ```