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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/config.yml +14 -14
  3. data/ext/herb/extension_helpers.c +9 -15
  4. data/ext/herb/extension_helpers.h +3 -3
  5. data/ext/herb/nodes.c +1 -1
  6. data/lib/herb/3.0/herb.so +0 -0
  7. data/lib/herb/3.1/herb.so +0 -0
  8. data/lib/herb/3.2/herb.so +0 -0
  9. data/lib/herb/3.3/herb.so +0 -0
  10. data/lib/herb/3.4/herb.so +0 -0
  11. data/lib/herb/engine.rb +10 -6
  12. data/lib/herb/version.rb +1 -1
  13. data/src/analyze.c +43 -80
  14. data/src/ast_node.c +10 -13
  15. data/src/ast_nodes.c +31 -33
  16. data/src/buffer.c +10 -1
  17. data/src/errors.c +35 -35
  18. data/src/include/ast_node.h +3 -3
  19. data/src/include/ast_nodes.h +32 -32
  20. data/src/include/errors.h +21 -21
  21. data/src/include/lexer_peek_helpers.h +8 -6
  22. data/src/include/lexer_struct.h +10 -9
  23. data/src/include/location.h +10 -13
  24. data/src/include/parser_helpers.h +1 -1
  25. data/src/include/position.h +3 -14
  26. data/src/include/pretty_print.h +1 -1
  27. data/src/include/prism_helpers.h +1 -1
  28. data/src/include/range.h +4 -13
  29. data/src/include/token.h +0 -3
  30. data/src/include/token_struct.h +2 -2
  31. data/src/include/version.h +1 -1
  32. data/src/lexer.c +3 -2
  33. data/src/lexer_peek_helpers.c +10 -4
  34. data/src/location.c +9 -37
  35. data/src/parser.c +98 -119
  36. data/src/parser_helpers.c +15 -15
  37. data/src/pretty_print.c +7 -12
  38. data/src/prism_helpers.c +7 -7
  39. data/src/range.c +2 -35
  40. data/src/token.c +25 -29
  41. data/templates/javascript/packages/core/src/visitor.ts.erb +29 -1
  42. data/templates/src/ast_nodes.c.erb +1 -3
  43. data/templates/src/errors.c.erb +5 -7
  44. data/templates/src/include/ast_nodes.h.erb +2 -2
  45. data/templates/src/include/errors.h.erb +3 -3
  46. metadata +2 -3
  47. 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* location;
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* 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);
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
- size_t position;
13
- size_t line;
14
- size_t column;
15
- size_t previous_position;
16
- size_t previous_line;
17
- size_t previous_column;
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
- size_t source_length;
16
+ uint32_t source_length;
16
17
 
17
- size_t current_line;
18
- size_t current_column;
19
- size_t current_position;
18
+ uint32_t current_line;
19
+ uint32_t current_column;
20
+ uint32_t current_position;
20
21
 
21
- size_t previous_line;
22
- size_t previous_column;
23
- size_t previous_position;
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
- size_t stall_counter;
28
- size_t last_position;
28
+ uint32_t stall_counter;
29
+ uint32_t last_position;
29
30
  bool stalled;
30
31
  } lexer_T;
31
32
 
@@ -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* start;
10
- position_T* end;
10
+ position_T start;
11
+ position_T end;
11
12
  } location_T;
12
13
 
13
- location_T* location_init(position_T* start, position_T* end);
14
- location_T* location_from(size_t start_line, size_t start_column, size_t end_line, size_t end_column);
15
-
16
- position_T* location_start(location_T* location);
17
- position_T* location_end_(location_T* location);
18
-
19
- size_t location_sizeof(void);
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
@@ -19,7 +19,7 @@ void parser_append_literal_node_from_buffer(
19
19
  const parser_T* parser,
20
20
  buffer_T* buffer,
21
21
  array_T* children,
22
- position_T* start
22
+ position_T start
23
23
  );
24
24
 
25
25
  bool parser_in_svg_context(const parser_T* parser);
@@ -1,22 +1,11 @@
1
1
  #ifndef HERB_POSITION_H
2
2
  #define HERB_POSITION_H
3
3
 
4
- #include <stdlib.h>
4
+ #include <stdint.h>
5
5
 
6
6
  typedef struct POSITION_STRUCT {
7
- size_t line;
8
- size_t column;
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
@@ -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* location, buffer_T* buffer);
24
+ void pretty_print_location(location_T location, buffer_T* buffer);
25
25
 
26
26
  void pretty_print_property(
27
27
  const char* name,
@@ -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* position_from_source_with_offset(const char* source, size_t offset);
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
- size_t from;
8
- size_t to;
8
+ uint32_t from;
9
+ uint32_t to;
9
10
  } range_T;
10
11
 
11
- range_T* range_init(size_t from, size_t to);
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);
@@ -50,8 +50,8 @@ typedef enum {
50
50
 
51
51
  typedef struct TOKEN_STRUCT {
52
52
  char* value;
53
- range_T* range;
54
- location_T* location;
53
+ range_T range;
54
+ location_T location;
55
55
  token_type_T type;
56
56
  } token_T;
57
57
 
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.7.4"
4
+ #define HERB_VERSION "0.7.5"
5
5
 
6
6
  #endif
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 %zu, col %zu)\n",
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
- size_t saved_position = lexer->current_position;
77
- size_t saved_line = lexer->current_line;
78
- size_t saved_column = lexer->current_column;
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
- size_t location_sizeof(void) {
6
- return sizeof(location_T);
7
- }
8
-
9
- location_T* location_init(position_T* start, position_T* end) {
10
- location_T* location = safe_malloc(location_sizeof());
11
-
12
- location->start = start;
13
- location->end = 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
  }