herb 0.8.10-arm-linux-gnu → 0.9.0-arm-linux-gnu
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.
- checksums.yaml +4 -4
- data/Makefile +11 -3
- data/README.md +64 -34
- data/Rakefile +48 -40
- data/config.yml +317 -34
- data/ext/herb/error_helpers.c +367 -140
- data/ext/herb/error_helpers.h +1 -0
- data/ext/herb/extconf.rb +67 -28
- data/ext/herb/extension.c +317 -51
- data/ext/herb/extension.h +1 -0
- data/ext/herb/extension_helpers.c +23 -14
- data/ext/herb/extension_helpers.h +2 -2
- data/ext/herb/nodes.c +537 -270
- data/ext/herb/nodes.h +1 -0
- data/herb.gemspec +3 -2
- data/lib/herb/3.0/herb.so +0 -0
- data/lib/herb/3.1/herb.so +0 -0
- data/lib/herb/3.2/herb.so +0 -0
- data/lib/herb/3.3/herb.so +0 -0
- data/lib/herb/3.4/herb.so +0 -0
- data/lib/herb/4.0/herb.so +0 -0
- data/lib/herb/ast/helpers.rb +3 -3
- data/lib/herb/ast/node.rb +15 -2
- data/lib/herb/ast/nodes.rb +1132 -157
- data/lib/herb/bootstrap.rb +87 -0
- data/lib/herb/cli.rb +341 -31
- data/lib/herb/configuration.rb +248 -0
- data/lib/herb/defaults.yml +32 -0
- data/lib/herb/engine/compiler.rb +78 -11
- data/lib/herb/engine/debug_visitor.rb +13 -3
- data/lib/herb/engine/error_formatter.rb +13 -9
- data/lib/herb/engine/parser_error_overlay.rb +10 -6
- data/lib/herb/engine/validator.rb +8 -3
- data/lib/herb/engine/validators/nesting_validator.rb +2 -2
- data/lib/herb/engine.rb +82 -35
- data/lib/herb/errors.rb +563 -88
- data/lib/herb/lex_result.rb +1 -0
- data/lib/herb/location.rb +7 -3
- data/lib/herb/parse_result.rb +12 -2
- data/lib/herb/parser_options.rb +57 -0
- data/lib/herb/position.rb +1 -0
- data/lib/herb/prism_inspect.rb +116 -0
- data/lib/herb/project.rb +923 -331
- data/lib/herb/range.rb +1 -0
- data/lib/herb/token.rb +7 -1
- data/lib/herb/version.rb +1 -1
- data/lib/herb/visitor.rb +37 -2
- data/lib/herb/warnings.rb +6 -1
- data/lib/herb.rb +35 -3
- data/sig/herb/ast/helpers.rbs +2 -2
- data/sig/herb/ast/node.rbs +12 -2
- data/sig/herb/ast/nodes.rbs +641 -128
- data/sig/herb/bootstrap.rbs +31 -0
- data/sig/herb/configuration.rbs +89 -0
- data/sig/herb/engine/compiler.rbs +9 -1
- data/sig/herb/engine/debug_visitor.rbs +2 -0
- data/sig/herb/engine/validator.rbs +5 -1
- data/sig/herb/engine.rbs +17 -3
- data/sig/herb/errors.rbs +258 -63
- data/sig/herb/location.rbs +4 -0
- data/sig/herb/parse_result.rbs +4 -2
- data/sig/herb/parser_options.rbs +42 -0
- data/sig/herb/position.rbs +1 -0
- data/sig/herb/prism_inspect.rbs +28 -0
- data/sig/herb/range.rbs +1 -0
- data/sig/herb/token.rbs +6 -0
- data/sig/herb/visitor.rbs +25 -4
- data/sig/herb/warnings.rbs +6 -1
- data/sig/herb.rbs +14 -0
- data/sig/herb_c_extension.rbs +5 -2
- data/sig/serialized_ast_errors.rbs +54 -6
- data/sig/serialized_ast_nodes.rbs +60 -6
- data/src/analyze/action_view/attribute_extraction_helpers.c +290 -0
- data/src/analyze/action_view/content_tag.c +70 -0
- data/src/analyze/action_view/link_to.c +143 -0
- data/src/analyze/action_view/registry.c +60 -0
- data/src/analyze/action_view/tag.c +64 -0
- data/src/analyze/action_view/tag_helper_node_builders.c +305 -0
- data/src/analyze/action_view/tag_helpers.c +748 -0
- data/src/analyze/action_view/turbo_frame_tag.c +88 -0
- data/src/analyze/analyze.c +882 -0
- data/src/{analyzed_ruby.c → analyze/analyzed_ruby.c} +13 -11
- data/src/analyze/builders.c +343 -0
- data/src/analyze/conditional_elements.c +594 -0
- data/src/analyze/conditional_open_tags.c +640 -0
- data/src/analyze/control_type.c +250 -0
- data/src/{analyze_helpers.c → analyze/helpers.c} +48 -23
- data/src/analyze/invalid_structures.c +193 -0
- data/src/{analyze_missing_end.c → analyze/missing_end.c} +33 -22
- data/src/analyze/parse_errors.c +84 -0
- data/src/analyze/prism_annotate.c +397 -0
- data/src/{analyze_transform.c → analyze/transform.c} +17 -3
- data/src/ast_node.c +17 -7
- data/src/ast_nodes.c +662 -387
- data/src/ast_pretty_print.c +190 -6
- data/src/errors.c +1076 -520
- data/src/extract.c +145 -49
- data/src/herb.c +52 -34
- data/src/html_util.c +241 -12
- data/src/include/analyze/action_view/attribute_extraction_helpers.h +36 -0
- data/src/include/analyze/action_view/tag_helper_handler.h +41 -0
- data/src/include/analyze/action_view/tag_helper_node_builders.h +70 -0
- data/src/include/analyze/action_view/tag_helpers.h +38 -0
- data/src/include/{analyze.h → analyze/analyze.h} +14 -4
- data/src/include/{analyzed_ruby.h → analyze/analyzed_ruby.h} +3 -3
- data/src/include/analyze/builders.h +27 -0
- data/src/include/analyze/conditional_elements.h +9 -0
- data/src/include/analyze/conditional_open_tags.h +9 -0
- data/src/include/analyze/control_type.h +14 -0
- data/src/include/{analyze_helpers.h → analyze/helpers.h} +4 -2
- data/src/include/analyze/invalid_structures.h +11 -0
- data/src/include/analyze/prism_annotate.h +16 -0
- data/src/include/ast_node.h +11 -5
- data/src/include/ast_nodes.h +117 -38
- data/src/include/ast_pretty_print.h +5 -0
- data/src/include/element_source.h +3 -8
- data/src/include/errors.h +148 -55
- data/src/include/extract.h +21 -5
- data/src/include/herb.h +18 -6
- data/src/include/herb_prism_node.h +13 -0
- data/src/include/html_util.h +7 -2
- data/src/include/io.h +3 -1
- data/src/include/lex_helpers.h +29 -0
- data/src/include/lexer.h +1 -1
- data/src/include/lexer_peek_helpers.h +87 -13
- data/src/include/lexer_struct.h +2 -0
- data/src/include/location.h +2 -1
- data/src/include/parser.h +27 -2
- data/src/include/parser_helpers.h +19 -3
- data/src/include/pretty_print.h +10 -5
- data/src/include/prism_context.h +45 -0
- data/src/include/prism_helpers.h +10 -7
- data/src/include/prism_serialized.h +12 -0
- data/src/include/token.h +16 -4
- data/src/include/token_struct.h +10 -3
- data/src/include/utf8.h +2 -1
- data/src/include/util/hb_allocator.h +78 -0
- data/src/include/util/hb_arena.h +6 -1
- data/src/include/util/hb_arena_debug.h +12 -1
- data/src/include/util/hb_array.h +7 -3
- data/src/include/util/hb_buffer.h +6 -4
- data/src/include/util/hb_foreach.h +79 -0
- data/src/include/util/hb_narray.h +8 -4
- data/src/include/util/hb_string.h +56 -9
- data/src/include/util.h +6 -3
- data/src/include/version.h +1 -1
- data/src/io.c +3 -2
- data/src/lexer.c +42 -30
- data/src/lexer_peek_helpers.c +12 -74
- data/src/location.c +2 -2
- data/src/main.c +53 -28
- data/src/parser.c +783 -247
- data/src/parser_helpers.c +110 -23
- data/src/parser_match_tags.c +109 -48
- data/src/pretty_print.c +29 -24
- data/src/prism_helpers.c +30 -27
- data/src/ruby_parser.c +2 -0
- data/src/token.c +151 -66
- data/src/token_matchers.c +0 -1
- data/src/utf8.c +7 -6
- data/src/util/hb_allocator.c +341 -0
- data/src/util/hb_arena.c +81 -56
- data/src/util/hb_arena_debug.c +32 -17
- data/src/util/hb_array.c +30 -15
- data/src/util/hb_buffer.c +17 -21
- data/src/util/hb_narray.c +22 -7
- data/src/util/hb_string.c +49 -35
- data/src/util.c +21 -11
- data/src/visitor.c +47 -0
- data/templates/ext/herb/error_helpers.c.erb +24 -11
- data/templates/ext/herb/error_helpers.h.erb +1 -0
- data/templates/ext/herb/nodes.c.erb +50 -16
- data/templates/ext/herb/nodes.h.erb +1 -0
- data/templates/java/error_helpers.c.erb +1 -1
- data/templates/java/nodes.c.erb +30 -8
- data/templates/java/org/herb/ast/Errors.java.erb +24 -1
- data/templates/java/org/herb/ast/Nodes.java.erb +80 -21
- data/templates/javascript/packages/core/src/errors.ts.erb +16 -3
- data/templates/javascript/packages/core/src/node-type-guards.ts.erb +3 -1
- data/templates/javascript/packages/core/src/nodes.ts.erb +109 -32
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +13 -4
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +43 -4
- data/templates/lib/herb/ast/nodes.rb.erb +88 -31
- data/templates/lib/herb/errors.rb.erb +15 -3
- data/templates/lib/herb/visitor.rb.erb +2 -2
- data/templates/rust/src/ast/nodes.rs.erb +97 -44
- data/templates/rust/src/errors.rs.erb +2 -1
- data/templates/rust/src/nodes.rs.erb +167 -15
- data/templates/rust/src/union_types.rs.erb +60 -0
- data/templates/rust/src/visitor.rs.erb +81 -0
- data/templates/src/{analyze_missing_end.c.erb → analyze/missing_end.c.erb} +9 -6
- data/templates/src/{analyze_transform.c.erb → analyze/transform.c.erb} +2 -2
- data/templates/src/ast_nodes.c.erb +34 -26
- data/templates/src/ast_pretty_print.c.erb +24 -5
- data/templates/src/errors.c.erb +60 -54
- data/templates/src/include/ast_nodes.h.erb +6 -2
- data/templates/src/include/ast_pretty_print.h.erb +5 -0
- data/templates/src/include/errors.h.erb +15 -11
- data/templates/src/include/util/hb_foreach.h.erb +20 -0
- data/templates/src/parser_match_tags.c.erb +10 -4
- data/templates/src/visitor.c.erb +2 -2
- data/templates/template.rb +204 -29
- data/templates/wasm/error_helpers.cpp.erb +9 -5
- data/templates/wasm/nodes.cpp.erb +41 -4
- metadata +57 -16
- data/src/analyze.c +0 -1608
- data/src/element_source.c +0 -12
- data/src/include/util/hb_system.h +0 -9
- data/src/util/hb_system.c +0 -30
data/src/lexer_peek_helpers.c
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
#include "include/lexer_peek_helpers.h"
|
|
2
2
|
#include "include/lexer.h"
|
|
3
|
-
#include "include/lexer_struct.h"
|
|
4
|
-
#include "include/macros.h"
|
|
5
3
|
#include "include/token.h"
|
|
6
|
-
#include "include/util/hb_string.h"
|
|
7
4
|
|
|
8
5
|
#include <ctype.h>
|
|
9
|
-
#include <stdbool.h>
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
return lexer->source.data[MAX(lexer->current_position - offset, 0)];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
char lexer_peek(const lexer_T* lexer, uint32_t offset) {
|
|
16
|
-
return lexer->source.data[MIN(lexer->current_position + offset, lexer->source.length)];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
bool lexer_peek_for(const lexer_T* lexer, uint32_t offset, hb_string_T pattern, const bool case_insensitive) {
|
|
7
|
+
static bool lexer_peek_for(const lexer_T* lexer, uint32_t offset, hb_string_T pattern, bool case_insensitive) {
|
|
20
8
|
hb_string_T remaining_source = hb_string_slice(lexer->source, lexer->current_position + offset);
|
|
21
9
|
remaining_source.length = MIN(pattern.length, remaining_source.length);
|
|
22
10
|
|
|
@@ -47,31 +35,19 @@ bool lexer_peek_for_html_comment_start(const lexer_T* lexer, uint32_t offset) {
|
|
|
47
35
|
return lexer_peek_for(lexer, offset, hb_string("<!--"), false);
|
|
48
36
|
}
|
|
49
37
|
|
|
50
|
-
bool
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
bool lexer_peek_erb_close_tag(const lexer_T* lexer, uint32_t offset) {
|
|
55
|
-
return lexer_peek_for(lexer, offset, hb_string("%>"), false);
|
|
56
|
-
}
|
|
38
|
+
bool lexer_peek_for_close_tag_start(const lexer_T* lexer, uint32_t offset) {
|
|
39
|
+
if (lexer_peek(lexer, offset) != '<' || lexer_peek(lexer, offset + 1) != '/') { return false; }
|
|
57
40
|
|
|
58
|
-
|
|
59
|
-
return lexer_peek_for(lexer, offset, hb_string("-%>"), false);
|
|
60
|
-
}
|
|
41
|
+
uint32_t position = offset + 2;
|
|
61
42
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
43
|
+
while (lexer_peek(lexer, position) == ' ' || lexer_peek(lexer, position) == '\t'
|
|
44
|
+
|| lexer_peek(lexer, position) == '\n' || lexer_peek(lexer, position) == '\r') {
|
|
45
|
+
position++;
|
|
46
|
+
}
|
|
65
47
|
|
|
66
|
-
|
|
67
|
-
return lexer_peek_for(lexer, offset, hb_string("=%>"), false);
|
|
68
|
-
}
|
|
48
|
+
char character = lexer_peek(lexer, position);
|
|
69
49
|
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
lexer_peek_erb_close_tag(lexer, offset) || lexer_peek_erb_dash_close_tag(lexer, offset)
|
|
73
|
-
|| lexer_peek_erb_percent_close_tag(lexer, offset) || lexer_peek_erb_equals_close_tag(lexer, offset)
|
|
74
|
-
);
|
|
50
|
+
return isalpha(character) || character == '_';
|
|
75
51
|
}
|
|
76
52
|
|
|
77
53
|
bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T token_type) {
|
|
@@ -84,13 +60,13 @@ bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T tok
|
|
|
84
60
|
token_T* token = lexer_next_token(lexer);
|
|
85
61
|
|
|
86
62
|
while (token && (token->type == TOKEN_WHITESPACE || token->type == TOKEN_NEWLINE)) {
|
|
87
|
-
token_free(token);
|
|
63
|
+
token_free(token, lexer->allocator);
|
|
88
64
|
token = lexer_next_token(lexer);
|
|
89
65
|
}
|
|
90
66
|
|
|
91
67
|
bool result = (token && token->type == token_type);
|
|
92
68
|
|
|
93
|
-
if (token) { token_free(token); }
|
|
69
|
+
if (token) { token_free(token, lexer->allocator); }
|
|
94
70
|
|
|
95
71
|
lexer->current_position = saved_position;
|
|
96
72
|
lexer->current_line = saved_line;
|
|
@@ -100,41 +76,3 @@ bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T tok
|
|
|
100
76
|
|
|
101
77
|
return result;
|
|
102
78
|
}
|
|
103
|
-
|
|
104
|
-
bool lexer_peek_for_close_tag_start(const lexer_T* lexer, uint32_t offset) {
|
|
105
|
-
if (lexer_peek(lexer, offset) != '<' || lexer_peek(lexer, offset + 1) != '/') { return false; }
|
|
106
|
-
|
|
107
|
-
uint32_t pos = offset + 2;
|
|
108
|
-
|
|
109
|
-
while (lexer_peek(lexer, pos) == ' ' || lexer_peek(lexer, pos) == '\t' || lexer_peek(lexer, pos) == '\n'
|
|
110
|
-
|| lexer_peek(lexer, pos) == '\r') {
|
|
111
|
-
pos++;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
char c = lexer_peek(lexer, pos);
|
|
115
|
-
|
|
116
|
-
return isalpha(c) || c == '_';
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
lexer_state_snapshot_T lexer_save_state(lexer_T* lexer) {
|
|
120
|
-
lexer_state_snapshot_T snapshot = { .position = lexer->current_position,
|
|
121
|
-
.line = lexer->current_line,
|
|
122
|
-
.column = lexer->current_column,
|
|
123
|
-
.previous_position = lexer->previous_position,
|
|
124
|
-
.previous_line = lexer->previous_line,
|
|
125
|
-
.previous_column = lexer->previous_column,
|
|
126
|
-
.current_character = lexer->current_character,
|
|
127
|
-
.state = lexer->state };
|
|
128
|
-
return snapshot;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
void lexer_restore_state(lexer_T* lexer, lexer_state_snapshot_T snapshot) {
|
|
132
|
-
lexer->current_position = snapshot.position;
|
|
133
|
-
lexer->current_line = snapshot.line;
|
|
134
|
-
lexer->current_column = snapshot.column;
|
|
135
|
-
lexer->previous_position = snapshot.previous_position;
|
|
136
|
-
lexer->previous_line = snapshot.previous_line;
|
|
137
|
-
lexer->previous_column = snapshot.previous_column;
|
|
138
|
-
lexer->current_character = snapshot.current_character;
|
|
139
|
-
lexer->state = snapshot.state;
|
|
140
|
-
}
|
data/src/location.c
CHANGED
|
@@ -17,8 +17,8 @@ void location_from_positions(location_T* location, position_T start, position_T
|
|
|
17
17
|
location->end = end;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
location_T* location_create(position_T start, position_T end) {
|
|
21
|
-
location_T* location =
|
|
20
|
+
location_T* location_create(position_T start, position_T end, hb_allocator_T* allocator) {
|
|
21
|
+
location_T* location = hb_allocator_alloc(allocator, sizeof(location_T));
|
|
22
22
|
|
|
23
23
|
if (location != NULL) {
|
|
24
24
|
location->start = start;
|
data/src/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
|
}
|