Herb C Reference
Loading...
Searching...
No Matches
lex_helpers.h
Go to the documentation of this file.
1#ifndef HERB_LEX_HELPERS_H
2#define HERB_LEX_HELPERS_H
3
4#include "herb.h"
5#include "token.h"
6#include "util/hb_allocator.h"
7#include "util/hb_array.h"
8#include "util/hb_buffer.h"
9#include "util/hb_string.h"
10
11#include <stdlib.h>
12
13static inline void herb_lex_to_buffer(const char* source, hb_buffer_T* output, hb_allocator_T* allocator) {
14 hb_array_T* tokens = herb_lex(source, allocator);
15
16 for (size_t i = 0; i < hb_array_size(tokens); i++) {
17 token_T* token = hb_array_get(tokens, i);
18
19 hb_string_T type = token_to_string(allocator, token);
20 hb_buffer_append_string(output, type);
21 hb_allocator_dealloc(allocator, type.data);
22
23 hb_buffer_append(output, "\n");
24 }
25
26 herb_free_tokens(&tokens, allocator);
27}
28
29#endif
HERB_EXPORTED_FUNCTION void herb_free_tokens(hb_array_T **tokens, hb_allocator_T *allocator)
Definition herb.c:69
HERB_EXPORTED_FUNCTION hb_array_T * herb_lex(const char *source, hb_allocator_T *allocator)
Definition herb.c:15
static void herb_lex_to_buffer(const char *source, hb_buffer_T *output, hb_allocator_T *allocator)
Definition lex_helpers.h:13
Definition token_struct.h:58
hb_string_T token_to_string(hb_allocator_T *allocator, const token_T *token)
Definition token.c:164