herb 0.7.5 → 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.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +8 -5
  3. data/config.yml +26 -6
  4. data/ext/herb/error_helpers.c +57 -3
  5. data/ext/herb/error_helpers.h +1 -1
  6. data/ext/herb/extconf.rb +1 -0
  7. data/ext/herb/extension.c +10 -24
  8. data/ext/herb/extension_helpers.c +3 -3
  9. data/ext/herb/extension_helpers.h +1 -1
  10. data/ext/herb/nodes.c +72 -37
  11. data/herb.gemspec +0 -2
  12. data/lib/herb/ast/helpers.rb +11 -0
  13. data/lib/herb/ast/node.rb +15 -6
  14. data/lib/herb/ast/nodes.rb +609 -392
  15. data/lib/herb/cli.rb +31 -0
  16. data/lib/herb/colors.rb +82 -0
  17. data/lib/herb/engine/compiler.rb +140 -14
  18. data/lib/herb/engine/debug_visitor.rb +1 -5
  19. data/lib/herb/engine/parser_error_overlay.rb +1 -1
  20. data/lib/herb/engine.rb +8 -14
  21. data/lib/herb/errors.rb +166 -56
  22. data/lib/herb/location.rb +2 -2
  23. data/lib/herb/project.rb +86 -21
  24. data/lib/herb/token.rb +14 -2
  25. data/lib/herb/version.rb +1 -1
  26. data/lib/herb.rb +1 -0
  27. data/sig/herb/ast/helpers.rbs +3 -0
  28. data/sig/herb/ast/node.rbs +12 -5
  29. data/sig/herb/ast/nodes.rbs +124 -62
  30. data/sig/herb/colors.rbs +35 -0
  31. data/sig/herb/engine/compiler.rbs +23 -1
  32. data/sig/herb/errors.rbs +74 -20
  33. data/sig/herb/token.rbs +8 -0
  34. data/sig/herb_c_extension.rbs +1 -1
  35. data/sig/serialized_ast_errors.rbs +8 -0
  36. data/src/analyze.c +420 -171
  37. data/src/analyze_helpers.c +5 -0
  38. data/src/analyze_missing_end.c +147 -0
  39. data/src/analyze_transform.c +196 -0
  40. data/src/analyzed_ruby.c +23 -2
  41. data/src/ast_node.c +5 -5
  42. data/src/ast_nodes.c +179 -179
  43. data/src/ast_pretty_print.c +232 -232
  44. data/src/element_source.c +7 -6
  45. data/src/errors.c +246 -126
  46. data/src/extract.c +92 -34
  47. data/src/herb.c +37 -49
  48. data/src/html_util.c +34 -96
  49. data/src/include/analyze.h +10 -2
  50. data/src/include/analyze_helpers.h +3 -0
  51. data/src/include/analyzed_ruby.h +4 -2
  52. data/src/include/ast_node.h +2 -2
  53. data/src/include/ast_nodes.h +67 -66
  54. data/src/include/ast_pretty_print.h +2 -2
  55. data/src/include/element_source.h +3 -1
  56. data/src/include/errors.h +30 -14
  57. data/src/include/extract.h +4 -4
  58. data/src/include/herb.h +6 -7
  59. data/src/include/html_util.h +4 -5
  60. data/src/include/lexer.h +1 -3
  61. data/src/include/lexer_peek_helpers.h +14 -14
  62. data/src/include/lexer_struct.h +3 -2
  63. data/src/include/macros.h +4 -0
  64. data/src/include/parser.h +12 -6
  65. data/src/include/parser_helpers.h +25 -15
  66. data/src/include/pretty_print.h +38 -28
  67. data/src/include/token.h +5 -8
  68. data/src/include/utf8.h +3 -2
  69. data/src/include/util/hb_arena.h +31 -0
  70. data/src/include/util/hb_arena_debug.h +8 -0
  71. data/src/include/util/hb_array.h +33 -0
  72. data/src/include/util/hb_buffer.h +34 -0
  73. data/src/include/util/hb_string.h +29 -0
  74. data/src/include/util/hb_system.h +9 -0
  75. data/src/include/util.h +3 -14
  76. data/src/include/version.h +1 -1
  77. data/src/include/visitor.h +1 -1
  78. data/src/io.c +7 -4
  79. data/src/lexer.c +61 -88
  80. data/src/lexer_peek_helpers.c +35 -37
  81. data/src/main.c +19 -23
  82. data/src/parser.c +282 -201
  83. data/src/parser_helpers.c +46 -40
  84. data/src/parser_match_tags.c +316 -0
  85. data/src/pretty_print.c +82 -106
  86. data/src/token.c +18 -65
  87. data/src/utf8.c +4 -4
  88. data/src/util/hb_arena.c +179 -0
  89. data/src/util/hb_arena_debug.c +237 -0
  90. data/src/{array.c → util/hb_array.c} +26 -27
  91. data/src/util/hb_buffer.c +203 -0
  92. data/src/util/hb_string.c +85 -0
  93. data/src/util/hb_system.c +30 -0
  94. data/src/util.c +29 -99
  95. data/src/visitor.c +54 -54
  96. data/templates/ext/herb/error_helpers.c.erb +3 -3
  97. data/templates/ext/herb/error_helpers.h.erb +1 -1
  98. data/templates/ext/herb/nodes.c.erb +11 -6
  99. data/templates/java/error_helpers.c.erb +75 -0
  100. data/templates/java/error_helpers.h.erb +20 -0
  101. data/templates/java/nodes.c.erb +97 -0
  102. data/templates/java/nodes.h.erb +23 -0
  103. data/templates/java/org/herb/ast/Errors.java.erb +121 -0
  104. data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
  105. data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
  106. data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
  107. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
  108. data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
  109. data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
  110. data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
  111. data/templates/lib/herb/ast/nodes.rb.erb +28 -16
  112. data/templates/lib/herb/errors.rb.erb +17 -12
  113. data/templates/rust/src/ast/nodes.rs.erb +220 -0
  114. data/templates/rust/src/errors.rs.erb +216 -0
  115. data/templates/rust/src/nodes.rs.erb +374 -0
  116. data/templates/src/analyze_missing_end.c.erb +36 -0
  117. data/templates/src/analyze_transform.c.erb +24 -0
  118. data/templates/src/ast_nodes.c.erb +14 -14
  119. data/templates/src/ast_pretty_print.c.erb +36 -36
  120. data/templates/src/errors.c.erb +31 -31
  121. data/templates/src/include/ast_nodes.h.erb +10 -9
  122. data/templates/src/include/ast_pretty_print.h.erb +2 -2
  123. data/templates/src/include/errors.h.erb +6 -6
  124. data/templates/src/parser_match_tags.c.erb +38 -0
  125. data/templates/src/visitor.c.erb +4 -4
  126. data/templates/template.rb +22 -3
  127. data/templates/wasm/error_helpers.cpp.erb +9 -9
  128. data/templates/wasm/error_helpers.h.erb +1 -1
  129. data/templates/wasm/nodes.cpp.erb +9 -9
  130. data/templates/wasm/nodes.h.erb +1 -1
  131. data/vendor/prism/Rakefile +4 -1
  132. data/vendor/prism/config.yml +2 -1
  133. data/vendor/prism/include/prism/ast.h +31 -1
  134. data/vendor/prism/include/prism/diagnostic.h +1 -0
  135. data/vendor/prism/include/prism/version.h +3 -3
  136. data/vendor/prism/src/diagnostic.c +3 -1
  137. data/vendor/prism/src/prism.c +130 -71
  138. data/vendor/prism/src/util/pm_string.c +6 -8
  139. data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
  140. data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
  141. data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
  142. data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
  143. data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
  144. data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
  145. metadata +34 -20
  146. data/lib/herb/libherb/array.rb +0 -51
  147. data/lib/herb/libherb/ast_node.rb +0 -50
  148. data/lib/herb/libherb/buffer.rb +0 -56
  149. data/lib/herb/libherb/extract_result.rb +0 -20
  150. data/lib/herb/libherb/lex_result.rb +0 -32
  151. data/lib/herb/libherb/libherb.rb +0 -52
  152. data/lib/herb/libherb/parse_result.rb +0 -20
  153. data/lib/herb/libherb/token.rb +0 -46
  154. data/lib/herb/libherb.rb +0 -35
  155. data/src/buffer.c +0 -241
  156. data/src/include/array.h +0 -33
  157. data/src/include/buffer.h +0 -39
  158. data/src/include/json.h +0 -28
  159. data/src/include/memory.h +0 -12
  160. data/src/json.c +0 -205
  161. data/src/memory.c +0 -53
