@herb-tools/node 0.8.10 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/binding.gyp +26 -8
- package/dist/herb-node.cjs +41 -12
- package/dist/herb-node.cjs.map +1 -1
- package/dist/herb-node.esm.js +8 -1
- package/dist/herb-node.esm.js.map +1 -1
- package/dist/types/node-backend.d.ts +3 -1
- package/extension/error_helpers.cpp +395 -73
- package/extension/error_helpers.h +13 -3
- package/extension/extension_helpers.cpp +38 -35
- package/extension/extension_helpers.h +2 -2
- package/extension/herb.cpp +183 -64
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.c +290 -0
- package/extension/libherb/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/analyze/action_view/content_tag.c +70 -0
- package/extension/libherb/analyze/action_view/link_to.c +143 -0
- package/extension/libherb/analyze/action_view/registry.c +60 -0
- package/extension/libherb/analyze/action_view/tag.c +64 -0
- package/extension/libherb/analyze/action_view/tag_helper_handler.h +41 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.c +305 -0
- package/extension/libherb/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/analyze/action_view/tag_helpers.c +748 -0
- package/extension/libherb/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/analyze/action_view/turbo_frame_tag.c +88 -0
- package/extension/libherb/analyze/analyze.c +882 -0
- package/extension/libherb/{include → analyze}/analyze.h +14 -4
- package/extension/libherb/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
- package/extension/libherb/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/analyze/builders.c +343 -0
- package/extension/libherb/analyze/builders.h +27 -0
- package/extension/libherb/analyze/conditional_elements.c +594 -0
- package/extension/libherb/analyze/conditional_elements.h +9 -0
- package/extension/libherb/analyze/conditional_open_tags.c +640 -0
- package/extension/libherb/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/analyze/control_type.c +250 -0
- package/extension/libherb/analyze/control_type.h +14 -0
- package/extension/libherb/{analyze_helpers.c → analyze/helpers.c} +48 -23
- package/extension/libherb/{analyze_helpers.h → analyze/helpers.h} +4 -2
- package/extension/libherb/analyze/invalid_structures.c +193 -0
- package/extension/libherb/analyze/invalid_structures.h +11 -0
- package/extension/libherb/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
- package/extension/libherb/analyze/parse_errors.c +84 -0
- package/extension/libherb/analyze/prism_annotate.c +397 -0
- package/extension/libherb/analyze/prism_annotate.h +16 -0
- package/extension/libherb/{analyze_transform.c → analyze/transform.c} +17 -3
- package/extension/libherb/ast_node.c +17 -7
- package/extension/libherb/ast_node.h +11 -5
- package/extension/libherb/ast_nodes.c +663 -388
- package/extension/libherb/ast_nodes.h +118 -39
- package/extension/libherb/ast_pretty_print.c +191 -7
- package/extension/libherb/ast_pretty_print.h +6 -1
- package/extension/libherb/element_source.h +3 -8
- package/extension/libherb/errors.c +1077 -521
- package/extension/libherb/errors.h +149 -56
- package/extension/libherb/extract.c +145 -49
- package/extension/libherb/extract.h +21 -5
- package/extension/libherb/herb.c +52 -34
- package/extension/libherb/herb.h +18 -6
- package/extension/libherb/herb_prism_node.h +13 -0
- package/extension/libherb/html_util.c +241 -12
- package/extension/libherb/html_util.h +7 -2
- package/extension/libherb/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_handler.h +41 -0
- package/extension/libherb/include/analyze/action_view/tag_helper_node_builders.h +70 -0
- package/extension/libherb/include/analyze/action_view/tag_helpers.h +38 -0
- package/extension/libherb/{analyze.h → include/analyze/analyze.h} +14 -4
- package/extension/libherb/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- package/extension/libherb/include/analyze/builders.h +27 -0
- package/extension/libherb/include/analyze/conditional_elements.h +9 -0
- package/extension/libherb/include/analyze/conditional_open_tags.h +9 -0
- package/extension/libherb/include/analyze/control_type.h +14 -0
- package/extension/libherb/include/{analyze_helpers.h → analyze/helpers.h} +4 -2
- package/extension/libherb/include/analyze/invalid_structures.h +11 -0
- package/extension/libherb/include/analyze/prism_annotate.h +16 -0
- package/extension/libherb/include/ast_node.h +11 -5
- package/extension/libherb/include/ast_nodes.h +118 -39
- package/extension/libherb/include/ast_pretty_print.h +6 -1
- package/extension/libherb/include/element_source.h +3 -8
- package/extension/libherb/include/errors.h +149 -56
- package/extension/libherb/include/extract.h +21 -5
- package/extension/libherb/include/herb.h +18 -6
- package/extension/libherb/include/herb_prism_node.h +13 -0
- package/extension/libherb/include/html_util.h +7 -2
- package/extension/libherb/include/io.h +3 -1
- package/extension/libherb/include/lex_helpers.h +29 -0
- package/extension/libherb/include/lexer.h +1 -1
- package/extension/libherb/include/lexer_peek_helpers.h +87 -13
- package/extension/libherb/include/lexer_struct.h +2 -0
- package/extension/libherb/include/location.h +2 -1
- package/extension/libherb/include/parser.h +27 -2
- package/extension/libherb/include/parser_helpers.h +19 -3
- package/extension/libherb/include/pretty_print.h +10 -5
- package/extension/libherb/include/prism_context.h +45 -0
- package/extension/libherb/include/prism_helpers.h +10 -7
- package/extension/libherb/include/prism_serialized.h +12 -0
- package/extension/libherb/include/token.h +16 -4
- package/extension/libherb/include/token_struct.h +10 -3
- package/extension/libherb/include/utf8.h +2 -1
- package/extension/libherb/include/util/hb_allocator.h +78 -0
- package/extension/libherb/include/util/hb_arena.h +6 -1
- package/extension/libherb/include/util/hb_arena_debug.h +12 -1
- package/extension/libherb/include/util/hb_array.h +7 -3
- package/extension/libherb/include/util/hb_buffer.h +6 -4
- package/extension/libherb/include/util/hb_foreach.h +79 -0
- package/extension/libherb/include/util/hb_narray.h +8 -4
- package/extension/libherb/include/util/hb_string.h +56 -9
- package/extension/libherb/include/util.h +6 -3
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/io.c +3 -2
- package/extension/libherb/io.h +3 -1
- package/extension/libherb/lex_helpers.h +29 -0
- package/extension/libherb/lexer.c +42 -30
- package/extension/libherb/lexer.h +1 -1
- package/extension/libherb/lexer_peek_helpers.c +12 -74
- package/extension/libherb/lexer_peek_helpers.h +87 -13
- package/extension/libherb/lexer_struct.h +2 -0
- package/extension/libherb/location.c +2 -2
- package/extension/libherb/location.h +2 -1
- package/extension/libherb/main.c +53 -28
- package/extension/libherb/parser.c +783 -247
- package/extension/libherb/parser.h +27 -2
- package/extension/libherb/parser_helpers.c +110 -23
- package/extension/libherb/parser_helpers.h +19 -3
- package/extension/libherb/parser_match_tags.c +110 -49
- package/extension/libherb/pretty_print.c +29 -24
- package/extension/libherb/pretty_print.h +10 -5
- package/extension/libherb/prism_context.h +45 -0
- package/extension/libherb/prism_helpers.c +30 -27
- package/extension/libherb/prism_helpers.h +10 -7
- package/extension/libherb/prism_serialized.h +12 -0
- package/extension/libherb/ruby_parser.c +2 -0
- package/extension/libherb/token.c +151 -66
- package/extension/libherb/token.h +16 -4
- package/extension/libherb/token_matchers.c +0 -1
- package/extension/libherb/token_struct.h +10 -3
- package/extension/libherb/utf8.c +7 -6
- package/extension/libherb/utf8.h +2 -1
- package/extension/libherb/util/hb_allocator.c +341 -0
- package/extension/libherb/util/hb_allocator.h +78 -0
- package/extension/libherb/util/hb_arena.c +81 -56
- package/extension/libherb/util/hb_arena.h +6 -1
- package/extension/libherb/util/hb_arena_debug.c +32 -17
- package/extension/libherb/util/hb_arena_debug.h +12 -1
- package/extension/libherb/util/hb_array.c +30 -15
- package/extension/libherb/util/hb_array.h +7 -3
- package/extension/libherb/util/hb_buffer.c +17 -21
- package/extension/libherb/util/hb_buffer.h +6 -4
- package/extension/libherb/util/hb_foreach.h +79 -0
- package/extension/libherb/util/hb_narray.c +22 -7
- package/extension/libherb/util/hb_narray.h +8 -4
- package/extension/libherb/util/hb_string.c +49 -35
- package/extension/libherb/util/hb_string.h +56 -9
- package/extension/libherb/util.c +21 -11
- package/extension/libherb/util.h +6 -3
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +48 -1
- package/extension/nodes.cpp +451 -6
- package/extension/nodes.h +8 -1
- package/package.json +12 -8
- package/src/node-backend.ts +11 -1
- package/dist/types/index-cjs.d.cts +0 -1
- package/extension/libherb/analyze.c +0 -1608
- package/extension/libherb/element_source.c +0 -12
- package/extension/libherb/include/util/hb_system.h +0 -9
- package/extension/libherb/util/hb_system.c +0 -30
- package/extension/libherb/util/hb_system.h +0 -9
- package/src/index-cjs.cts +0 -22
- /package/dist/types/{index-esm.d.mts → index.d.ts} +0 -0
- /package/src/{index-esm.mts → index.ts} +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include "ast_node.h"
|
|
5
5
|
#include "lexer.h"
|
|
6
|
+
#include "util/hb_allocator.h"
|
|
6
7
|
#include "util/hb_array.h"
|
|
7
8
|
|
|
8
9
|
typedef enum {
|
|
@@ -17,17 +18,32 @@ typedef enum { PARSER_STATE_DATA, PARSER_STATE_FOREIGN_CONTENT } parser_state_T;
|
|
|
17
18
|
|
|
18
19
|
typedef struct PARSER_OPTIONS_STRUCT {
|
|
19
20
|
bool track_whitespace;
|
|
21
|
+
bool analyze;
|
|
22
|
+
bool strict;
|
|
23
|
+
bool action_view_helpers;
|
|
24
|
+
bool prism_program;
|
|
25
|
+
bool prism_nodes;
|
|
26
|
+
bool prism_nodes_deep;
|
|
20
27
|
} parser_options_T;
|
|
21
28
|
|
|
29
|
+
typedef struct MATCH_TAGS_CONTEXT_STRUCT {
|
|
30
|
+
hb_array_T* errors;
|
|
31
|
+
const parser_options_T* options;
|
|
32
|
+
hb_allocator_T* allocator;
|
|
33
|
+
} match_tags_context_T;
|
|
34
|
+
|
|
22
35
|
extern const parser_options_T HERB_DEFAULT_PARSER_OPTIONS;
|
|
23
36
|
|
|
24
37
|
typedef struct PARSER_STRUCT {
|
|
38
|
+
hb_allocator_T* allocator;
|
|
25
39
|
lexer_T* lexer;
|
|
26
40
|
token_T* current_token;
|
|
27
41
|
hb_array_T* open_tags_stack;
|
|
28
42
|
parser_state_T state;
|
|
29
43
|
foreign_content_type_T foreign_content_type;
|
|
30
44
|
parser_options_T options;
|
|
45
|
+
size_t consecutive_error_count;
|
|
46
|
+
bool in_recovery_mode;
|
|
31
47
|
} parser_T;
|
|
32
48
|
|
|
33
49
|
size_t parser_sizeof(void);
|
|
@@ -36,10 +52,19 @@ void herb_parser_init(parser_T* parser, lexer_T* lexer, parser_options_T options
|
|
|
36
52
|
|
|
37
53
|
AST_DOCUMENT_NODE_T* herb_parser_parse(parser_T* parser);
|
|
38
54
|
|
|
39
|
-
void herb_parser_match_html_tags_post_analyze(
|
|
55
|
+
void herb_parser_match_html_tags_post_analyze(
|
|
56
|
+
AST_DOCUMENT_NODE_T* document,
|
|
57
|
+
const parser_options_T* options,
|
|
58
|
+
hb_allocator_T* allocator
|
|
59
|
+
);
|
|
40
60
|
void herb_parser_deinit(parser_T* parser);
|
|
41
61
|
|
|
42
|
-
void match_tags_in_node_array(
|
|
62
|
+
void match_tags_in_node_array(
|
|
63
|
+
hb_array_T* nodes,
|
|
64
|
+
hb_array_T* errors,
|
|
65
|
+
const parser_options_T* options,
|
|
66
|
+
hb_allocator_T* allocator
|
|
67
|
+
);
|
|
43
68
|
bool match_tags_visitor(const AST_NODE_T* node, void* data);
|
|
44
69
|
|
|
45
70
|
#endif
|
|
@@ -13,11 +13,21 @@ void parser_push_open_tag(const parser_T* parser, token_T* tag_name);
|
|
|
13
13
|
bool parser_check_matching_tag(const parser_T* parser, hb_string_T tag_name);
|
|
14
14
|
token_T* parser_pop_open_tag(const parser_T* parser);
|
|
15
15
|
|
|
16
|
-
void
|
|
16
|
+
void parser_append_unexpected_error_impl(
|
|
17
17
|
parser_T* parser,
|
|
18
|
+
hb_array_T* errors,
|
|
18
19
|
const char* description,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
token_type_T first_token,
|
|
21
|
+
...
|
|
22
|
+
);
|
|
23
|
+
#define parser_append_unexpected_error(parser, errors, description, ...) \
|
|
24
|
+
parser_append_unexpected_error_impl(parser, errors, description, __VA_ARGS__, TOKEN_SENTINEL)
|
|
25
|
+
|
|
26
|
+
void parser_append_unexpected_error_string(
|
|
27
|
+
parser_T* parser,
|
|
28
|
+
hb_array_T* errors,
|
|
29
|
+
const char* description,
|
|
30
|
+
const char* expected
|
|
21
31
|
);
|
|
22
32
|
void parser_append_unexpected_token_error(parser_T* parser, token_type_T expected_type, hb_array_T* errors);
|
|
23
33
|
|
|
@@ -44,6 +54,7 @@ token_T* parser_consume_if_present(parser_T* parser, token_type_T type);
|
|
|
44
54
|
token_T* parser_consume_expected(parser_T* parser, token_type_T type, hb_array_T* array);
|
|
45
55
|
|
|
46
56
|
AST_HTML_ELEMENT_NODE_T* parser_handle_missing_close_tag(
|
|
57
|
+
parser_T* parser,
|
|
47
58
|
AST_HTML_OPEN_TAG_NODE_T* open_tag,
|
|
48
59
|
hb_array_T* body,
|
|
49
60
|
hb_array_T* errors
|
|
@@ -54,4 +65,9 @@ void parser_handle_mismatched_tags(
|
|
|
54
65
|
hb_array_T* errors
|
|
55
66
|
);
|
|
56
67
|
|
|
68
|
+
void parser_synchronize(parser_T* parser, hb_array_T* errors);
|
|
69
|
+
|
|
70
|
+
bool parser_can_close_ancestor(const parser_T* parser, hb_string_T tag_name);
|
|
71
|
+
size_t parser_find_ancestor_depth(const parser_T* parser, hb_string_T tag_name);
|
|
72
|
+
|
|
57
73
|
#endif
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
#ifndef HERB_PRETTY_PRINT_H
|
|
2
2
|
#define HERB_PRETTY_PRINT_H
|
|
3
3
|
|
|
4
|
-
#
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
#include "util/hb_buffer.h"
|
|
4
|
+
#ifdef HERB_EXCLUDE_PRETTYPRINT
|
|
5
|
+
// Pretty print support excluded
|
|
6
|
+
#else
|
|
8
7
|
|
|
9
|
-
#include
|
|
8
|
+
# include "analyze/analyzed_ruby.h"
|
|
9
|
+
# include "ast_nodes.h"
|
|
10
|
+
# include "location.h"
|
|
11
|
+
# include "util/hb_buffer.h"
|
|
12
|
+
|
|
13
|
+
# include <stdbool.h>
|
|
10
14
|
|
|
11
15
|
void pretty_print_indent(hb_buffer_T* buffer, size_t indent);
|
|
12
16
|
void pretty_print_newline(size_t indent, size_t relative_indent, hb_buffer_T* buffer);
|
|
@@ -101,3 +105,4 @@ void pretty_print_errors(
|
|
|
101
105
|
);
|
|
102
106
|
|
|
103
107
|
#endif
|
|
108
|
+
#endif
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#ifndef HERB_PRISM_CONTEXT_H
|
|
2
|
+
#define HERB_PRISM_CONTEXT_H
|
|
3
|
+
|
|
4
|
+
#include "util/hb_allocator.h"
|
|
5
|
+
#include "util/hb_buffer.h"
|
|
6
|
+
#include <prism.h>
|
|
7
|
+
#include <stdbool.h>
|
|
8
|
+
|
|
9
|
+
typedef struct {
|
|
10
|
+
pm_parser_t parser;
|
|
11
|
+
pm_options_t pm_opts;
|
|
12
|
+
pm_node_t* root;
|
|
13
|
+
hb_buffer_T ruby_buf;
|
|
14
|
+
|
|
15
|
+
bool has_structural;
|
|
16
|
+
pm_parser_t structural_parser;
|
|
17
|
+
pm_options_t structural_pm_opts;
|
|
18
|
+
pm_node_t* structural_root;
|
|
19
|
+
hb_buffer_T structural_buf;
|
|
20
|
+
|
|
21
|
+
hb_allocator_T* allocator;
|
|
22
|
+
} herb_prism_context_T;
|
|
23
|
+
|
|
24
|
+
static inline void herb_prism_context_free(herb_prism_context_T* context) {
|
|
25
|
+
if (!context) { return; }
|
|
26
|
+
|
|
27
|
+
if (context->root) { pm_node_destroy(&context->parser, context->root); }
|
|
28
|
+
|
|
29
|
+
pm_parser_free(&context->parser);
|
|
30
|
+
pm_options_free(&context->pm_opts);
|
|
31
|
+
hb_buffer_free(&context->ruby_buf);
|
|
32
|
+
|
|
33
|
+
if (context->has_structural) {
|
|
34
|
+
if (context->structural_root) { pm_node_destroy(&context->structural_parser, context->structural_root); }
|
|
35
|
+
|
|
36
|
+
pm_parser_free(&context->structural_parser);
|
|
37
|
+
pm_options_free(&context->structural_pm_opts);
|
|
38
|
+
|
|
39
|
+
if (context->structural_buf.value) { hb_buffer_free(&context->structural_buf); }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
hb_allocator_dealloc(context->allocator, context);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#endif
|
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
#ifndef HERB_PRISM_HELPERS_H
|
|
2
2
|
#define HERB_PRISM_HELPERS_H
|
|
3
3
|
|
|
4
|
-
#include "analyzed_ruby.h"
|
|
4
|
+
#include "analyze/analyzed_ruby.h"
|
|
5
5
|
#include "ast_nodes.h"
|
|
6
6
|
#include "errors.h"
|
|
7
7
|
#include "location.h"
|
|
8
8
|
#include "position.h"
|
|
9
|
+
#include "util/hb_allocator.h"
|
|
9
10
|
|
|
10
11
|
#include <prism.h>
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
hb_string_T pm_error_level_to_string(pm_error_level_t level);
|
|
13
14
|
|
|
14
15
|
RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
|
|
15
16
|
const pm_diagnostic_t* error,
|
|
16
17
|
const AST_NODE_T* node,
|
|
17
18
|
const char* source,
|
|
18
|
-
pm_parser_t* parser
|
|
19
|
+
pm_parser_t* parser,
|
|
20
|
+
hb_allocator_T* allocator
|
|
19
21
|
);
|
|
20
22
|
|
|
21
23
|
RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error_with_positions(
|
|
22
24
|
const pm_diagnostic_t* error,
|
|
23
25
|
position_T start,
|
|
24
|
-
position_T end
|
|
26
|
+
position_T end,
|
|
27
|
+
hb_allocator_T* allocator
|
|
25
28
|
);
|
|
26
29
|
|
|
27
|
-
location_T* get_then_keyword_location(analyzed_ruby_T* analyzed, const char* source);
|
|
28
|
-
location_T* get_then_keyword_location_wrapped(const char* source, bool is_in_clause);
|
|
29
|
-
location_T* get_then_keyword_location_elsif_wrapped(const char* source);
|
|
30
|
+
location_T* get_then_keyword_location(analyzed_ruby_T* analyzed, const char* source, hb_allocator_T* allocator);
|
|
31
|
+
location_T* get_then_keyword_location_wrapped(const char* source, bool is_in_clause, hb_allocator_T* allocator);
|
|
32
|
+
location_T* get_then_keyword_location_elsif_wrapped(const char* source, hb_allocator_T* allocator);
|
|
30
33
|
|
|
31
34
|
#endif
|
|
@@ -4,15 +4,27 @@
|
|
|
4
4
|
#include "lexer_struct.h"
|
|
5
5
|
#include "position.h"
|
|
6
6
|
#include "token_struct.h"
|
|
7
|
+
#include "util/hb_allocator.h"
|
|
7
8
|
#include "util/hb_string.h"
|
|
8
9
|
|
|
10
|
+
#include <stdarg.h>
|
|
11
|
+
|
|
9
12
|
token_T* token_init(hb_string_T value, token_type_T type, lexer_T* lexer);
|
|
10
|
-
hb_string_T token_to_string(const token_T* token);
|
|
11
|
-
|
|
13
|
+
hb_string_T token_to_string(hb_allocator_T* allocator, const token_T* token);
|
|
14
|
+
hb_string_T token_type_to_string(token_type_T type);
|
|
15
|
+
hb_string_T token_type_to_friendly_string(token_type_T type);
|
|
16
|
+
char* token_types_to_friendly_string_va(hb_allocator_T* allocator, token_type_T first_token, ...);
|
|
17
|
+
char* token_types_to_friendly_string_valist(hb_allocator_T* allocator, token_type_T first_token, va_list args);
|
|
18
|
+
|
|
19
|
+
#define token_types_to_friendly_string(allocator, ...) \
|
|
20
|
+
token_types_to_friendly_string_va(allocator, __VA_ARGS__, TOKEN_SENTINEL)
|
|
21
|
+
|
|
22
|
+
hb_string_T token_value(const token_T* token);
|
|
23
|
+
int token_type(const token_T* token);
|
|
12
24
|
|
|
13
|
-
token_T* token_copy(token_T* token);
|
|
25
|
+
token_T* token_copy(token_T* token, hb_allocator_T* allocator);
|
|
14
26
|
|
|
15
|
-
void token_free(token_T* token);
|
|
27
|
+
void token_free(token_T* token, hb_allocator_T* allocator);
|
|
16
28
|
|
|
17
29
|
bool token_value_empty(const token_T* token);
|
|
18
30
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#ifndef HERB_TOKEN_STRUCT_H
|
|
2
2
|
#define HERB_TOKEN_STRUCT_H
|
|
3
3
|
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
|
|
4
6
|
#include "location.h"
|
|
5
7
|
#include "range.h"
|
|
8
|
+
#include "util/hb_string.h"
|
|
6
9
|
|
|
7
10
|
typedef enum {
|
|
8
11
|
TOKEN_WHITESPACE, // ' '
|
|
@@ -21,8 +24,9 @@ typedef enum {
|
|
|
21
24
|
TOKEN_HTML_TAG_END, // >
|
|
22
25
|
TOKEN_HTML_TAG_SELF_CLOSE, // />
|
|
23
26
|
|
|
24
|
-
TOKEN_HTML_COMMENT_START,
|
|
25
|
-
TOKEN_HTML_COMMENT_END,
|
|
27
|
+
TOKEN_HTML_COMMENT_START, // <!--
|
|
28
|
+
TOKEN_HTML_COMMENT_END, // -->
|
|
29
|
+
TOKEN_HTML_COMMENT_INVALID_END, // --!>
|
|
26
30
|
|
|
27
31
|
TOKEN_ERB_START, // <%, <%=, <%%=, <%#, <%-, <%==, <%%
|
|
28
32
|
TOKEN_ERB_CONTENT, // Ruby Code
|
|
@@ -48,8 +52,11 @@ typedef enum {
|
|
|
48
52
|
TOKEN_EOF,
|
|
49
53
|
} token_type_T;
|
|
50
54
|
|
|
55
|
+
// Sentinel value for variadic functions
|
|
56
|
+
#define TOKEN_SENTINEL 99999999
|
|
57
|
+
|
|
51
58
|
typedef struct TOKEN_STRUCT {
|
|
52
|
-
|
|
59
|
+
hb_string_T value;
|
|
53
60
|
range_T range;
|
|
54
61
|
location_T location;
|
|
55
62
|
token_type_T type;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#ifndef HERB_UTF8_H
|
|
2
2
|
#define HERB_UTF8_H
|
|
3
3
|
|
|
4
|
+
#include "util/hb_string.h"
|
|
4
5
|
#include <stdbool.h>
|
|
5
6
|
#include <stdint.h>
|
|
6
7
|
#include <stdlib.h>
|
|
7
8
|
|
|
8
9
|
uint32_t utf8_char_byte_length(unsigned char first_byte);
|
|
9
|
-
uint32_t utf8_sequence_length(
|
|
10
|
+
uint32_t utf8_sequence_length(hb_string_T value);
|
|
10
11
|
bool utf8_is_valid_continuation_byte(unsigned char byte);
|
|
11
12
|
|
|
12
13
|
#endif
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
#ifndef HERB_ALLOCATOR_H
|
|
2
|
+
#define HERB_ALLOCATOR_H
|
|
3
|
+
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
|
|
7
|
+
#include "hb_arena.h"
|
|
8
|
+
|
|
9
|
+
#ifndef HB_ALLOCATOR_DEFAULT_ARENA_SIZE
|
|
10
|
+
# define HB_ALLOCATOR_DEFAULT_ARENA_SIZE (1024 * 16)
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
typedef enum {
|
|
14
|
+
HB_ALLOCATOR_MALLOC,
|
|
15
|
+
HB_ALLOCATOR_ARENA,
|
|
16
|
+
HB_ALLOCATOR_TRACKING,
|
|
17
|
+
} hb_allocator_type_T;
|
|
18
|
+
|
|
19
|
+
typedef struct {
|
|
20
|
+
void* pointer;
|
|
21
|
+
size_t size;
|
|
22
|
+
} hb_allocator_tracking_entry_T;
|
|
23
|
+
|
|
24
|
+
typedef struct {
|
|
25
|
+
size_t allocation_count;
|
|
26
|
+
size_t deallocation_count;
|
|
27
|
+
size_t untracked_deallocation_count;
|
|
28
|
+
size_t bytes_allocated;
|
|
29
|
+
size_t bytes_deallocated;
|
|
30
|
+
hb_allocator_tracking_entry_T* buckets;
|
|
31
|
+
size_t buckets_capacity;
|
|
32
|
+
size_t buckets_used;
|
|
33
|
+
void** untracked_pointers;
|
|
34
|
+
size_t untracked_pointers_size;
|
|
35
|
+
size_t untracked_pointers_capacity;
|
|
36
|
+
} hb_allocator_tracking_stats_T;
|
|
37
|
+
|
|
38
|
+
typedef struct hb_allocator {
|
|
39
|
+
void* (*alloc)(struct hb_allocator* self, size_t size);
|
|
40
|
+
void* (*realloc)(struct hb_allocator* self, void* pointer, size_t old_size, size_t new_size);
|
|
41
|
+
void (*dealloc)(struct hb_allocator* self, void* pointer);
|
|
42
|
+
char* (*strdup)(struct hb_allocator* self, const char* string);
|
|
43
|
+
char* (*strndup)(struct hb_allocator* self, const char* string, size_t length);
|
|
44
|
+
void (*destroy)(struct hb_allocator* self);
|
|
45
|
+
void* context;
|
|
46
|
+
} hb_allocator_T;
|
|
47
|
+
|
|
48
|
+
bool hb_allocator_init(hb_allocator_T* allocator, hb_allocator_type_T type);
|
|
49
|
+
bool hb_allocator_init_with_size(hb_allocator_T* allocator, hb_allocator_type_T type, size_t initial_size);
|
|
50
|
+
void hb_allocator_destroy(hb_allocator_T* allocator);
|
|
51
|
+
|
|
52
|
+
hb_allocator_T hb_allocator_with_malloc(void);
|
|
53
|
+
hb_allocator_T hb_allocator_with_arena(hb_arena_T* arena);
|
|
54
|
+
hb_allocator_T hb_allocator_with_tracking(void);
|
|
55
|
+
|
|
56
|
+
hb_allocator_tracking_stats_T* hb_allocator_tracking_stats(hb_allocator_T* allocator);
|
|
57
|
+
|
|
58
|
+
static inline void* hb_allocator_alloc(hb_allocator_T* allocator, size_t size) {
|
|
59
|
+
return allocator->alloc(allocator, size);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static inline void* hb_allocator_realloc(hb_allocator_T* allocator, void* pointer, size_t old_size, size_t new_size) {
|
|
63
|
+
return allocator->realloc(allocator, pointer, old_size, new_size);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static inline void hb_allocator_dealloc(hb_allocator_T* allocator, void* pointer) {
|
|
67
|
+
allocator->dealloc(allocator, pointer);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static inline char* hb_allocator_strdup(hb_allocator_T* allocator, const char* string) {
|
|
71
|
+
return allocator->strdup(allocator, string);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static inline char* hb_allocator_strndup(hb_allocator_T* allocator, const char* string, size_t length) {
|
|
75
|
+
return allocator->strndup(allocator, string, length);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#endif
|
|
@@ -20,12 +20,17 @@ typedef struct HB_ARENA_STRUCT {
|
|
|
20
20
|
size_t allocation_count;
|
|
21
21
|
} hb_arena_T;
|
|
22
22
|
|
|
23
|
+
#define hb_arena_for_each_page(arena) for (hb_arena_page_T* page = (arena)->head; page != NULL; page = page->next)
|
|
24
|
+
|
|
25
|
+
#define hb_arena_for_each_page_const(arena) \
|
|
26
|
+
for (const hb_arena_page_T* page = (arena)->head; page != NULL; page = page->next)
|
|
27
|
+
|
|
23
28
|
bool hb_arena_init(hb_arena_T* allocator, size_t initial_size);
|
|
24
29
|
void* hb_arena_alloc(hb_arena_T* allocator, size_t size);
|
|
25
30
|
size_t hb_arena_position(hb_arena_T* allocator);
|
|
26
31
|
size_t hb_arena_capacity(hb_arena_T* allocator);
|
|
27
32
|
void hb_arena_reset(hb_arena_T* allocator);
|
|
28
|
-
void hb_arena_reset_to(hb_arena_T* allocator, size_t
|
|
33
|
+
void hb_arena_reset_to(hb_arena_T* allocator, size_t target_position);
|
|
29
34
|
void hb_arena_free(hb_arena_T* allocator);
|
|
30
35
|
|
|
31
36
|
#endif
|
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
|
|
4
4
|
#include "hb_arena.h"
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
typedef struct {
|
|
7
|
+
size_t pages;
|
|
8
|
+
size_t total_capacity;
|
|
9
|
+
size_t total_used;
|
|
10
|
+
size_t total_available;
|
|
11
|
+
size_t allocations;
|
|
12
|
+
size_t fragmentation;
|
|
13
|
+
size_t default_page_size;
|
|
14
|
+
} hb_arena_stats_T;
|
|
15
|
+
|
|
16
|
+
hb_arena_stats_T hb_arena_get_stats(const hb_arena_T* arena);
|
|
17
|
+
void hb_arena_print_stats(const hb_arena_T* arena);
|
|
7
18
|
|
|
8
19
|
#endif
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
#ifndef HERB_ARRAY_H
|
|
2
2
|
#define HERB_ARRAY_H
|
|
3
3
|
|
|
4
|
+
#include <stdbool.h>
|
|
4
5
|
#include <stdlib.h>
|
|
5
6
|
|
|
7
|
+
struct hb_allocator;
|
|
8
|
+
|
|
6
9
|
typedef struct HB_ARRAY_STRUCT {
|
|
7
10
|
void** items;
|
|
8
11
|
size_t size;
|
|
9
12
|
size_t capacity;
|
|
13
|
+
struct hb_allocator* allocator;
|
|
10
14
|
} hb_array_T;
|
|
11
15
|
|
|
12
|
-
hb_array_T* hb_array_init(size_t capacity);
|
|
16
|
+
hb_array_T* hb_array_init(size_t capacity, struct hb_allocator* allocator);
|
|
13
17
|
|
|
14
18
|
void* hb_array_get(const hb_array_T* array, size_t index);
|
|
15
19
|
void* hb_array_first(hb_array_T* array);
|
|
16
20
|
void* hb_array_last(hb_array_T* array);
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
bool hb_array_append(hb_array_T* array, void* item);
|
|
19
23
|
void hb_array_set(const hb_array_T* array, size_t index, void* item);
|
|
20
24
|
void hb_array_free(hb_array_T** array);
|
|
21
25
|
void hb_array_remove(hb_array_T* array, size_t index);
|
|
@@ -23,7 +27,7 @@ void hb_array_remove(hb_array_T* array, size_t index);
|
|
|
23
27
|
size_t hb_array_index_of(hb_array_T* array, void* item);
|
|
24
28
|
void hb_array_remove_item(hb_array_T* array, void* item);
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
bool hb_array_push(hb_array_T* array, void* item);
|
|
27
31
|
void* hb_array_pop(hb_array_T* array);
|
|
28
32
|
|
|
29
33
|
size_t hb_array_capacity(const hb_array_T* array);
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
#ifndef HERB_BUFFER_H
|
|
2
2
|
#define HERB_BUFFER_H
|
|
3
3
|
|
|
4
|
-
#include "hb_arena.h"
|
|
5
4
|
#include "hb_string.h"
|
|
6
5
|
|
|
7
6
|
#include <stdbool.h>
|
|
8
7
|
#include <stdlib.h>
|
|
9
8
|
|
|
9
|
+
struct hb_allocator;
|
|
10
|
+
|
|
10
11
|
typedef struct HB_BUFFER_STRUCT {
|
|
11
|
-
|
|
12
|
+
struct hb_allocator* allocator;
|
|
12
13
|
char* value;
|
|
13
14
|
size_t length;
|
|
14
15
|
size_t capacity;
|
|
15
16
|
} hb_buffer_T;
|
|
16
17
|
|
|
17
|
-
bool hb_buffer_init(hb_buffer_T* buffer, size_t capacity);
|
|
18
|
-
bool hb_buffer_init_arena(hb_buffer_T* buffer, hb_arena_T* allocator, size_t capacity);
|
|
18
|
+
bool hb_buffer_init(hb_buffer_T* buffer, size_t capacity, struct hb_allocator* allocator);
|
|
19
19
|
|
|
20
20
|
void hb_buffer_append(hb_buffer_T* buffer, const char* text);
|
|
21
21
|
void hb_buffer_append_with_length(hb_buffer_T* buffer, const char* text, size_t length);
|
|
@@ -28,9 +28,11 @@ void hb_buffer_concat(hb_buffer_T* destination, hb_buffer_T* source);
|
|
|
28
28
|
char* hb_buffer_value(const hb_buffer_T* buffer);
|
|
29
29
|
|
|
30
30
|
size_t hb_buffer_length(const hb_buffer_T* buffer);
|
|
31
|
+
bool hb_buffer_is_empty(const hb_buffer_T* buffer);
|
|
31
32
|
size_t hb_buffer_capacity(const hb_buffer_T* buffer);
|
|
32
33
|
size_t hb_buffer_sizeof(void);
|
|
33
34
|
|
|
35
|
+
void hb_buffer_free(hb_buffer_T* buffer);
|
|
34
36
|
void hb_buffer_clear(hb_buffer_T* buffer);
|
|
35
37
|
|
|
36
38
|
#endif
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.9.0/templates/src/include/util/hb_foreach.h.erb
|
|
3
|
+
|
|
4
|
+
#ifndef HB_FOREACH_H
|
|
5
|
+
#define HB_FOREACH_H
|
|
6
|
+
|
|
7
|
+
#define HB_ARG64(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,_51,_52,_53,_54,_55,_56,_57,_58,_59,_60,_61,_62,_63,_64,count,...) count
|
|
8
|
+
#define HB_NARGS(...) HB_ARG64(__VA_ARGS__,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1)
|
|
9
|
+
|
|
10
|
+
#define HB_FOR_EACH_1(macro, head) macro(head)
|
|
11
|
+
#define HB_FOR_EACH_2(macro, head, ...) macro(head), HB_FOR_EACH_1(macro, __VA_ARGS__)
|
|
12
|
+
#define HB_FOR_EACH_3(macro, head, ...) macro(head), HB_FOR_EACH_2(macro, __VA_ARGS__)
|
|
13
|
+
#define HB_FOR_EACH_4(macro, head, ...) macro(head), HB_FOR_EACH_3(macro, __VA_ARGS__)
|
|
14
|
+
#define HB_FOR_EACH_5(macro, head, ...) macro(head), HB_FOR_EACH_4(macro, __VA_ARGS__)
|
|
15
|
+
#define HB_FOR_EACH_6(macro, head, ...) macro(head), HB_FOR_EACH_5(macro, __VA_ARGS__)
|
|
16
|
+
#define HB_FOR_EACH_7(macro, head, ...) macro(head), HB_FOR_EACH_6(macro, __VA_ARGS__)
|
|
17
|
+
#define HB_FOR_EACH_8(macro, head, ...) macro(head), HB_FOR_EACH_7(macro, __VA_ARGS__)
|
|
18
|
+
#define HB_FOR_EACH_9(macro, head, ...) macro(head), HB_FOR_EACH_8(macro, __VA_ARGS__)
|
|
19
|
+
#define HB_FOR_EACH_10(macro, head, ...) macro(head), HB_FOR_EACH_9(macro, __VA_ARGS__)
|
|
20
|
+
#define HB_FOR_EACH_11(macro, head, ...) macro(head), HB_FOR_EACH_10(macro, __VA_ARGS__)
|
|
21
|
+
#define HB_FOR_EACH_12(macro, head, ...) macro(head), HB_FOR_EACH_11(macro, __VA_ARGS__)
|
|
22
|
+
#define HB_FOR_EACH_13(macro, head, ...) macro(head), HB_FOR_EACH_12(macro, __VA_ARGS__)
|
|
23
|
+
#define HB_FOR_EACH_14(macro, head, ...) macro(head), HB_FOR_EACH_13(macro, __VA_ARGS__)
|
|
24
|
+
#define HB_FOR_EACH_15(macro, head, ...) macro(head), HB_FOR_EACH_14(macro, __VA_ARGS__)
|
|
25
|
+
#define HB_FOR_EACH_16(macro, head, ...) macro(head), HB_FOR_EACH_15(macro, __VA_ARGS__)
|
|
26
|
+
#define HB_FOR_EACH_17(macro, head, ...) macro(head), HB_FOR_EACH_16(macro, __VA_ARGS__)
|
|
27
|
+
#define HB_FOR_EACH_18(macro, head, ...) macro(head), HB_FOR_EACH_17(macro, __VA_ARGS__)
|
|
28
|
+
#define HB_FOR_EACH_19(macro, head, ...) macro(head), HB_FOR_EACH_18(macro, __VA_ARGS__)
|
|
29
|
+
#define HB_FOR_EACH_20(macro, head, ...) macro(head), HB_FOR_EACH_19(macro, __VA_ARGS__)
|
|
30
|
+
#define HB_FOR_EACH_21(macro, head, ...) macro(head), HB_FOR_EACH_20(macro, __VA_ARGS__)
|
|
31
|
+
#define HB_FOR_EACH_22(macro, head, ...) macro(head), HB_FOR_EACH_21(macro, __VA_ARGS__)
|
|
32
|
+
#define HB_FOR_EACH_23(macro, head, ...) macro(head), HB_FOR_EACH_22(macro, __VA_ARGS__)
|
|
33
|
+
#define HB_FOR_EACH_24(macro, head, ...) macro(head), HB_FOR_EACH_23(macro, __VA_ARGS__)
|
|
34
|
+
#define HB_FOR_EACH_25(macro, head, ...) macro(head), HB_FOR_EACH_24(macro, __VA_ARGS__)
|
|
35
|
+
#define HB_FOR_EACH_26(macro, head, ...) macro(head), HB_FOR_EACH_25(macro, __VA_ARGS__)
|
|
36
|
+
#define HB_FOR_EACH_27(macro, head, ...) macro(head), HB_FOR_EACH_26(macro, __VA_ARGS__)
|
|
37
|
+
#define HB_FOR_EACH_28(macro, head, ...) macro(head), HB_FOR_EACH_27(macro, __VA_ARGS__)
|
|
38
|
+
#define HB_FOR_EACH_29(macro, head, ...) macro(head), HB_FOR_EACH_28(macro, __VA_ARGS__)
|
|
39
|
+
#define HB_FOR_EACH_30(macro, head, ...) macro(head), HB_FOR_EACH_29(macro, __VA_ARGS__)
|
|
40
|
+
#define HB_FOR_EACH_31(macro, head, ...) macro(head), HB_FOR_EACH_30(macro, __VA_ARGS__)
|
|
41
|
+
#define HB_FOR_EACH_32(macro, head, ...) macro(head), HB_FOR_EACH_31(macro, __VA_ARGS__)
|
|
42
|
+
#define HB_FOR_EACH_33(macro, head, ...) macro(head), HB_FOR_EACH_32(macro, __VA_ARGS__)
|
|
43
|
+
#define HB_FOR_EACH_34(macro, head, ...) macro(head), HB_FOR_EACH_33(macro, __VA_ARGS__)
|
|
44
|
+
#define HB_FOR_EACH_35(macro, head, ...) macro(head), HB_FOR_EACH_34(macro, __VA_ARGS__)
|
|
45
|
+
#define HB_FOR_EACH_36(macro, head, ...) macro(head), HB_FOR_EACH_35(macro, __VA_ARGS__)
|
|
46
|
+
#define HB_FOR_EACH_37(macro, head, ...) macro(head), HB_FOR_EACH_36(macro, __VA_ARGS__)
|
|
47
|
+
#define HB_FOR_EACH_38(macro, head, ...) macro(head), HB_FOR_EACH_37(macro, __VA_ARGS__)
|
|
48
|
+
#define HB_FOR_EACH_39(macro, head, ...) macro(head), HB_FOR_EACH_38(macro, __VA_ARGS__)
|
|
49
|
+
#define HB_FOR_EACH_40(macro, head, ...) macro(head), HB_FOR_EACH_39(macro, __VA_ARGS__)
|
|
50
|
+
#define HB_FOR_EACH_41(macro, head, ...) macro(head), HB_FOR_EACH_40(macro, __VA_ARGS__)
|
|
51
|
+
#define HB_FOR_EACH_42(macro, head, ...) macro(head), HB_FOR_EACH_41(macro, __VA_ARGS__)
|
|
52
|
+
#define HB_FOR_EACH_43(macro, head, ...) macro(head), HB_FOR_EACH_42(macro, __VA_ARGS__)
|
|
53
|
+
#define HB_FOR_EACH_44(macro, head, ...) macro(head), HB_FOR_EACH_43(macro, __VA_ARGS__)
|
|
54
|
+
#define HB_FOR_EACH_45(macro, head, ...) macro(head), HB_FOR_EACH_44(macro, __VA_ARGS__)
|
|
55
|
+
#define HB_FOR_EACH_46(macro, head, ...) macro(head), HB_FOR_EACH_45(macro, __VA_ARGS__)
|
|
56
|
+
#define HB_FOR_EACH_47(macro, head, ...) macro(head), HB_FOR_EACH_46(macro, __VA_ARGS__)
|
|
57
|
+
#define HB_FOR_EACH_48(macro, head, ...) macro(head), HB_FOR_EACH_47(macro, __VA_ARGS__)
|
|
58
|
+
#define HB_FOR_EACH_49(macro, head, ...) macro(head), HB_FOR_EACH_48(macro, __VA_ARGS__)
|
|
59
|
+
#define HB_FOR_EACH_50(macro, head, ...) macro(head), HB_FOR_EACH_49(macro, __VA_ARGS__)
|
|
60
|
+
#define HB_FOR_EACH_51(macro, head, ...) macro(head), HB_FOR_EACH_50(macro, __VA_ARGS__)
|
|
61
|
+
#define HB_FOR_EACH_52(macro, head, ...) macro(head), HB_FOR_EACH_51(macro, __VA_ARGS__)
|
|
62
|
+
#define HB_FOR_EACH_53(macro, head, ...) macro(head), HB_FOR_EACH_52(macro, __VA_ARGS__)
|
|
63
|
+
#define HB_FOR_EACH_54(macro, head, ...) macro(head), HB_FOR_EACH_53(macro, __VA_ARGS__)
|
|
64
|
+
#define HB_FOR_EACH_55(macro, head, ...) macro(head), HB_FOR_EACH_54(macro, __VA_ARGS__)
|
|
65
|
+
#define HB_FOR_EACH_56(macro, head, ...) macro(head), HB_FOR_EACH_55(macro, __VA_ARGS__)
|
|
66
|
+
#define HB_FOR_EACH_57(macro, head, ...) macro(head), HB_FOR_EACH_56(macro, __VA_ARGS__)
|
|
67
|
+
#define HB_FOR_EACH_58(macro, head, ...) macro(head), HB_FOR_EACH_57(macro, __VA_ARGS__)
|
|
68
|
+
#define HB_FOR_EACH_59(macro, head, ...) macro(head), HB_FOR_EACH_58(macro, __VA_ARGS__)
|
|
69
|
+
#define HB_FOR_EACH_60(macro, head, ...) macro(head), HB_FOR_EACH_59(macro, __VA_ARGS__)
|
|
70
|
+
#define HB_FOR_EACH_61(macro, head, ...) macro(head), HB_FOR_EACH_60(macro, __VA_ARGS__)
|
|
71
|
+
#define HB_FOR_EACH_62(macro, head, ...) macro(head), HB_FOR_EACH_61(macro, __VA_ARGS__)
|
|
72
|
+
#define HB_FOR_EACH_63(macro, head, ...) macro(head), HB_FOR_EACH_62(macro, __VA_ARGS__)
|
|
73
|
+
#define HB_FOR_EACH_64(macro, head, ...) macro(head), HB_FOR_EACH_63(macro, __VA_ARGS__)
|
|
74
|
+
|
|
75
|
+
#define HB_CONCAT(left, right) left ## right
|
|
76
|
+
#define HB_FOR_EACH_N(count) HB_CONCAT(HB_FOR_EACH_, count)
|
|
77
|
+
#define HB_FOR_EACH(macro, ...) HB_FOR_EACH_N(HB_NARGS(__VA_ARGS__))(macro, __VA_ARGS__)
|
|
78
|
+
|
|
79
|
+
#endif
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
#ifndef HERB_NARRAY_H
|
|
2
2
|
#define HERB_NARRAY_H
|
|
3
3
|
|
|
4
|
+
#include <stdbool.h>
|
|
4
5
|
#include <stdint.h>
|
|
5
6
|
#include <stdlib.h>
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
#include "hb_allocator.h"
|
|
7
9
|
|
|
8
10
|
typedef struct HB_NARRAY_STRUCT {
|
|
11
|
+
hb_allocator_T* allocator;
|
|
9
12
|
uint8_t* items;
|
|
10
13
|
size_t item_size;
|
|
11
14
|
size_t size;
|
|
12
15
|
size_t capacity;
|
|
13
16
|
} hb_narray_T;
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
#define hb_narray_pointer_init(array, initial_capacity
|
|
18
|
+
bool hb_narray_init(hb_narray_T* array, size_t item_size, size_t initial_capacity, hb_allocator_T* allocator);
|
|
19
|
+
#define hb_narray_pointer_init(array, initial_capacity, allocator) \
|
|
20
|
+
(hb_narray_init(array, sizeof(void*), initial_capacity, allocator))
|
|
17
21
|
|
|
18
22
|
void* hb_narray_get(const hb_narray_T* array, size_t index);
|
|
19
23
|
void* hb_narray_first(hb_narray_T* array);
|
|
20
24
|
void* hb_narray_last(hb_narray_T* array);
|
|
21
25
|
size_t hb_narray_size(const hb_narray_T* array);
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
bool hb_narray_append(hb_narray_T* array, void* item);
|
|
24
28
|
void hb_narray_remove(hb_narray_T* array, size_t index);
|
|
25
29
|
void hb_narray_deinit(hb_narray_T* array);
|
|
26
30
|
|