@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
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
#define HERB_ANALYZE_H
|
|
3
3
|
|
|
4
4
|
#include "analyzed_ruby.h"
|
|
5
|
-
#include "array.h"
|
|
6
5
|
#include "ast_nodes.h"
|
|
6
|
+
#include "util/hb_array.h"
|
|
7
7
|
|
|
8
8
|
typedef struct ANALYZE_RUBY_CONTEXT_STRUCT {
|
|
9
9
|
AST_DOCUMENT_NODE_T* document;
|
|
10
10
|
AST_NODE_T* parent;
|
|
11
|
-
|
|
11
|
+
hb_array_T* ruby_context_stack;
|
|
12
12
|
} analyze_ruby_context_T;
|
|
13
13
|
|
|
14
14
|
typedef enum {
|
|
@@ -33,7 +33,15 @@ typedef enum {
|
|
|
33
33
|
CONTROL_TYPE_UNKNOWN
|
|
34
34
|
} control_type_t;
|
|
35
35
|
|
|
36
|
+
typedef struct {
|
|
37
|
+
int loop_depth;
|
|
38
|
+
int rescue_depth;
|
|
39
|
+
} invalid_erb_context_T;
|
|
40
|
+
|
|
36
41
|
void herb_analyze_parse_errors(AST_DOCUMENT_NODE_T* document, const char* source);
|
|
37
42
|
void herb_analyze_parse_tree(AST_DOCUMENT_NODE_T* document, const char* source);
|
|
38
43
|
|
|
44
|
+
hb_array_T* rewrite_node_array(AST_NODE_T* node, hb_array_T* array, analyze_ruby_context_T* context);
|
|
45
|
+
bool transform_erb_nodes(const AST_NODE_T* node, void* data);
|
|
46
|
+
|
|
39
47
|
#endif
|
|
@@ -238,6 +238,11 @@ bool search_else_nodes(analyzed_ruby_T* analyzed) {
|
|
|
238
238
|
|
|
239
239
|
bool search_end_nodes(analyzed_ruby_T* analyzed) {
|
|
240
240
|
if (has_error_message(analyzed, "unexpected 'end', ignoring it")) {
|
|
241
|
+
if (has_error_message(analyzed, "unexpected '=', ignoring it")) {
|
|
242
|
+
// `=end`
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
|
|
241
246
|
analyzed->has_end = true;
|
|
242
247
|
return true;
|
|
243
248
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
#include <stdbool.h>
|
|
6
6
|
|
|
7
7
|
#include "analyzed_ruby.h"
|
|
8
|
+
#include "ast_node.h"
|
|
8
9
|
|
|
9
10
|
bool has_if_node(analyzed_ruby_T* analyzed);
|
|
10
11
|
bool has_elsif_node(analyzed_ruby_T* analyzed);
|
|
@@ -46,4 +47,6 @@ bool search_rescue_nodes(analyzed_ruby_T* analyzed);
|
|
|
46
47
|
bool search_ensure_nodes(analyzed_ruby_T* analyzed);
|
|
47
48
|
bool search_yield_nodes(const pm_node_t* node, void* data);
|
|
48
49
|
|
|
50
|
+
void check_erb_node_for_missing_end(const AST_NODE_T* node);
|
|
51
|
+
|
|
49
52
|
#endif
|
|
@@ -0,0 +1,147 @@
|
|
|
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.8.0/templates/src/analyze_missing_end.c.erb
|
|
3
|
+
|
|
4
|
+
#include "include/analyze_helpers.h"
|
|
5
|
+
#include "include/errors.h"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
void check_erb_node_for_missing_end(const AST_NODE_T* node) {
|
|
9
|
+
switch (node->type) {
|
|
10
|
+
case AST_ERB_IF_NODE: {
|
|
11
|
+
const AST_ERB_IF_NODE_T* erb_if_node = (const AST_ERB_IF_NODE_T*) node;
|
|
12
|
+
|
|
13
|
+
if (erb_if_node->end_node == NULL) {
|
|
14
|
+
append_missingerb_end_tag_error(
|
|
15
|
+
"`<" "%" " if " "%" ">`",
|
|
16
|
+
erb_if_node->tag_opening->location.start,
|
|
17
|
+
erb_if_node->tag_closing->location.end,
|
|
18
|
+
node->errors
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
case AST_ERB_BLOCK_NODE: {
|
|
26
|
+
const AST_ERB_BLOCK_NODE_T* erb_block_node = (const AST_ERB_BLOCK_NODE_T*) node;
|
|
27
|
+
|
|
28
|
+
if (erb_block_node->end_node == NULL) {
|
|
29
|
+
append_missingerb_end_tag_error(
|
|
30
|
+
"ERB block",
|
|
31
|
+
erb_block_node->tag_opening->location.start,
|
|
32
|
+
erb_block_node->tag_closing->location.end,
|
|
33
|
+
node->errors
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
case AST_ERB_CASE_NODE: {
|
|
41
|
+
const AST_ERB_CASE_NODE_T* erb_case_node = (const AST_ERB_CASE_NODE_T*) node;
|
|
42
|
+
|
|
43
|
+
if (erb_case_node->end_node == NULL) {
|
|
44
|
+
append_missingerb_end_tag_error(
|
|
45
|
+
"`<" "%" " case " "%" ">`",
|
|
46
|
+
erb_case_node->tag_opening->location.start,
|
|
47
|
+
erb_case_node->tag_closing->location.end,
|
|
48
|
+
node->errors
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
case AST_ERB_CASE_MATCH_NODE: {
|
|
56
|
+
const AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (const AST_ERB_CASE_MATCH_NODE_T*) node;
|
|
57
|
+
|
|
58
|
+
if (erb_case_match_node->end_node == NULL) {
|
|
59
|
+
append_missingerb_end_tag_error(
|
|
60
|
+
"`<" "%" " case " "%" ">`",
|
|
61
|
+
erb_case_match_node->tag_opening->location.start,
|
|
62
|
+
erb_case_match_node->tag_closing->location.end,
|
|
63
|
+
node->errors
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
case AST_ERB_WHILE_NODE: {
|
|
71
|
+
const AST_ERB_WHILE_NODE_T* erb_while_node = (const AST_ERB_WHILE_NODE_T*) node;
|
|
72
|
+
|
|
73
|
+
if (erb_while_node->end_node == NULL) {
|
|
74
|
+
append_missingerb_end_tag_error(
|
|
75
|
+
"`<" "%" " while " "%" ">`",
|
|
76
|
+
erb_while_node->tag_opening->location.start,
|
|
77
|
+
erb_while_node->tag_closing->location.end,
|
|
78
|
+
node->errors
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
case AST_ERB_UNTIL_NODE: {
|
|
86
|
+
const AST_ERB_UNTIL_NODE_T* erb_until_node = (const AST_ERB_UNTIL_NODE_T*) node;
|
|
87
|
+
|
|
88
|
+
if (erb_until_node->end_node == NULL) {
|
|
89
|
+
append_missingerb_end_tag_error(
|
|
90
|
+
"`<" "%" " until " "%" ">`",
|
|
91
|
+
erb_until_node->tag_opening->location.start,
|
|
92
|
+
erb_until_node->tag_closing->location.end,
|
|
93
|
+
node->errors
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
case AST_ERB_FOR_NODE: {
|
|
101
|
+
const AST_ERB_FOR_NODE_T* erb_for_node = (const AST_ERB_FOR_NODE_T*) node;
|
|
102
|
+
|
|
103
|
+
if (erb_for_node->end_node == NULL) {
|
|
104
|
+
append_missingerb_end_tag_error(
|
|
105
|
+
"`<" "%" " for " "%" ">`",
|
|
106
|
+
erb_for_node->tag_opening->location.start,
|
|
107
|
+
erb_for_node->tag_closing->location.end,
|
|
108
|
+
node->errors
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
case AST_ERB_BEGIN_NODE: {
|
|
116
|
+
const AST_ERB_BEGIN_NODE_T* erb_begin_node = (const AST_ERB_BEGIN_NODE_T*) node;
|
|
117
|
+
|
|
118
|
+
if (erb_begin_node->end_node == NULL) {
|
|
119
|
+
append_missingerb_end_tag_error(
|
|
120
|
+
"`<" "%" " begin " "%" ">`",
|
|
121
|
+
erb_begin_node->tag_opening->location.start,
|
|
122
|
+
erb_begin_node->tag_closing->location.end,
|
|
123
|
+
node->errors
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
case AST_ERB_UNLESS_NODE: {
|
|
131
|
+
const AST_ERB_UNLESS_NODE_T* erb_unless_node = (const AST_ERB_UNLESS_NODE_T*) node;
|
|
132
|
+
|
|
133
|
+
if (erb_unless_node->end_node == NULL) {
|
|
134
|
+
append_missingerb_end_tag_error(
|
|
135
|
+
"`<" "%" " unless " "%" ">`",
|
|
136
|
+
erb_unless_node->tag_opening->location.start,
|
|
137
|
+
erb_unless_node->tag_closing->location.end,
|
|
138
|
+
node->errors
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
default: break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
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.8.0/templates/src/analyze_transform.c.erb
|
|
3
|
+
|
|
4
|
+
#include "include/analyze.h"
|
|
5
|
+
#include "include/visitor.h"
|
|
6
|
+
|
|
7
|
+
bool transform_erb_nodes(const AST_NODE_T* node, void* data) {
|
|
8
|
+
analyze_ruby_context_T* context = (analyze_ruby_context_T*) data;
|
|
9
|
+
context->parent = (AST_NODE_T*) node;
|
|
10
|
+
|
|
11
|
+
if (node->type == AST_DOCUMENT_NODE) {
|
|
12
|
+
AST_DOCUMENT_NODE_T* document_node = (AST_DOCUMENT_NODE_T*) node;
|
|
13
|
+
hb_array_T* old_array = document_node->children;
|
|
14
|
+
document_node->children = rewrite_node_array((AST_NODE_T*) node, document_node->children, context);
|
|
15
|
+
hb_array_free(&old_array);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (node->type == AST_HTML_OPEN_TAG_NODE) {
|
|
19
|
+
AST_HTML_OPEN_TAG_NODE_T* html_open_tag_node = (AST_HTML_OPEN_TAG_NODE_T*) node;
|
|
20
|
+
hb_array_T* old_array = html_open_tag_node->children;
|
|
21
|
+
html_open_tag_node->children = rewrite_node_array((AST_NODE_T*) node, html_open_tag_node->children, context);
|
|
22
|
+
hb_array_free(&old_array);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (node->type == AST_HTML_CLOSE_TAG_NODE) {
|
|
26
|
+
AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = (AST_HTML_CLOSE_TAG_NODE_T*) node;
|
|
27
|
+
hb_array_T* old_array = html_close_tag_node->children;
|
|
28
|
+
html_close_tag_node->children = rewrite_node_array((AST_NODE_T*) node, html_close_tag_node->children, context);
|
|
29
|
+
hb_array_free(&old_array);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (node->type == AST_HTML_ELEMENT_NODE) {
|
|
33
|
+
AST_HTML_ELEMENT_NODE_T* html_element_node = (AST_HTML_ELEMENT_NODE_T*) node;
|
|
34
|
+
hb_array_T* old_array = html_element_node->body;
|
|
35
|
+
html_element_node->body = rewrite_node_array((AST_NODE_T*) node, html_element_node->body, context);
|
|
36
|
+
hb_array_free(&old_array);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (node->type == AST_HTML_ATTRIBUTE_VALUE_NODE) {
|
|
40
|
+
AST_HTML_ATTRIBUTE_VALUE_NODE_T* html_attribute_value_node = (AST_HTML_ATTRIBUTE_VALUE_NODE_T*) node;
|
|
41
|
+
hb_array_T* old_array = html_attribute_value_node->children;
|
|
42
|
+
html_attribute_value_node->children = rewrite_node_array((AST_NODE_T*) node, html_attribute_value_node->children, context);
|
|
43
|
+
hb_array_free(&old_array);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (node->type == AST_HTML_ATTRIBUTE_NAME_NODE) {
|
|
47
|
+
AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = (AST_HTML_ATTRIBUTE_NAME_NODE_T*) node;
|
|
48
|
+
hb_array_T* old_array = html_attribute_name_node->children;
|
|
49
|
+
html_attribute_name_node->children = rewrite_node_array((AST_NODE_T*) node, html_attribute_name_node->children, context);
|
|
50
|
+
hb_array_free(&old_array);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (node->type == AST_HTML_COMMENT_NODE) {
|
|
54
|
+
AST_HTML_COMMENT_NODE_T* html_comment_node = (AST_HTML_COMMENT_NODE_T*) node;
|
|
55
|
+
hb_array_T* old_array = html_comment_node->children;
|
|
56
|
+
html_comment_node->children = rewrite_node_array((AST_NODE_T*) node, html_comment_node->children, context);
|
|
57
|
+
hb_array_free(&old_array);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (node->type == AST_HTML_DOCTYPE_NODE) {
|
|
61
|
+
AST_HTML_DOCTYPE_NODE_T* html_doctype_node = (AST_HTML_DOCTYPE_NODE_T*) node;
|
|
62
|
+
hb_array_T* old_array = html_doctype_node->children;
|
|
63
|
+
html_doctype_node->children = rewrite_node_array((AST_NODE_T*) node, html_doctype_node->children, context);
|
|
64
|
+
hb_array_free(&old_array);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (node->type == AST_XML_DECLARATION_NODE) {
|
|
68
|
+
AST_XML_DECLARATION_NODE_T* xml_declaration_node = (AST_XML_DECLARATION_NODE_T*) node;
|
|
69
|
+
hb_array_T* old_array = xml_declaration_node->children;
|
|
70
|
+
xml_declaration_node->children = rewrite_node_array((AST_NODE_T*) node, xml_declaration_node->children, context);
|
|
71
|
+
hb_array_free(&old_array);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (node->type == AST_CDATA_NODE) {
|
|
75
|
+
AST_CDATA_NODE_T* cdata_node = (AST_CDATA_NODE_T*) node;
|
|
76
|
+
hb_array_T* old_array = cdata_node->children;
|
|
77
|
+
cdata_node->children = rewrite_node_array((AST_NODE_T*) node, cdata_node->children, context);
|
|
78
|
+
hb_array_free(&old_array);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (node->type == AST_ERB_ELSE_NODE) {
|
|
82
|
+
AST_ERB_ELSE_NODE_T* erb_else_node = (AST_ERB_ELSE_NODE_T*) node;
|
|
83
|
+
hb_array_T* old_array = erb_else_node->statements;
|
|
84
|
+
erb_else_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_else_node->statements, context);
|
|
85
|
+
hb_array_free(&old_array);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (node->type == AST_ERB_IF_NODE) {
|
|
89
|
+
AST_ERB_IF_NODE_T* erb_if_node = (AST_ERB_IF_NODE_T*) node;
|
|
90
|
+
hb_array_T* old_array = erb_if_node->statements;
|
|
91
|
+
erb_if_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_if_node->statements, context);
|
|
92
|
+
hb_array_free(&old_array);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (node->type == AST_ERB_BLOCK_NODE) {
|
|
96
|
+
AST_ERB_BLOCK_NODE_T* erb_block_node = (AST_ERB_BLOCK_NODE_T*) node;
|
|
97
|
+
hb_array_T* old_array = erb_block_node->body;
|
|
98
|
+
erb_block_node->body = rewrite_node_array((AST_NODE_T*) node, erb_block_node->body, context);
|
|
99
|
+
hb_array_free(&old_array);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (node->type == AST_ERB_WHEN_NODE) {
|
|
103
|
+
AST_ERB_WHEN_NODE_T* erb_when_node = (AST_ERB_WHEN_NODE_T*) node;
|
|
104
|
+
hb_array_T* old_array = erb_when_node->statements;
|
|
105
|
+
erb_when_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_when_node->statements, context);
|
|
106
|
+
hb_array_free(&old_array);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (node->type == AST_ERB_CASE_NODE) {
|
|
110
|
+
AST_ERB_CASE_NODE_T* erb_case_node = (AST_ERB_CASE_NODE_T*) node;
|
|
111
|
+
hb_array_T* old_array = erb_case_node->children;
|
|
112
|
+
erb_case_node->children = rewrite_node_array((AST_NODE_T*) node, erb_case_node->children, context);
|
|
113
|
+
hb_array_free(&old_array);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (node->type == AST_ERB_CASE_NODE) {
|
|
117
|
+
AST_ERB_CASE_NODE_T* erb_case_node = (AST_ERB_CASE_NODE_T*) node;
|
|
118
|
+
hb_array_T* old_array = erb_case_node->conditions;
|
|
119
|
+
erb_case_node->conditions = rewrite_node_array((AST_NODE_T*) node, erb_case_node->conditions, context);
|
|
120
|
+
hb_array_free(&old_array);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (node->type == AST_ERB_CASE_MATCH_NODE) {
|
|
124
|
+
AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (AST_ERB_CASE_MATCH_NODE_T*) node;
|
|
125
|
+
hb_array_T* old_array = erb_case_match_node->children;
|
|
126
|
+
erb_case_match_node->children = rewrite_node_array((AST_NODE_T*) node, erb_case_match_node->children, context);
|
|
127
|
+
hb_array_free(&old_array);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (node->type == AST_ERB_CASE_MATCH_NODE) {
|
|
131
|
+
AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node = (AST_ERB_CASE_MATCH_NODE_T*) node;
|
|
132
|
+
hb_array_T* old_array = erb_case_match_node->conditions;
|
|
133
|
+
erb_case_match_node->conditions = rewrite_node_array((AST_NODE_T*) node, erb_case_match_node->conditions, context);
|
|
134
|
+
hb_array_free(&old_array);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (node->type == AST_ERB_WHILE_NODE) {
|
|
138
|
+
AST_ERB_WHILE_NODE_T* erb_while_node = (AST_ERB_WHILE_NODE_T*) node;
|
|
139
|
+
hb_array_T* old_array = erb_while_node->statements;
|
|
140
|
+
erb_while_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_while_node->statements, context);
|
|
141
|
+
hb_array_free(&old_array);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (node->type == AST_ERB_UNTIL_NODE) {
|
|
145
|
+
AST_ERB_UNTIL_NODE_T* erb_until_node = (AST_ERB_UNTIL_NODE_T*) node;
|
|
146
|
+
hb_array_T* old_array = erb_until_node->statements;
|
|
147
|
+
erb_until_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_until_node->statements, context);
|
|
148
|
+
hb_array_free(&old_array);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (node->type == AST_ERB_FOR_NODE) {
|
|
152
|
+
AST_ERB_FOR_NODE_T* erb_for_node = (AST_ERB_FOR_NODE_T*) node;
|
|
153
|
+
hb_array_T* old_array = erb_for_node->statements;
|
|
154
|
+
erb_for_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_for_node->statements, context);
|
|
155
|
+
hb_array_free(&old_array);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (node->type == AST_ERB_RESCUE_NODE) {
|
|
159
|
+
AST_ERB_RESCUE_NODE_T* erb_rescue_node = (AST_ERB_RESCUE_NODE_T*) node;
|
|
160
|
+
hb_array_T* old_array = erb_rescue_node->statements;
|
|
161
|
+
erb_rescue_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_rescue_node->statements, context);
|
|
162
|
+
hb_array_free(&old_array);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (node->type == AST_ERB_ENSURE_NODE) {
|
|
166
|
+
AST_ERB_ENSURE_NODE_T* erb_ensure_node = (AST_ERB_ENSURE_NODE_T*) node;
|
|
167
|
+
hb_array_T* old_array = erb_ensure_node->statements;
|
|
168
|
+
erb_ensure_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_ensure_node->statements, context);
|
|
169
|
+
hb_array_free(&old_array);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (node->type == AST_ERB_BEGIN_NODE) {
|
|
173
|
+
AST_ERB_BEGIN_NODE_T* erb_begin_node = (AST_ERB_BEGIN_NODE_T*) node;
|
|
174
|
+
hb_array_T* old_array = erb_begin_node->statements;
|
|
175
|
+
erb_begin_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_begin_node->statements, context);
|
|
176
|
+
hb_array_free(&old_array);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (node->type == AST_ERB_UNLESS_NODE) {
|
|
180
|
+
AST_ERB_UNLESS_NODE_T* erb_unless_node = (AST_ERB_UNLESS_NODE_T*) node;
|
|
181
|
+
hb_array_T* old_array = erb_unless_node->statements;
|
|
182
|
+
erb_unless_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_unless_node->statements, context);
|
|
183
|
+
hb_array_free(&old_array);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (node->type == AST_ERB_IN_NODE) {
|
|
187
|
+
AST_ERB_IN_NODE_T* erb_in_node = (AST_ERB_IN_NODE_T*) node;
|
|
188
|
+
hb_array_T* old_array = erb_in_node->statements;
|
|
189
|
+
erb_in_node->statements = rewrite_node_array((AST_NODE_T*) node, erb_in_node->statements, context);
|
|
190
|
+
hb_array_free(&old_array);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
herb_visit_child_nodes(node, transform_erb_nodes, data);
|
|
194
|
+
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#include "include/analyzed_ruby.h"
|
|
2
|
+
#include "include/util/hb_string.h"
|
|
2
3
|
|
|
3
4
|
#include <prism.h>
|
|
4
5
|
#include <string.h>
|
|
5
6
|
|
|
6
|
-
analyzed_ruby_T* init_analyzed_ruby(
|
|
7
|
+
analyzed_ruby_T* init_analyzed_ruby(hb_string_T source) {
|
|
7
8
|
analyzed_ruby_T* analyzed = malloc(sizeof(analyzed_ruby_T));
|
|
8
9
|
|
|
9
|
-
pm_parser_init(&analyzed->parser, (const uint8_t*) source,
|
|
10
|
+
pm_parser_init(&analyzed->parser, (const uint8_t*) source.data, source.length, NULL);
|
|
10
11
|
|
|
11
12
|
analyzed->root = pm_parse(&analyzed->parser);
|
|
12
13
|
analyzed->valid = (analyzed->parser.error_list.size == 0);
|
|
@@ -42,3 +43,23 @@ void free_analyzed_ruby(analyzed_ruby_T* analyzed) {
|
|
|
42
43
|
|
|
43
44
|
free(analyzed);
|
|
44
45
|
}
|
|
46
|
+
|
|
47
|
+
const char* erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed) {
|
|
48
|
+
if (analyzed->has_end) {
|
|
49
|
+
return "`<% end %>`";
|
|
50
|
+
} else if (analyzed->has_else_node) {
|
|
51
|
+
return "`<% else %>`";
|
|
52
|
+
} else if (analyzed->has_elsif_node) {
|
|
53
|
+
return "`<% elsif %>`";
|
|
54
|
+
} else if (analyzed->has_when_node) {
|
|
55
|
+
return "`<% when %>`";
|
|
56
|
+
} else if (analyzed->has_in_node) {
|
|
57
|
+
return "`<% in %>`";
|
|
58
|
+
} else if (analyzed->has_rescue_node) {
|
|
59
|
+
return "`<% rescue %>`";
|
|
60
|
+
} else if (analyzed->has_ensure_node) {
|
|
61
|
+
return "`<% ensure %>`";
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return NULL;
|
|
65
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#ifndef HERB_ANALYZED_RUBY_H
|
|
2
2
|
#define HERB_ANALYZED_RUBY_H
|
|
3
3
|
|
|
4
|
-
#include "
|
|
4
|
+
#include "util/hb_array.h"
|
|
5
|
+
#include "util/hb_string.h"
|
|
5
6
|
|
|
6
7
|
#include <prism.h>
|
|
7
8
|
|
|
@@ -30,7 +31,8 @@ typedef struct ANALYZED_RUBY_STRUCT {
|
|
|
30
31
|
bool has_yield_node;
|
|
31
32
|
} analyzed_ruby_T;
|
|
32
33
|
|
|
33
|
-
analyzed_ruby_T* init_analyzed_ruby(
|
|
34
|
+
analyzed_ruby_T* init_analyzed_ruby(hb_string_T source);
|
|
34
35
|
void free_analyzed_ruby(analyzed_ruby_T* analyzed);
|
|
36
|
+
const char* erb_keyword_from_analyzed_ruby(const analyzed_ruby_T* analyzed);
|
|
35
37
|
|
|
36
38
|
#endif
|
|
@@ -12,14 +12,15 @@ size_t ast_node_sizeof(void) {
|
|
|
12
12
|
return sizeof(struct AST_NODE_STRUCT);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T
|
|
15
|
+
void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T start, position_T end, hb_array_T* errors) {
|
|
16
16
|
if (!node) { return; }
|
|
17
17
|
|
|
18
18
|
node->type = type;
|
|
19
|
-
node->location =
|
|
19
|
+
node->location.start = start;
|
|
20
|
+
node->location.end = end;
|
|
20
21
|
|
|
21
22
|
if (errors == NULL) {
|
|
22
|
-
node->errors =
|
|
23
|
+
node->errors = hb_array_init(8);
|
|
23
24
|
} else {
|
|
24
25
|
node->errors = errors;
|
|
25
26
|
}
|
|
@@ -28,7 +29,7 @@ void ast_node_init(AST_NODE_T* node, const ast_node_type_T type, position_T* sta
|
|
|
28
29
|
AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token) {
|
|
29
30
|
AST_LITERAL_NODE_T* literal = malloc(sizeof(AST_LITERAL_NODE_T));
|
|
30
31
|
|
|
31
|
-
ast_node_init(&literal->base, AST_LITERAL_NODE, token->location
|
|
32
|
+
ast_node_init(&literal->base, AST_LITERAL_NODE, token->location.start, token->location.end, NULL);
|
|
32
33
|
|
|
33
34
|
literal->content = herb_strdup(token->value);
|
|
34
35
|
|
|
@@ -40,35 +41,31 @@ ast_node_type_T ast_node_type(const AST_NODE_T* node) {
|
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
size_t ast_node_errors_count(const AST_NODE_T* node) {
|
|
43
|
-
return
|
|
44
|
+
return hb_array_size(node->errors);
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
hb_array_T* ast_node_errors(const AST_NODE_T* node) {
|
|
47
48
|
return node->errors;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
void ast_node_append_error(const AST_NODE_T* node, ERROR_T* error) {
|
|
51
|
-
|
|
52
|
+
hb_array_append(node->errors, error);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
void ast_node_set_start(AST_NODE_T* node, position_T
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
node->location->start = position_copy(position);
|
|
55
|
+
void ast_node_set_start(AST_NODE_T* node, position_T position) {
|
|
56
|
+
node->location.start = position;
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
void ast_node_set_end(AST_NODE_T* node, position_T
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
node->location->end = position_copy(position);
|
|
59
|
+
void ast_node_set_end(AST_NODE_T* node, position_T position) {
|
|
60
|
+
node->location.end = position;
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
void ast_node_set_start_from_token(AST_NODE_T* node, const token_T* token) {
|
|
67
|
-
ast_node_set_start(node, token->location
|
|
64
|
+
ast_node_set_start(node, token->location.start);
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
void ast_node_set_end_from_token(AST_NODE_T* node, const token_T* token) {
|
|
71
|
-
ast_node_set_end(node, token->location
|
|
68
|
+
ast_node_set_end(node, token->location.end);
|
|
72
69
|
}
|
|
73
70
|
|
|
74
71
|
void ast_node_set_positions_from_token(AST_NODE_T* node, const token_T* token) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#include "position.h"
|
|
7
7
|
#include "token_struct.h"
|
|
8
8
|
|
|
9
|
-
void ast_node_init(AST_NODE_T* node, ast_node_type_T type, position_T
|
|
9
|
+
void ast_node_init(AST_NODE_T* node, ast_node_type_T type, position_T start, position_T end, hb_array_T* errors);
|
|
10
10
|
void ast_node_free(AST_NODE_T* node);
|
|
11
11
|
|
|
12
12
|
AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token);
|
|
@@ -18,11 +18,11 @@ ast_node_type_T ast_node_type(const AST_NODE_T* node);
|
|
|
18
18
|
|
|
19
19
|
char* ast_node_name(AST_NODE_T* node);
|
|
20
20
|
|
|
21
|
-
void ast_node_set_start(AST_NODE_T* node, position_T
|
|
22
|
-
void ast_node_set_end(AST_NODE_T* node, position_T
|
|
21
|
+
void ast_node_set_start(AST_NODE_T* node, position_T position);
|
|
22
|
+
void ast_node_set_end(AST_NODE_T* node, position_T position);
|
|
23
23
|
|
|
24
24
|
size_t ast_node_errors_count(const AST_NODE_T* node);
|
|
25
|
-
|
|
25
|
+
hb_array_T* ast_node_errors(const AST_NODE_T* node);
|
|
26
26
|
void ast_node_append_error(const AST_NODE_T* node, ERROR_T* error);
|
|
27
27
|
|
|
28
28
|
void ast_node_set_start_from_token(AST_NODE_T* node, const token_T* token);
|