@@ -1,47 +1,57 @@
1
1
  #ifndef HERB_PARSER_HELPERS_H
2
2
  #define HERB_PARSER_HELPERS_H
3
3
 
4
- #include "array.h"
5
4
  #include "ast_nodes.h"
6
- #include "buffer.h"
7
5
  #include "errors.h"
8
6
  #include "parser.h"
9
7
  #include "token.h"
8
+ #include "util/hb_array.h"
9
+ #include "util/hb_buffer.h"
10
+ #include "util/hb_string.h"
10
11
 
11
12
  void parser_push_open_tag(const parser_T* parser, token_T* tag_name);
12
- bool parser_check_matching_tag(const parser_T* parser, const char* tag_name);
13
+ bool parser_check_matching_tag(const parser_T* parser, hb_string_T tag_name);
13
14
  token_T* parser_pop_open_tag(const parser_T* parser);
14
15
 
15
- void parser_append_unexpected_error(parser_T* parser, const char* description, const char* expected, array_T* errors);
16
- void parser_append_unexpected_token_error(parser_T* parser, token_type_T expected_type, array_T* errors);
16
+ void parser_append_unexpected_error(
17
+ parser_T* parser,
18
+ const char* description,
19
+ const char* expected,
20
+ hb_array_T* errors
21
+ );
22
+ void parser_append_unexpected_token_error(parser_T* parser, token_type_T expected_type, hb_array_T* errors);
17
23
 
