herb 0.7.4-aarch64-linux-gnu → 0.8.0-aarch64-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 +8 -5
- data/config.yml +40 -20
- data/ext/herb/error_helpers.c +57 -3
- data/ext/herb/error_helpers.h +1 -1
- data/ext/herb/extconf.rb +1 -0
- data/ext/herb/extension.c +10 -24
- data/ext/herb/extension_helpers.c +12 -18
- data/ext/herb/extension_helpers.h +4 -4
- data/ext/herb/nodes.c +72 -37
- data/herb.gemspec +0 -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/ast/helpers.rb +11 -0
- data/lib/herb/ast/node.rb +15 -6
- data/lib/herb/ast/nodes.rb +609 -392
- data/lib/herb/cli.rb +31 -0
- data/lib/herb/colors.rb +82 -0
- data/lib/herb/engine/compiler.rb +140 -14
- data/lib/herb/engine/debug_visitor.rb +1 -5
- data/lib/herb/engine/parser_error_overlay.rb +1 -1
- data/lib/herb/engine.rb +18 -20
- data/lib/herb/errors.rb +166 -56
- data/lib/herb/location.rb +2 -2
- data/lib/herb/project.rb +86 -21
- data/lib/herb/token.rb +14 -2
- data/lib/herb/version.rb +1 -1
- data/lib/herb.rb +1 -0
- data/sig/herb/ast/helpers.rbs +3 -0
- data/sig/herb/ast/node.rbs +12 -5
- data/sig/herb/ast/nodes.rbs +124 -62
- data/sig/herb/colors.rbs +35 -0
- data/sig/herb/engine/compiler.rbs +23 -1
- data/sig/herb/errors.rbs +74 -20
- data/sig/herb/token.rbs +8 -0
- data/sig/herb_c_extension.rbs +1 -1
- data/sig/serialized_ast_errors.rbs +8 -0
- data/src/analyze.c +461 -249
- data/src/analyze_helpers.c +5 -0
- data/src/analyze_missing_end.c +147 -0
- data/src/analyze_transform.c +196 -0
- data/src/analyzed_ruby.c +23 -2
- data/src/ast_node.c +14 -17
- data/src/ast_nodes.c +179 -181
- data/src/ast_pretty_print.c +232 -232
- data/src/element_source.c +7 -6
- data/src/errors.c +272 -152
- data/src/extract.c +92 -34
- data/src/herb.c +37 -49
- data/src/html_util.c +34 -96
- data/src/include/analyze.h +10 -2
- data/src/include/analyze_helpers.h +3 -0
- data/src/include/analyzed_ruby.h +4 -2
- data/src/include/ast_node.h +4 -4
- data/src/include/ast_nodes.h +68 -67
- data/src/include/ast_pretty_print.h +2 -2
- data/src/include/element_source.h +3 -1
- data/src/include/errors.h +42 -26
- data/src/include/extract.h +4 -4
- data/src/include/herb.h +6 -7
- data/src/include/html_util.h +4 -5
- data/src/include/lexer.h +1 -3
- data/src/include/lexer_peek_helpers.h +21 -19
- data/src/include/lexer_struct.h +12 -10
- data/src/include/location.h +10 -13
- data/src/include/macros.h +4 -0
- data/src/include/parser.h +12 -6
- data/src/include/parser_helpers.h +26 -16
- data/src/include/position.h +3 -14
- data/src/include/pretty_print.h +38 -28
- data/src/include/prism_helpers.h +1 -1
- data/src/include/range.h +4 -13
- data/src/include/token.h +5 -11
- data/src/include/token_struct.h +2 -2
- data/src/include/utf8.h +3 -2
- data/src/include/util/hb_arena.h +31 -0
- data/src/include/util/hb_arena_debug.h +8 -0
- data/src/include/util/hb_array.h +33 -0
- data/src/include/util/hb_buffer.h +34 -0
- data/src/include/util/hb_string.h +29 -0
- data/src/include/util/hb_system.h +9 -0
- data/src/include/util.h +3 -14
- data/src/include/version.h +1 -1
- data/src/include/visitor.h +1 -1
- data/src/io.c +7 -4
- data/src/lexer.c +62 -88
- data/src/lexer_peek_helpers.c +42 -38
- data/src/location.c +9 -37
- data/src/main.c +19 -23
- data/src/parser.c +373 -313
- data/src/parser_helpers.c +60 -54
- data/src/parser_match_tags.c +316 -0
- data/src/pretty_print.c +88 -117
- data/src/prism_helpers.c +7 -7
- data/src/range.c +2 -35
- data/src/token.c +36 -87
- data/src/utf8.c +4 -4
- data/src/util/hb_arena.c +179 -0
- data/src/util/hb_arena_debug.c +237 -0
- data/src/{array.c → util/hb_array.c} +26 -27
- data/src/util/hb_buffer.c +203 -0
- data/src/util/hb_string.c +85 -0
- data/src/util/hb_system.c +30 -0
- data/src/util.c +29 -99
- data/src/visitor.c +54 -54
- data/templates/ext/herb/error_helpers.c.erb +3 -3
- data/templates/ext/herb/error_helpers.h.erb +1 -1
- data/templates/ext/herb/nodes.c.erb +11 -6
- data/templates/java/error_helpers.c.erb +75 -0
- data/templates/java/error_helpers.h.erb +20 -0
- data/templates/java/nodes.c.erb +97 -0
- data/templates/java/nodes.h.erb +23 -0
- data/templates/java/org/herb/ast/Errors.java.erb +121 -0
- data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
- data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
- data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
- data/templates/javascript/packages/core/src/visitor.ts.erb +29 -1
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
- data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
- data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
- data/templates/lib/herb/ast/nodes.rb.erb +28 -16
- data/templates/lib/herb/errors.rb.erb +17 -12
- data/templates/rust/src/ast/nodes.rs.erb +220 -0
- data/templates/rust/src/errors.rs.erb +216 -0
- data/templates/rust/src/nodes.rs.erb +374 -0
- data/templates/src/analyze_missing_end.c.erb +36 -0
- data/templates/src/analyze_transform.c.erb +24 -0
- data/templates/src/ast_nodes.c.erb +14 -16
- data/templates/src/ast_pretty_print.c.erb +36 -36
- data/templates/src/errors.c.erb +36 -38
- data/templates/src/include/ast_nodes.h.erb +11 -10
- data/templates/src/include/ast_pretty_print.h.erb +2 -2
- data/templates/src/include/errors.h.erb +9 -9
- data/templates/src/parser_match_tags.c.erb +38 -0
- data/templates/src/visitor.c.erb +4 -4
- data/templates/template.rb +22 -3
- data/templates/wasm/error_helpers.cpp.erb +9 -9
- data/templates/wasm/error_helpers.h.erb +1 -1
- data/templates/wasm/nodes.cpp.erb +9 -9
- data/templates/wasm/nodes.h.erb +1 -1
- data/vendor/prism/Rakefile +4 -1
- data/vendor/prism/config.yml +2 -1
- data/vendor/prism/include/prism/ast.h +31 -1
- data/vendor/prism/include/prism/diagnostic.h +1 -0
- data/vendor/prism/include/prism/version.h +3 -3
- data/vendor/prism/src/diagnostic.c +3 -1
- data/vendor/prism/src/prism.c +130 -71
- data/vendor/prism/src/util/pm_string.c +6 -8
- data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
- data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
- data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
- data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
- data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
- data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
- metadata +34 -21
- data/lib/herb/libherb/array.rb +0 -51
- data/lib/herb/libherb/ast_node.rb +0 -50
- data/lib/herb/libherb/buffer.rb +0 -56
- data/lib/herb/libherb/extract_result.rb +0 -20
- data/lib/herb/libherb/lex_result.rb +0 -32
- data/lib/herb/libherb/libherb.rb +0 -52
- data/lib/herb/libherb/parse_result.rb +0 -20
- data/lib/herb/libherb/token.rb +0 -46
- data/lib/herb/libherb.rb +0 -35
- data/src/buffer.c +0 -232
- data/src/include/array.h +0 -33
- data/src/include/buffer.h +0 -39
- data/src/include/json.h +0 -28
- data/src/include/memory.h +0 -12
- data/src/json.c +0 -205
- data/src/memory.c +0 -53
- data/src/position.c +0 -33
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0b363f5d92afe92881c17ec763dc7bfc28ee6a8aac39e79ca7d101c3d1000f1c
|
|
4
|
+
data.tar.gz: ef2ec88c8c8adb3f28849ce10b59fdb4b312e2c413227a293696033a179620f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11ea667b4b365ba99fdcabf1250e82132bb7dcebe5c4daa5a68ad4b6cb129dc79fa4ee0c3f69b6312acaaa08b5d589b0d37542d1cfa10ae8bec48a5c5cc5e8d4
|
|
7
|
+
data.tar.gz: ffdf788c56319b72f96a096f85d64c0599bb3b97cca978daae00c9c4a8954044a46b237cdce1658ace4ca8b6c346daa4d52e224da0bcf8a265871ac241a1298e
|
data/Makefile
CHANGED
|
@@ -61,22 +61,22 @@ shared_flags = $(production_flags) $(shared_library_flags) $(prism_flags)
|
|
|
61
61
|
ifeq ($(os),Linux)
|
|
62
62
|
test_cflags = $(test_flags) -I/usr/include/check
|
|
63
63
|
test_ldflags = -L/usr/lib/x86_64-linux-gnu -lcheck -lm -lsubunit $(prism_ldflags)
|
|
64
|
-
cc = clang-
|
|
65
|
-
clang_format = clang-format-
|
|
66
|
-
clang_tidy = clang-tidy-
|
|
64
|
+
cc = clang-21
|
|
65
|
+
clang_format = clang-format-21
|
|
66
|
+
clang_tidy = clang-tidy-21
|
|
67
67
|
endif
|
|
68
68
|
|
|
69
69
|
ifeq ($(os),Darwin)
|
|
70
70
|
brew_prefix := $(shell brew --prefix check)
|
|
71
71
|
test_cflags = $(test_flags) -I$(brew_prefix)/include
|
|
72
72
|
test_ldflags = -L$(brew_prefix)/lib -lcheck -lm $(prism_ldflags)
|
|
73
|
-
llvm_path = $(shell brew --prefix llvm@
|
|
73
|
+
llvm_path = $(shell brew --prefix llvm@21)
|
|
74
74
|
cc = $(llvm_path)/bin/clang
|
|
75
75
|
clang_format = $(llvm_path)/bin/clang-format
|
|
76
76
|
clang_tidy = $(llvm_path)/bin/clang-tidy
|
|
77
77
|
endif
|
|
78
78
|
|
|
79
|
-
all: templates prism $(exec) $(lib_name) $(static_lib_name) test wasm
|
|
79
|
+
all: templates prism $(exec) $(lib_name) $(static_lib_name) test wasm clangd_config
|
|
80
80
|
|
|
81
81
|
$(exec): $(objects)
|
|
82
82
|
$(cc) $(objects) $(flags) $(ldflags) $(prism_ldflags) -o $(exec)
|
|
@@ -122,5 +122,8 @@ lint:
|
|
|
122
122
|
tidy:
|
|
123
123
|
$(clang_tidy) $(project_files) -- $(flags)
|
|
124
124
|
|
|
125
|
+
clangd_config:
|
|
126
|
+
@echo "$(flags) $(test_cflags)" | tr ' ' '\n' | sort -u > compile_flags.txt
|
|
127
|
+
|
|
125
128
|
wasm:
|
|
126
129
|
cd wasm && make
|
data/config.yml
CHANGED
|
@@ -30,12 +30,12 @@ errors:
|
|
|
30
30
|
|
|
31
31
|
- name: UnexpectedTokenError
|
|
32
32
|
message:
|
|
33
|
-
template: "Found `%s` when expecting `%s` at (%
|
|
33
|
+
template: "Found `%s` when expecting `%s` at (%u:%u)."
|
|
34
34
|
arguments:
|
|
35
35
|
- token_type_to_string(found->type)
|
|
36
36
|
- token_type_to_string(expected_type)
|
|
37
|
-
- found->location
|
|
38
|
-
- found->location
|
|
37
|
+
- found->location.start.line
|
|
38
|
+
- found->location.start.column
|
|
39
39
|
|
|
40
40
|
fields:
|
|
41
41
|
- name: expected_type
|
|
@@ -46,11 +46,11 @@ errors:
|
|
|
46
46
|
|
|
47
47
|
- name: MissingOpeningTagError
|
|
48
48
|
message:
|
|
49
|
-
template: "Found closing tag `</%s>` at (%
|
|
49
|
+
template: "Found closing tag `</%s>` at (%u:%u) without a matching opening tag in the same scope."
|
|
50
50
|
arguments:
|
|
51
51
|
- closing_tag->value
|
|
52
|
-
- closing_tag->location
|
|
53
|
-
- closing_tag->location
|
|
52
|
+
- closing_tag->location.start.line
|
|
53
|
+
- closing_tag->location.start.column
|
|
54
54
|
|
|
55
55
|
fields:
|
|
56
56
|
- name: closing_tag
|
|
@@ -58,11 +58,11 @@ errors:
|
|
|
58
58
|
|
|
59
59
|
- name: MissingClosingTagError
|
|
60
60
|
message:
|
|
61
|
-
template: "Opening tag `<%s>` at (%
|
|
61
|
+
template: "Opening tag `<%s>` at (%u:%u) doesn't have a matching closing tag `</%s>` in the same scope."
|
|
62
62
|
arguments:
|
|
63
63
|
- opening_tag->value
|
|
64
|
-
- opening_tag->location
|
|
65
|
-
- opening_tag->location
|
|
64
|
+
- opening_tag->location.start.line
|
|
65
|
+
- opening_tag->location.start.column
|
|
66
66
|
- opening_tag->value
|
|
67
67
|
|
|
68
68
|
fields:
|
|
@@ -71,14 +71,14 @@ errors:
|
|
|
71
71
|
|
|
72
72
|
- name: TagNamesMismatchError
|
|
73
73
|
message:
|
|
74
|
-
template: "Opening tag `<%s>` at (%
|
|
74
|
+
template: "Opening tag `<%s>` at (%u:%u) closed with `</%s>` at (%u:%u)."
|
|
75
75
|
arguments:
|
|
76
76
|
- opening_tag->value
|
|
77
|
-
- opening_tag->location
|
|
78
|
-
- opening_tag->location
|
|
77
|
+
- opening_tag->location.start.line
|
|
78
|
+
- opening_tag->location.start.column
|
|
79
79
|
- closing_tag->value
|
|
80
|
-
- closing_tag->location
|
|
81
|
-
- closing_tag->location
|
|
80
|
+
- closing_tag->location.start.line
|
|
81
|
+
- closing_tag->location.start.column
|
|
82
82
|
|
|
83
83
|
fields:
|
|
84
84
|
- name: opening_tag
|
|
@@ -89,12 +89,12 @@ errors:
|
|
|
89
89
|
|
|
90
90
|
- name: QuotesMismatchError
|
|
91
91
|
message:
|
|
92
|
-
template: "String opened with %s but closed with %s at (%
|
|
92
|
+
template: "String opened with %s but closed with %s at (%u:%u)."
|
|
93
93
|
arguments:
|
|
94
94
|
- opening_quote->value
|
|
95
95
|
- closing_quote->value
|
|
96
|
-
- closing_quote->location
|
|
97
|
-
- closing_quote->location
|
|
96
|
+
- closing_quote->location.start.line
|
|
97
|
+
- closing_quote->location.start.column
|
|
98
98
|
|
|
99
99
|
fields:
|
|
100
100
|
- name: opening_quote
|
|
@@ -124,11 +124,11 @@ errors:
|
|
|
124
124
|
|
|
125
125
|
- name: UnclosedElementError
|
|
126
126
|
message:
|
|
127
|
-
template: "Tag `<%s>` opened at (%
|
|
127
|
+
template: "Tag `<%s>` opened at (%u:%u) was never closed before the end of document."
|
|
128
128
|
arguments:
|
|
129
129
|
- opening_tag->value
|
|
130
|
-
- opening_tag->location
|
|
131
|
-
- opening_tag->location
|
|
130
|
+
- opening_tag->location.start.line
|
|
131
|
+
- opening_tag->location.start.column
|
|
132
132
|
|
|
133
133
|
fields:
|
|
134
134
|
- name: opening_tag
|
|
@@ -151,6 +151,26 @@ errors:
|
|
|
151
151
|
- name: level
|
|
152
152
|
type: string
|
|
153
153
|
|
|
154
|
+
- name: ERBControlFlowScopeError
|
|
155
|
+
message:
|
|
156
|
+
template: "%s appears outside its control flow block. Keep ERB control flow statements together within the same HTML scope (tag, attribute, or content)."
|
|
157
|
+
arguments:
|
|
158
|
+
- keyword
|
|
159
|
+
|
|
160
|
+
fields:
|
|
161
|
+
- name: keyword
|
|
162
|
+
type: string
|
|
163
|
+
|
|
164
|
+
- name: MissingERBEndTagError
|
|
165
|
+
message:
|
|
166
|
+
template: "%s started here but never closed with an end tag. The end tag may be in a different scope."
|
|
167
|
+
arguments:
|
|
168
|
+
- keyword
|
|
169
|
+
|
|
170
|
+
fields:
|
|
171
|
+
- name: keyword
|
|
172
|
+
type: string
|
|
173
|
+
|
|
154
174
|
warnings:
|
|
155
175
|
fields: []
|
|
156
176
|
types: []
|
data/ext/herb/error_helpers.c
CHANGED
|
@@ -265,6 +265,58 @@ static VALUE rb_ruby_parse_error_from_c_struct(RUBY_PARSE_ERROR_T* ruby_parse_er
|
|
|
265
265
|
return rb_class_new_instance(6, args, RubyParseError);
|
|
266
266
|
};
|
|
267
267
|
|
|
268
|
+
static VALUE rb_erb_control_flow_scope_error_from_c_struct(ERB_CONTROL_FLOW_SCOPE_ERROR_T* erb_control_flow_scope_error) {
|
|
269
|
+
if (erb_control_flow_scope_error == NULL) { return Qnil; }
|
|
270
|
+
|
|
271
|
+
ERROR_T* error = &erb_control_flow_scope_error->base;
|
|
272
|
+
|
|
273
|
+
VALUE Herb = rb_define_module("Herb");
|
|
274
|
+
VALUE Errors = rb_define_module_under(Herb, "Errors");
|
|
275
|
+
VALUE Error = rb_define_class_under(Errors, "Error", rb_cObject);
|
|
276
|
+
VALUE ERBControlFlowScopeError = rb_define_class_under(Errors, "ERBControlFlowScopeError", Error);
|
|
277
|
+
|
|
278
|
+
VALUE type = rb_utf8_str_new_cstr(error_type_to_string(error));
|
|
279
|
+
VALUE location = rb_location_from_c_struct(error->location);
|
|
280
|
+
VALUE message = rb_utf8_str_new_cstr(error->message);
|
|
281
|
+
|
|
282
|
+
VALUE erb_control_flow_scope_error_keyword = rb_utf8_str_new_cstr(erb_control_flow_scope_error->keyword);
|
|
283
|
+
|
|
284
|
+
VALUE args[4] = {
|
|
285
|
+
type,
|
|
286
|
+
location,
|
|
287
|
+
message,
|
|
288
|
+
erb_control_flow_scope_error_keyword
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
return rb_class_new_instance(4, args, ERBControlFlowScopeError);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
static VALUE rb_missingerb_end_tag_error_from_c_struct(MISSINGERB_END_TAG_ERROR_T* missingerb_end_tag_error) {
|
|
295
|
+
if (missingerb_end_tag_error == NULL) { return Qnil; }
|
|
296
|
+
|
|
297
|
+
ERROR_T* error = &missingerb_end_tag_error->base;
|
|
298
|
+
|
|
299
|
+
VALUE Herb = rb_define_module("Herb");
|
|
300
|
+
VALUE Errors = rb_define_module_under(Herb, "Errors");
|
|
301
|
+
VALUE Error = rb_define_class_under(Errors, "Error", rb_cObject);
|
|
302
|
+
VALUE MissingERBEndTagError = rb_define_class_under(Errors, "MissingERBEndTagError", Error);
|
|
303
|
+
|
|
304
|
+
VALUE type = rb_utf8_str_new_cstr(error_type_to_string(error));
|
|
305
|
+
VALUE location = rb_location_from_c_struct(error->location);
|
|
306
|
+
VALUE message = rb_utf8_str_new_cstr(error->message);
|
|
307
|
+
|
|
308
|
+
VALUE missingerb_end_tag_error_keyword = rb_utf8_str_new_cstr(missingerb_end_tag_error->keyword);
|
|
309
|
+
|
|
310
|
+
VALUE args[4] = {
|
|
311
|
+
type,
|
|
312
|
+
location,
|
|
313
|
+
message,
|
|
314
|
+
missingerb_end_tag_error_keyword
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
return rb_class_new_instance(4, args, MissingERBEndTagError);
|
|
318
|
+
};
|
|
319
|
+
|
|
268
320
|
|
|
269
321
|
VALUE rb_error_from_c_struct(ERROR_T* error) {
|
|
270
322
|
if (!error) { return Qnil; }
|
|
@@ -279,17 +331,19 @@ VALUE rb_error_from_c_struct(ERROR_T* error) {
|
|
|
279
331
|
case VOID_ELEMENT_CLOSING_TAG_ERROR: return rb_void_element_closing_tag_error_from_c_struct((VOID_ELEMENT_CLOSING_TAG_ERROR_T*) error); break;
|
|
280
332
|
case UNCLOSED_ELEMENT_ERROR: return rb_unclosed_element_error_from_c_struct((UNCLOSED_ELEMENT_ERROR_T*) error); break;
|
|
281
333
|
case RUBY_PARSE_ERROR: return rb_ruby_parse_error_from_c_struct((RUBY_PARSE_ERROR_T*) error); break;
|
|
334
|
+
case ERB_CONTROL_FLOW_SCOPE_ERROR: return rb_erb_control_flow_scope_error_from_c_struct((ERB_CONTROL_FLOW_SCOPE_ERROR_T*) error); break;
|
|
335
|
+
case MISSINGERB_END_TAG_ERROR: return rb_missingerb_end_tag_error_from_c_struct((MISSINGERB_END_TAG_ERROR_T*) error); break;
|
|
282
336
|
}
|
|
283
337
|
|
|
284
338
|
return Qnil;
|
|
285
339
|
}
|
|
286
340
|
|
|
287
|
-
VALUE rb_errors_array_from_c_array(
|
|
341
|
+
VALUE rb_errors_array_from_c_array(hb_array_T* array) {
|
|
288
342
|
VALUE rb_array = rb_ary_new();
|
|
289
343
|
|
|
290
344
|
if (array) {
|
|
291
|
-
for (size_t i = 0; i <
|
|
292
|
-
ERROR_T* child_node = (ERROR_T*)
|
|
345
|
+
for (size_t i = 0; i < hb_array_size(array); i++) {
|
|
346
|
+
ERROR_T* child_node = (ERROR_T*) hb_array_get(array, i);
|
|
293
347
|
|
|
294
348
|
if (child_node) {
|
|
295
349
|
VALUE rb_child = rb_error_from_c_struct(child_node);
|
data/ext/herb/error_helpers.h
CHANGED
data/ext/herb/extconf.rb
CHANGED
data/ext/herb/extension.c
CHANGED
|
@@ -19,7 +19,7 @@ VALUE cParseResult;
|
|
|
19
19
|
static VALUE Herb_lex(VALUE self, VALUE source) {
|
|
20
20
|
char* string = (char*) check_string(source);
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
hb_array_T* tokens = herb_lex(string);
|
|
23
23
|
|
|
24
24
|
VALUE result = create_lex_result(tokens, source);
|
|
25
25
|
|
|
@@ -30,7 +30,7 @@ static VALUE Herb_lex(VALUE self, VALUE source) {
|
|
|
30
30
|
|
|
31
31
|
static VALUE Herb_lex_file(VALUE self, VALUE path) {
|
|
32
32
|
char* file_path = (char*) check_string(path);
|
|
33
|
-
|
|
33
|
+
hb_array_T* tokens = herb_lex_file(file_path);
|
|
34
34
|
|
|
35
35
|
VALUE source_value = read_file_to_ruby_string(file_path);
|
|
36
36
|
VALUE result = create_lex_result(tokens, source_value);
|
|
@@ -78,6 +78,8 @@ static VALUE Herb_parse_file(VALUE self, VALUE path) {
|
|
|
78
78
|
|
|
79
79
|
AST_DOCUMENT_NODE_T* root = herb_parse(string, NULL);
|
|
80
80
|
|
|
81
|
+
herb_analyze_parse_tree(root, string);
|
|
82
|
+
|
|
81
83
|
VALUE result = create_parse_result(root, source_value);
|
|
82
84
|
|
|
83
85
|
ast_node_free((AST_NODE_T*) root);
|
|
@@ -85,45 +87,30 @@ static VALUE Herb_parse_file(VALUE self, VALUE path) {
|
|
|
85
87
|
return result;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
|
-
static VALUE Herb_lex_to_json(VALUE self, VALUE source) {
|
|
89
|
-
char* string = (char*) check_string(source);
|
|
90
|
-
buffer_T output;
|
|
91
|
-
|
|
92
|
-
if (!buffer_init(&output)) { return Qnil; }
|
|
93
|
-
|
|
94
|
-
herb_lex_json_to_buffer(string, &output);
|
|
95
|
-
|
|
96
|
-
VALUE result = rb_str_new(output.value, output.length);
|
|
97
|
-
|
|
98
|
-
buffer_free(&output);
|
|
99
|
-
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
90
|
static VALUE Herb_extract_ruby(VALUE self, VALUE source) {
|
|
104
91
|
char* string = (char*) check_string(source);
|
|
105
|
-
|
|
92
|
+
hb_buffer_T output;
|
|
106
93
|
|
|
107
|
-
if (!
|
|
94
|
+
if (!hb_buffer_init(&output, strlen(string))) { return Qnil; }
|
|
108
95
|
|
|
109
96
|
herb_extract_ruby_to_buffer(string, &output);
|
|
110
97
|
|
|
111
98
|
VALUE result = rb_utf8_str_new_cstr(output.value);
|
|
112
|
-
|
|
99
|
+
free(output.value);
|
|
113
100
|
|
|
114
101
|
return result;
|
|
115
102
|
}
|
|
116
103
|
|
|
117
104
|
static VALUE Herb_extract_html(VALUE self, VALUE source) {
|
|
118
105
|
char* string = (char*) check_string(source);
|
|
119
|
-
|
|
106
|
+
hb_buffer_T output;
|
|
120
107
|
|
|
121
|
-
if (!
|
|
108
|
+
if (!hb_buffer_init(&output, strlen(string))) { return Qnil; }
|
|
122
109
|
|
|
123
110
|
herb_extract_html_to_buffer(string, &output);
|
|
124
111
|
|
|
125
112
|
VALUE result = rb_utf8_str_new_cstr(output.value);
|
|
126
|
-
|
|
113
|
+
free(output.value);
|
|
127
114
|
|
|
128
115
|
return result;
|
|
129
116
|
}
|
|
@@ -151,7 +138,6 @@ void Init_herb(void) {
|
|
|
151
138
|
rb_define_singleton_method(mHerb, "lex", Herb_lex, 1);
|
|
152
139
|
rb_define_singleton_method(mHerb, "parse_file", Herb_parse_file, 1);
|
|
153
140
|
rb_define_singleton_method(mHerb, "lex_file", Herb_lex_file, 1);
|
|
154
|
-
rb_define_singleton_method(mHerb, "lex_to_json", Herb_lex_to_json, 1);
|
|
155
141
|
rb_define_singleton_method(mHerb, "extract_ruby", Herb_extract_ruby, 1);
|
|
156
142
|
rb_define_singleton_method(mHerb, "extract_html", Herb_extract_html, 1);
|
|
157
143
|
rb_define_singleton_method(mHerb, "version", Herb_version, 0);
|
|
@@ -20,32 +20,26 @@ const char* check_string(VALUE value) {
|
|
|
20
20
|
return RSTRING_PTR(value);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
VALUE rb_position_from_c_struct(position_T
|
|
24
|
-
if (!position) { return Qnil; }
|
|
25
|
-
|
|
23
|
+
VALUE rb_position_from_c_struct(position_T position) {
|
|
26
24
|
VALUE args[2];
|
|
27
|
-
args[0] =
|
|
28
|
-
args[1] =
|
|
25
|
+
args[0] = UINT2NUM(position.line);
|
|
26
|
+
args[1] = UINT2NUM(position.column);
|
|
29
27
|
|
|
30
28
|
return rb_class_new_instance(2, args, cPosition);
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
VALUE rb_location_from_c_struct(location_T
|
|
34
|
-
if (!location) { return Qnil; }
|
|
35
|
-
|
|
31
|
+
VALUE rb_location_from_c_struct(location_T location) {
|
|
36
32
|
VALUE args[2];
|
|
37
|
-
args[0] = rb_position_from_c_struct(location
|
|
38
|
-
args[1] = rb_position_from_c_struct(location
|
|
33
|
+
args[0] = rb_position_from_c_struct(location.start);
|
|
34
|
+
args[1] = rb_position_from_c_struct(location.end);
|
|
39
35
|
|
|
40
36
|
return rb_class_new_instance(2, args, cLocation);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
|
-
VALUE rb_range_from_c_struct(range_T
|
|
44
|
-
if (!range) { return Qnil; }
|
|
45
|
-
|
|
39
|
+
VALUE rb_range_from_c_struct(range_T range) {
|
|
46
40
|
VALUE args[2];
|
|
47
|
-
args[0] =
|
|
48
|
-
args[1] =
|
|
41
|
+
args[0] = UINT2NUM(range.from);
|
|
42
|
+
args[1] = UINT2NUM(range.to);
|
|
49
43
|
|
|
50
44
|
return rb_class_new_instance(2, args, cRange);
|
|
51
45
|
}
|
|
@@ -64,13 +58,13 @@ VALUE rb_token_from_c_struct(token_T* token) {
|
|
|
64
58
|
return rb_class_new_instance(4, args, cToken);
|
|
65
59
|
}
|
|
66
60
|
|
|
67
|
-
VALUE create_lex_result(
|
|
61
|
+
VALUE create_lex_result(hb_array_T* tokens, VALUE source) {
|
|
68
62
|
VALUE value = rb_ary_new();
|
|
69
63
|
VALUE warnings = rb_ary_new();
|
|
70
64
|
VALUE errors = rb_ary_new();
|
|
71
65
|
|
|
72
|
-
for (size_t i = 0; i <
|
|
73
|
-
token_T* token =
|
|
66
|
+
for (size_t i = 0; i < hb_array_size(tokens); i++) {
|
|
67
|
+
token_T* token = hb_array_get(tokens, i);
|
|
74
68
|
if (token != NULL) { rb_ary_push(value, rb_token_from_c_struct(token)); }
|
|
75
69
|
}
|
|
76
70
|
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
const char* check_string(VALUE value);
|
|
13
13
|
VALUE read_file_to_ruby_string(const char* file_path);
|
|
14
14
|
|
|
15
|
-
VALUE rb_position_from_c_struct(position_T
|
|
16
|
-
VALUE rb_location_from_c_struct(location_T
|
|
15
|
+
VALUE rb_position_from_c_struct(position_T position);
|
|
16
|
+
VALUE rb_location_from_c_struct(location_T location);
|
|
17
17
|
|
|
18
18
|
VALUE rb_token_from_c_struct(token_T* token);
|
|
19
|
-
VALUE rb_range_from_c_struct(range_T
|
|
19
|
+
VALUE rb_range_from_c_struct(range_T range);
|
|
20
20
|
|
|
21
|
-
VALUE create_lex_result(
|
|
21
|
+
VALUE create_lex_result(hb_array_T* tokens, VALUE source);
|
|
22
22
|
VALUE create_parse_result(AST_DOCUMENT_NODE_T* root, VALUE source);
|
|
23
23
|
|
|
24
24
|
#endif
|