more ideas
This commit is contained in:
parent
0b061ad658
commit
6b4c826680
59
README.md
59
README.md
@ -9,24 +9,34 @@ These functions are responsible for the library's "life time".
|
|||||||
`hl_init()` must be called before any other library function.
|
`hl_init()` must be called before any other library function.
|
||||||
`hl_deinit()` will ensure all occupied memory is freed.
|
`hl_deinit()` will ensure all occupied memory is freed.
|
||||||
|
|
||||||
|
|
||||||
```C
|
```C
|
||||||
void render_string(const char * const string, const char * const mode);
|
void render_string(const char * const string, const char * const mode); //XXX: rename
|
||||||
```
|
```
|
||||||
This function matches _string_ against all known highlighting rules and dispatches the appropriate callback depending on _mode_.
|
This function matches _string_ against all known highlighting rules and dispatches the appropriate callback depending on _mode_.
|
||||||
|
|
||||||
|
|
||||||
```C
|
```C
|
||||||
#define HLPATH //?!
|
#define HLPATH //?!
|
||||||
```
|
```
|
||||||
Coma separated list of directories to be searched for syntax scripts. `#undef` to disable it entirely.
|
Coma separated list of directories to be searched for syntax scripts. `#undef` to disable it entirely.
|
||||||
|
|
||||||
|
|
||||||
```C
|
```C
|
||||||
typedef void (*attribute_callback_t)(const char * const string, const int length, void * const attributes);
|
typedef void (*attribute_callback_t)(const char * const string, const int length, void * const attributes);
|
||||||
```
|
```
|
||||||
The type used for defining appropriate callbacks for render_string().
|
The type used for defining appropriate callbacks for render\_string().
|
||||||
+ string - string to be outputed
|
+ string - string to be outputed
|
||||||
+ length - number of characters that matched a highlighting rule
|
+ length - number of characters that matched a highlighting rule
|
||||||
+ attributes - arbitrary data associated with the matched rule; intended to hold color/font information for example
|
+ attributes - arbitrary data associated with the matched rule; intended to hold color/font information for example
|
||||||
|
|
||||||
|
|
||||||
|
```C
|
||||||
|
struct token_table_t;
|
||||||
|
```
|
||||||
|
Holds a group of tokens belonging to the same language.
|
||||||
|
|
||||||
|
|
||||||
```C
|
```C
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char * key;
|
char * key;
|
||||||
@ -35,8 +45,12 @@ typedef struct {
|
|||||||
```
|
```
|
||||||
The type for defining display modes.
|
The type for defining display modes.
|
||||||
|
|
||||||
void new_display_mode(display_t * mode);
|
|
||||||
This is how you append a display mode that render_string() will search based on _.key_.
|
```C
|
||||||
|
void new_display_mode(display_t * mode);
|
||||||
|
```
|
||||||
|
This is how you append a display mode that render\_string() will search based on _.key_.
|
||||||
|
|
||||||
|
|
||||||
```C
|
```C
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@ -57,24 +71,59 @@ These are the valid type of distinct token types.
|
|||||||
+ MATCH - a regular expression to be recognized
|
+ MATCH - a regular expression to be recognized
|
||||||
+ REGION - a regular expression where the starting and ending patters are to be distinguished from the contents
|
+ REGION - a regular expression where the starting and ending patters are to be distinguished from the contents
|
||||||
|
|
||||||
|
|
||||||
The universal way to add a new pattern to be recognized is with:
|
The universal way to add a new pattern to be recognized is with:
|
||||||
```C
|
```C
|
||||||
token * new_token(const char * const syntax, const token_type_t t, const hl_group_t * const g);
|
token * new_token(const char * const syntax, const token_type_t t, const hl_group_t * const g);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
There are also convinience functions:
|
There are also convinience functions:
|
||||||
```C
|
```C
|
||||||
// NOTE: the return value is the number tokens successfully inserted
|
// NOTE: the return value is the number tokens successfully inserted
|
||||||
int new_keyword_tokens(const char * const * words, hl_group_t * const g); // _words_ must be NULL terminated
|
int new_keyword_tokens(const char * const * words, hl_group_t * const g); // _words_ must be NULL terminated
|
||||||
int new_syntax_character_tokens(const char * const chars, hl_group_t * const g);
|
int new_syntax_character_tokens(const char * const chars, hl_group_t * const g);
|
||||||
```
|
```
|
||||||
The regex engine used for MATCHes is Jeger by default, emulating Vim regex.
|
|
||||||
|
|
||||||
|
The regex engine used for MATCH-es is Jeger by default, emulating Vim regex.
|
||||||
However the regex engine can be overridden:
|
However the regex engine can be overridden:
|
||||||
```C
|
```C
|
||||||
// ?!
|
// ?!
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Default
|
||||||
|
There are default of most anything defined for convenience. They can be disable with `#undef`-ing the following macro:
|
||||||
|
```C
|
||||||
|
#define HL_DEFAULTS
|
||||||
|
```
|
||||||
|
|
||||||
|
```C
|
||||||
|
hl_group_t * normal_hl
|
||||||
|
hl_group_t * error_hl
|
||||||
|
hl_group_t * warning_hl
|
||||||
|
hl_group_t * search_hl
|
||||||
|
|
||||||
|
hl_group_t * underlined_hl
|
||||||
|
hl_group_t * bold_hl
|
||||||
|
hl_group_t * italics_hl
|
||||||
|
|
||||||
|
hl_group_t * comment_hl
|
||||||
|
hl_group_t * block_hl
|
||||||
|
hl_group_t * operator_hl
|
||||||
|
hl_group_t * constant_hl
|
||||||
|
hl_group_t * special_hl
|
||||||
|
hl_group_t * identifier_hl
|
||||||
|
hl_group_t * type_hl
|
||||||
|
|
||||||
|
// ---
|
||||||
|
token_table_t std_token_table;
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
# hl
|
# hl
|
||||||
General purpose highlighter (and demo program for libhl).
|
General purpose highlighter (and demo program for libhl).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user