18
24
  void parser_append_literal_node_from_buffer(
19
25
  const parser_T* parser,
20
- buffer_T* buffer,
21
- array_T* children,
26
+ hb_buffer_T* buffer,
27
+ hb_array_T* children,
22
28
  position_T start
23
29
  );
24
30
 
25
31
  bool parser_in_svg_context(const parser_T* parser);
26
32
 
27
- foreign_content_type_T parser_get_foreign_content_type(const char* tag_name);
28
- bool parser_is_foreign_content_tag(const char* tag_name);
29
- const char* parser_get_foreign_content_closing_tag(foreign_content_type_T type);
33
+ foreign_content_type_T parser_get_foreign_content_type(hb_string_T tag_name);
34
+ bool parser_is_foreign_content_tag(hb_string_T tag_name);
35
+ hb_string_T parser_get_foreign_content_closing_tag(foreign_content_type_T type);
30
36
 
31
37
  void parser_enter_foreign_content(parser_T* parser, foreign_content_type_T type);
32
38
  void parser_exit_foreign_content(parser_T* parser);
33
39
 
34
- bool parser_is_expected_closing_tag_name(const char* tag_name, foreign_content_type_T expected_type);
40
+ bool parser_is_expected_closing_tag_name(hb_string_T tag_name, foreign_content_type_T expected_type);
35
41
 
36
42
  token_T* parser_advance(parser_T* parser);
37
43
  token_T* parser_consume_if_present(parser_T* parser, token_type_T type);
38
- token_T* parser_consume_expected(parser_T* parser, token_type_T type, array_T* array);
44
+ token_T* parser_consume_expected(parser_T* parser, token_type_T type, hb_array_T* array);
39
45
 
40
46
  AST_HTML_ELEMENT_NODE_T* parser_handle_missing_close_tag(
41
47
  AST_HTML_OPEN_TAG_NODE_T* open_tag,
42
- array_T* body,
43
- array_T* errors
48
+ hb_array_T* body,
49
+ hb_array_T* errors
50
+ );
51
+ void parser_handle_mismatched_tags(
52
+ const parser_T* parser,
53
+ const AST_HTML_CLOSE_TAG_NODE_T* close_tag,
54
+ hb_array_T* errors
44
55
  );
