@herb-tools/node 0.7.4 → 0.7.5
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 +0 -1
- package/dist/herb-node.esm.js +1 -1
- package/extension/error_helpers.cpp +1 -1
- package/extension/error_helpers.h +1 -1
- package/extension/extension_helpers.cpp +9 -27
- package/extension/extension_helpers.h +3 -3
- package/extension/libherb/analyze.c +43 -80
- package/extension/libherb/ast_node.c +10 -13
- package/extension/libherb/ast_node.h +3 -3
- package/extension/libherb/ast_nodes.c +32 -34
- package/extension/libherb/ast_nodes.h +33 -33
- package/extension/libherb/ast_pretty_print.c +1 -1
- package/extension/libherb/ast_pretty_print.h +1 -1
- package/extension/libherb/buffer.c +10 -1
- package/extension/libherb/errors.c +36 -36
- package/extension/libherb/errors.h +22 -22
- package/extension/libherb/include/ast_node.h +3 -3
- package/extension/libherb/include/ast_nodes.h +33 -33
- package/extension/libherb/include/ast_pretty_print.h +1 -1
- package/extension/libherb/include/errors.h +22 -22
- package/extension/libherb/include/lexer_peek_helpers.h +8 -6
- package/extension/libherb/include/lexer_struct.h +10 -9
- package/extension/libherb/include/location.h +10 -13
- package/extension/libherb/include/parser_helpers.h +1 -1
- package/extension/libherb/include/position.h +3 -14
- package/extension/libherb/include/pretty_print.h +1 -1
- package/extension/libherb/include/prism_helpers.h +1 -1
- package/extension/libherb/include/range.h +4 -13
- package/extension/libherb/include/token.h +0 -3
- package/extension/libherb/include/token_struct.h +2 -2
- package/extension/libherb/include/version.h +1 -1
- package/extension/libherb/lexer.c +3 -2
- package/extension/libherb/lexer_peek_helpers.c +10 -4
- package/extension/libherb/lexer_peek_helpers.h +8 -6
- package/extension/libherb/lexer_struct.h +10 -9
- package/extension/libherb/location.c +9 -37
- package/extension/libherb/location.h +10 -13
- package/extension/libherb/parser.c +98 -119
- package/extension/libherb/parser_helpers.c +15 -15
- package/extension/libherb/parser_helpers.h +1 -1
- package/extension/libherb/position.h +3 -14
- package/extension/libherb/pretty_print.c +7 -12
- package/extension/libherb/pretty_print.h +1 -1
- 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 +25 -29
- package/extension/libherb/token.h +0 -3
- package/extension/libherb/token_struct.h +2 -2
- package/extension/libherb/version.h +1 -1
- package/extension/libherb/visitor.c +1 -1
- package/extension/nodes.cpp +1 -1
- package/extension/nodes.h +1 -1
- package/package.json +2 -2
- package/extension/libherb/position.c +0 -33
|
@@ -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
|
|
@@ -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
|
|
@@ -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);
|
|
@@ -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);
|
|
@@ -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
|
}
|
|
@@ -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);
|
|
@@ -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
|
|
|
@@ -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
|
}
|
|
@@ -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
|