herb 0.7.4-x86-linux-gnu → 0.7.5-x86-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/config.yml +14 -14
- data/ext/herb/extension_helpers.c +9 -15
- data/ext/herb/extension_helpers.h +3 -3
- data/ext/herb/nodes.c +1 -1
- 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.rb +10 -6
- data/lib/herb/version.rb +1 -1
- data/src/analyze.c +43 -80
- data/src/ast_node.c +10 -13
- data/src/ast_nodes.c +31 -33
- data/src/buffer.c +10 -1
- data/src/errors.c +35 -35
- data/src/include/ast_node.h +3 -3
- data/src/include/ast_nodes.h +32 -32
- data/src/include/errors.h +21 -21
- data/src/include/lexer_peek_helpers.h +8 -6
- data/src/include/lexer_struct.h +10 -9
- data/src/include/location.h +10 -13
- data/src/include/parser_helpers.h +1 -1
- data/src/include/position.h +3 -14
- data/src/include/pretty_print.h +1 -1
- data/src/include/prism_helpers.h +1 -1
- data/src/include/range.h +4 -13
- data/src/include/token.h +0 -3
- data/src/include/token_struct.h +2 -2
- data/src/include/version.h +1 -1
- data/src/lexer.c +3 -2
- data/src/lexer_peek_helpers.c +10 -4
- data/src/location.c +9 -37
- data/src/parser.c +98 -119
- data/src/parser_helpers.c +15 -15
- data/src/pretty_print.c +7 -12
- data/src/prism_helpers.c +7 -7
- data/src/range.c +2 -35
- data/src/token.c +25 -29
- data/templates/javascript/packages/core/src/visitor.ts.erb +29 -1
- data/templates/src/ast_nodes.c.erb +1 -3
- data/templates/src/errors.c.erb +5 -7
- data/templates/src/include/ast_nodes.h.erb +2 -2
- data/templates/src/include/errors.h.erb +3 -3
- metadata +2 -3
- data/src/position.c +0 -33
data/src/include/errors.h
CHANGED
@@ -25,7 +25,7 @@ typedef enum {
|
|
25
25
|
|
26
26
|
typedef struct ERROR_STRUCT {
|
27
27
|
error_type_T type;
|
28
|
-
location_T
|
28
|
+
location_T location;
|
29
29
|
char* message;
|
30
30
|
} ERROR_T;
|
31
31
|
|
@@ -84,26 +84,26 @@ typedef struct {
|
|
84
84
|
const char* level;
|
85
85
|
} RUBY_PARSE_ERROR_T;
|
86
86
|
|
87
|
-
UNEXPECTED_ERROR_T* unexpected_error_init(const char* description, const char* expected, const char* found, position_T
|
88
|
-
void append_unexpected_error(const char* description, const char* expected, const char* found, position_T
|
89
|
-
UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T
|
90
|
-
void append_unexpected_token_error(token_type_T expected_type, token_T* found, position_T
|
91
|
-
MISSING_OPENING_TAG_ERROR_T* missing_opening_tag_error_init(token_T* closing_tag, position_T
|
92
|
-
void append_missing_opening_tag_error(token_T* closing_tag, position_T
|
93
|
-
MISSING_CLOSING_TAG_ERROR_T* missing_closing_tag_error_init(token_T* opening_tag, position_T
|
94
|
-
void append_missing_closing_tag_error(token_T* opening_tag, position_T
|
95
|
-
TAG_NAMES_MISMATCH_ERROR_T* tag_names_mismatch_error_init(token_T* opening_tag, token_T* closing_tag, position_T
|
96
|
-
void append_tag_names_mismatch_error(token_T* opening_tag, token_T* closing_tag, position_T
|
97
|
-
QUOTES_MISMATCH_ERROR_T* quotes_mismatch_error_init(token_T* opening_quote, token_T* closing_quote, position_T
|
98
|
-
void append_quotes_mismatch_error(token_T* opening_quote, token_T* closing_quote, position_T
|
99
|
-
VOID_ELEMENT_CLOSING_TAG_ERROR_T* void_element_closing_tag_error_init(token_T* tag_name, const char* expected, const char* found, position_T
|
100
|
-
void append_void_element_closing_tag_error(token_T* tag_name, const char* expected, const char* found, position_T
|
101
|
-
UNCLOSED_ELEMENT_ERROR_T* unclosed_element_error_init(token_T* opening_tag, position_T
|
102
|
-
void append_unclosed_element_error(token_T* opening_tag, position_T
|
103
|
-
RUBY_PARSE_ERROR_T* ruby_parse_error_init(const char* error_message, const char* diagnostic_id, const char* level, position_T
|
104
|
-
void append_ruby_parse_error(const char* error_message, const char* diagnostic_id, const char* level, position_T
|
105
|
-
|
106
|
-
void error_init(ERROR_T* error, error_type_T type, position_T
|
87
|
+
UNEXPECTED_ERROR_T* unexpected_error_init(const char* description, const char* expected, const char* found, position_T start, position_T end);
|
88
|
+
void append_unexpected_error(const char* description, const char* expected, const char* found, position_T start, position_T end, array_T* errors);
|
89
|
+
UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T start, position_T end);
|
90
|
+
void append_unexpected_token_error(token_type_T expected_type, token_T* found, position_T start, position_T end, array_T* errors);
|
91
|
+
MISSING_OPENING_TAG_ERROR_T* missing_opening_tag_error_init(token_T* closing_tag, position_T start, position_T end);
|
92
|
+
void append_missing_opening_tag_error(token_T* closing_tag, position_T start, position_T end, array_T* errors);
|
93
|
+
MISSING_CLOSING_TAG_ERROR_T* missing_closing_tag_error_init(token_T* opening_tag, position_T start, position_T end);
|
94
|
+
void append_missing_closing_tag_error(token_T* opening_tag, position_T start, position_T end, array_T* errors);
|
95
|
+
TAG_NAMES_MISMATCH_ERROR_T* tag_names_mismatch_error_init(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end);
|
96
|
+
void append_tag_names_mismatch_error(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end, array_T* errors);
|
97
|
+
QUOTES_MISMATCH_ERROR_T* quotes_mismatch_error_init(token_T* opening_quote, token_T* closing_quote, position_T start, position_T end);
|
98
|
+
void append_quotes_mismatch_error(token_T* opening_quote, token_T* closing_quote, position_T start, position_T end, array_T* errors);
|
99
|
+
VOID_ELEMENT_CLOSING_TAG_ERROR_T* void_element_closing_tag_error_init(token_T* tag_name, const char* expected, const char* found, position_T start, position_T end);
|
100
|
+
void append_void_element_closing_tag_error(token_T* tag_name, const char* expected, const char* found, position_T start, position_T end, array_T* errors);
|
101
|
+
UNCLOSED_ELEMENT_ERROR_T* unclosed_element_error_init(token_T* opening_tag, position_T start, position_T end);
|
102
|
+
void append_unclosed_element_error(token_T* opening_tag, position_T start, position_T end, array_T* errors);
|
103
|
+
RUBY_PARSE_ERROR_T* ruby_parse_error_init(const char* error_message, const char* diagnostic_id, const char* level, position_T start, position_T end);
|
104
|
+
void append_ruby_parse_error(const char* error_message, const char* diagnostic_id, const char* level, position_T start, position_T end, array_T* errors);
|
105
|
+
|
106
|
+
void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end);
|
107
107
|
|
108
108
|
size_t error_sizeof(void);
|
109
109
|
error_type_T error_type(ERROR_T* error);
|
@@ -5,16 +5,17 @@
|
|
5
5
|
#include "token_struct.h"
|
6
6
|
|
7
7
|
#include <stdbool.h>
|
8
|
+
#include <stdint.h>
|
8
9
|
#include <stdio.h>
|
9
10
|
#include <stdlib.h>
|
10
11
|
|
11
12
|
typedef struct {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
uint32_t position;
|
14
|
+
uint32_t line;
|
15
|
+
uint32_t column;
|
16
|
+
uint32_t previous_position;
|
17
|
+
uint32_t previous_line;
|
18
|
+
uint32_t previous_column;
|
18
19
|
char current_character;
|
19
20
|
lexer_state_T state;
|
20
21
|
} lexer_state_snapshot_T;
|
@@ -31,6 +32,7 @@ bool lexer_peek_for_html_comment_end(const lexer_T* lexer, int offset);
|
|
31
32
|
bool lexer_peek_erb_close_tag(const lexer_T* lexer, int offset);
|
32
33
|
bool lexer_peek_erb_dash_close_tag(const lexer_T* lexer, int offset);
|
33
34
|
bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer, int offset);
|
35
|
+
bool lexer_peek_erb_equals_close_tag(const lexer_T* lexer, int offset);
|
34
36
|
bool lexer_peek_erb_end(const lexer_T* lexer, int offset);
|
35
37
|
|
36
38
|
char lexer_backtrack(const lexer_T* lexer, int offset);
|
data/src/include/lexer_struct.h
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
#define HERB_LEXER_STRUCT_H
|
3
3
|
|
4
4
|
#include <stdbool.h>
|
5
|
+
#include <stdint.h>
|
5
6
|
#include <stdlib.h>
|
6
7
|
|
7
8
|
typedef enum {
|
@@ -12,20 +13,20 @@ typedef enum {
|
|
12
13
|
|
13
14
|
typedef struct LEXER_STRUCT {
|
14
15
|
const char* source;
|
15
|
-
|
16
|
+
uint32_t source_length;
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
uint32_t current_line;
|
19
|
+
uint32_t current_column;
|
20
|
+
uint32_t current_position;
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
uint32_t previous_line;
|
23
|
+
uint32_t previous_column;
|
24
|
+
uint32_t previous_position;
|
24
25
|
|
25
26
|
char current_character;
|
26
27
|
lexer_state_T state;
|
27
|
-
|
28
|
-
|
28
|
+
uint32_t stall_counter;
|
29
|
+
uint32_t last_position;
|
29
30
|
bool stalled;
|
30
31
|
} lexer_T;
|
31
32
|
|
data/src/include/location.h
CHANGED
@@ -1,25 +1,22 @@
|
|
1
1
|
#ifndef HERB_LOCATION_H
|
2
2
|
#define HERB_LOCATION_H
|
3
3
|
|
4
|
+
#include <stdint.h>
|
4
5
|
#include <stdlib.h>
|
5
6
|
|
6
7
|
#include "position.h"
|
7
8
|
|
8
9
|
typedef struct LOCATION_STRUCT {
|
9
|
-
position_T
|
10
|
-
position_T
|
10
|
+
position_T start;
|
11
|
+
position_T end;
|
11
12
|
} location_T;
|
12
13
|
|
13
|
-
|
14
|
-
location_T*
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
location_T* location_copy(location_T* location);
|
22
|
-
|
23
|
-
void location_free(location_T* location);
|
14
|
+
void location_from(
|
15
|
+
location_T* location,
|
16
|
+
uint32_t start_line,
|
17
|
+
uint32_t start_column,
|
18
|
+
uint32_t end_line,
|
19
|
+
uint32_t end_column
|
20
|
+
);
|
24
21
|
|
25
22
|
#endif
|
data/src/include/position.h
CHANGED
@@ -1,22 +1,11 @@
|
|
1
1
|
#ifndef HERB_POSITION_H
|
2
2
|
#define HERB_POSITION_H
|
3
3
|
|
4
|
-
#include <
|
4
|
+
#include <stdint.h>
|
5
5
|
|
6
6
|
typedef struct POSITION_STRUCT {
|
7
|
-
|
8
|
-
|
7
|
+
uint32_t line;
|
8
|
+
uint32_t column;
|
9
9
|
} position_T;
|
10
10
|
|
11
|
-
position_T* position_init(size_t line, size_t column);
|
12
|
-
|
13
|
-
size_t position_line(const position_T* position);
|
14
|
-
size_t position_column(const position_T* position);
|
15
|
-
|
16
|
-
size_t position_sizeof(void);
|
17
|
-
|
18
|
-
position_T* position_copy(position_T* position);
|
19
|
-
|
20
|
-
void position_free(position_T* position);
|
21
|
-
|
22
11
|
#endif
|
data/src/include/pretty_print.h
CHANGED
@@ -21,7 +21,7 @@ void pretty_print_position_property(
|
|
21
21
|
buffer_T* buffer
|
22
22
|
);
|
23
23
|
|
24
|
-
void pretty_print_location(location_T
|
24
|
+
void pretty_print_location(location_T location, buffer_T* buffer);
|
25
25
|
|
26
26
|
void pretty_print_property(
|
27
27
|
const char* name,
|
data/src/include/prism_helpers.h
CHANGED
@@ -16,6 +16,6 @@ RUBY_PARSE_ERROR_T* ruby_parse_error_from_prism_error(
|
|
16
16
|
pm_parser_t* parser
|
17
17
|
);
|
18
18
|
|
19
|
-
position_T
|
19
|
+
position_T position_from_source_with_offset(const char* source, size_t offset);
|
20
20
|
|
21
21
|
#endif
|
data/src/include/range.h
CHANGED
@@ -1,23 +1,14 @@
|
|
1
1
|
#ifndef HERB_RANGE_H
|
2
2
|
#define HERB_RANGE_H
|
3
3
|
|
4
|
+
#include <stdint.h>
|
4
5
|
#include <stdlib.h>
|
5
6
|
|
6
7
|
typedef struct RANGE_STRUCT {
|
7
|
-
|
8
|
-
|
8
|
+
uint32_t from;
|
9
|
+
uint32_t to;
|
9
10
|
} range_T;
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
size_t range_from(const range_T* range);
|
14
|
-
size_t range_to(const range_T* range);
|
15
|
-
size_t range_length(range_T* range);
|
16
|
-
|
17
|
-
range_T* range_copy(range_T* range);
|
18
|
-
|
19
|
-
size_t range_sizeof(void);
|
20
|
-
|
21
|
-
void range_free(range_T* range);
|
12
|
+
uint32_t range_length(range_T range);
|
22
13
|
|
23
14
|
#endif
|
data/src/include/token.h
CHANGED
@@ -13,9 +13,6 @@ const char* token_type_to_string(token_type_T type);
|
|
13
13
|
char* token_value(const token_T* token);
|
14
14
|
int token_type(const token_T* token);
|
15
15
|
|
16
|
-
position_T* token_start_position(token_T* token);
|
17
|
-
position_T* token_end_position(token_T* token);
|
18
|
-
|
19
16
|
size_t token_sizeof(void);
|
20
17
|
|
21
18
|
token_T* token_copy(token_T* token);
|
data/src/include/token_struct.h
CHANGED
data/src/include/version.h
CHANGED
data/src/lexer.c
CHANGED
@@ -42,7 +42,7 @@ lexer_T* lexer_init(const char* source) {
|
|
42
42
|
lexer->state = STATE_DATA;
|
43
43
|
|
44
44
|
lexer->source = source;
|
45
|
-
lexer->source_length = strlen(source);
|
45
|
+
lexer->source_length = (uint32_t) strlen(source);
|
46
46
|
lexer->current_character = source[0];
|
47
47
|
|
48
48
|
lexer->current_line = 1;
|
@@ -66,7 +66,7 @@ token_T* lexer_error(lexer_T* lexer, const char* message) {
|
|
66
66
|
snprintf(
|
67
67
|
error_message,
|
68
68
|
sizeof(error_message),
|
69
|
-
"[Lexer] Error: %s (character '%c', line %
|
69
|
+
"[Lexer] Error: %s (character '%c', line %u, col %u)\n",
|
70
70
|
message,
|
71
71
|
lexer->current_character,
|
72
72
|
lexer->current_line,
|
@@ -256,6 +256,7 @@ static token_T* lexer_parse_erb_close(lexer_T* lexer) {
|
|
256
256
|
lexer->state = STATE_DATA;
|
257
257
|
|
258
258
|
if (lexer_peek_erb_percent_close_tag(lexer, 0)) { return lexer_advance_with(lexer, "%%>", TOKEN_ERB_END); }
|
259
|
+
if (lexer_peek_erb_equals_close_tag(lexer, 0)) { return lexer_advance_with(lexer, "=%>", TOKEN_ERB_END); }
|
259
260
|
if (lexer_peek_erb_dash_close_tag(lexer, 0)) { return lexer_advance_with(lexer, "-%>", TOKEN_ERB_END); }
|
260
261
|
|
261
262
|
return lexer_advance_with(lexer, "%>", TOKEN_ERB_END);
|
data/src/lexer_peek_helpers.c
CHANGED
@@ -65,18 +65,23 @@ bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer, const int offset) {
|
|
65
65
|
return lexer_peek_for(lexer, offset, "%%>", false);
|
66
66
|
}
|
67
67
|
|
68
|
+
bool lexer_peek_erb_equals_close_tag(const lexer_T* lexer, const int offset) {
|
69
|
+
return lexer_peek_for(lexer, offset, "=%>", false);
|
70
|
+
}
|
71
|
+
|
68
72
|
bool lexer_peek_erb_end(const lexer_T* lexer, const int offset) {
|
69
73
|
return (
|
70
74
|
lexer_peek_erb_close_tag(lexer, offset) || lexer_peek_erb_dash_close_tag(lexer, offset)
|
71
|
-
|| lexer_peek_erb_percent_close_tag(lexer, offset)
|
75
|
+
|| lexer_peek_erb_percent_close_tag(lexer, offset) || lexer_peek_erb_equals_close_tag(lexer, offset)
|
72
76
|
);
|
73
77
|
}
|
74
78
|
|
75
79
|
bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T token_type) {
|
76
|
-
|
77
|
-
|
78
|
-
|
80
|
+
uint32_t saved_position = lexer->current_position;
|
81
|
+
uint32_t saved_line = lexer->current_line;
|
82
|
+
uint32_t saved_column = lexer->current_column;
|
79
83
|
char saved_character = lexer->current_character;
|
84
|
+
lexer_state_T saved_state = lexer->state;
|
80
85
|
|
81
86
|
token_T* token = lexer_next_token(lexer);
|
82
87
|
|
@@ -93,6 +98,7 @@ bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T tok
|
|
93
98
|
lexer->current_line = saved_line;
|
94
99
|
lexer->current_column = saved_column;
|
95
100
|
lexer->current_character = saved_character;
|
101
|
+
lexer->state = saved_state;
|
96
102
|
|
97
103
|
return result;
|
98
104
|
}
|
data/src/location.c
CHANGED
@@ -1,41 +1,13 @@
|
|
1
1
|
#include "include/location.h"
|
2
|
-
#include "include/memory.h"
|
3
2
|
#include "include/position.h"
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
location->start =
|
13
|
-
location->end =
|
14
|
-
|
15
|
-
return location;
|
16
|
-
}
|
17
|
-
|
18
|
-
location_T* location_from(size_t start_line, size_t start_column, size_t end_line, size_t end_column) {
|
19
|
-
return location_init(position_init(start_line, start_column), position_init(end_line, end_column));
|
20
|
-
}
|
21
|
-
|
22
|
-
position_T* location_start(location_T* location) {
|
23
|
-
return location->start;
|
24
|
-
}
|
25
|
-
|
26
|
-
position_T* location_end(location_T* location) {
|
27
|
-
return location->end;
|
28
|
-
}
|
29
|
-
|
30
|
-
location_T* location_copy(location_T* location) {
|
31
|
-
if (location == NULL) { return NULL; }
|
32
|
-
|
33
|
-
return location_init(position_copy(location->start), position_copy(location->end));
|
34
|
-
}
|
35
|
-
|
36
|
-
void location_free(location_T* location) {
|
37
|
-
if (location->start != NULL) { position_free(location->start); }
|
38
|
-
if (location->end != NULL) { position_free(location->end); }
|
39
|
-
|
40
|
-
free(location);
|
4
|
+
void location_from(
|
5
|
+
location_T* location,
|
6
|
+
uint32_t start_line,
|
7
|
+
uint32_t start_column,
|
8
|
+
uint32_t end_line,
|
9
|
+
uint32_t end_column
|
10
|
+
) {
|
11
|
+
location->start = (position_T) { .line = start_line, .column = start_column };
|
12
|
+
location->end = (position_T) { .line = end_line, .column = end_column };
|
41
13
|
}
|