45
- void parser_handle_mismatched_tags(const parser_T* parser, const AST_HTML_CLOSE_TAG_NODE_T* close_tag, array_T* errors);
46
56
 
47
57
  #endif
@@ -3,91 +3,101 @@
3
3
 
4
4
  #include "analyzed_ruby.h"
5
5
  #include "ast_nodes.h"
6
- #include "buffer.h"
7
6
  #include "location.h"
7
+ #include "util/hb_buffer.h"
8
8
 
9
9
  #include <stdbool.h>
10
10
 
11
- void pretty_print_indent(buffer_T* buffer, size_t indent);
12
- void pretty_print_newline(size_t indent, size_t relative_indent, buffer_T* buffer);
13
- void pretty_print_label(const char* name, size_t indent, size_t relative_indent, bool last_property, buffer_T* buffer);
11
+ void pretty_print_indent(hb_buffer_T* buffer, size_t indent);
12
+ void pretty_print_newline(size_t indent, size_t relative_indent, hb_buffer_T* buffer);
13
+ void pretty_print_label(
14
+ hb_string_T name,
15
+ size_t indent,
16
+ size_t relative_indent,
17
+ bool last_property,
18
+ hb_buffer_T* buffer
19
+ );
14
20
 
15
21
  void pretty_print_position_property(
16
22
  position_T* position,
17
- const char* name,
23
+ hb_string_T name,
18
24
  size_t indent,
19
25
  size_t relative_indent,
20
26
  bool last_property,
21
- buffer_T* buffer
27
+ hb_buffer_T* buffer
22
28
  );
23
29
 
24
- void pretty_print_location(location_T location, buffer_T* buffer);
30
+ void pretty_print_location(location_T location, hb_buffer_T* buffer);
25
31
 
26
32
  void pretty_print_property(
27
- const char* name,
28
- const char* value,
33
+ hb_string_T name,
34
+ hb_string_T value,
29
35
  size_t indent,
30
36
  size_t relative_indent,
31
37
  bool last_property,
32
- buffer_T* buffer
38
+ hb_buffer_T* buffer
33
39
  );
34
40
 
35
41
  void pretty_print_size_t_property(
36
42
  size_t value,
37
- const char* name,
43
+ hb_string_T name,
38
44
  size_t indent,
39
45
  size_t relative_indent,
40
46
  bool last_property,
41
- buffer_T* buffer
47
+ hb_buffer_T* buffer
42
48
  );
43
49
 
44
50
  void pretty_print_string_property(
45
- const char* string,
46
- const char* name,
51
+ hb_string_T string,
52
+ hb_string_T name,
47
53
  size_t indent,
48
54
  size_t relative_indent,
49
55
  bool last_property,
50
- buffer_T* buffer
56
+ hb_buffer_T* buffer
51
57
  );
52
58
 
53
59
  void pretty_print_quoted_property(
54
- const char* name,
55
- const char* value,
60
+ hb_string_T name,
61
+ hb_string_T value,
56
62
  size_t indent,
57
63
  size_t relative_indent,
58
64
  bool last_property,
59
- buffer_T* buffer
65
+ hb_buffer_T* buffer
60
66
  );
61
67
 
62
68
  void pretty_print_boolean_property(
63
- const char* name,
69
+ hb_string_T name,
64
70
  bool value,
65
71
  size_t indent,
66
72
  size_t relative_indent,
67
73
  bool last_property,
68
- buffer_T* buffer
74
+ hb_buffer_T* buffer
69
75
  );
70
76
 
71
77
  void pretty_print_token_property(
72
78
  token_T* token,
73
- const char* name,
79
+ hb_string_T name,
74
80
  size_t indent,
75
81
  size_t relative_indent,
76
82
  bool last_property,
77
- buffer_T* buffer
83
+ hb_buffer_T* buffer
78
84
  );
79
85
 
80
86
  void pretty_print_array(
81
- const char* name,
82
- array_T* array,
87
+ hb_string_T name,
88
+ hb_array_T* array,
83
89
  size_t indent,
84
90
  size_t relative_indent,
85
91
  bool last_property,
86
- buffer_T* buffer
92
+ hb_buffer_T* buffer
87
93
  );
