@herb-tools/node 0.7.4 → 0.8.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/binding.gyp +8 -5
- package/dist/herb-node.esm.js +6 -6
- package/dist/herb-node.esm.js.map +1 -1
- package/extension/error_helpers.cpp +67 -9
- package/extension/error_helpers.h +4 -2
- package/extension/extension_helpers.cpp +20 -31
- package/extension/extension_helpers.h +7 -5
- package/extension/herb.cpp +10 -42
- package/extension/libherb/analyze.c +461 -249
- package/extension/libherb/analyze.h +10 -2
- package/extension/libherb/analyze_helpers.c +5 -0
- package/extension/libherb/analyze_helpers.h +3 -0
- package/extension/libherb/analyze_missing_end.c +147 -0
- package/extension/libherb/analyze_transform.c +196 -0
- package/extension/libherb/analyzed_ruby.c +23 -2
- package/extension/libherb/analyzed_ruby.h +4 -2
- package/extension/libherb/ast_node.c +14 -17
- package/extension/libherb/ast_node.h +4 -4
- package/extension/libherb/ast_nodes.c +180 -182
- package/extension/libherb/ast_nodes.h +69 -68
- package/extension/libherb/ast_pretty_print.c +233 -233
- package/extension/libherb/ast_pretty_print.h +3 -3
- package/extension/libherb/element_source.c +7 -6
- package/extension/libherb/element_source.h +3 -1
- package/extension/libherb/errors.c +273 -153
- package/extension/libherb/errors.h +43 -27
- package/extension/libherb/extract.c +92 -34
- package/extension/libherb/extract.h +4 -4
- package/extension/libherb/herb.c +37 -49
- package/extension/libherb/herb.h +6 -7
- package/extension/libherb/html_util.c +34 -96
- package/extension/libherb/html_util.h +4 -5
- package/extension/libherb/include/analyze.h +10 -2
- package/extension/libherb/include/analyze_helpers.h +3 -0
- package/extension/libherb/include/analyzed_ruby.h +4 -2
- package/extension/libherb/include/ast_node.h +4 -4
- package/extension/libherb/include/ast_nodes.h +69 -68
- package/extension/libherb/include/ast_pretty_print.h +3 -3
- package/extension/libherb/include/element_source.h +3 -1
- package/extension/libherb/include/errors.h +43 -27
- package/extension/libherb/include/extract.h +4 -4
- package/extension/libherb/include/herb.h +6 -7
- package/extension/libherb/include/html_util.h +4 -5
- package/extension/libherb/include/lexer.h +1 -3
- package/extension/libherb/include/lexer_peek_helpers.h +21 -19
- package/extension/libherb/include/lexer_struct.h +12 -10
- package/extension/libherb/include/location.h +10 -13
- package/extension/libherb/include/macros.h +4 -0
- package/extension/libherb/include/parser.h +12 -6
- package/extension/libherb/include/parser_helpers.h +26 -16
- package/extension/libherb/include/position.h +3 -14
- package/extension/libherb/include/pretty_print.h +38 -28
- package/extension/libherb/include/prism_helpers.h +1 -1
- package/extension/libherb/include/range.h +4 -13
- package/extension/libherb/include/token.h +5 -11
- package/extension/libherb/include/token_struct.h +2 -2
- package/extension/libherb/include/utf8.h +3 -2
- package/extension/libherb/include/util/hb_arena.h +31 -0
- package/extension/libherb/include/util/hb_arena_debug.h +8 -0
- package/extension/libherb/include/util/hb_array.h +33 -0
- package/extension/libherb/include/util/hb_buffer.h +34 -0
- package/extension/libherb/include/util/hb_string.h +29 -0
- package/extension/libherb/include/util/hb_system.h +9 -0
- package/extension/libherb/include/util.h +3 -14
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/include/visitor.h +1 -1
- package/extension/libherb/io.c +7 -4
- package/extension/libherb/lexer.c +62 -88
- package/extension/libherb/lexer.h +1 -3
- package/extension/libherb/lexer_peek_helpers.c +42 -38
- package/extension/libherb/lexer_peek_helpers.h +21 -19
- package/extension/libherb/lexer_struct.h +12 -10
- package/extension/libherb/location.c +9 -37
- package/extension/libherb/location.h +10 -13
- package/extension/libherb/macros.h +4 -0
- package/extension/libherb/main.c +19 -23
- package/extension/libherb/parser.c +373 -313
- package/extension/libherb/parser.h +12 -6
- package/extension/libherb/parser_helpers.c +60 -54
- package/extension/libherb/parser_helpers.h +26 -16
- package/extension/libherb/parser_match_tags.c +316 -0
- package/extension/libherb/position.h +3 -14
- package/extension/libherb/pretty_print.c +88 -117
- package/extension/libherb/pretty_print.h +38 -28
- package/extension/libherb/prism_helpers.c +7 -7
- package/extension/libherb/prism_helpers.h +1 -1
- package/extension/libherb/range.c +2 -35
- package/extension/libherb/range.h +4 -13
- package/extension/libherb/token.c +36 -87
- package/extension/libherb/token.h +5 -11
- package/extension/libherb/token_struct.h +2 -2
- package/extension/libherb/utf8.c +4 -4
- package/extension/libherb/utf8.h +3 -2
- package/extension/libherb/util/hb_arena.c +179 -0
- package/extension/libherb/util/hb_arena.h +31 -0
- package/extension/libherb/util/hb_arena_debug.c +237 -0
- package/extension/libherb/util/hb_arena_debug.h +8 -0
- package/extension/libherb/{array.c → util/hb_array.c} +26 -27
- package/extension/libherb/util/hb_array.h +33 -0
- package/extension/libherb/util/hb_buffer.c +203 -0
- package/extension/libherb/util/hb_buffer.h +34 -0
- package/extension/libherb/util/hb_string.c +85 -0
- package/extension/libherb/util/hb_string.h +29 -0
- package/extension/libherb/util/hb_system.c +30 -0
- package/extension/libherb/util/hb_system.h +9 -0
- package/extension/libherb/util.c +29 -99
- package/extension/libherb/util.h +3 -14
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +55 -55
- package/extension/libherb/visitor.h +1 -1
- package/extension/nodes.cpp +40 -40
- package/extension/nodes.h +2 -2
- package/extension/prism/include/prism/ast.h +31 -1
- package/extension/prism/include/prism/diagnostic.h +1 -0
- package/extension/prism/include/prism/version.h +3 -3
- package/extension/prism/src/diagnostic.c +3 -1
- package/extension/prism/src/prism.c +130 -71
- package/extension/prism/src/util/pm_string.c +6 -8
- package/package.json +3 -3
- package/extension/libherb/array.h +0 -33
- package/extension/libherb/buffer.c +0 -232
- package/extension/libherb/buffer.h +0 -39
- package/extension/libherb/include/array.h +0 -33
- package/extension/libherb/include/buffer.h +0 -39
- package/extension/libherb/include/json.h +0 -28
- package/extension/libherb/include/memory.h +0 -12
- package/extension/libherb/json.c +0 -205
- package/extension/libherb/json.h +0 -28
- package/extension/libherb/memory.c +0 -53
- package/extension/libherb/memory.h +0 -12
- package/extension/libherb/position.c +0 -33
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
#ifndef HERB_BUFFER_H
|
|
2
|
-
#define HERB_BUFFER_H
|
|
3
|
-
|
|
4
|
-
#include <stdbool.h>
|
|
5
|
-
#include <stdlib.h>
|
|
6
|
-
|
|
7
|
-
typedef struct BUFFER_STRUCT {
|
|
8
|
-
char* value;
|
|
9
|
-
size_t length;
|
|
10
|
-
size_t capacity;
|
|
11
|
-
} buffer_T;
|
|
12
|
-
|
|
13
|
-
bool buffer_init(buffer_T* buffer);
|
|
14
|
-
buffer_T buffer_new(void);
|
|
15
|
-
|
|
16
|
-
bool buffer_increase_capacity(buffer_T* buffer, size_t additional_capacity);
|
|
17
|
-
bool buffer_has_capacity(buffer_T* buffer, size_t required_length);
|
|
18
|
-
bool buffer_expand_capacity(buffer_T* buffer);
|
|
19
|
-
bool buffer_expand_if_needed(buffer_T* buffer, size_t required_length);
|
|
20
|
-
bool buffer_resize(buffer_T* buffer, size_t new_capacity);
|
|
21
|
-
|
|
22
|
-
void buffer_append(buffer_T* buffer, const char* text);
|
|
23
|
-
void buffer_append_with_length(buffer_T* buffer, const char* text, size_t length);
|
|
24
|
-
void buffer_append_char(buffer_T* buffer, char character);
|
|
25
|
-
void buffer_append_repeated(buffer_T* buffer, char character, size_t length);
|
|
26
|
-
void buffer_append_whitespace(buffer_T* buffer, size_t length);
|
|
27
|
-
void buffer_prepend(buffer_T* buffer, const char* text);
|
|
28
|
-
void buffer_concat(buffer_T* destination, buffer_T* source);
|
|
29
|
-
|
|
30
|
-
char* buffer_value(const buffer_T* buffer);
|
|
31
|
-
|
|
32
|
-
size_t buffer_length(const buffer_T* buffer);
|
|
33
|
-
size_t buffer_capacity(const buffer_T* buffer);
|
|
34
|
-
size_t buffer_sizeof(void);
|
|
35
|
-
|
|
36
|
-
void buffer_clear(buffer_T* buffer);
|
|
37
|
-
void buffer_free(buffer_T* buffer);
|
|
38
|
-
|
|
39
|
-
#endif
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#ifndef HERB_ARRAY_H
|
|
2
|
-
#define HERB_ARRAY_H
|
|
3
|
-
|
|
4
|
-
#include <stdlib.h>
|
|
5
|
-
|
|
6
|
-
typedef struct ARRAY_STRUCT {
|
|
7
|
-
void** items;
|
|
8
|
-
size_t size;
|
|
9
|
-
size_t capacity;
|
|
10
|
-
} array_T;
|
|
11
|
-
|
|
12
|
-
array_T* array_init(size_t capacity);
|
|
13
|
-
|
|
14
|
-
void* array_get(const array_T* array, size_t index);
|
|
15
|
-
void* array_first(array_T* array);
|
|
16
|
-
void* array_last(array_T* array);
|
|
17
|
-
|
|
18
|
-
void array_append(array_T* array, void* item);
|
|
19
|
-
void array_set(const array_T* array, size_t index, void* item);
|
|
20
|
-
void array_free(array_T** array);
|
|
21
|
-
void array_remove(array_T* array, size_t index);
|
|
22
|
-
|
|
23
|
-
size_t array_index_of(array_T* array, void* item);
|
|
24
|
-
void array_remove_item(array_T* array, void* item);
|
|
25
|
-
|
|
26
|
-
void array_push(array_T* array, void* item);
|
|
27
|
-
void* array_pop(array_T* array);
|
|
28
|
-
|
|
29
|
-
size_t array_capacity(const array_T* array);
|
|
30
|
-
size_t array_size(const array_T* array);
|
|
31
|
-
size_t array_sizeof(void);
|
|
32
|
-
|
|
33
|
-
#endif
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
#ifndef HERB_BUFFER_H
|
|
2
|
-
#define HERB_BUFFER_H
|
|
3
|
-
|
|
4
|
-
#include <stdbool.h>
|
|
5
|
-
#include <stdlib.h>
|
|
6
|
-
|
|
7
|
-
typedef struct BUFFER_STRUCT {
|
|
8
|
-
char* value;
|
|
9
|
-
size_t length;
|
|
10
|
-
size_t capacity;
|
|
11
|
-
} buffer_T;
|
|
12
|
-
|
|
13
|
-
bool buffer_init(buffer_T* buffer);
|
|
14
|
-
buffer_T buffer_new(void);
|
|
15
|
-
|
|
16
|
-
bool buffer_increase_capacity(buffer_T* buffer, size_t additional_capacity);
|
|
17
|
-
bool buffer_has_capacity(buffer_T* buffer, size_t required_length);
|
|
18
|
-
bool buffer_expand_capacity(buffer_T* buffer);
|
|
19
|
-
bool buffer_expand_if_needed(buffer_T* buffer, size_t required_length);
|
|
20
|
-
bool buffer_resize(buffer_T* buffer, size_t new_capacity);
|
|
21
|
-
|
|
22
|
-
void buffer_append(buffer_T* buffer, const char* text);
|
|
23
|
-
void buffer_append_with_length(buffer_T* buffer, const char* text, size_t length);
|
|
24
|
-
void buffer_append_char(buffer_T* buffer, char character);
|
|
25
|
-
void buffer_append_repeated(buffer_T* buffer, char character, size_t length);
|
|
26
|
-
void buffer_append_whitespace(buffer_T* buffer, size_t length);
|
|
27
|
-
void buffer_prepend(buffer_T* buffer, const char* text);
|
|
28
|
-
void buffer_concat(buffer_T* destination, buffer_T* source);
|
|
29
|
-
|
|
30
|
-
char* buffer_value(const buffer_T* buffer);
|
|
31
|
-
|
|
32
|
-
size_t buffer_length(const buffer_T* buffer);
|
|
33
|
-
size_t buffer_capacity(const buffer_T* buffer);
|
|
34
|
-
size_t buffer_sizeof(void);
|
|
35
|
-
|
|
36
|
-
void buffer_clear(buffer_T* buffer);
|
|
37
|
-
void buffer_free(buffer_T* buffer);
|
|
38
|
-
|
|
39
|
-
#endif
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#ifndef HERB_JSON_H
|
|
2
|
-
#define HERB_JSON_H
|
|
3
|
-
|
|
4
|
-
#include "buffer.h"
|
|
5
|
-
|
|
6
|
-
void json_start_root_object(buffer_T* json);
|
|
7
|
-
void json_start_root_array(buffer_T* json);
|
|
8
|
-
|
|
9
|
-
void json_escape_string(buffer_T* json, const char* string);
|
|
10
|
-
|
|
11
|
-
void json_add_string(buffer_T* json, const char* key, const char* value);
|
|
12
|
-
void json_add_int(buffer_T* json, const char* key, int value);
|
|
13
|
-
void json_add_size_t(buffer_T* json, const char* key, size_t value);
|
|
14
|
-
void json_add_double(buffer_T* json, const char* key, double value);
|
|
15
|
-
void json_add_bool(buffer_T* json, const char* key, int value);
|
|
16
|
-
|
|
17
|
-
void json_add_raw_string(buffer_T* json, const char* string);
|
|
18
|
-
|
|
19
|
-
void json_start_object(buffer_T* json, const char* key);
|
|
20
|
-
void json_end_object(buffer_T* json);
|
|
21
|
-
|
|
22
|
-
void json_start_array(buffer_T* json, const char* key);
|
|
23
|
-
void json_end_array(buffer_T* json);
|
|
24
|
-
|
|
25
|
-
void json_double_to_string(double value, char* buffer);
|
|
26
|
-
void json_int_to_string(int value, char* buffer);
|
|
27
|
-
|
|
28
|
-
#endif
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#ifndef HERB_MEMORY_H
|
|
2
|
-
#define HERB_MEMORY_H
|
|
3
|
-
|
|
4
|
-
#include <stddef.h>
|
|
5
|
-
|
|
6
|
-
void* safe_malloc(size_t size);
|
|
7
|
-
void* safe_realloc(void* pointer, size_t new_size);
|
|
8
|
-
|
|
9
|
-
void* nullable_safe_malloc(size_t size);
|
|
10
|
-
void* nullable_safe_realloc(void* pointer, size_t new_size);
|
|
11
|
-
|
|
12
|
-
#endif
|
package/extension/libherb/json.c
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
#include "include/json.h"
|
|
2
|
-
#include "include/buffer.h"
|
|
3
|
-
|
|
4
|
-
void json_escape_string(buffer_T* json, const char* string) {
|
|
5
|
-
if (!string) {
|
|
6
|
-
buffer_append(json, "null");
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
buffer_append(json, "\"");
|
|
11
|
-
|
|
12
|
-
while (*string) {
|
|
13
|
-
switch (*string) {
|
|
14
|
-
case '\"': buffer_append(json, "\\\""); break;
|
|
15
|
-
case '\\': buffer_append(json, "\\\\"); break;
|
|
16
|
-
case '\n': buffer_append(json, "\\n"); break;
|
|
17
|
-
case '\t': buffer_append(json, "\\t"); break;
|
|
18
|
-
default: buffer_append_char(json, *string); break;
|
|
19
|
-
}
|
|
20
|
-
string++;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
buffer_append(json, "\"");
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
void json_int_to_string(const int value, char* buffer) {
|
|
27
|
-
char string[20]; // Enough to hold all possible int values
|
|
28
|
-
int i = 0;
|
|
29
|
-
|
|
30
|
-
// Handle negative numbers
|
|
31
|
-
unsigned int abs_value = (unsigned int) abs(value);
|
|
32
|
-
|
|
33
|
-
do {
|
|
34
|
-
string[i++] = (char) ((abs_value % 10) + '0');
|
|
35
|
-
abs_value /= 10;
|
|
36
|
-
} while (abs_value > 0);
|
|
37
|
-
|
|
38
|
-
if (value < 0) { string[i++] = '-'; }
|
|
39
|
-
|
|
40
|
-
int j = 0;
|
|
41
|
-
|
|
42
|
-
while (i > 0) {
|
|
43
|
-
buffer[j++] = string[--i];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
buffer[j] = '\0';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
void json_double_to_string(const double value, char* buffer) {
|
|
50
|
-
const int int_part = (int) value;
|
|
51
|
-
const double frac_part = value - (double) int_part;
|
|
52
|
-
const int frac_as_int = (int) (frac_part * 100); // Keep 2 decimal places
|
|
53
|
-
|
|
54
|
-
char int_buffer[20];
|
|
55
|
-
char frac_buffer[5];
|
|
56
|
-
|
|
57
|
-
json_int_to_string(int_part, int_buffer);
|
|
58
|
-
json_int_to_string(frac_as_int < 0 ? -frac_as_int : frac_as_int, frac_buffer);
|
|
59
|
-
|
|
60
|
-
char* pointer = buffer;
|
|
61
|
-
for (const char* source = int_buffer; *source != '\0'; ++source) {
|
|
62
|
-
*pointer++ = *source;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
*pointer++ = '.';
|
|
66
|
-
|
|
67
|
-
for (const char* source = frac_buffer; *source != '\0'; ++source) {
|
|
68
|
-
*pointer++ = *source;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
*pointer = '\0';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
void json_add_string(buffer_T* json, const char* key, const char* value) {
|
|
75
|
-
if (!json) { return; }
|
|
76
|
-
|
|
77
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
78
|
-
|
|
79
|
-
if (key) {
|
|
80
|
-
json_escape_string(json, key);
|
|
81
|
-
buffer_append(json, ": ");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
json_escape_string(json, value);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
void json_add_double(buffer_T* json, const char* key, const double value) {
|
|
88
|
-
if (!json) { return; }
|
|
89
|
-
|
|
90
|
-
char number[32];
|
|
91
|
-
json_double_to_string(value, number);
|
|
92
|
-
|
|
93
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
94
|
-
|
|
95
|
-
if (key) {
|
|
96
|
-
json_escape_string(json, key);
|
|
97
|
-
buffer_append(json, ": ");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
buffer_append(json, number);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
void json_add_int(buffer_T* json, const char* key, const int value) {
|
|
104
|
-
if (!json) { return; }
|
|
105
|
-
|
|
106
|
-
char number[20];
|
|
107
|
-
json_int_to_string(value, number);
|
|
108
|
-
|
|
109
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
110
|
-
|
|
111
|
-
if (key) {
|
|
112
|
-
json_escape_string(json, key);
|
|
113
|
-
buffer_append(json, ": ");
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
buffer_append(json, number);
|
|
117
|
-
if (json->length == 1) { buffer_append(json, " "); }
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
void json_add_size_t(buffer_T* json, const char* key, size_t value) {
|
|
121
|
-
if (!json) { return; }
|
|
122
|
-
|
|
123
|
-
char number[32];
|
|
124
|
-
char temp[32];
|
|
125
|
-
int i = 0;
|
|
126
|
-
|
|
127
|
-
do {
|
|
128
|
-
temp[i++] = (char) ((value % 10) + '0');
|
|
129
|
-
value /= 10;
|
|
130
|
-
} while (value > 0);
|
|
131
|
-
|
|
132
|
-
int j = 0;
|
|
133
|
-
while (i > 0) {
|
|
134
|
-
number[j++] = temp[--i];
|
|
135
|
-
}
|
|
136
|
-
number[j] = '\0';
|
|
137
|
-
|
|
138
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
139
|
-
|
|
140
|
-
if (key) {
|
|
141
|
-
json_escape_string(json, key);
|
|
142
|
-
buffer_append(json, ": ");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
buffer_append(json, number);
|
|
146
|
-
if (json->length == 1) { buffer_append(json, " "); }
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
void json_add_bool(buffer_T* json, const char* key, const int value) {
|
|
150
|
-
if (!json) { return; }
|
|
151
|
-
|
|
152
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
153
|
-
|
|
154
|
-
if (key) {
|
|
155
|
-
json_escape_string(json, key);
|
|
156
|
-
buffer_append(json, ": ");
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
buffer_append(json, value ? "true" : "false");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
void json_add_raw_string(buffer_T* json, const char* string) {
|
|
163
|
-
if (!json) { return; }
|
|
164
|
-
|
|
165
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
166
|
-
|
|
167
|
-
buffer_append(json, string);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
void json_start_root_object(buffer_T* json) {
|
|
171
|
-
if (json) { buffer_append(json, "{"); }
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
void json_start_object(buffer_T* json, const char* key) {
|
|
175
|
-
if (!json) { return; }
|
|
176
|
-
|
|
177
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
178
|
-
|
|
179
|
-
if (key) {
|
|
180
|
-
json_escape_string(json, key);
|
|
181
|
-
buffer_append(json, ": ");
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
buffer_append(json, "{");
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
void json_end_object(buffer_T* json) {
|
|
188
|
-
if (json) { buffer_append(json, "}"); }
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
void json_start_root_array(buffer_T* json) {
|
|
192
|
-
if (json) { buffer_append(json, "["); }
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
void json_start_array(buffer_T* json, const char* key) {
|
|
196
|
-
if (!json) { return; }
|
|
197
|
-
|
|
198
|
-
if (json->length > 1) { buffer_append(json, ", "); }
|
|
199
|
-
json_escape_string(json, key);
|
|
200
|
-
buffer_append(json, ": [");
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
void json_end_array(buffer_T* json) {
|
|
204
|
-
if (json) { buffer_append(json, "]"); }
|
|
205
|
-
}
|
package/extension/libherb/json.h
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#ifndef HERB_JSON_H
|
|
2
|
-
#define HERB_JSON_H
|
|
3
|
-
|
|
4
|
-
#include "buffer.h"
|
|
5
|
-
|
|
6
|
-
void json_start_root_object(buffer_T* json);
|
|
7
|
-
void json_start_root_array(buffer_T* json);
|
|
8
|
-
|
|
9
|
-
void json_escape_string(buffer_T* json, const char* string);
|
|
10
|
-
|
|
11
|
-
void json_add_string(buffer_T* json, const char* key, const char* value);
|
|
12
|
-
void json_add_int(buffer_T* json, const char* key, int value);
|
|
13
|
-
void json_add_size_t(buffer_T* json, const char* key, size_t value);
|
|
14
|
-
void json_add_double(buffer_T* json, const char* key, double value);
|
|
15
|
-
void json_add_bool(buffer_T* json, const char* key, int value);
|
|
16
|
-
|
|
17
|
-
void json_add_raw_string(buffer_T* json, const char* string);
|
|
18
|
-
|
|
19
|
-
void json_start_object(buffer_T* json, const char* key);
|
|
20
|
-
void json_end_object(buffer_T* json);
|
|
21
|
-
|
|
22
|
-
void json_start_array(buffer_T* json, const char* key);
|
|
23
|
-
void json_end_array(buffer_T* json);
|
|
24
|
-
|
|
25
|
-
void json_double_to_string(double value, char* buffer);
|
|
26
|
-
void json_int_to_string(int value, char* buffer);
|
|
27
|
-
|
|
28
|
-
#endif
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#include "memory.h"
|
|
2
|
-
|
|
3
|
-
#include <stdbool.h>
|
|
4
|
-
#include <stdio.h>
|
|
5
|
-
#include <stdlib.h>
|
|
6
|
-
|
|
7
|
-
static void* safe_malloc_internal(const size_t size, const bool fail_fast) {
|
|
8
|
-
if (size == 0) { return NULL; }
|
|
9
|
-
|
|
10
|
-
void* pointer = malloc(size);
|
|
11
|
-
|
|
12
|
-
if (!pointer) {
|
|
13
|
-
fprintf(stderr, "Error: Failed to allocate %zu bytes.\n", size);
|
|
14
|
-
fflush(stderr);
|
|
15
|
-
if (fail_fast) { exit(1); }
|
|
16
|
-
return NULL;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return pointer;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
static void* safe_realloc_internal(void* pointer, const size_t new_size, const bool fail_fast) {
|
|
23
|
-
if (new_size == 0) { return NULL; }
|
|
24
|
-
|
|
25
|
-
if (!pointer) { return safe_malloc_internal(new_size, fail_fast); }
|
|
26
|
-
|
|
27
|
-
void* new_pointer = realloc(pointer, new_size);
|
|
28
|
-
|
|
29
|
-
if (!new_pointer) {
|
|
30
|
-
fprintf(stderr, "Error: Memory reallocation failed (size: %zu bytes).\n", new_size);
|
|
31
|
-
fflush(stderr);
|
|
32
|
-
if (fail_fast) { exit(1); }
|
|
33
|
-
return NULL;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return new_pointer;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
void* safe_malloc(const size_t size) {
|
|
40
|
-
return safe_malloc_internal(size, true);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
void* nullable_safe_malloc(const size_t size) {
|
|
44
|
-
return safe_malloc_internal(size, false);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
void* safe_realloc(void* pointer, const size_t new_size) {
|
|
48
|
-
return safe_realloc_internal(pointer, new_size, true);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
void* nullable_safe_realloc(void* pointer, const size_t new_size) {
|
|
52
|
-
return safe_realloc_internal(pointer, new_size, false);
|
|
53
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#ifndef HERB_MEMORY_H
|
|
2
|
-
#define HERB_MEMORY_H
|
|
3
|
-
|
|
4
|
-
#include <stddef.h>
|
|
5
|
-
|
|
6
|
-
void* safe_malloc(size_t size);
|
|
7
|
-
void* safe_realloc(void* pointer, size_t new_size);
|
|
8
|
-
|
|
9
|
-
void* nullable_safe_malloc(size_t size);
|
|
10
|
-
void* nullable_safe_realloc(void* pointer, size_t new_size);
|
|
11
|
-
|
|
12
|
-
#endif
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
#include "include/position.h"
|
|
2
|
-
#include "include/memory.h"
|
|
3
|
-
|
|
4
|
-
size_t position_sizeof(void) {
|
|
5
|
-
return sizeof(position_T);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
position_T* position_init(const size_t line, const size_t column) {
|
|
9
|
-
position_T* position = safe_malloc(position_sizeof());
|
|
10
|
-
|
|
11
|
-
position->line = line;
|
|
12
|
-
position->column = column;
|
|
13
|
-
|
|
14
|
-
return position;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
size_t position_line(const position_T* position) {
|
|
18
|
-
return position->line;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
size_t position_column(const position_T* position) {
|
|
22
|
-
return position->column;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
position_T* position_copy(position_T* position) {
|
|
26
|
-
if (position == NULL) { return NULL; }
|
|
27
|
-
|
|
28
|
-
return position_init(position_line(position), position_column(position));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
void position_free(position_T* position) {
|
|
32
|
-
free(position);
|
|
33
|
-
}
|