@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
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#include "../include/util/hb_string.h"
|
|
2
|
+
#include "../include/macros.h"
|
|
3
|
+
|
|
4
|
+
#include <stdlib.h>
|
|
5
|
+
#include <string.h>
|
|
6
|
+
#include <strings.h>
|
|
7
|
+
|
|
8
|
+
hb_string_T hb_string(const char* null_terminated_c_string) {
|
|
9
|
+
hb_string_T string;
|
|
10
|
+
|
|
11
|
+
string.data = (char*) null_terminated_c_string;
|
|
12
|
+
string.length = (uint32_t) strlen(null_terminated_c_string);
|
|
13
|
+
|
|
14
|
+
return string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
hb_string_T hb_string_slice(hb_string_T string, uint32_t offset) {
|
|
18
|
+
hb_string_T slice;
|
|
19
|
+
if (string.length < offset) {
|
|
20
|
+
slice.data = NULL;
|
|
21
|
+
slice.length = 0;
|
|
22
|
+
|
|
23
|
+
return slice;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
slice.data = string.data + offset;
|
|
27
|
+
slice.length = string.length - offset;
|
|
28
|
+
|
|
29
|
+
return slice;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
bool hb_string_equals(hb_string_T a, hb_string_T b) {
|
|
33
|
+
if (a.length != b.length) { return false; }
|
|
34
|
+
|
|
35
|
+
return strncmp(a.data, b.data, a.length) == 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bool hb_string_equals_case_insensitive(hb_string_T a, hb_string_T b) {
|
|
39
|
+
if (a.length != b.length) { return false; }
|
|
40
|
+
|
|
41
|
+
return strncasecmp(a.data, b.data, a.length) == 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
bool hb_string_starts_with(hb_string_T string, hb_string_T expected_prefix) {
|
|
45
|
+
if (hb_string_is_empty(string) || hb_string_is_empty(expected_prefix)) { return false; }
|
|
46
|
+
if (string.length < expected_prefix.length) { return false; }
|
|
47
|
+
|
|
48
|
+
return strncmp(string.data, expected_prefix.data, expected_prefix.length) == 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
bool hb_string_is_empty(hb_string_T string) {
|
|
52
|
+
return string.length == 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
hb_string_T hb_string_truncate(hb_string_T string, uint32_t max_length) {
|
|
56
|
+
hb_string_T truncated_string = { .data = string.data, .length = MIN(string.length, max_length) };
|
|
57
|
+
|
|
58
|
+
return truncated_string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
hb_string_T hb_string_range(hb_string_T string, uint32_t from, uint32_t to) {
|
|
62
|
+
return hb_string_truncate(hb_string_slice(string, from), to - from);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
char* hb_string_to_c_string_using_malloc(hb_string_T string) {
|
|
66
|
+
size_t string_length_in_bytes = sizeof(char) * (string.length);
|
|
67
|
+
char* buffer = malloc(string_length_in_bytes + sizeof(char) * 1);
|
|
68
|
+
|
|
69
|
+
if (!hb_string_is_empty(string)) { memcpy(buffer, string.data, string_length_in_bytes); }
|
|
70
|
+
|
|
71
|
+
buffer[string_length_in_bytes] = '\0';
|
|
72
|
+
|
|
73
|
+
return buffer;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
char* hb_string_to_c_string(hb_arena_T* allocator, hb_string_T string) {
|
|
77
|
+
size_t string_length_in_bytes = sizeof(char) * (string.length);
|
|
78
|
+
char* buffer = hb_arena_alloc(allocator, string_length_in_bytes + sizeof(char) * 1);
|
|
79
|
+
|
|
80
|
+
if (!hb_string_is_empty(string)) { memcpy(buffer, string.data, string_length_in_bytes); }
|
|
81
|
+
|
|
82
|
+
buffer[string_length_in_bytes] = '\0';
|
|
83
|
+
|
|
84
|
+
return buffer;
|
|
85
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#ifndef HERB_STRING_H
|
|
2
|
+
#define HERB_STRING_H
|
|
3
|
+
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
#include <stddef.h>
|
|
6
|
+
#include <stdint.h>
|
|
7
|
+
|
|
8
|
+
#include "hb_arena.h"
|
|
9
|
+
|
|
10
|
+
typedef struct HB_STRING_STRUCT {
|
|
11
|
+
char* data;
|
|
12
|
+
uint32_t length;
|
|
13
|
+
} hb_string_T;
|
|
14
|
+
|
|
15
|
+
hb_string_T hb_string(const char* null_terminated_c_string);
|
|
16
|
+
hb_string_T hb_string_slice(hb_string_T string, uint32_t offset);
|
|
17
|
+
bool hb_string_equals(hb_string_T a, hb_string_T b);
|
|
18
|
+
bool hb_string_equals_case_insensitive(hb_string_T a, hb_string_T b);
|
|
19
|
+
bool hb_string_starts_with(hb_string_T string, hb_string_T expected_prefix);
|
|
20
|
+
bool hb_string_is_empty(hb_string_T string);
|
|
21
|
+
hb_string_T hb_string_truncate(hb_string_T string, uint32_t max_length);
|
|
22
|
+
|
|
23
|
+
hb_string_T hb_string_range(hb_string_T string, uint32_t from, uint32_t to);
|
|
24
|
+
|
|
25
|
+
char* hb_string_to_c_string_using_malloc(hb_string_T string);
|
|
26
|
+
|
|
27
|
+
char* hb_string_to_c_string(hb_arena_T* allocator, hb_string_T string);
|
|
28
|
+
|
|
29
|
+
#endif
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#include "../include/util/hb_system.h"
|
|
2
|
+
|
|
3
|
+
#ifdef __linux__
|
|
4
|
+
#define _GNU_SOURCE
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
#ifdef HB_USE_MALLOC
|
|
8
|
+
#include <stdlib.h>
|
|
9
|
+
#else
|
|
10
|
+
#include <sys/mman.h>
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
void* hb_system_allocate_memory(size_t size) {
|
|
14
|
+
#ifdef HB_USE_MALLOC
|
|
15
|
+
return malloc(size);
|
|
16
|
+
#else
|
|
17
|
+
void* memory = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
18
|
+
if (memory == MAP_FAILED) { return NULL; }
|
|
19
|
+
|
|
20
|
+
return memory;
|
|
21
|
+
#endif
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
void hb_system_free_memory(void* ptr, size_t size) {
|
|
25
|
+
#ifdef HB_USE_MALLOC
|
|
26
|
+
free(ptr);
|
|
27
|
+
#else
|
|
28
|
+
munmap(ptr, size);
|
|
29
|
+
#endif
|
|
30
|
+
}
|
package/extension/libherb/util.c
CHANGED
|
@@ -1,118 +1,55 @@
|
|
|
1
1
|
#include "include/util.h"
|
|
2
|
+
#include "include/util/hb_buffer.h"
|
|
3
|
+
#include "include/util/hb_string.h"
|
|
2
4
|
|
|
3
|
-
#include <ctype.h>
|
|
4
5
|
#include <stdio.h>
|
|
5
6
|
#include <stdlib.h>
|
|
6
7
|
#include <string.h>
|
|
7
8
|
|
|
8
|
-
int
|
|
9
|
-
return character == '
|
|
9
|
+
int is_newline(int character) {
|
|
10
|
+
return character == '\n' || character == '\r';
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
int count_in_string(const char* string, const char character) {
|
|
17
|
-
int count = 0;
|
|
13
|
+
hb_string_T escape_newlines(hb_string_T input) {
|
|
14
|
+
hb_buffer_T buffer;
|
|
18
15
|
|
|
19
|
-
|
|
20
|
-
if (*string == character) { count++; }
|
|
16
|
+
hb_buffer_init(&buffer, input.length);
|
|
21
17
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
} else if (*string == '\n') {
|
|
36
|
-
count++;
|
|
18
|
+
for (size_t i = 0; i < input.length; ++i) {
|
|
19
|
+
switch (input.data[i]) {
|
|
20
|
+
case '\n': {
|
|
21
|
+
hb_buffer_append_char(&buffer, '\\');
|
|
22
|
+
hb_buffer_append_char(&buffer, 'n');
|
|
23
|
+
} break;
|
|
24
|
+
case '\r': {
|
|
25
|
+
hb_buffer_append_char(&buffer, '\\');
|
|
26
|
+
hb_buffer_append_char(&buffer, 'r');
|
|
27
|
+
} break;
|
|
28
|
+
default: {
|
|
29
|
+
hb_buffer_append_char(&buffer, input.data[i]);
|
|
30
|
+
}
|
|
37
31
|
}
|
|
38
|
-
|
|
39
|
-
string++;
|
|
40
32
|
}
|
|
41
33
|
|
|
42
|
-
return
|
|
34
|
+
return hb_string(buffer.value);
|
|
43
35
|
}
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
while (*string != '\0') {
|
|
49
|
-
if (*string == find) { *string = replace; }
|
|
37
|
+
static hb_string_T wrap_string(hb_string_T input, char character) {
|
|
38
|
+
hb_buffer_T buffer;
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return original_string;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
char* escape_newlines(const char* input) {
|
|
58
|
-
char* output = calloc(strlen(input) * 2 + 1, sizeof(char));
|
|
59
|
-
char* orig_output = output;
|
|
60
|
-
|
|
61
|
-
while (*input) {
|
|
62
|
-
if (*input == '\n') {
|
|
63
|
-
*output++ = '\\';
|
|
64
|
-
*output++ = 'n';
|
|
65
|
-
} else if (*input == '\r') {
|
|
66
|
-
*output++ = '\\';
|
|
67
|
-
*output++ = 'r';
|
|
68
|
-
} else {
|
|
69
|
-
*output++ = *input;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
input++;
|
|
73
|
-
}
|
|
40
|
+
hb_buffer_init(&buffer, input.length + 2);
|
|
74
41
|
|
|
75
|
-
|
|
42
|
+
hb_buffer_append_char(&buffer, character);
|
|
43
|
+
hb_buffer_append_string(&buffer, input);
|
|
44
|
+
hb_buffer_append_char(&buffer, character);
|
|
76
45
|
|
|
77
|
-
return
|
|
46
|
+
return hb_string(buffer.value);
|
|
78
47
|
}
|
|
79
48
|
|
|
80
|
-
|
|
81
|
-
if (input == NULL) { return NULL; }
|
|
82
|
-
|
|
83
|
-
const size_t length = strlen(input);
|
|
84
|
-
char* wrapped = malloc(length + 3);
|
|
85
|
-
|
|
86
|
-
if (wrapped == NULL) { return NULL; }
|
|
87
|
-
|
|
88
|
-
wrapped[0] = character;
|
|
89
|
-
strcpy(wrapped + 1, input);
|
|
90
|
-
wrapped[length + 1] = character;
|
|
91
|
-
wrapped[length + 2] = '\0';
|
|
92
|
-
|
|
93
|
-
return wrapped;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
char* quoted_string(const char* input) {
|
|
49
|
+
hb_string_T quoted_string(hb_string_T input) {
|
|
97
50
|
return wrap_string(input, '"');
|
|
98
51
|
}
|
|
99
52
|
|
|
100
|
-
// Check if a string is blank (NULL, empty, or only contains whitespace)
|
|
101
|
-
bool string_blank(const char* input) {
|
|
102
|
-
if (input == NULL || input[0] == '\0') { return true; }
|
|
103
|
-
|
|
104
|
-
for (const char* p = input; *p != '\0'; p++) {
|
|
105
|
-
if (!isspace(*p)) { return false; }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Check if a string is present (not blank)
|
|
112
|
-
bool string_present(const char* input) {
|
|
113
|
-
return !string_blank(input);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
53
|
char* herb_strdup(const char* s) {
|
|
117
54
|
size_t len = strlen(s) + 1;
|
|
118
55
|
char* copy = malloc(len);
|
|
@@ -121,10 +58,3 @@ char* herb_strdup(const char* s) {
|
|
|
121
58
|
|
|
122
59
|
return copy;
|
|
123
60
|
}
|
|
124
|
-
|
|
125
|
-
char* size_t_to_string(const size_t value) {
|
|
126
|
-
char* buffer = malloc(21);
|
|
127
|
-
snprintf(buffer, 21, "%zu", value);
|
|
128
|
-
|
|
129
|
-
return buffer;
|
|
130
|
-
}
|
package/extension/libherb/util.h
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
#ifndef HERB_UTIL_H
|
|
2
2
|
#define HERB_UTIL_H
|
|
3
3
|
|
|
4
|
+
#include "util/hb_string.h"
|
|
4
5
|
#include <stdbool.h>
|
|
5
6
|
#include <stdlib.h>
|
|
6
7
|
|
|
7
|
-
int is_whitespace(int character);
|
|
8
8
|
int is_newline(int character);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
char* replace_char(char* string, char find, char replace);
|
|
14
|
-
char* escape_newlines(const char* input);
|
|
15
|
-
char* quoted_string(const char* input);
|
|
16
|
-
char* wrap_string(const char* input, char character);
|
|
17
|
-
|
|
18
|
-
bool string_blank(const char* input);
|
|
19
|
-
bool string_present(const char* input);
|
|
20
|
-
|
|
10
|
+
hb_string_T escape_newlines(hb_string_T input);
|
|
11
|
+
hb_string_T quoted_string(hb_string_T input);
|
|
21
12
|
char* herb_strdup(const char* s);
|
|
22
13
|
|
|
23
|
-
char* size_t_to_string(size_t value);
|
|
24
|
-
|
|
25
14
|
#endif
|
|
@@ -1,12 +1,12 @@
|
|
|
1
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.
|
|
2
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-0.8.0/templates/src/visitor.c.erb
|
|
3
3
|
|
|
4
4
|
#include <stdio.h>
|
|
5
5
|
|
|
6
|
-
#include "include/array.h"
|
|
7
|
-
#include "include/visitor.h"
|
|
8
6
|
#include "include/ast_node.h"
|
|
9
7
|
#include "include/ast_nodes.h"
|
|
8
|
+
#include "include/util/hb_array.h"
|
|
9
|
+
#include "include/visitor.h"
|
|
10
10
|
|
|
11
11
|
void herb_visit_node(const AST_NODE_T* node, bool (*visitor)(const AST_NODE_T*, void*), void* data) {
|
|
12
12
|
if (visitor(node, data) && node != NULL) {
|
|
@@ -24,8 +24,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
24
24
|
const AST_DOCUMENT_NODE_T* document_node = ((const AST_DOCUMENT_NODE_T *) node);
|
|
25
25
|
|
|
26
26
|
if (document_node->children != NULL) {
|
|
27
|
-
for (size_t index = 0; index <
|
|
28
|
-
herb_visit_node(
|
|
27
|
+
for (size_t index = 0; index < hb_array_size(document_node->children); index++) {
|
|
28
|
+
herb_visit_node(hb_array_get(document_node->children, index), visitor, data);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -35,8 +35,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
35
35
|
const AST_HTML_OPEN_TAG_NODE_T* html_open_tag_node = ((const AST_HTML_OPEN_TAG_NODE_T *) node);
|
|
36
36
|
|
|
37
37
|
if (html_open_tag_node->children != NULL) {
|
|
38
|
-
for (size_t index = 0; index <
|
|
39
|
-
herb_visit_node(
|
|
38
|
+
for (size_t index = 0; index < hb_array_size(html_open_tag_node->children); index++) {
|
|
39
|
+
herb_visit_node(hb_array_get(html_open_tag_node->children, index), visitor, data);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -46,8 +46,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
46
46
|
const AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = ((const AST_HTML_CLOSE_TAG_NODE_T *) node);
|
|
47
47
|
|
|
48
48
|
if (html_close_tag_node->children != NULL) {
|
|
49
|
-
for (size_t index = 0; index <
|
|
50
|
-
herb_visit_node(
|
|
49
|
+
for (size_t index = 0; index < hb_array_size(html_close_tag_node->children); index++) {
|
|
50
|
+
herb_visit_node(hb_array_get(html_close_tag_node->children, index), visitor, data);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -61,8 +61,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
if (html_element_node->body != NULL) {
|
|
64
|
-
for (size_t index = 0; index <
|
|
65
|
-
herb_visit_node(
|
|
64
|
+
for (size_t index = 0; index < hb_array_size(html_element_node->body); index++) {
|
|
65
|
+
herb_visit_node(hb_array_get(html_element_node->body, index), visitor, data);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -76,8 +76,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
76
76
|
const AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node = ((const AST_HTML_ATTRIBUTE_VALUE_NODE_T *) node);
|
|
77
77
|
|
|
78
78
|
if (html_attribute_value_node->children != NULL) {
|
|
79
|
-
for (size_t index = 0; index <
|
|
80
|
-
herb_visit_node(
|
|
79
|
+
for (size_t index = 0; index < hb_array_size(html_attribute_value_node->children); index++) {
|
|
80
|
+
herb_visit_node(hb_array_get(html_attribute_value_node->children, index), visitor, data);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
|
|
@@ -87,8 +87,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
87
87
|
const AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = ((const AST_HTML_ATTRIBUTE_NAME_NODE_T *) node);
|
|
88
88
|
|
|
89
89
|
if (html_attribute_name_node->children != NULL) {
|
|
90
|
-
for (size_t index = 0; index <
|
|
91
|
-
herb_visit_node(
|
|
90
|
+
for (size_t index = 0; index < hb_array_size(html_attribute_name_node->children); index++) {
|
|
91
|
+
herb_visit_node(hb_array_get(html_attribute_name_node->children, index), visitor, data);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -111,8 +111,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
111
111
|
const AST_HTML_COMMENT_NODE_T* html_comment_node = ((const AST_HTML_COMMENT_NODE_T *) node);
|
|
112
112
|
|
|
113
113
|
if (html_comment_node->children != NULL) {
|
|
114
|
-
for (size_t index = 0; index <
|
|
115
|
-
herb_visit_node(
|
|
114
|
+
for (size_t index = 0; index < hb_array_size(html_comment_node->children); index++) {
|
|
115
|
+
herb_visit_node(hb_array_get(html_comment_node->children, index), visitor, data);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -122,8 +122,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
122
122
|
const AST_HTML_DOCTYPE_NODE_T* html_doctype_node = ((const AST_HTML_DOCTYPE_NODE_T *) node);
|
|
123
123
|
|
|
124
124
|
if (html_doctype_node->children != NULL) {
|
|
125
|
-
for (size_t index = 0; index <
|
|
126
|
-
herb_visit_node(
|
|
125
|
+
for (size_t index = 0; index < hb_array_size(html_doctype_node->children); index++) {
|
|
126
|
+
herb_visit_node(hb_array_get(html_doctype_node->children, index), visitor, data);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
@@ -133,8 +133,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
133
133
|
const AST_XML_DECLARATION_NODE_T* xml_declaration_node = ((const AST_XML_DECLARATION_NODE_T *) node);
|
|
134
134
|
|
|
135
135
|
if (xml_declaration_node->children != NULL) {
|
|
136
|
-
for (size_t index = 0; index <
|
|
137
|
-
herb_visit_node(
|
|
136
|
+
for (size_t index = 0; index < hb_array_size(xml_declaration_node->children); index++) {
|
|
137
|
+
herb_visit_node(hb_array_get(xml_declaration_node->children, index), visitor, data);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
140
|
|
|
@@ -144,8 +144,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
144
144
|
const AST_CDATA_NODE_T* cdata_node = ((const AST_CDATA_NODE_T *) node);
|
|
145
145
|
|
|
146
146
|
if (cdata_node->children != NULL) {
|
|
147
|
-
for (size_t index = 0; index <
|
|
148
|
-
herb_visit_node(
|
|
147
|
+
for (size_t index = 0; index < hb_array_size(cdata_node->children); index++) {
|
|
148
|
+
herb_visit_node(hb_array_get(cdata_node->children, index), visitor, data);
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -155,8 +155,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
155
155
|
const AST_ERB_ELSE_NODE_T* erb_else_node = ((const AST_ERB_ELSE_NODE_T *) node);
|
|
156
156
|
|
|
157
157
|
if (erb_else_node->statements != NULL) {
|
|
158
|
-
for (size_t index = 0; index <
|
|
159
|
-
herb_visit_node(
|
|
158
|
+
for (size_t index = 0; index < hb_array_size(erb_else_node->statements); index++) {
|
|
159
|
+
herb_visit_node(hb_array_get(erb_else_node->statements, index), visitor, data);
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -166,8 +166,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
166
166
|
const AST_ERB_IF_NODE_T* erb_if_node = ((const AST_ERB_IF_NODE_T *) node);
|
|
167
167
|
|
|
168
168
|
if (erb_if_node->statements != NULL) {
|
|
169
|
-
for (size_t index = 0; index <
|
|
170
|
-
herb_visit_node(
|
|
169
|
+
for (size_t index = 0; index < hb_array_size(erb_if_node->statements); index++) {
|
|
170
|
+
herb_visit_node(hb_array_get(erb_if_node->statements, index), visitor, data);
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
@@ -185,8 +185,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
185
185
|
const AST_ERB_BLOCK_NODE_T* erb_block_node = ((const AST_ERB_BLOCK_NODE_T *) node);
|
|
186
186
|
|
|
187
187
|
if (erb_block_node->body != NULL) {
|
|
188
|
-
for (size_t index = 0; index <
|
|
189
|
-
herb_visit_node(
|
|
188
|
+
for (size_t index = 0; index < hb_array_size(erb_block_node->body); index++) {
|
|
189
|
+
herb_visit_node(hb_array_get(erb_block_node->body, index), visitor, data);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
|
|
@@ -200,8 +200,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
200
200
|
const AST_ERB_WHEN_NODE_T* erb_when_node = ((const AST_ERB_WHEN_NODE_T *) node);
|
|
201
201
|
|
|
202
202
|
if (erb_when_node->statements != NULL) {
|
|
203
|
-
for (size_t index = 0; index <
|
|
204
|
-
herb_visit_node(
|
|
203
|
+
for (size_t index = 0; index < hb_array_size(erb_when_node->statements); index++) {
|
|
204
|
+
herb_visit_node(hb_array_get(erb_when_node->statements, index), visitor, data);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
@@ -211,14 +211,14 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
211
211
|
const AST_ERB_CASE_NODE_T* erb_case_node = ((const AST_ERB_CASE_NODE_T *) node);
|
|
212
212
|
|
|
213
213
|
if (erb_case_node->children != NULL) {
|
|
214
|
-
for (size_t index = 0; index <
|
|
215
|
-
herb_visit_node(
|
|
214
|
+
for (size_t index = 0; index < hb_array_size(erb_case_node->children); index++) {
|
|
215
|
+
herb_visit_node(hb_array_get(erb_case_node->children, index), visitor, data);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
if (erb_case_node->conditions != NULL) {
|
|
220
|
-
for (size_t index = 0; index <
|
|
221
|
-
herb_visit_node(
|
|
220
|
+
for (size_t index = 0; index < hb_array_size(erb_case_node->conditions); index++) {
|
|
221
|
+
herb_visit_node(hb_array_get(erb_case_node->conditions, index), visitor, data);
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
@@ -236,14 +236,14 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
236
236
|
const AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = ((const AST_ERB_CASE_MATCH_NODE_T *) node);
|
|
237
237
|
|
|
238
238
|
if (erb_case_match_node->children != NULL) {
|
|
239
|
-
for (size_t index = 0; index <
|
|
240
|
-
herb_visit_node(
|
|
239
|
+
for (size_t index = 0; index < hb_array_size(erb_case_match_node->children); index++) {
|
|
240
|
+
herb_visit_node(hb_array_get(erb_case_match_node->children, index), visitor, data);
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
if (erb_case_match_node->conditions != NULL) {
|
|
245
|
-
for (size_t index = 0; index <
|
|
246
|
-
herb_visit_node(
|
|
245
|
+
for (size_t index = 0; index < hb_array_size(erb_case_match_node->conditions); index++) {
|
|
246
|
+
herb_visit_node(hb_array_get(erb_case_match_node->conditions, index), visitor, data);
|
|
247
247
|
}
|
|
248
248
|
}
|
|
249
249
|
|
|
@@ -261,8 +261,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
261
261
|
const AST_ERB_WHILE_NODE_T* erb_while_node = ((const AST_ERB_WHILE_NODE_T *) node);
|
|
262
262
|
|
|
263
263
|
if (erb_while_node->statements != NULL) {
|
|
264
|
-
for (size_t index = 0; index <
|
|
265
|
-
herb_visit_node(
|
|
264
|
+
for (size_t index = 0; index < hb_array_size(erb_while_node->statements); index++) {
|
|
265
|
+
herb_visit_node(hb_array_get(erb_while_node->statements, index), visitor, data);
|
|
266
266
|
}
|
|
267
267
|
}
|
|
268
268
|
|
|
@@ -276,8 +276,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
276
276
|
const AST_ERB_UNTIL_NODE_T* erb_until_node = ((const AST_ERB_UNTIL_NODE_T *) node);
|
|
277
277
|
|
|
278
278
|
if (erb_until_node->statements != NULL) {
|
|
279
|
-
for (size_t index = 0; index <
|
|
280
|
-
herb_visit_node(
|
|
279
|
+
for (size_t index = 0; index < hb_array_size(erb_until_node->statements); index++) {
|
|
280
|
+
herb_visit_node(hb_array_get(erb_until_node->statements, index), visitor, data);
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
|
|
@@ -291,8 +291,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
291
291
|
const AST_ERB_FOR_NODE_T* erb_for_node = ((const AST_ERB_FOR_NODE_T *) node);
|
|
292
292
|
|
|
293
293
|
if (erb_for_node->statements != NULL) {
|
|
294
|
-
for (size_t index = 0; index <
|
|
295
|
-
herb_visit_node(
|
|
294
|
+
for (size_t index = 0; index < hb_array_size(erb_for_node->statements); index++) {
|
|
295
|
+
herb_visit_node(hb_array_get(erb_for_node->statements, index), visitor, data);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
|
|
@@ -306,8 +306,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
306
306
|
const AST_ERB_RESCUE_NODE_T* erb_rescue_node = ((const AST_ERB_RESCUE_NODE_T *) node);
|
|
307
307
|
|
|
308
308
|
if (erb_rescue_node->statements != NULL) {
|
|
309
|
-
for (size_t index = 0; index <
|
|
310
|
-
herb_visit_node(
|
|
309
|
+
for (size_t index = 0; index < hb_array_size(erb_rescue_node->statements); index++) {
|
|
310
|
+
herb_visit_node(hb_array_get(erb_rescue_node->statements, index), visitor, data);
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
|
|
@@ -321,8 +321,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
321
321
|
const AST_ERB_ENSURE_NODE_T* erb_ensure_node = ((const AST_ERB_ENSURE_NODE_T *) node);
|
|
322
322
|
|
|
323
323
|
if (erb_ensure_node->statements != NULL) {
|
|
324
|
-
for (size_t index = 0; index <
|
|
325
|
-
herb_visit_node(
|
|
324
|
+
for (size_t index = 0; index < hb_array_size(erb_ensure_node->statements); index++) {
|
|
325
|
+
herb_visit_node(hb_array_get(erb_ensure_node->statements, index), visitor, data);
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
|
|
@@ -332,8 +332,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
332
332
|
const AST_ERB_BEGIN_NODE_T* erb_begin_node = ((const AST_ERB_BEGIN_NODE_T *) node);
|
|
333
333
|
|
|
334
334
|
if (erb_begin_node->statements != NULL) {
|
|
335
|
-
for (size_t index = 0; index <
|
|
336
|
-
herb_visit_node(
|
|
335
|
+
for (size_t index = 0; index < hb_array_size(erb_begin_node->statements); index++) {
|
|
336
|
+
herb_visit_node(hb_array_get(erb_begin_node->statements, index), visitor, data);
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
339
|
|
|
@@ -359,8 +359,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
359
359
|
const AST_ERB_UNLESS_NODE_T* erb_unless_node = ((const AST_ERB_UNLESS_NODE_T *) node);
|
|
360
360
|
|
|
361
361
|
if (erb_unless_node->statements != NULL) {
|
|
362
|
-
for (size_t index = 0; index <
|
|
363
|
-
herb_visit_node(
|
|
362
|
+
for (size_t index = 0; index < hb_array_size(erb_unless_node->statements); index++) {
|
|
363
|
+
herb_visit_node(hb_array_get(erb_unless_node->statements, index), visitor, data);
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
366
|
|
|
@@ -378,8 +378,8 @@ void herb_visit_child_nodes(const AST_NODE_T *node, bool (*visitor)(const AST_NO
|
|
|
378
378
|
const AST_ERB_IN_NODE_T* erb_in_node = ((const AST_ERB_IN_NODE_T *) node);
|
|
379
379
|
|
|
380
380
|
if (erb_in_node->statements != NULL) {
|
|
381
|
-
for (size_t index = 0; index <
|
|
382
|
-
herb_visit_node(
|
|
381
|
+
for (size_t index = 0; index < hb_array_size(erb_in_node->statements); index++) {
|
|
382
|
+
herb_visit_node(hb_array_get(erb_in_node->statements, index), visitor, data);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
385
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#ifndef HERB_VISITOR_H
|
|
2
2
|
#define HERB_VISITOR_H
|
|
3
3
|
|
|
4
|
-
#include "array.h"
|
|
5
4
|
#include "ast_node.h"
|
|
6
5
|
#include "ast_nodes.h"
|
|
6
|
+
#include "util/hb_array.h"
|
|
7
7
|
|
|
8
8
|
void herb_visit_node(const AST_NODE_T* node, bool (*visitor)(const AST_NODE_T*, void*), void* data);
|
|
9
9
|
void herb_visit_child_nodes(const AST_NODE_T* node, bool (*visitor)(const AST_NODE_T* node, void* data), void* data);
|