88
94
 
89
- void pretty_print_errors(AST_NODE_T* node, size_t indent, size_t relative_indent, bool last_property, buffer_T* buffer);
90
-
91
- void pretty_print_analyzed_ruby(analyzed_ruby_T* analyzed, const char* source);
95
+ void pretty_print_errors(
96
+ AST_NODE_T* node,
97
+ size_t indent,
98
+ size_t relative_indent,
99
+ bool last_property,
100
+ hb_buffer_T* buffer
101
+ );
92
102
 
93
103
  #endif
data/src/include/token.h CHANGED
@@ -4,19 +4,16 @@
4
4
  #include "lexer_struct.h"
5
5
  #include "position.h"
6
6
  #include "token_struct.h"
7
+ #include "util/hb_string.h"
7
8
 
8
- token_T* token_init(const char* value, token_type_T type, lexer_T* lexer);
9
- char* token_to_string(const token_T* token);
10
- char* token_to_json(const token_T* token);
9
+ token_T* token_init(hb_string_T value, token_type_T type, lexer_T* lexer);
10
+ hb_string_T token_to_string(const token_T* token);
11
11
  const char* token_type_to_string(token_type_T type);
12
12
 
13
- char* token_value(const token_T* token);
14
- int token_type(const token_T* token);
15
-
16
- size_t token_sizeof(void);
17
-
18
13
  token_T* token_copy(token_T* token);
19
14
 
20
15
  void token_free(token_T* token);
21
16
 
17
+ bool token_value_empty(const token_T* token);
18
+
22
19
  #endif
data/src/include/utf8.h CHANGED
@@ -2,10 +2,11 @@
2
2
  #define HERB_UTF8_H
3
3
 
4
4
  #include <stdbool.h>
5
+ #include <stdint.h>
5
6
  #include <stdlib.h>
6
7
 
7
- int utf8_char_byte_length(unsigned char first_byte);
8
- int utf8_sequence_length(const char* str, size_t position, size_t max_length);
8
+ uint32_t utf8_char_byte_length(unsigned char first_byte);
9
+ uint32_t utf8_sequence_length(const char* str, size_t position, size_t max_length);
9
10
  bool utf8_is_valid_continuation_byte(unsigned char byte);
10
11
 
11
12
  #endif
