@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
package/extension/libherb/main.c
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
#define _POSIX_C_SOURCE 199309L // Enables `clock_gettime()`
|
|
2
2
|
|
|
3
|
-
#include "include/analyze.h"
|
|
4
3
|
#include "include/ast_node.h"
|
|
5
4
|
#include "include/ast_nodes.h"
|
|
6
|
-
|
|
5
|
+
|
|
6
|
+
#ifndef HERB_EXCLUDE_PRETTYPRINT
|
|
7
|
+
# include "include/ast_pretty_print.h"
|
|
8
|
+
#endif
|
|
9
|
+
|
|
7
10
|
#include "include/extract.h"
|
|
8
11
|
#include "include/herb.h"
|
|
9
12
|
#include "include/io.h"
|
|
13
|
+
#include "include/lex_helpers.h"
|
|
14
|
+
#include "include/macros.h"
|
|
10
15
|
#include "include/ruby_parser.h"
|
|
16
|
+
#include "include/util/hb_allocator.h"
|
|
17
|
+
#include "include/util/hb_arena.h"
|
|
18
|
+
#include "include/util/hb_arena_debug.h"
|
|
11
19
|
#include "include/util/hb_buffer.h"
|
|
12
20
|
#include "include/util/string.h"
|
|
13
21
|
|
|
@@ -38,7 +46,7 @@ int main(const int argc, char* argv[]) {
|
|
|
38
46
|
if (argc < 2) {
|
|
39
47
|
puts("./herb [command] [options]\n");
|
|
40
48
|
|
|
41
|
-
puts("Herb 🌿 Powerful and seamless HTML-aware ERB
|
|
49
|
+
puts("Herb 🌿 Powerful and seamless HTML-aware ERB toolchain.\n");
|
|
42
50
|
|
|
43
51
|
puts("./herb lex [file] - Lex a file");
|
|
44
52
|
puts("./herb parse [file] - Parse a file");
|
|
@@ -54,74 +62,90 @@ int main(const int argc, char* argv[]) {
|
|
|
54
62
|
return EXIT_FAILURE;
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
|
|
65
|
+
hb_allocator_T malloc_allocator = hb_allocator_with_malloc();
|
|
66
|
+
char* source = herb_read_file(argv[2], &malloc_allocator);
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
hb_allocator_T allocator;
|
|
69
|
+
if (!hb_allocator_init(&allocator, HB_ALLOCATOR_ARENA)) {
|
|
70
|
+
fprintf(stderr, "Failed to initialize allocator\n");
|
|
71
|
+
hb_allocator_dealloc(&malloc_allocator, source);
|
|
72
|
+
return EXIT_FAILURE;
|
|
73
|
+
}
|
|
60
74
|
|
|
61
|
-
|
|
75
|
+
hb_buffer_T output;
|
|
76
|
+
if (!hb_buffer_init(&output, 4096, &allocator)) { return 1; }
|
|
62
77
|
|
|
63
78
|
struct timespec start, end;
|
|
64
79
|
clock_gettime(CLOCK_MONOTONIC, &start);
|
|
65
80
|
|
|
81
|
+
int silent = 0;
|
|
82
|
+
if (argc > 3 && string_equals(argv[3], "--silent")) { silent = 1; }
|
|
83
|
+
|
|
66
84
|
if (string_equals(argv[1], "lex")) {
|
|
67
|
-
herb_lex_to_buffer(source, &output);
|
|
85
|
+
herb_lex_to_buffer(source, &output, &allocator);
|
|
68
86
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
|
69
87
|
|
|
88
|
+
if (!silent) { hb_arena_print_stats((hb_arena_T*) allocator.context); }
|
|
89
|
+
|
|
70
90
|
puts(output.value);
|
|
71
91
|
print_time_diff(start, end, "lexing");
|
|
72
92
|
|
|
73
|
-
|
|
74
|
-
|
|
93
|
+
hb_buffer_free(&output);
|
|
94
|
+
hb_allocator_destroy(&allocator);
|
|
95
|
+
hb_allocator_dealloc(&malloc_allocator, source);
|
|
75
96
|
|
|
76
97
|
return EXIT_SUCCESS;
|
|
77
98
|
}
|
|
78
99
|
|
|
79
100
|
if (string_equals(argv[1], "parse")) {
|
|
80
|
-
AST_DOCUMENT_NODE_T* root = herb_parse(source, NULL);
|
|
81
|
-
|
|
82
|
-
herb_analyze_parse_tree(root, source);
|
|
101
|
+
AST_DOCUMENT_NODE_T* root = herb_parse(source, NULL, &allocator);
|
|
83
102
|
|
|
84
103
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
|
85
104
|
|
|
86
|
-
int silent = 0;
|
|
87
|
-
if (argc > 3 && string_equals(argv[3], "--silent")) { silent = 1; }
|
|
88
|
-
|
|
89
105
|
if (!silent) {
|
|
106
|
+
hb_arena_print_stats((hb_arena_T*) allocator.context);
|
|
107
|
+
|
|
108
|
+
#ifndef HERB_EXCLUDE_PRETTYPRINT
|
|
90
109
|
ast_pretty_print_node((AST_NODE_T*) root, 0, 0, &output);
|
|
91
110
|
puts(output.value);
|
|
111
|
+
#endif
|
|
92
112
|
|
|
93
113
|
print_time_diff(start, end, "parsing");
|
|
94
114
|
}
|
|
95
115
|
|
|
96
|
-
ast_node_free((AST_NODE_T*) root);
|
|
97
|
-
|
|
98
|
-
|
|
116
|
+
ast_node_free((AST_NODE_T*) root, &allocator);
|
|
117
|
+
|
|
118
|
+
hb_buffer_free(&output);
|
|
119
|
+
hb_allocator_destroy(&allocator);
|
|
120
|
+
hb_allocator_dealloc(&malloc_allocator, source);
|
|
99
121
|
|
|
100
122
|
return EXIT_SUCCESS;
|
|
101
123
|
}
|
|
102
124
|
|
|
103
125
|
if (string_equals(argv[1], "ruby")) {
|
|
104
|
-
herb_extract_ruby_to_buffer(source, &output);
|
|
126
|
+
herb_extract_ruby_to_buffer(source, &output, &allocator);
|
|
105
127
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
|
106
128
|
|
|
107
129
|
puts(output.value);
|
|
108
130
|
print_time_diff(start, end, "extracting Ruby");
|
|
109
131
|
|
|
110
|
-
|
|
111
|
-
|
|
132
|
+
hb_buffer_free(&output);
|
|
133
|
+
hb_allocator_destroy(&allocator);
|
|
134
|
+
hb_allocator_dealloc(&malloc_allocator, source);
|
|
112
135
|
|
|
113
136
|
return EXIT_SUCCESS;
|
|
114
137
|
}
|
|
115
138
|
|
|
116
139
|
if (string_equals(argv[1], "html")) {
|
|
117
|
-
herb_extract_html_to_buffer(source, &output);
|
|
140
|
+
herb_extract_html_to_buffer(source, &output, &allocator);
|
|
118
141
|
clock_gettime(CLOCK_MONOTONIC, &end);
|
|
119
142
|
|
|
120
143
|
puts(output.value);
|
|
121
144
|
print_time_diff(start, end, "extracting HTML");
|
|
122
145
|
|
|
123
|
-
|
|
124
|
-
|
|
146
|
+
hb_buffer_free(&output);
|
|
147
|
+
hb_allocator_destroy(&allocator);
|
|
148
|
+
hb_allocator_dealloc(&malloc_allocator, source);
|
|
125
149
|
|
|
126
150
|
return EXIT_SUCCESS;
|
|
127
151
|
}
|
|
@@ -129,14 +153,15 @@ int main(const int argc, char* argv[]) {
|
|
|
129
153
|
if (string_equals(argv[1], "prism")) {
|
|
130
154
|
printf("HTML+ERB File: \n%s\n", source);
|
|
131
155
|
|
|
132
|
-
char* ruby_source = herb_extract(source, HERB_EXTRACT_LANGUAGE_RUBY);
|
|
156
|
+
char* ruby_source = herb_extract(source, HERB_EXTRACT_LANGUAGE_RUBY, &allocator);
|
|
133
157
|
printf("Extracted Ruby: \n%s\n", ruby_source);
|
|
134
158
|
|
|
135
159
|
herb_parse_ruby_to_stdout(ruby_source);
|
|
136
160
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
161
|
+
hb_allocator_dealloc(&allocator, ruby_source);
|
|
162
|
+
hb_buffer_free(&output);
|
|
163
|
+
hb_allocator_destroy(&allocator);
|
|
164
|
+
hb_allocator_dealloc(&malloc_allocator, source);
|
|
140
165
|
|
|
141
166
|
return EXIT_SUCCESS;
|
|
142
167
|
}
|