Compare commits
No commits in common. "db1199cfa8d25964e338b8b5db4016964e7d7643" and "8a3adb7862163803b31845c43944e0fdaca6c238" have entirely different histories.
db1199cfa8
...
8a3adb7862
49
README.md
49
README.md
@ -2,25 +2,20 @@
|
|||||||
|
|
||||||
## API
|
## API
|
||||||
```C
|
```C
|
||||||
int hl_init(void);
|
int hl_init(void);
|
||||||
int hl_deinit(void);
|
int hl_deinit(void);
|
||||||
```
|
```
|
||||||
These functions are responsible for the library's "life time".
|
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);
|
||||||
```
|
```
|
||||||
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 //?!
|
typedef void (*attribute_callback_t)(const char * const string, const int length, void * const attributes);
|
||||||
```
|
|
||||||
Coma separated list of directories to be searched for syntax scripts. `#undef` to disable it entirely.
|
|
||||||
|
|
||||||
```C
|
|
||||||
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
|
||||||
@ -39,12 +34,12 @@ The type for defining display modes.
|
|||||||
This is how you append a display mode that render_string() will search based on _.key_.
|
This is how you append a display mode that render_string() will search based on _.key_.
|
||||||
|
|
||||||
```C
|
```C
|
||||||
typedef enum {
|
typedef enum {
|
||||||
KEYSYMBOL,
|
KEYSYMBOL,
|
||||||
KEYWORD,
|
KEYWORD,
|
||||||
MATCH,
|
MATCH,
|
||||||
REGION
|
REGION
|
||||||
} token_type_t;
|
} token_type_t;
|
||||||
```
|
```
|
||||||
These are the valid type of distinct token types.
|
These are the valid type of distinct token types.
|
||||||
|
|
||||||
@ -59,13 +54,14 @@ These are the valid type of distinct token types.
|
|||||||
|
|
||||||
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 MATCHes is Jeger by default, emulating Vim regex.
|
||||||
However the regex engine can be overridden:
|
However the regex engine can be overridden:
|
||||||
@ -81,20 +77,19 @@ General purpose highlighter (and demo program for libhl).
|
|||||||
## Usage
|
## Usage
|
||||||
hl will read from stdin and write to stdout.
|
hl will read from stdin and write to stdout.
|
||||||
```bash
|
```bash
|
||||||
hl < source/main.c
|
hl < source/main.c
|
||||||
```
|
```
|
||||||
|
|
||||||
### Cli Options
|
### Cli Options
|
||||||
```bash
|
```bash
|
||||||
-h : display help message
|
-h : display help message
|
||||||
-I <dir> : syntax file look up directory
|
-I <dir> : syntax file look up directory
|
||||||
-s <syntax> : specify syntax to load
|
-s <syntax> : specify syntax to load
|
||||||
```
|
```
|
||||||
|
|
||||||
### Environment variables
|
### Environment variables
|
||||||
```bash
|
```bash
|
||||||
$HLPATH : colon separated list of directories searched for syntax script files;
|
$HLPATH : colon separated list of directories searched for syntax script files
|
||||||
overriddes the value of the HLPATH macro
|
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
@ -105,15 +100,15 @@ All Vim highlighing scripts should be valid hl scripts.
|
|||||||
The instrunctions in particular are:
|
The instrunctions in particular are:
|
||||||
|
|
||||||
```vimscript
|
```vimscript
|
||||||
sy[ntax] keyword <hl_group> <word>+
|
sy[ntax] keyword <hl_group> <word>+
|
||||||
sy[ntax] match <hl_group> <regex>
|
sy[ntax] match <hl_group> <regex>
|
||||||
sy[ntax] region <hl_group> start=<string|match> end=<string|match>
|
sy[ntax] region <hl_group> start=<string|match> end=<string|match>
|
||||||
hi[ghtlight] link <from_group> <to_group>
|
hi[ghtlight] link <from_group> <to_group>
|
||||||
hi[ghtlight] def <group> <display_t>=<data>+
|
hi[ghtlight] def <group> <display_t>=<data>+
|
||||||
```
|
```
|
||||||
|
|
||||||
Additionally hl recognizes:
|
Additionally hl recognizes:
|
||||||
|
|
||||||
```vimscript
|
```vimscript
|
||||||
syn[ntax] keysymbol <char>+
|
syn[ntax] keysymbol <char>+
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user