@@ -0,0 +1,31 @@
1
+ #ifndef HERB_ARENA_H
2
+ #define HERB_ARENA_H
3
+
4
+ #include <stdbool.h>
5
+ #include <stddef.h>
6
+
7
+ typedef struct HB_ARENA_PAGE_STRUCT hb_arena_page_T;
8
+
9
+ struct HB_ARENA_PAGE_STRUCT {
10
+ hb_arena_page_T* next;
11
+ size_t capacity;
12
+ size_t position;
13
+ char memory[];
14
+ };
15
+
16
+ typedef struct HB_ARENA_STRUCT {
17
+ hb_arena_page_T* head;
18
+ hb_arena_page_T* tail;
19
+ size_t default_page_size;
20
+ size_t allocation_count;
21
+ } hb_arena_T;
22
+
23
+ bool hb_arena_init(hb_arena_T* allocator, size_t initial_size);
24
+ void* hb_arena_alloc(hb_arena_T* allocator, size_t size);
25
+ size_t hb_arena_position(hb_arena_T* allocator);
26
+ size_t hb_arena_capacity(hb_arena_T* allocator);
27
+ void hb_arena_reset(hb_arena_T* allocator);
28
+ void hb_arena_reset_to(hb_arena_T* allocator, size_t new_position);
29
+ void hb_arena_free(hb_arena_T* allocator);
30
+
31
+ #endif
@@ -0,0 +1,8 @@
1
+ #ifndef HERB_ARENA_DEBUG_H
2
+ #define HERB_ARENA_DEBUG_H
3
+
4
+ #include "hb_arena.h"
5
+
6
+ void hb_arena_print_stats(const hb_arena_T* allocator);
7
+
8
+ #endif
@@ -0,0 +1,33 @@
1
+ #ifndef HERB_ARRAY_H
2
+ #define HERB_ARRAY_H
3
+
4
+ #include <stdlib.h>
5
+
6
+ typedef struct HB_ARRAY_STRUCT {
7
+ void** items;
8
+ size_t size;
9
+ size_t capacity;
10
+ } hb_array_T;
11
+
12
+ hb_array_T* hb_array_init(size_t capacity);
13
+
14
+ void* hb_array_get(const hb_array_T* array, size_t index);
15
+ void* hb_array_first(hb_array_T* array);
16
+ void* hb_array_last(hb_array_T* array);
17
+
18
+ void hb_array_append(hb_array_T* array, void* item);
19
+ void hb_array_set(const hb_array_T* array, size_t index, void* item);
20
+ void hb_array_free(hb_array_T** array);
21
+ void hb_array_remove(hb_array_T* array, size_t index);
22
+
23
+ size_t hb_array_index_of(hb_array_T* array, void* item);
24
+ void hb_array_remove_item(hb_array_T* array, void* item);
25
+
26
+ void hb_array_push(hb_array_T* array, void* item);
27
+ void* hb_array_pop(hb_array_T* array);
28
+
29
+ size_t hb_array_capacity(const hb_array_T* array);
30
+ size_t hb_array_size(const hb_array_T* array);
31
+ size_t hb_array_sizeof(void);
32
+
33
+ #endif
@@ -0,0 +1,34 @@
1
+ #ifndef HERB_BUFFER_H
2
+ #define HERB_BUFFER_H
3
+
4
+ #include "hb_string.h"
5
+
6
+ #include <stdbool.h>
7
+ #include <stdlib.h>
8
+
9
+ typedef struct HB_BUFFER_STRUCT {
10
+ char* value;
11
+ size_t length;
12
+ size_t capacity;
13
+ } hb_buffer_T;
14
+
15
+ bool hb_buffer_init(hb_buffer_T* buffer, size_t capacity);
16
+
17
+ void hb_buffer_append(hb_buffer_T* buffer, const char* text);
18
+ void hb_buffer_append_with_length(hb_buffer_T* buffer, const char* text, size_t length);
19
+ void hb_buffer_append_string(hb_buffer_T* buffer, hb_string_T string);
20
+ void hb_buffer_append_char(hb_buffer_T* buffer, char character);
21
+ void hb_buffer_append_whitespace(hb_buffer_T* buffer, size_t length);
22
+ void hb_buffer_prepend(hb_buffer_T* buffer, const char* text);
23
+ void hb_buffer_concat(hb_buffer_T* destination, hb_buffer_T* source);
24
+
25
+ char* hb_buffer_value(const hb_buffer_T* buffer);
26
+
27
+ size_t hb_buffer_length(const hb_buffer_T* buffer);
28
+ size_t hb_buffer_capacity(const hb_buffer_T* buffer);
29
+ size_t hb_buffer_sizeof(void);
30
+
31
+ void hb_buffer_clear(hb_buffer_T* buffer);
32
+ void hb_buffer_free(hb_buffer_T** buffer);
33
+
34
+ #endif
@@ -0,0 +1,29 @@
1
+ #ifndef HERB_STRING_H
2
+ #define HERB_STRING_H
3
+
4
+ #include <stdbool.h>
5
+ #include <stddef.h>
6
+ #include <stdint.h>
7
+
8
+ #include "hb_arena.h"
9
+
10
+ typedef struct HB_STRING_STRUCT {
11
+ char* data;
12
+ uint32_t length;
13
+ } hb_string_T;
14
+
15
+ hb_string_T hb_string(const char* null_terminated_c_string);
16
+ hb_string_T hb_string_slice(hb_string_T string, uint32_t offset);
17
+ bool hb_string_equals(hb_string_T a, hb_string_T b);
18
+ bool hb_string_equals_case_insensitive(hb_string_T a, hb_string_T b);
19
+ bool hb_string_starts_with(hb_string_T string, hb_string_T expected_prefix);
20
+ bool hb_string_is_empty(hb_string_T string);
21
+ hb_string_T hb_string_truncate(hb_string_T string, uint32_t max_length);
22
+
23
+ hb_string_T hb_string_range(hb_string_T string, uint32_t from, uint32_t to);
24
+
25
+ char* hb_string_to_c_string_using_malloc(hb_string_T string);
26
+
27
+ char* hb_string_to_c_string(hb_arena_T* allocator, hb_string_T string);
28
+
29
+ #endif
@@ -0,0 +1,9 @@
1
+ #ifndef HERB_SYSTEM_H
2
+ #define HERB_SYSTEM_H
3
+
4
+ #include <stddef.h>
5
+
6
+ void* hb_system_allocate_memory(size_t size);
7
+ void hb_system_free_memory(void* ptr, size_t size);
8
+
9
+ #endif
data/src/include/util.h CHANGED
@@ -1,25 +1,14 @@
1
1
  #ifndef HERB_UTIL_H
