herb 0.8.2-x86_64-linux-musl → 0.8.4-x86_64-linux-musl
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/ext/herb/error_helpers.c +1 -1
- data/ext/herb/extconf.rb +1 -1
- data/ext/herb/extension.c +1 -1
- data/ext/herb/extension_helpers.c +1 -1
- data/ext/herb/nodes.c +2 -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/engine/debug_visitor.rb +24 -1
- data/lib/herb/engine/error_formatter.rb +13 -5
- data/lib/herb/version.rb +1 -1
- data/sig/herb/engine/debug_visitor.rbs +5 -0
- data/src/analyze.c +69 -27
- data/src/ast_node.c +30 -1
- data/src/ast_nodes.c +157 -53
- data/src/errors.c +5 -5
- data/src/extract.c +7 -73
- data/src/herb.c +9 -9
- data/src/include/ast_node.h +2 -0
- data/src/include/extract.h +0 -1
- data/src/include/herb.h +8 -7
- data/src/include/macros.h +8 -0
- data/src/include/position.h +5 -0
- data/src/include/prism_helpers.h +5 -1
- data/src/include/version.h +1 -1
- data/src/parser.c +6 -6
- data/src/parser_helpers.c +4 -4
- data/src/position.c +27 -0
- data/src/pretty_print.c +6 -6
- data/src/prism_helpers.c +14 -15
- data/src/util/hb_system.c +3 -3
- data/src/visitor.c +26 -26
- data/templates/ext/herb/error_helpers.c.erb +1 -1
- data/templates/ext/herb/nodes.c.erb +1 -1
- data/templates/java/error_helpers.c.erb +1 -1
- data/templates/java/nodes.c.erb +2 -2
- data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +1 -1
- data/templates/javascript/packages/node/extension/nodes.cpp.erb +1 -1
- data/templates/rust/src/ast/nodes.rs.erb +2 -2
- data/templates/src/ast_nodes.c.erb +7 -3
- data/templates/src/errors.c.erb +5 -5
- data/templates/src/visitor.c.erb +1 -1
- data/templates/wasm/error_helpers.cpp.erb +1 -1
- data/templates/wasm/nodes.cpp.erb +1 -1
- metadata +2 -1
data/src/extract.c
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
#include <stdlib.h>
|
|
8
8
|
#include <string.h>
|
|
9
9
|
|
|
10
|
-
void
|
|
10
|
+
void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output) {
|
|
11
11
|
hb_array_T* tokens = herb_lex(source);
|
|
12
12
|
bool skip_erb_content = false;
|
|
13
13
|
bool is_comment_tag = false;
|
|
14
14
|
|
|
15
|
-
for (size_t i = 0; i <
|
|
15
|
+
for (size_t i = 0; i < tokens->size; i++) {
|
|
16
16
|
const token_T* token = hb_array_get(tokens, i);
|
|
17
17
|
|
|
18
18
|
switch (token->type) {
|
|
@@ -76,75 +76,9 @@ void herb_extract_ruby_to_buffer_with_semicolons(const char* source, hb_buffer_T
|
|
|
76
76
|
break;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
for (size_t j = i + 1; j < hb_array_size(tokens); j++) {
|
|
83
|
-
const token_T* next_token = hb_array_get(tokens, j);
|
|
84
|
-
|
|
85
|
-
if (next_token->type == TOKEN_NEWLINE) { break; }
|
|
86
|
-
|
|
87
|
-
if (next_token->type == TOKEN_ERB_START && next_token->location.start.line == current_line) {
|
|
88
|
-
needs_semicolon = true;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (needs_semicolon) {
|
|
94
|
-
hb_buffer_append_char(output, ' ');
|
|
95
|
-
hb_buffer_append_char(output, ';');
|
|
96
|
-
hb_buffer_append_whitespace(output, range_length(token->range) - 2);
|
|
97
|
-
} else {
|
|
98
|
-
hb_buffer_append_whitespace(output, range_length(token->range));
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
default: {
|
|
104
|
-
hb_buffer_append_whitespace(output, range_length(token->range));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
herb_free_tokens(&tokens);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output) {
|
|
113
|
-
hb_array_T* tokens = herb_lex(source);
|
|
114
|
-
bool skip_erb_content = false;
|
|
115
|
-
|
|
116
|
-
for (size_t i = 0; i < hb_array_size(tokens); i++) {
|
|
117
|
-
const token_T* token = hb_array_get(tokens, i);
|
|
118
|
-
|
|
119
|
-
switch (token->type) {
|
|
120
|
-
case TOKEN_NEWLINE: {
|
|
121
|
-
hb_buffer_append(output, token->value);
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
case TOKEN_ERB_START: {
|
|
126
|
-
if (strcmp(token->value, "<%#") == 0 || strcmp(token->value, "<%%") == 0 || strcmp(token->value, "<%%=") == 0) {
|
|
127
|
-
skip_erb_content = true;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
hb_buffer_append_whitespace(output, range_length(token->range));
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
case TOKEN_ERB_CONTENT: {
|
|
135
|
-
if (skip_erb_content == false) {
|
|
136
|
-
hb_buffer_append(output, token->value);
|
|
137
|
-
} else {
|
|
138
|
-
hb_buffer_append_whitespace(output, range_length(token->range));
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
case TOKEN_ERB_END: {
|
|
145
|
-
skip_erb_content = false;
|
|
146
|
-
|
|
147
|
-
hb_buffer_append_whitespace(output, range_length(token->range));
|
|
79
|
+
hb_buffer_append_char(output, ' ');
|
|
80
|
+
hb_buffer_append_char(output, ';');
|
|
81
|
+
hb_buffer_append_whitespace(output, range_length(token->range) - 2);
|
|
148
82
|
break;
|
|
149
83
|
}
|
|
150
84
|
|
|
@@ -160,7 +94,7 @@ void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output) {
|
|
|
160
94
|
void herb_extract_html_to_buffer(const char* source, hb_buffer_T* output) {
|
|
161
95
|
hb_array_T* tokens = herb_lex(source);
|
|
162
96
|
|
|
163
|
-
for (size_t i = 0; i <
|
|
97
|
+
for (size_t i = 0; i < tokens->size; i++) {
|
|
164
98
|
const token_T* token = hb_array_get(tokens, i);
|
|
165
99
|
|
|
166
100
|
switch (token->type) {
|
|
@@ -180,7 +114,7 @@ char* herb_extract_ruby_with_semicolons(const char* source) {
|
|
|
180
114
|
hb_buffer_T output;
|
|
181
115
|
hb_buffer_init(&output, strlen(source));
|
|
182
116
|
|
|
183
|
-
|
|
117
|
+
herb_extract_ruby_to_buffer(source, &output);
|
|
184
118
|
|
|
185
119
|
return output.value;
|
|
186
120
|
}
|
data/src/herb.c
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
#include <prism.h>
|
|
11
11
|
#include <stdlib.h>
|
|
12
12
|
|
|
13
|
-
hb_array_T* herb_lex(const char* source) {
|
|
13
|
+
HERB_EXPORTED_FUNCTION hb_array_T* herb_lex(const char* source) {
|
|
14
14
|
lexer_T lexer = { 0 };
|
|
15
15
|
lexer_init(&lexer, source);
|
|
16
16
|
|
|
@@ -26,7 +26,7 @@ hb_array_T* herb_lex(const char* source) {
|
|
|
26
26
|
return tokens;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options) {
|
|
29
|
+
HERB_EXPORTED_FUNCTION AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options) {
|
|
30
30
|
if (!source) { source = ""; }
|
|
31
31
|
|
|
32
32
|
lexer_T lexer = { 0 };
|
|
@@ -46,7 +46,7 @@ AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options) {
|
|
|
46
46
|
return document;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
hb_array_T* herb_lex_file(const char* path) {
|
|
49
|
+
HERB_EXPORTED_FUNCTION hb_array_T* herb_lex_file(const char* path) {
|
|
50
50
|
char* source = herb_read_file(path);
|
|
51
51
|
hb_array_T* tokens = herb_lex(source);
|
|
52
52
|
|
|
@@ -55,10 +55,10 @@ hb_array_T* herb_lex_file(const char* path) {
|
|
|
55
55
|
return tokens;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
void herb_lex_to_buffer(const char* source, hb_buffer_T* output) {
|
|
58
|
+
HERB_EXPORTED_FUNCTION void herb_lex_to_buffer(const char* source, hb_buffer_T* output) {
|
|
59
59
|
hb_array_T* tokens = herb_lex(source);
|
|
60
60
|
|
|
61
|
-
for (size_t i = 0; i <
|
|
61
|
+
for (size_t i = 0; i < tokens->size; i++) {
|
|
62
62
|
token_T* token = hb_array_get(tokens, i);
|
|
63
63
|
|
|
64
64
|
hb_string_T type = token_to_string(token);
|
|
@@ -71,10 +71,10 @@ void herb_lex_to_buffer(const char* source, hb_buffer_T* output) {
|
|
|
71
71
|
herb_free_tokens(&tokens);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
void herb_free_tokens(hb_array_T** tokens) {
|
|
74
|
+
HERB_EXPORTED_FUNCTION void herb_free_tokens(hb_array_T** tokens) {
|
|
75
75
|
if (!tokens || !*tokens) { return; }
|
|
76
76
|
|
|
77
|
-
for (size_t i = 0; i <
|
|
77
|
+
for (size_t i = 0; i < (*tokens)->size; i++) {
|
|
78
78
|
token_T* token = hb_array_get(*tokens, i);
|
|
79
79
|
if (token) { token_free(token); }
|
|
80
80
|
}
|
|
@@ -82,10 +82,10 @@ void herb_free_tokens(hb_array_T** tokens) {
|
|
|
82
82
|
hb_array_free(tokens);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
const char* herb_version(void) {
|
|
85
|
+
HERB_EXPORTED_FUNCTION const char* herb_version(void) {
|
|
86
86
|
return HERB_VERSION;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
const char* herb_prism_version(void) {
|
|
89
|
+
HERB_EXPORTED_FUNCTION const char* herb_prism_version(void) {
|
|
90
90
|
return PRISM_VERSION;
|
|
91
91
|
}
|
data/src/include/ast_node.h
CHANGED
|
@@ -32,4 +32,6 @@ void ast_node_set_positions_from_token(AST_NODE_T* node, const token_T* token);
|
|
|
32
32
|
|
|
33
33
|
bool ast_node_is(const AST_NODE_T* node, ast_node_type_T type);
|
|
34
34
|
|
|
35
|
+
AST_NODE_T* find_erb_content_at_offset(AST_DOCUMENT_NODE_T* document, const char* source, size_t offset);
|
|
36
|
+
|
|
35
37
|
#endif
|
data/src/include/extract.h
CHANGED
|
@@ -12,7 +12,6 @@ void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output);
|
|
|
12
12
|
void herb_extract_html_to_buffer(const char* source, hb_buffer_T* output);
|
|
13
13
|
|
|
14
14
|
char* herb_extract_ruby_with_semicolons(const char* source);
|
|
15
|
-
void herb_extract_ruby_to_buffer_with_semicolons(const char* source, hb_buffer_T* output);
|
|
16
15
|
|
|
17
16
|
char* herb_extract(const char* source, herb_extract_language_T language);
|
|
18
17
|
char* herb_extract_from_file(const char* path, herb_extract_language_T language);
|
data/src/include/herb.h
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include "ast_node.h"
|
|
5
5
|
#include "extract.h"
|
|
6
|
+
#include "macros.h"
|
|
6
7
|
#include "parser.h"
|
|
7
8
|
#include "util/hb_array.h"
|
|
8
9
|
#include "util/hb_buffer.h"
|
|
@@ -13,17 +14,17 @@
|
|
|
13
14
|
extern "C" {
|
|
14
15
|
#endif
|
|
15
16
|
|
|
16
|
-
void herb_lex_to_buffer(const char* source, hb_buffer_T* output);
|
|
17
|
+
HERB_EXPORTED_FUNCTION void herb_lex_to_buffer(const char* source, hb_buffer_T* output);
|
|
17
18
|
|
|
18
|
-
hb_array_T* herb_lex(const char* source);
|
|
19
|
-
hb_array_T* herb_lex_file(const char* path);
|
|
19
|
+
HERB_EXPORTED_FUNCTION hb_array_T* herb_lex(const char* source);
|
|
20
|
+
HERB_EXPORTED_FUNCTION hb_array_T* herb_lex_file(const char* path);
|
|
20
21
|
|
|
21
|
-
AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options);
|
|
22
|
+
HERB_EXPORTED_FUNCTION AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options);
|
|
22
23
|
|
|
23
|
-
const char* herb_version(void);
|
|
24
|
-
const char* herb_prism_version(void);
|
|
24
|
+
HERB_EXPORTED_FUNCTION const char* herb_version(void);
|
|
25
|
+
HERB_EXPORTED_FUNCTION const char* herb_prism_version(void);
|
|
25
26
|
|
|
26
|
-
void herb_free_tokens(hb_array_T** tokens);
|
|
27
|
+
HERB_EXPORTED_FUNCTION void herb_free_tokens(hb_array_T** tokens);
|
|
27
28
|
|
|
28
29
|
#ifdef __cplusplus
|
|
29
30
|
}
|
data/src/include/macros.h
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
#ifndef HERB_MACROS_H
|
|
2
2
|
#define HERB_MACROS_H
|
|
3
3
|
|
|
4
|
+
#ifndef HERB_EXPORTED_FUNCTION
|
|
5
|
+
# ifdef HERB_EXPORT_SYMBOLS
|
|
6
|
+
# define HERB_EXPORTED_FUNCTION __attribute__((__visibility__("default"))) extern
|
|
7
|
+
# else
|
|
8
|
+
# define HERB_EXPORTED_FUNCTION
|
|
9
|
+
# endif
|
|
10
|
+
#endif
|
|
11
|
+
|
|
4
12
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
5
13
|
|
|
6
14
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
data/src/include/position.h
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#ifndef HERB_POSITION_H
|
|
2
2
|
#define HERB_POSITION_H
|
|
3
3
|
|
|
4
|
+
#include <stdbool.h>
|
|
5
|
+
#include <stddef.h>
|
|
4
6
|
#include <stdint.h>
|
|
5
7
|
|
|
6
8
|
typedef struct POSITION_STRUCT {
|
|
@@ -8,4 +10,7 @@ typedef struct POSITION_STRUCT {
|
|
|
8
10
|
uint32_t column;
|
|
9
11
|
} position_T;
|
|
10
12
|
|
|
13
|
+
position_T position_from_source_with_offset(const char* source, size_t offset);
|
|
14
|
+
bool position_is_within_range(position_T position, position_T start, position_T end);
|
|
15
|
+
|
|
11
16
|
#endif
|
data/src/include/prism_helpers.h
CHANGED
|
@@ -16,6 +16,10 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
|
|
|
16
16
|
pm_parser_t* parser
|
|
17
17
|
);
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error_with_positions(
|
|
20
|
+
const pm_diagnostic_t* error,
|
|
21
|
+
position_T start,
|
|
22
|
+
position_T end
|
|
23
|
+
);
|
|
20
24
|
|
|
21
25
|
#endif
|
data/src/include/version.h
CHANGED
data/src/parser.c
CHANGED
|
@@ -1142,7 +1142,7 @@ static void parser_parse_in_data_state(parser_T* parser, hb_array_T* children, h
|
|
|
1142
1142
|
static size_t find_matching_close_tag(hb_array_T* nodes, size_t start_idx, hb_string_T tag_name) {
|
|
1143
1143
|
int depth = 0;
|
|
1144
1144
|
|
|
1145
|
-
for (size_t i = start_idx + 1; i <
|
|
1145
|
+
for (size_t i = start_idx + 1; i < nodes->size; i++) {
|
|
1146
1146
|
AST_NODE_T* node = (AST_NODE_T*) hb_array_get(nodes, i);
|
|
1147
1147
|
if (node == NULL) { continue; }
|
|
1148
1148
|
|
|
@@ -1166,9 +1166,9 @@ static size_t find_matching_close_tag(hb_array_T* nodes, size_t start_idx, hb_st
|
|
|
1166
1166
|
static hb_array_T* parser_build_elements_from_tags(hb_array_T* nodes, hb_array_T* errors);
|
|
1167
1167
|
|
|
1168
1168
|
static hb_array_T* parser_build_elements_from_tags(hb_array_T* nodes, hb_array_T* errors) {
|
|
1169
|
-
hb_array_T* result = hb_array_init(
|
|
1169
|
+
hb_array_T* result = hb_array_init(nodes->size);
|
|
1170
1170
|
|
|
1171
|
-
for (size_t index = 0; index <
|
|
1171
|
+
for (size_t index = 0; index < nodes->size; index++) {
|
|
1172
1172
|
AST_NODE_T* node = (AST_NODE_T*) hb_array_get(nodes, index);
|
|
1173
1173
|
if (node == NULL) { continue; }
|
|
1174
1174
|
|
|
@@ -1179,7 +1179,7 @@ static hb_array_T* parser_build_elements_from_tags(hb_array_T* nodes, hb_array_T
|
|
|
1179
1179
|
size_t close_index = find_matching_close_tag(nodes, index, tag_name);
|
|
1180
1180
|
|
|
1181
1181
|
if (close_index == (size_t) -1) {
|
|
1182
|
-
if (
|
|
1182
|
+
if (open_tag->base.errors->size == 0) {
|
|
1183
1183
|
append_missing_closing_tag_error(
|
|
1184
1184
|
open_tag->tag_name,
|
|
1185
1185
|
open_tag->base.location.start,
|
|
@@ -1223,7 +1223,7 @@ static hb_array_T* parser_build_elements_from_tags(hb_array_T* nodes, hb_array_T
|
|
|
1223
1223
|
AST_HTML_CLOSE_TAG_NODE_T* close_tag = (AST_HTML_CLOSE_TAG_NODE_T*) node;
|
|
1224
1224
|
|
|
1225
1225
|
if (!is_void_element(hb_string(close_tag->tag_name->value))) {
|
|
1226
|
-
if (
|
|
1226
|
+
if (close_tag->base.errors->size == 0) {
|
|
1227
1227
|
append_missing_opening_tag_error(
|
|
1228
1228
|
close_tag->tag_name,
|
|
1229
1229
|
close_tag->base.location.start,
|
|
@@ -1297,7 +1297,7 @@ void herb_parser_deinit(parser_T* parser) {
|
|
|
1297
1297
|
}
|
|
1298
1298
|
|
|
1299
1299
|
void match_tags_in_node_array(hb_array_T* nodes, hb_array_T* errors) {
|
|
1300
|
-
if (nodes == NULL ||
|
|
1300
|
+
if (nodes == NULL || nodes->size == 0) { return; }
|
|
1301
1301
|
|
|
1302
1302
|
hb_array_T* processed = parser_build_elements_from_tags(nodes, errors);
|
|
1303
1303
|
|
data/src/parser_helpers.c
CHANGED
|
@@ -19,7 +19,7 @@ void parser_push_open_tag(const parser_T* parser, token_T* tag_name) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
bool parser_check_matching_tag(const parser_T* parser, hb_string_T tag_name) {
|
|
22
|
-
if (
|
|
22
|
+
if (parser->open_tags_stack->size == 0) { return false; }
|
|
23
23
|
|
|
24
24
|
token_T* top_token = hb_array_last(parser->open_tags_stack);
|
|
25
25
|
if (top_token == NULL || top_token->value == NULL) { return false; };
|
|
@@ -28,7 +28,7 @@ bool parser_check_matching_tag(const parser_T* parser, hb_string_T tag_name) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
token_T* parser_pop_open_tag(const parser_T* parser) {
|
|
31
|
-
if (
|
|
31
|
+
if (parser->open_tags_stack->size == 0) { return NULL; }
|
|
32
32
|
|
|
33
33
|
return hb_array_pop(parser->open_tags_stack);
|
|
34
34
|
}
|
|
@@ -42,7 +42,7 @@ token_T* parser_pop_open_tag(const parser_T* parser) {
|
|
|
42
42
|
bool parser_in_svg_context(const parser_T* parser) {
|
|
43
43
|
if (!parser || !parser->open_tags_stack) { return false; }
|
|
44
44
|
|
|
45
|
-
size_t stack_size =
|
|
45
|
+
size_t stack_size = parser->open_tags_stack->size;
|
|
46
46
|
|
|
47
47
|
for (size_t i = 0; i < stack_size; i++) {
|
|
48
48
|
token_T* tag = (token_T*) hb_array_get(parser->open_tags_stack, i);
|
|
@@ -191,7 +191,7 @@ void parser_handle_mismatched_tags(
|
|
|
191
191
|
const AST_HTML_CLOSE_TAG_NODE_T* close_tag,
|
|
192
192
|
hb_array_T* errors
|
|
193
193
|
) {
|
|
194
|
-
if (
|
|
194
|
+
if (parser->open_tags_stack->size > 0) {
|
|
195
195
|
token_T* expected_tag = hb_array_last(parser->open_tags_stack);
|
|
196
196
|
token_T* actual_tag = close_tag->tag_name;
|
|
197
197
|
|
data/src/position.c
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#include "include/position.h"
|
|
2
|
+
#include "include/util.h"
|
|
3
|
+
|
|
4
|
+
position_T position_from_source_with_offset(const char* source, size_t offset) {
|
|
5
|
+
position_T position = { .line = 1, .column = 0 };
|
|
6
|
+
|
|
7
|
+
for (size_t i = 0; i < offset; i++) {
|
|
8
|
+
if (is_newline(source[i])) {
|
|
9
|
+
position.line++;
|
|
10
|
+
position.column = 0;
|
|
11
|
+
} else {
|
|
12
|
+
position.column++;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return position;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
bool position_is_within_range(position_T position, position_T start, position_T end) {
|
|
20
|
+
if (position.line < start.line) { return false; }
|
|
21
|
+
if (position.line == start.line && position.column < start.column) { return false; }
|
|
22
|
+
|
|
23
|
+
if (position.line > end.line) { return false; }
|
|
24
|
+
if (position.line == end.line && position.column > end.column) { return false; }
|
|
25
|
+
|
|
26
|
+
return true;
|
|
27
|
+
}
|
data/src/pretty_print.c
CHANGED
|
@@ -113,7 +113,7 @@ void pretty_print_array(
|
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
if (
|
|
116
|
+
if (array->size == 0) {
|
|
117
117
|
pretty_print_property(name, hb_string("[]"), indent, relative_indent, last_property, buffer);
|
|
118
118
|
|
|
119
119
|
return;
|
|
@@ -124,17 +124,17 @@ void pretty_print_array(
|
|
|
124
124
|
hb_buffer_append(buffer, "(");
|
|
125
125
|
|
|
126
126
|
char count[16];
|
|
127
|
-
sprintf(count, "%zu",
|
|
127
|
+
sprintf(count, "%zu", array->size);
|
|
128
128
|
hb_buffer_append(buffer, count);
|
|
129
129
|
hb_buffer_append(buffer, ")\n");
|
|
130
130
|
|
|
131
131
|
if (indent < 20) {
|
|
132
|
-
for (size_t i = 0; i <
|
|
132
|
+
for (size_t i = 0; i < array->size; i++) {
|
|
133
133
|
AST_NODE_T* child = hb_array_get(array, i);
|
|
134
134
|
pretty_print_indent(buffer, indent);
|
|
135
135
|
pretty_print_indent(buffer, relative_indent + 1);
|
|
136
136
|
|
|
137
|
-
if (i ==
|
|
137
|
+
if (i == array->size - 1) {
|
|
138
138
|
hb_buffer_append(buffer, "└── ");
|
|
139
139
|
} else {
|
|
140
140
|
hb_buffer_append(buffer, "├── ");
|
|
@@ -142,7 +142,7 @@ void pretty_print_array(
|
|
|
142
142
|
|
|
143
143
|
ast_pretty_print_node(child, indent + 1, relative_indent + 1, buffer);
|
|
144
144
|
|
|
145
|
-
if (i !=
|
|
145
|
+
if (i != array->size - 1) { pretty_print_newline(indent + 1, relative_indent, buffer); }
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
hb_buffer_append(buffer, "\n");
|
|
@@ -155,7 +155,7 @@ void pretty_print_errors(
|
|
|
155
155
|
const bool last_property,
|
|
156
156
|
hb_buffer_T* buffer
|
|
157
157
|
) {
|
|
158
|
-
if (node->errors != NULL &&
|
|
158
|
+
if (node->errors != NULL && node->errors->size > 0) {
|
|
159
159
|
error_pretty_print_array("errors", node->errors, indent, relative_indent, last_property, buffer);
|
|
160
160
|
hb_buffer_append(buffer, "\n");
|
|
161
161
|
}
|
data/src/prism_helpers.c
CHANGED
|
@@ -16,21 +16,6 @@ const char* pm_error_level_to_string(pm_error_level_t level) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
position_T position_from_source_with_offset(const char* source, size_t offset) {
|
|
20
|
-
position_T position = { .line = 1, .column = 0 };
|
|
21
|
-
|
|
22
|
-
for (size_t i = 0; i < offset; i++) {
|
|
23
|
-
if (is_newline(source[i])) {
|
|
24
|
-
position.line++;
|
|
25
|
-
position.column = 0;
|
|
26
|
-
} else {
|
|
27
|
-
position.column++;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return position;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
19
|
RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
|
|
35
20
|
const pm_diagnostic_t* error,
|
|
36
21
|
const AST_NODE_T* node,
|
|
@@ -51,3 +36,17 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
|
|
|
51
36
|
end
|
|
52
37
|
);
|
|
53
38
|
}
|
|
39
|
+
|
|
40
|
+
RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error_with_positions(
|
|
41
|
+
const pm_diagnostic_t* error,
|
|
42
|
+
position_T start,
|
|
43
|
+
position_T end
|
|
44
|
+
) {
|
|
45
|
+
return ruby_parse_error_init(
|
|
46
|
+
error->message,
|
|
47
|
+
pm_diagnostic_id_human(error->diag_id),
|
|
48
|
+
pm_error_level_to_string(error->level),
|
|
49
|
+
start,
|
|
50
|
+
end
|
|
51
|
+
);
|
|
52
|
+
}
|
data/src/util/hb_system.c
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#include "../include/util/hb_system.h"
|
|
2
2
|
|
|
3
3
|
#ifdef __linux__
|
|
4
|
-
#define _GNU_SOURCE
|
|
4
|
+
# define _GNU_SOURCE
|
|
5
5
|
#endif
|
|
6
6
|
|
|
7
7
|
#ifdef HB_USE_MALLOC
|
|
8
|
-
#include <stdlib.h>
|
|
8
|
+
# include <stdlib.h>
|
|
9
9
|
#else
|
|
10
|
-
#include <sys/mman.h>
|
|
10
|
+
# include <sys/mman.h>
|
|
11
11
|
#endif
|
|
12
12
|
|
|
13
13
|
void* hb_system_allocate_memory(size_t size) {
|