herb 0.1.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 +7 -0
- data/License.txt +21 -0
- data/Makefile +121 -0
- data/README.md +166 -0
- data/Rakefile +184 -0
- data/exe/herb +5 -0
- data/ext/herb/error_helpers.c +302 -0
- data/ext/herb/error_helpers.h +15 -0
- data/ext/herb/extconf.rb +75 -0
- data/ext/herb/extension.c +110 -0
- data/ext/herb/extension.h +6 -0
- data/ext/herb/extension_helpers.c +117 -0
- data/ext/herb/extension_helpers.h +24 -0
- data/ext/herb/nodes.c +936 -0
- data/ext/herb/nodes.h +12 -0
- data/herb.gemspec +49 -0
- 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/node.rb +61 -0
- data/lib/herb/ast/nodes.rb +1542 -0
- data/lib/herb/ast.rb +6 -0
- data/lib/herb/cli.rb +164 -0
- data/lib/herb/errors.rb +352 -0
- data/lib/herb/lex_result.rb +20 -0
- data/lib/herb/libherb/array.rb +48 -0
- data/lib/herb/libherb/ast_node.rb +47 -0
- data/lib/herb/libherb/buffer.rb +53 -0
- data/lib/herb/libherb/extract_result.rb +17 -0
- data/lib/herb/libherb/lex_result.rb +29 -0
- data/lib/herb/libherb/libherb.rb +49 -0
- data/lib/herb/libherb/parse_result.rb +17 -0
- data/lib/herb/libherb/token.rb +43 -0
- data/lib/herb/libherb.rb +32 -0
- data/lib/herb/location.rb +42 -0
- data/lib/herb/parse_result.rb +26 -0
- data/lib/herb/position.rb +36 -0
- data/lib/herb/project.rb +361 -0
- data/lib/herb/range.rb +40 -0
- data/lib/herb/result.rb +21 -0
- data/lib/herb/token.rb +43 -0
- data/lib/herb/token_list.rb +11 -0
- data/lib/herb/version.rb +5 -0
- data/lib/herb.rb +32 -0
- data/src/analyze.c +989 -0
- data/src/analyze_helpers.c +241 -0
- data/src/analyzed_ruby.c +35 -0
- data/src/array.c +137 -0
- data/src/ast_node.c +81 -0
- data/src/ast_nodes.c +866 -0
- data/src/ast_pretty_print.c +588 -0
- data/src/buffer.c +199 -0
- data/src/errors.c +740 -0
- data/src/extract.c +110 -0
- data/src/herb.c +103 -0
- data/src/html_util.c +143 -0
- data/src/include/analyze.h +36 -0
- data/src/include/analyze_helpers.h +43 -0
- data/src/include/analyzed_ruby.h +33 -0
- data/src/include/array.h +33 -0
- data/src/include/ast_node.h +35 -0
- data/src/include/ast_nodes.h +303 -0
- data/src/include/ast_pretty_print.h +17 -0
- data/src/include/buffer.h +36 -0
- data/src/include/errors.h +125 -0
- data/src/include/extract.h +20 -0
- data/src/include/herb.h +32 -0
- data/src/include/html_util.h +13 -0
- data/src/include/io.h +9 -0
- data/src/include/json.h +28 -0
- data/src/include/lexer.h +13 -0
- data/src/include/lexer_peek_helpers.h +23 -0
- data/src/include/lexer_struct.h +32 -0
- data/src/include/location.h +25 -0
- data/src/include/macros.h +10 -0
- data/src/include/memory.h +12 -0
- data/src/include/parser.h +22 -0
- data/src/include/parser_helpers.h +33 -0
- data/src/include/position.h +22 -0
- data/src/include/pretty_print.h +53 -0
- data/src/include/prism_helpers.h +18 -0
- data/src/include/range.h +23 -0
- data/src/include/ruby_parser.h +6 -0
- data/src/include/token.h +25 -0
- data/src/include/token_matchers.h +21 -0
- data/src/include/token_struct.h +51 -0
- data/src/include/util.h +25 -0
- data/src/include/version.h +6 -0
- data/src/include/visitor.h +11 -0
- data/src/io.c +30 -0
- data/src/json.c +205 -0
- data/src/lexer.c +284 -0
- data/src/lexer_peek_helpers.c +59 -0
- data/src/location.c +41 -0
- data/src/main.c +162 -0
- data/src/memory.c +53 -0
- data/src/parser.c +704 -0
- data/src/parser_helpers.c +161 -0
- data/src/position.c +33 -0
- data/src/pretty_print.c +242 -0
- data/src/prism_helpers.c +50 -0
- data/src/range.c +38 -0
- data/src/ruby_parser.c +47 -0
- data/src/token.c +194 -0
- data/src/token_matchers.c +32 -0
- data/src/util.c +128 -0
- data/src/visitor.c +321 -0
- metadata +159 -0
data/src/extract.c
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#include "include/array.h"
|
2
|
+
#include "include/buffer.h"
|
3
|
+
#include "include/herb.h"
|
4
|
+
#include "include/io.h"
|
5
|
+
#include "include/lexer.h"
|
6
|
+
|
7
|
+
#include <stdlib.h>
|
8
|
+
|
9
|
+
void herb_extract_ruby_to_buffer_with_semicolons(const char* source, buffer_T* output) {
|
10
|
+
const array_T* tokens = herb_lex(source);
|
11
|
+
|
12
|
+
for (size_t i = 0; i < array_size(tokens); i++) {
|
13
|
+
const token_T* token = array_get(tokens, i);
|
14
|
+
|
15
|
+
switch (token->type) {
|
16
|
+
case TOKEN_NEWLINE:
|
17
|
+
case TOKEN_ERB_CONTENT: buffer_append(output, token->value); break;
|
18
|
+
case TOKEN_ERB_END: {
|
19
|
+
buffer_append_char(output, ';');
|
20
|
+
buffer_append_whitespace(output, range_length(token->range) - 1);
|
21
|
+
break;
|
22
|
+
}
|
23
|
+
|
24
|
+
case TOKEN_ERB_START: {
|
25
|
+
if (strcmp(token->value, "<%#") == 0) {
|
26
|
+
buffer_append_char(output, ' ');
|
27
|
+
buffer_append_char(output, ' ');
|
28
|
+
buffer_append_char(output, '#');
|
29
|
+
} else {
|
30
|
+
buffer_append_whitespace(output, range_length(token->range));
|
31
|
+
}
|
32
|
+
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
|
36
|
+
default: buffer_append_whitespace(output, range_length(token->range));
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
void herb_extract_ruby_to_buffer(const char* source, buffer_T* output) {
|
42
|
+
const array_T* tokens = herb_lex(source);
|
43
|
+
|
44
|
+
for (size_t i = 0; i < array_size(tokens); i++) {
|
45
|
+
const token_T* token = array_get(tokens, i);
|
46
|
+
|
47
|
+
switch (token->type) {
|
48
|
+
case TOKEN_NEWLINE:
|
49
|
+
case TOKEN_ERB_CONTENT: buffer_append(output, token->value); break;
|
50
|
+
case TOKEN_ERB_START: {
|
51
|
+
if (strcmp(token->value, "<%#") == 0) {
|
52
|
+
buffer_append_char(output, ' ');
|
53
|
+
buffer_append_char(output, ' ');
|
54
|
+
buffer_append_char(output, '#');
|
55
|
+
} else {
|
56
|
+
buffer_append_whitespace(output, range_length(token->range));
|
57
|
+
}
|
58
|
+
|
59
|
+
break;
|
60
|
+
}
|
61
|
+
|
62
|
+
default: buffer_append_whitespace(output, range_length(token->range));
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
void herb_extract_html_to_buffer(const char* source, buffer_T* output) {
|
68
|
+
const array_T* tokens = herb_lex(source);
|
69
|
+
|
70
|
+
for (size_t i = 0; i < array_size(tokens); i++) {
|
71
|
+
const token_T* token = array_get(tokens, i);
|
72
|
+
|
73
|
+
switch (token->type) {
|
74
|
+
case TOKEN_ERB_START:
|
75
|
+
case TOKEN_ERB_CONTENT:
|
76
|
+
case TOKEN_ERB_END: buffer_append_whitespace(output, range_length(token->range)); break;
|
77
|
+
default: buffer_append(output, token->value);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
char* herb_extract_ruby_with_semicolons(const char* source) {
|
83
|
+
buffer_T output;
|
84
|
+
buffer_init(&output);
|
85
|
+
|
86
|
+
herb_extract_ruby_to_buffer_with_semicolons(source, &output);
|
87
|
+
|
88
|
+
return output.value;
|
89
|
+
}
|
90
|
+
|
91
|
+
char* herb_extract(const char* source, const herb_extract_language_T language) {
|
92
|
+
buffer_T output;
|
93
|
+
buffer_init(&output);
|
94
|
+
|
95
|
+
switch (language) {
|
96
|
+
case HERB_EXTRACT_LANGUAGE_RUBY: herb_extract_ruby_to_buffer(source, &output); break;
|
97
|
+
case HERB_EXTRACT_LANGUAGE_HTML: herb_extract_html_to_buffer(source, &output); break;
|
98
|
+
}
|
99
|
+
|
100
|
+
return output.value;
|
101
|
+
}
|
102
|
+
|
103
|
+
char* herb_extract_from_file(const char* path, const herb_extract_language_T language) {
|
104
|
+
char* source = herb_read_file(path);
|
105
|
+
char* output = herb_extract(source, language);
|
106
|
+
|
107
|
+
free(source);
|
108
|
+
|
109
|
+
return output;
|
110
|
+
}
|
data/src/herb.c
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
#include "include/herb.h"
|
2
|
+
#include "include/array.h"
|
3
|
+
#include "include/buffer.h"
|
4
|
+
#include "include/io.h"
|
5
|
+
#include "include/json.h"
|
6
|
+
#include "include/lexer.h"
|
7
|
+
#include "include/parser.h"
|
8
|
+
#include "include/token.h"
|
9
|
+
#include "include/version.h"
|
10
|
+
|
11
|
+
#include <prism.h>
|
12
|
+
#include <stdlib.h>
|
13
|
+
|
14
|
+
array_T* herb_lex(const char* source) {
|
15
|
+
lexer_T* lexer = lexer_init(source);
|
16
|
+
token_T* token = NULL;
|
17
|
+
array_T* tokens = array_init(128);
|
18
|
+
|
19
|
+
while ((token = lexer_next_token(lexer))->type != TOKEN_EOF) {
|
20
|
+
array_append(tokens, token);
|
21
|
+
}
|
22
|
+
|
23
|
+
array_append(tokens, token);
|
24
|
+
|
25
|
+
lexer_free(lexer);
|
26
|
+
|
27
|
+
return tokens;
|
28
|
+
}
|
29
|
+
|
30
|
+
AST_DOCUMENT_NODE_T* herb_parse(const char* source) {
|
31
|
+
lexer_T* lexer = lexer_init(source);
|
32
|
+
parser_T* parser = parser_init(lexer);
|
33
|
+
|
34
|
+
AST_DOCUMENT_NODE_T* document = parser_parse(parser);
|
35
|
+
|
36
|
+
parser_free(parser);
|
37
|
+
|
38
|
+
return document;
|
39
|
+
}
|
40
|
+
|
41
|
+
array_T* herb_lex_file(const char* path) {
|
42
|
+
char* source = herb_read_file(path);
|
43
|
+
array_T* tokens = herb_lex(source);
|
44
|
+
|
45
|
+
free(source);
|
46
|
+
|
47
|
+
return tokens;
|
48
|
+
}
|
49
|
+
|
50
|
+
void herb_lex_to_buffer(const char* source, buffer_T* output) {
|
51
|
+
array_T* tokens = herb_lex(source);
|
52
|
+
|
53
|
+
for (size_t i = 0; i < array_size(tokens); i++) {
|
54
|
+
token_T* token = array_get(tokens, i);
|
55
|
+
|
56
|
+
char* type = token_to_string(token);
|
57
|
+
buffer_append(output, type);
|
58
|
+
free(type);
|
59
|
+
|
60
|
+
buffer_append(output, "\n");
|
61
|
+
}
|
62
|
+
|
63
|
+
herb_free_tokens(&tokens);
|
64
|
+
}
|
65
|
+
|
66
|
+
void herb_lex_json_to_buffer(const char* source, buffer_T* output) {
|
67
|
+
array_T* tokens = herb_lex(source);
|
68
|
+
|
69
|
+
buffer_T json = buffer_new();
|
70
|
+
json_start_root_array(&json);
|
71
|
+
|
72
|
+
for (size_t i = 0; i < array_size(tokens); i++) {
|
73
|
+
token_T* token = array_get(tokens, i);
|
74
|
+
char* token_json = token_to_json(token);
|
75
|
+
json_add_raw_string(&json, token_json);
|
76
|
+
free(token_json);
|
77
|
+
}
|
78
|
+
|
79
|
+
json_end_array(&json);
|
80
|
+
buffer_concat(output, &json);
|
81
|
+
|
82
|
+
buffer_free(&json);
|
83
|
+
herb_free_tokens(&tokens);
|
84
|
+
}
|
85
|
+
|
86
|
+
void herb_free_tokens(array_T** tokens) {
|
87
|
+
if (!tokens || !*tokens) { return; }
|
88
|
+
|
89
|
+
for (size_t i = 0; i < array_size(*tokens); i++) {
|
90
|
+
token_T* token = array_get(*tokens, i);
|
91
|
+
if (token) { token_free(token); }
|
92
|
+
}
|
93
|
+
|
94
|
+
array_free(tokens);
|
95
|
+
}
|
96
|
+
|
97
|
+
const char* herb_version(void) {
|
98
|
+
return HERB_VERSION;
|
99
|
+
}
|
100
|
+
|
101
|
+
const char* herb_prism_version(void) {
|
102
|
+
return PRISM_VERSION;
|
103
|
+
}
|
data/src/html_util.c
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
#include "include/html_util.h"
|
2
|
+
#include "include/util.h"
|
3
|
+
|
4
|
+
#include <ctype.h>
|
5
|
+
#include <stdbool.h>
|
6
|
+
#include <stddef.h>
|
7
|
+
#include <stdlib.h>
|
8
|
+
#include <string.h>
|
9
|
+
#include <strings.h>
|
10
|
+
|
11
|
+
// https://developer.mozilla.org/en-US/docs/Glossary/Void_element
|
12
|
+
bool is_void_element(const char* tag_name) {
|
13
|
+
if (tag_name == NULL) { return false; }
|
14
|
+
|
15
|
+
const char* void_tags[] = {
|
16
|
+
"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr",
|
17
|
+
};
|
18
|
+
|
19
|
+
for (size_t i = 0; i < sizeof(void_tags) / sizeof(char*); i++) {
|
20
|
+
if (strcasecmp(tag_name, void_tags[i]) == 0) { return true; }
|
21
|
+
}
|
22
|
+
|
23
|
+
return false;
|
24
|
+
}
|
25
|
+
|
26
|
+
bool is_html4_void_element(const char* tag_name) {
|
27
|
+
if (tag_name == NULL) { return false; }
|
28
|
+
|
29
|
+
const char* html4_void_tags[] = {
|
30
|
+
"basefont", "bgsound", "command", "frame", "image", "keygen",
|
31
|
+
};
|
32
|
+
|
33
|
+
for (size_t i = 0; i < sizeof(html4_void_tags) / sizeof(char*); i++) {
|
34
|
+
if (strcasecmp(tag_name, html4_void_tags[i]) == 0) { return true; }
|
35
|
+
}
|
36
|
+
|
37
|
+
return false;
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* @brief Creates an opening HTML tag string like "<tag_name>"
|
42
|
+
*
|
43
|
+
* @param tag_name The name of the HTML tag to be enclosed in a opening tag
|
44
|
+
* @return A newly allocated string containing the opening tag, or NULL if memory allocation fails
|
45
|
+
* @note The caller is responsible for freeing the returned string
|
46
|
+
*
|
47
|
+
* Example:
|
48
|
+
* @code
|
49
|
+
* char* tag = html_opening_tag_string("div");
|
50
|
+
* if (tag) {
|
51
|
+
* printf("%s\n", tag); // Prints: <div>
|
52
|
+
* free(tag);
|
53
|
+
* }
|
54
|
+
* @endcode
|
55
|
+
*/
|
56
|
+
char* html_opening_tag_string(const char* tag_name) {
|
57
|
+
if (tag_name == NULL) { return herb_strdup("<>"); }
|
58
|
+
|
59
|
+
size_t length = strlen(tag_name);
|
60
|
+
char* result = (char*) malloc(length + 3); // +3 for '<', '>', and '\0'
|
61
|
+
|
62
|
+
if (result == NULL) { return NULL; }
|
63
|
+
|
64
|
+
result[0] = '<';
|
65
|
+
|
66
|
+
memcpy(result + 1, tag_name, length);
|
67
|
+
|
68
|
+
result[length + 1] = '>';
|
69
|
+
result[length + 2] = '\0';
|
70
|
+
|
71
|
+
return result;
|
72
|
+
}
|
73
|
+
|
74
|
+
/**
|
75
|
+
* @brief Creates a closing HTML tag string like "</tag_name>"
|
76
|
+
*
|
77
|
+
* @param tag_name The name of the HTML tag to be enclosed in a closing tag
|
78
|
+
* @return A newly allocated string containing the closing tag, or NULL if memory allocation fails
|
79
|
+
* @note The caller is responsible for freeing the returned string
|
80
|
+
*
|
81
|
+
* Example:
|
82
|
+
* @code
|
83
|
+
* char* tag = html_closing_tag_string("div");
|
84
|
+
* if (tag) {
|
85
|
+
* printf("%s\n", tag); // Prints: </div>
|
86
|
+
* free(tag);
|
87
|
+
* }
|
88
|
+
* @endcode
|
89
|
+
*/
|
90
|
+
char* html_closing_tag_string(const char* tag_name) {
|
91
|
+
if (tag_name == NULL) { return herb_strdup("</>"); }
|
92
|
+
|
93
|
+
size_t length = strlen(tag_name);
|
94
|
+
char* result = (char*) malloc(length + 4); // +4 for '<', '/', '>', and '\0'
|
95
|
+
|
96
|
+
if (result == NULL) { return NULL; }
|
97
|
+
|
98
|
+
result[0] = '<';
|
99
|
+
result[1] = '/';
|
100
|
+
|
101
|
+
memcpy(result + 2, tag_name, length);
|
102
|
+
|
103
|
+
result[length + 2] = '>';
|
104
|
+
result[length + 3] = '\0';
|
105
|
+
|
106
|
+
return result;
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* @brief Creates a self-closing HTML tag string like "<tag_name />"
|
111
|
+
*
|
112
|
+
* @param tag_name The name of the HTML tag to be enclosed in a self-closing tag
|
113
|
+
* @return A newly allocated string containing the self-closing tag, or NULL if memory allocation fails
|
114
|
+
* @note The caller is responsible for freeing the returned string
|
115
|
+
*
|
116
|
+
* Example:
|
117
|
+
* @code
|
118
|
+
* char* tag = html_self_closing_tag_string("br");
|
119
|
+
* if (tag) {
|
120
|
+
* printf("%s\n", tag); // Prints: <br />
|
121
|
+
* free(tag);
|
122
|
+
* }
|
123
|
+
* @endcode
|
124
|
+
*/
|
125
|
+
char* html_self_closing_tag_string(const char* tag_name) {
|
126
|
+
if (tag_name == NULL) { return herb_strdup("< />"); }
|
127
|
+
|
128
|
+
size_t length = strlen(tag_name);
|
129
|
+
char* result = (char*) malloc(length + 5); // +5 for '<', ' ', '/', '>', and '\0'
|
130
|
+
|
131
|
+
if (result == NULL) { return NULL; }
|
132
|
+
|
133
|
+
result[0] = '<';
|
134
|
+
|
135
|
+
memcpy(result + 1, tag_name, length);
|
136
|
+
|
137
|
+
result[length + 1] = ' ';
|
138
|
+
result[length + 2] = '/';
|
139
|
+
result[length + 3] = '>';
|
140
|
+
result[length + 4] = '\0';
|
141
|
+
|
142
|
+
return result;
|
143
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#ifndef HERB_ANALYZE_H
|
2
|
+
#define HERB_ANALYZE_H
|
3
|
+
|
4
|
+
#include "analyzed_ruby.h"
|
5
|
+
#include "array.h"
|
6
|
+
#include "ast_nodes.h"
|
7
|
+
|
8
|
+
typedef struct ANALYZE_RUBY_CONTEXT_STRUCT {
|
9
|
+
AST_DOCUMENT_NODE_T* document;
|
10
|
+
AST_NODE_T* parent;
|
11
|
+
array_T* ruby_context_stack;
|
12
|
+
} analyze_ruby_context_T;
|
13
|
+
|
14
|
+
typedef enum {
|
15
|
+
CONTROL_TYPE_IF,
|
16
|
+
CONTROL_TYPE_ELSIF,
|
17
|
+
CONTROL_TYPE_ELSE,
|
18
|
+
CONTROL_TYPE_END,
|
19
|
+
CONTROL_TYPE_CASE,
|
20
|
+
CONTROL_TYPE_WHEN,
|
21
|
+
CONTROL_TYPE_BEGIN,
|
22
|
+
CONTROL_TYPE_RESCUE,
|
23
|
+
CONTROL_TYPE_ENSURE,
|
24
|
+
CONTROL_TYPE_UNLESS,
|
25
|
+
CONTROL_TYPE_WHILE,
|
26
|
+
CONTROL_TYPE_UNTIL,
|
27
|
+
CONTROL_TYPE_FOR,
|
28
|
+
CONTROL_TYPE_BLOCK,
|
29
|
+
CONTROL_TYPE_BLOCK_CLOSE,
|
30
|
+
CONTROL_TYPE_UNKNOWN
|
31
|
+
} control_type_t;
|
32
|
+
|
33
|
+
void herb_analyze_parse_errors(AST_DOCUMENT_NODE_T* document, const char* source);
|
34
|
+
void herb_analyze_parse_tree(AST_DOCUMENT_NODE_T* document, const char* source);
|
35
|
+
|
36
|
+
#endif
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#ifndef HERB_ANALYZE_HELPERS_H
|
2
|
+
#define HERB_ANALYZE_HELPERS_H
|
3
|
+
|
4
|
+
#include <prism.h>
|
5
|
+
#include <stdbool.h>
|
6
|
+
|
7
|
+
#include "analyzed_ruby.h"
|
8
|
+
|
9
|
+
bool has_if_node(analyzed_ruby_T* analyzed);
|
10
|
+
bool has_elsif_node(analyzed_ruby_T* analyzed);
|
11
|
+
bool has_else_node(analyzed_ruby_T* analyzed);
|
12
|
+
bool has_end(analyzed_ruby_T* analyzed);
|
13
|
+
bool has_block_node(analyzed_ruby_T* analyzed);
|
14
|
+
bool has_block_closing(analyzed_ruby_T* analyzed);
|
15
|
+
bool has_case_node(analyzed_ruby_T* analyzed);
|
16
|
+
bool has_when_node(analyzed_ruby_T* analyzed);
|
17
|
+
bool has_for_node(analyzed_ruby_T* analyzed);
|
18
|
+
bool has_while_node(analyzed_ruby_T* analyzed);
|
19
|
+
bool has_until_node(analyzed_ruby_T* analyzed);
|
20
|
+
bool has_begin_node(analyzed_ruby_T* analyzed);
|
21
|
+
bool has_rescue_node(analyzed_ruby_T* analyzed);
|
22
|
+
bool has_ensure_node(analyzed_ruby_T* analyzed);
|
23
|
+
bool has_unless_node(analyzed_ruby_T* analyzed);
|
24
|
+
|
25
|
+
bool has_error_message(analyzed_ruby_T* anlayzed, const char* message);
|
26
|
+
|
27
|
+
bool search_if_nodes(const pm_node_t* node, void* data);
|
28
|
+
bool search_block_nodes(const pm_node_t* node, void* data);
|
29
|
+
bool search_case_nodes(const pm_node_t* node, void* data);
|
30
|
+
bool search_while_nodes(const pm_node_t* node, void* data);
|
31
|
+
bool search_for_nodes(const pm_node_t* node, void* data);
|
32
|
+
bool search_until_nodes(const pm_node_t* node, void* data);
|
33
|
+
bool search_begin_nodes(const pm_node_t* node, void* data);
|
34
|
+
bool search_unless_nodes(const pm_node_t* node, void* data);
|
35
|
+
bool search_elsif_nodes(analyzed_ruby_T* analyzed);
|
36
|
+
bool search_else_nodes(analyzed_ruby_T* analyzed);
|
37
|
+
bool search_end_nodes(analyzed_ruby_T* analyzed);
|
38
|
+
bool search_block_closing_nodes(analyzed_ruby_T* analyzed);
|
39
|
+
bool search_when_nodes(analyzed_ruby_T* analyzed);
|
40
|
+
bool search_rescue_nodes(analyzed_ruby_T* analyzed);
|
41
|
+
bool search_ensure_nodes(analyzed_ruby_T* analyzed);
|
42
|
+
|
43
|
+
#endif
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#ifndef HERB_ANALYZED_RUBY_H
|
2
|
+
#define HERB_ANALYZED_RUBY_H
|
3
|
+
|
4
|
+
#include "array.h"
|
5
|
+
|
6
|
+
#include <prism.h>
|
7
|
+
|
8
|
+
typedef struct ANALYZED_RUBY_STRUCT {
|
9
|
+
pm_parser_t parser;
|
10
|
+
pm_node_t* root;
|
11
|
+
bool valid;
|
12
|
+
bool parsed;
|
13
|
+
bool has_if_node;
|
14
|
+
bool has_elsif_node;
|
15
|
+
bool has_else_node;
|
16
|
+
bool has_end;
|
17
|
+
bool has_block_closing;
|
18
|
+
bool has_block_node;
|
19
|
+
bool has_case_node;
|
20
|
+
bool has_when_node;
|
21
|
+
bool has_for_node;
|
22
|
+
bool has_while_node;
|
23
|
+
bool has_until_node;
|
24
|
+
bool has_begin_node;
|
25
|
+
bool has_rescue_node;
|
26
|
+
bool has_ensure_node;
|
27
|
+
bool has_unless_node;
|
28
|
+
} analyzed_ruby_T;
|
29
|
+
|
30
|
+
analyzed_ruby_T* init_analyzed_ruby(char* source);
|
31
|
+
void free_analyzed_ruby(analyzed_ruby_T* analyzed);
|
32
|
+
|
33
|
+
#endif
|
data/src/include/array.h
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#ifndef HERB_ARRAY_H
|
2
|
+
#define HERB_ARRAY_H
|
3
|
+
|
4
|
+
#include <stdlib.h>
|
5
|
+
|
6
|
+
typedef struct ARRAY_STRUCT {
|
7
|
+
void** items;
|
8
|
+
size_t size;
|
9
|
+
size_t capacity;
|
10
|
+
} array_T;
|
11
|
+
|
12
|
+
array_T* array_init(size_t capacity);
|
13
|
+
|
14
|
+
void* array_get(const array_T* array, size_t index);
|
15
|
+
void* array_first(array_T* array);
|
16
|
+
void* array_last(array_T* array);
|
17
|
+
|
18
|
+
void array_append(array_T* array, void* item);
|
19
|
+
void array_set(const array_T* array, size_t index, void* item);
|
20
|
+
void array_free(array_T** array);
|
21
|
+
void array_remove(array_T* array, size_t index);
|
22
|
+
|
23
|
+
size_t array_index_of(array_T* array, void* item);
|
24
|
+
void array_remove_item(array_T* array, void* item);
|
25
|
+
|
26
|
+
void array_push(array_T* array, void* item);
|
27
|
+
void* array_pop(array_T* array);
|
28
|
+
|
29
|
+
size_t array_capacity(const array_T* array);
|
30
|
+
size_t array_size(const array_T* array);
|
31
|
+
size_t array_sizeof(void);
|
32
|
+
|
33
|
+
#endif
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#ifndef HERB_AST_H
|
2
|
+
#define HERB_AST_H
|
3
|
+
|
4
|
+
#include "ast_nodes.h"
|
5
|
+
#include "errors.h"
|
6
|
+
#include "position.h"
|
7
|
+
#include "token_struct.h"
|
8
|
+
|
9
|
+
void ast_node_init(AST_NODE_T* node, ast_node_type_T type, position_T* start, position_T* end, array_T* errors);
|
10
|
+
void ast_node_free(AST_NODE_T* node);
|
11
|
+
|
12
|
+
AST_LITERAL_NODE_T* ast_literal_node_init_from_token(const token_T* token);
|
13
|
+
|
14
|
+
size_t ast_node_sizeof(void);
|
15
|
+
size_t ast_node_child_count(AST_NODE_T* node);
|
16
|
+
|
17
|
+
ast_node_type_T ast_node_type(const AST_NODE_T* node);
|
18
|
+
|
19
|
+
char* ast_node_name(AST_NODE_T* node);
|
20
|
+
|
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
|
+
|
24
|
+
size_t ast_node_errors_count(const AST_NODE_T* node);
|
25
|
+
array_T* ast_node_errors(const AST_NODE_T* node);
|
26
|
+
void ast_node_append_error(const AST_NODE_T* node, ERROR_T* error);
|
27
|
+
|
28
|
+
void ast_node_set_start_from_token(AST_NODE_T* node, const token_T* token);
|
29
|
+
void ast_node_set_end_from_token(AST_NODE_T* node, const token_T* token);
|
30
|
+
|
31
|
+
void ast_node_set_positions_from_token(AST_NODE_T* node, const token_T* token);
|
32
|
+
|
33
|
+
bool ast_node_is(const AST_NODE_T* node, ast_node_type_T type);
|
34
|
+
|
35
|
+
#endif
|