2
2
  #define HERB_UTIL_H
3
3
 
4
+ #include "util/hb_string.h"
4
5
  #include <stdbool.h>
5
6
  #include <stdlib.h>
6
7
 
7
- int is_whitespace(int character);
8
8
  int is_newline(int character);
9
9
 
10
- int count_in_string(const char* string, char character);
11
- int count_newlines(const char* string);
12
-
13
- char* replace_char(char* string, char find, char replace);
14
- char* escape_newlines(const char* input);
15
- char* quoted_string(const char* input);
16
- char* wrap_string(const char* input, char character);
17
-
18
- bool string_blank(const char* input);
19
- bool string_present(const char* input);
20
-
10
+ hb_string_T escape_newlines(hb_string_T input);
11
+ hb_string_T quoted_string(hb_string_T input);
21
12
  char* herb_strdup(const char* s);
22
13
 
23
- char* size_t_to_string(size_t value);
24
-
25
14
  #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.7.5"
4
+ #define HERB_VERSION "0.8.0"
5
5
 
6
6
  #endif
@@ -1,9 +1,9 @@
1
1
  #ifndef HERB_VISITOR_H
2
2
  #define HERB_VISITOR_H
3
3
 
4
- #include "array.h"
5
4
  #include "ast_node.h"
6
5
  #include "ast_nodes.h"
6
+ #include "util/hb_array.h"
7
7
 
8
8
  void herb_visit_node(const AST_NODE_T* node, bool (*visitor)(const AST_NODE_T*, void*), void* data);
9
9
  void herb_visit_child_nodes(const AST_NODE_T* node, bool (*visitor)(const AST_NODE_T* node, void* data), void* data);
data/src/io.c CHANGED
@@ -1,5 +1,5 @@
1
1
  #include "include/io.h"
2
- #include "include/buffer.h"
2
+ #include "include/util/hb_buffer.h"
3
3
 
4
4
  #include <errno.h>
5
5
  #include <stdio.h>
@@ -8,6 +8,8 @@
8
8
  #define FILE_READ_CHUNK 4096
9
9
 
10
10
  char* herb_read_file(const char* filename) {
11
+ if (!filename) { return NULL; }
12
+
11
13
  FILE* fp = fopen(filename, "rb");
12
14
 
13
15
  if (fp == NULL) {
@@ -15,16 +17,17 @@ char* herb_read_file(const char* filename) {
15
17
  exit(1);
16
18
  }
17
19
 
18
- buffer_T buffer = buffer_new();
20
+ hb_buffer_T buffer;
21
+ hb_buffer_init(&buffer, 4096);
19
22
 
20
23
  char chunk[FILE_READ_CHUNK];
21
24
  size_t bytes_read;
22
25
 
23
26
  while ((bytes_read = fread(chunk, 1, FILE_READ_CHUNK, fp)) > 0) {
24
- buffer_append_with_length(&buffer, chunk, bytes_read);
27
+ hb_buffer_append_with_length(&buffer, chunk, bytes_read);
25
28
  }
26
29
 
27
30
  fclose(fp);
28
31
 
29
- return buffer_value(&buffer);
32
+ return hb_buffer_value(&buffer);
30
33
  }