@herb-tools/node 0.7.4 → 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 (131) hide show
  1. package/binding.gyp +8 -5
  2. package/dist/herb-node.esm.js +6 -6
  3. package/dist/herb-node.esm.js.map +1 -1
  4. package/extension/error_helpers.cpp +67 -9
  5. package/extension/error_helpers.h +4 -2
  6. package/extension/extension_helpers.cpp +20 -31
  7. package/extension/extension_helpers.h +7 -5
  8. package/extension/herb.cpp +10 -42
  9. package/extension/libherb/analyze.c +461 -249
  10. package/extension/libherb/analyze.h +10 -2
  11. package/extension/libherb/analyze_helpers.c +5 -0
  12. package/extension/libherb/analyze_helpers.h +3 -0
  13. package/extension/libherb/analyze_missing_end.c +147 -0
  14. package/extension/libherb/analyze_transform.c +196 -0
  15. package/extension/libherb/analyzed_ruby.c +23 -2
  16. package/extension/libherb/analyzed_ruby.h +4 -2
  17. package/extension/libherb/ast_node.c +14 -17
  18. package/extension/libherb/ast_node.h +4 -4
  19. package/extension/libherb/ast_nodes.c +180 -182
  20. package/extension/libherb/ast_nodes.h +69 -68
  21. package/extension/libherb/ast_pretty_print.c +233 -233
  22. package/extension/libherb/ast_pretty_print.h +3 -3
  23. package/extension/libherb/element_source.c +7 -6
  24. package/extension/libherb/element_source.h +3 -1
  25. package/extension/libherb/errors.c +273 -153
  26. package/extension/libherb/errors.h +43 -27
  27. package/extension/libherb/extract.c +92 -34
  28. package/extension/libherb/extract.h +4 -4
  29. package/extension/libherb/herb.c +37 -49
  30. package/extension/libherb/herb.h +6 -7
  31. package/extension/libherb/html_util.c +34 -96
  32. package/extension/libherb/html_util.h +4 -5
  33. package/extension/libherb/include/analyze.h +10 -2
  34. package/extension/libherb/include/analyze_helpers.h +3 -0
  35. package/extension/libherb/include/analyzed_ruby.h +4 -2
  36. package/extension/libherb/include/ast_node.h +4 -4
  37. package/extension/libherb/include/ast_nodes.h +69 -68
  38. package/extension/libherb/include/ast_pretty_print.h +3 -3
  39. package/extension/libherb/include/element_source.h +3 -1
  40. package/extension/libherb/include/errors.h +43 -27
  41. package/extension/libherb/include/extract.h +4 -4
  42. package/extension/libherb/include/herb.h +6 -7
  43. package/extension/libherb/include/html_util.h +4 -5
  44. package/extension/libherb/include/lexer.h +1 -3
  45. package/extension/libherb/include/lexer_peek_helpers.h +21 -19
  46. package/extension/libherb/include/lexer_struct.h +12 -10
  47. package/extension/libherb/include/location.h +10 -13
  48. package/extension/libherb/include/macros.h +4 -0
  49. package/extension/libherb/include/parser.h +12 -6
  50. package/extension/libherb/include/parser_helpers.h +26 -16
  51. package/extension/libherb/include/position.h +3 -14
  52. package/extension/libherb/include/pretty_print.h +38 -28
  53. package/extension/libherb/include/prism_helpers.h +1 -1
  54. package/extension/libherb/include/range.h +4 -13
  55. package/extension/libherb/include/token.h +5 -11
  56. package/extension/libherb/include/token_struct.h +2 -2
  57. package/extension/libherb/include/utf8.h +3 -2
  58. package/extension/libherb/include/util/hb_arena.h +31 -0
  59. package/extension/libherb/include/util/hb_arena_debug.h +8 -0
  60. package/extension/libherb/include/util/hb_array.h +33 -0
  61. package/extension/libherb/include/util/hb_buffer.h +34 -0
  62. package/extension/libherb/include/util/hb_string.h +29 -0
  63. package/extension/libherb/include/util/hb_system.h +9 -0
  64. package/extension/libherb/include/util.h +3 -14
  65. package/extension/libherb/include/version.h +1 -1
  66. package/extension/libherb/include/visitor.h +1 -1
  67. package/extension/libherb/io.c +7 -4
  68. package/extension/libherb/lexer.c +62 -88
  69. package/extension/libherb/lexer.h +1 -3
  70. package/extension/libherb/lexer_peek_helpers.c +42 -38
  71. package/extension/libherb/lexer_peek_helpers.h +21 -19
  72. package/extension/libherb/lexer_struct.h +12 -10
  73. package/extension/libherb/location.c +9 -37
  74. package/extension/libherb/location.h +10 -13
  75. package/extension/libherb/macros.h +4 -0
  76. package/extension/libherb/main.c +19 -23
  77. package/extension/libherb/parser.c +373 -313
  78. package/extension/libherb/parser.h +12 -6
  79. package/extension/libherb/parser_helpers.c +60 -54
  80. package/extension/libherb/parser_helpers.h +26 -16
  81. package/extension/libherb/parser_match_tags.c +316 -0
  82. package/extension/libherb/position.h +3 -14
  83. package/extension/libherb/pretty_print.c +88 -117
  84. package/extension/libherb/pretty_print.h +38 -28
  85. package/extension/libherb/prism_helpers.c +7 -7
  86. package/extension/libherb/prism_helpers.h +1 -1
  87. package/extension/libherb/range.c +2 -35
  88. package/extension/libherb/range.h +4 -13
  89. package/extension/libherb/token.c +36 -87
  90. package/extension/libherb/token.h +5 -11
  91. package/extension/libherb/token_struct.h +2 -2
  92. package/extension/libherb/utf8.c +4 -4
  93. package/extension/libherb/utf8.h +3 -2
  94. package/extension/libherb/util/hb_arena.c +179 -0
  95. package/extension/libherb/util/hb_arena.h +31 -0
  96. package/extension/libherb/util/hb_arena_debug.c +237 -0
  97. package/extension/libherb/util/hb_arena_debug.h +8 -0
  98. package/extension/libherb/{array.c → util/hb_array.c} +26 -27
  99. package/extension/libherb/util/hb_array.h +33 -0
  100. package/extension/libherb/util/hb_buffer.c +203 -0
  101. package/extension/libherb/util/hb_buffer.h +34 -0
  102. package/extension/libherb/util/hb_string.c +85 -0
  103. package/extension/libherb/util/hb_string.h +29 -0
  104. package/extension/libherb/util/hb_system.c +30 -0
  105. package/extension/libherb/util/hb_system.h +9 -0
  106. package/extension/libherb/util.c +29 -99
  107. package/extension/libherb/util.h +3 -14
  108. package/extension/libherb/version.h +1 -1
  109. package/extension/libherb/visitor.c +55 -55
  110. package/extension/libherb/visitor.h +1 -1
  111. package/extension/nodes.cpp +40 -40
  112. package/extension/nodes.h +2 -2
  113. package/extension/prism/include/prism/ast.h +31 -1
  114. package/extension/prism/include/prism/diagnostic.h +1 -0
  115. package/extension/prism/include/prism/version.h +3 -3
  116. package/extension/prism/src/diagnostic.c +3 -1
  117. package/extension/prism/src/prism.c +130 -71
  118. package/extension/prism/src/util/pm_string.c +6 -8
  119. package/package.json +3 -3
  120. package/extension/libherb/array.h +0 -33
  121. package/extension/libherb/buffer.c +0 -232
  122. package/extension/libherb/buffer.h +0 -39
  123. package/extension/libherb/include/array.h +0 -33
  124. package/extension/libherb/include/buffer.h +0 -39
  125. package/extension/libherb/include/json.h +0 -28
  126. package/extension/libherb/include/memory.h +0 -12
  127. package/extension/libherb/json.c +0 -205
  128. package/extension/libherb/json.h +0 -28
  129. package/extension/libherb/memory.c +0 -53
  130. package/extension/libherb/memory.h +0 -12
  131. package/extension/libherb/position.c +0 -33
@@ -1,15 +1,15 @@
1
1
  // NOTE: This file is generated by the templates/template.rb script and should not
2
- // be modified manually. See /Users/marcoroth/Development/herb-release-0.7.4/templates/src/include/errors.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.0/templates/src/include/errors.h.erb
3
3
 
4
4
  #ifndef HERB_ERRORS_H
5
5
  #define HERB_ERRORS_H
6
6
 
7
- #include "array.h"
8
- #include "buffer.h"
9
7
  #include "errors.h"
10
8
  #include "location.h"
11
9
  #include "position.h"
12
10
  #include "token.h"
11
+ #include "util/hb_array.h"
12
+ #include "util/hb_buffer.h"
13
13
 
14
14
  typedef enum {
15
15
  UNEXPECTED_ERROR,
@@ -21,11 +21,13 @@ typedef enum {
21
21
  VOID_ELEMENT_CLOSING_TAG_ERROR,
22
22
  UNCLOSED_ELEMENT_ERROR,
23
23
  RUBY_PARSE_ERROR,
24
+ ERB_CONTROL_FLOW_SCOPE_ERROR,
25
+ MISSINGERB_END_TAG_ERROR,
24
26
  } error_type_T;
25
27
 
26
28
  typedef struct ERROR_STRUCT {
27
29
  error_type_T type;
28
- location_T* location;
30
+ location_T location;
29
31
  char* message;
30
32
  } ERROR_T;
31
33
 
@@ -84,26 +86,40 @@ typedef struct {
84
86
  const char* level;
85
87
  } RUBY_PARSE_ERROR_T;
86
88
 
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);
89
+ typedef struct {
90
+ ERROR_T base;
91
+ const char* keyword;
92
+ } ERB_CONTROL_FLOW_SCOPE_ERROR_T;
93
+
94
+ typedef struct {
95
+ ERROR_T base;
96
+ const char* keyword;
97
+ } MISSINGERB_END_TAG_ERROR_T;
98
+
99
+ UNEXPECTED_ERROR_T* unexpected_error_init(const char* description, const char* expected, const char* found, position_T start, position_T end);
100
+ void append_unexpected_error(const char* description, const char* expected, const char* found, position_T start, position_T end, hb_array_T* errors);
101
+ UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T start, position_T end);
102
+ void append_unexpected_token_error(token_type_T expected_type, token_T* found, position_T start, position_T end, hb_array_T* errors);
103
+ MISSING_OPENING_TAG_ERROR_T* missing_opening_tag_error_init(token_T* closing_tag, position_T start, position_T end);
104
+ void append_missing_opening_tag_error(token_T* closing_tag, position_T start, position_T end, hb_array_T* errors);
105
+ MISSING_CLOSING_TAG_ERROR_T* missing_closing_tag_error_init(token_T* opening_tag, position_T start, position_T end);
106
+ void append_missing_closing_tag_error(token_T* opening_tag, position_T start, position_T end, hb_array_T* errors);
107
+ TAG_NAMES_MISMATCH_ERROR_T* tag_names_mismatch_error_init(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end);
108
+ void append_tag_names_mismatch_error(token_T* opening_tag, token_T* closing_tag, position_T start, position_T end, hb_array_T* errors);
109
+ QUOTES_MISMATCH_ERROR_T* quotes_mismatch_error_init(token_T* opening_quote, token_T* closing_quote, position_T start, position_T end);
110
+ void append_quotes_mismatch_error(token_T* opening_quote, token_T* closing_quote, position_T start, position_T end, hb_array_T* errors);
111
+ 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);
112
+ void append_void_element_closing_tag_error(token_T* tag_name, const char* expected, const char* found, position_T start, position_T end, hb_array_T* errors);
113
+ UNCLOSED_ELEMENT_ERROR_T* unclosed_element_error_init(token_T* opening_tag, position_T start, position_T end);
114
+ void append_unclosed_element_error(token_T* opening_tag, position_T start, position_T end, hb_array_T* errors);
115
+ 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);
116
+ void append_ruby_parse_error(const char* error_message, const char* diagnostic_id, const char* level, position_T start, position_T end, hb_array_T* errors);
117
+ ERB_CONTROL_FLOW_SCOPE_ERROR_T* erb_control_flow_scope_error_init(const char* keyword, position_T start, position_T end);
118
+ void append_erb_control_flow_scope_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
119
+ MISSINGERB_END_TAG_ERROR_T* missingerb_end_tag_error_init(const char* keyword, position_T start, position_T end);
120
+ void append_missingerb_end_tag_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
121
+
122
+ void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end);
107
123
 
108
124
  size_t error_sizeof(void);
109
125
  error_type_T error_type(ERROR_T* error);
@@ -115,11 +131,11 @@ const char* error_human_type(ERROR_T* error);
115
131
 
116
132
  void error_free(ERROR_T* error);
117
133
 
118
- void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, buffer_T* buffer);
134
+ void error_pretty_print(ERROR_T* error, size_t indent, size_t relative_indent, hb_buffer_T* buffer);
119
135
 
120
136
  void error_pretty_print_array(
121
- const char* name, array_T* array, size_t indent, size_t relative_indent, bool last_property,
122
- buffer_T* buffer
137
+ const char* name, hb_array_T* array, size_t indent, size_t relative_indent, bool last_property,
138
+ hb_buffer_T* buffer
123
139
  );
124
140
 
125
141
  #endif
@@ -1,18 +1,18 @@
1
1
  #ifndef HERB_EXTRACT_H
2
2
  #define HERB_EXTRACT_H
3
3
 
4
- #include "buffer.h"
4
+ #include "util/hb_buffer.h"
5
5
 
6
6
  typedef enum {
7
7
  HERB_EXTRACT_LANGUAGE_RUBY,
8
8
  HERB_EXTRACT_LANGUAGE_HTML,
9
9
  } herb_extract_language_T;
10
10
 
11
- void herb_extract_ruby_to_buffer(const char* source, buffer_T* output);
12
- void herb_extract_html_to_buffer(const char* source, buffer_T* output);
11
+ void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output);
12
+ void herb_extract_html_to_buffer(const char* source, hb_buffer_T* output);
13
13
 
14
14
  char* herb_extract_ruby_with_semicolons(const char* source);
15
- void herb_extract_ruby_to_buffer_with_semicolons(const char* source, buffer_T* output);
15
+ void herb_extract_ruby_to_buffer_with_semicolons(const char* source, hb_buffer_T* output);
16
16
 
17
17
  char* herb_extract(const char* source, herb_extract_language_T language);
18
18
  char* herb_extract_from_file(const char* path, herb_extract_language_T language);
@@ -1,11 +1,11 @@
1
1
  #ifndef HERB_H
2
2
  #define HERB_H
3
3
 
4
- #include "array.h"
5
4
  #include "ast_node.h"
6
- #include "buffer.h"
7
5
  #include "extract.h"
8
6
  #include "parser.h"
7
+ #include "util/hb_array.h"
8
+ #include "util/hb_buffer.h"
9
9
 
10
10
  #include <stdint.h>
11
11
 
@@ -13,18 +13,17 @@
13
13
  extern "C" {
14
14
  #endif
15
15
 
16
- void herb_lex_to_buffer(const char* source, buffer_T* output);
17
- void herb_lex_json_to_buffer(const char* source, buffer_T* output);
16
+ void herb_lex_to_buffer(const char* source, hb_buffer_T* output);
18
17
 
19
- array_T* herb_lex(const char* source);
20
- array_T* herb_lex_file(const char* path);
18
+ hb_array_T* herb_lex(const char* source);
19
+ hb_array_T* herb_lex_file(const char* path);
21
20
 
22
21
  AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options);
23
22
 
24
23
  const char* herb_version(void);
25
24
  const char* herb_prism_version(void);
26
25
 
27
- void herb_free_tokens(array_T** tokens);
26
+ void herb_free_tokens(hb_array_T** tokens);
28
27
 
29
28
  #ifdef __cplusplus
30
29
  }
@@ -1,13 +1,12 @@
1
1
  #ifndef HERB_HTML_UTIL_H
2
2
  #define HERB_HTML_UTIL_H
3
3
 
4
+ #include "util/hb_string.h"
4
5
  #include <stdbool.h>
5
6
 
6
- bool is_void_element(const char* tag_name);
7
- bool is_html4_void_element(const char* tag_name);
7
+ bool is_void_element(hb_string_T tag_name);
8
8
 
9
- char* html_opening_tag_string(const char* tag_name);
10
- char* html_closing_tag_string(const char* tag_name);
11
- char* html_self_closing_tag_string(const char* tag_name);
9
+ hb_string_T html_closing_tag_string(hb_string_T tag_name);
10
+ hb_string_T html_self_closing_tag_string(hb_string_T tag_name);
12
11
 
13
12
  #endif
@@ -4,10 +4,8 @@
4
4
  #include "lexer_struct.h"
5
5
  #include "token_struct.h"
6
6
 
7
- lexer_T* lexer_init(const char* source);
7
+ void lexer_init(lexer_T* lexer, const char* source);
8
8
  token_T* lexer_next_token(lexer_T* lexer);
9
9
  token_T* lexer_error(lexer_T* lexer, const char* message);
10
10
 
11
- void lexer_free(lexer_T* lexer);
12
-
13
11
  #endif
@@ -5,38 +5,40 @@
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;
21
22
 
22
- char lexer_peek(const lexer_T* lexer, int offset);
23
- bool lexer_peek_for_doctype(const lexer_T* lexer, int offset);
24
- bool lexer_peek_for_xml_declaration(const lexer_T* lexer, int offset);
25
- bool lexer_peek_for_cdata_start(const lexer_T* lexer, int offset);
26
- bool lexer_peek_for_cdata_end(const lexer_T* lexer, int offset);
23
+ char lexer_peek(const lexer_T* lexer, uint32_t offset);
24
+ bool lexer_peek_for_doctype(const lexer_T* lexer, uint32_t offset);
25
+ bool lexer_peek_for_xml_declaration(const lexer_T* lexer, uint32_t offset);
26
+ bool lexer_peek_for_cdata_start(const lexer_T* lexer, uint32_t offset);
27
+ bool lexer_peek_for_cdata_end(const lexer_T* lexer, uint32_t offset);
27
28
 
28
- bool lexer_peek_for_html_comment_start(const lexer_T* lexer, int offset);
29
- bool lexer_peek_for_html_comment_end(const lexer_T* lexer, int offset);
29
+ bool lexer_peek_for_html_comment_start(const lexer_T* lexer, uint32_t offset);
30
+ bool lexer_peek_for_html_comment_end(const lexer_T* lexer, uint32_t offset);
30
31
 
31
- bool lexer_peek_erb_close_tag(const lexer_T* lexer, int offset);
32
- bool lexer_peek_erb_dash_close_tag(const lexer_T* lexer, int offset);
33
- bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer, int offset);
34
- bool lexer_peek_erb_end(const lexer_T* lexer, int offset);
32
+ bool lexer_peek_erb_close_tag(const lexer_T* lexer, uint32_t offset);
33
+ bool lexer_peek_erb_dash_close_tag(const lexer_T* lexer, uint32_t offset);
34
+ bool lexer_peek_erb_percent_close_tag(const lexer_T* lexer, uint32_t offset);
35
+ bool lexer_peek_erb_equals_close_tag(const lexer_T* lexer, uint32_t offset);
36
+ bool lexer_peek_erb_end(const lexer_T* lexer, uint32_t offset);
35
37
 
36
- char lexer_backtrack(const lexer_T* lexer, int offset);
38
+ char lexer_backtrack(const lexer_T* lexer, uint32_t offset);
37
39
 
38
40
  bool lexer_peek_for_token_type_after_whitespace(lexer_T* lexer, token_type_T token_type);
39
- bool lexer_peek_for_close_tag_start(const lexer_T* lexer, int offset);
41
+ bool lexer_peek_for_close_tag_start(const lexer_T* lexer, uint32_t offset);
40
42
 
41
43
  lexer_state_snapshot_T lexer_save_state(lexer_T* lexer);
42
44
  void lexer_restore_state(lexer_T* lexer, lexer_state_snapshot_T snapshot);
@@ -1,7 +1,10 @@
1
1
  #ifndef HERB_LEXER_STRUCT_H
2
2
  #define HERB_LEXER_STRUCT_H
3
3
 
4
+ #include "util/hb_string.h"
5
+
4
6
  #include <stdbool.h>
7
+ #include <stdint.h>
5
8
  #include <stdlib.h>
6
9
 
7
10
  typedef enum {
@@ -11,21 +14,20 @@ typedef enum {
11
14
  } lexer_state_T;
12
15
 
13
16
  typedef struct LEXER_STRUCT {
14
- const char* source;
15
- size_t source_length;
17
+ hb_string_T source;
16
18
 
17
- size_t current_line;
18
- size_t current_column;
19
- size_t current_position;
19
+ uint32_t current_line;
20
+ uint32_t current_column;
21
+ uint32_t current_position;
20
22
 
21
- size_t previous_line;
22
- size_t previous_column;
23
- size_t previous_position;
23
+ uint32_t previous_line;
24
+ uint32_t previous_column;
25
+ uint32_t previous_position;
24
26
 
25
27
  char current_character;
26
28
  lexer_state_T state;
27
- size_t stall_counter;
28
- size_t last_position;
29
+ uint32_t stall_counter;
30
+ uint32_t last_position;
29
31
  bool stalled;
30
32
  } lexer_T;
31
33
 
@@ -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
@@ -5,6 +5,10 @@
5
5
 
6
6
  #define MIN(a, b) ((a) < (b) ? (a) : (b))
7
7
 
8
+ #define KB(kb) (1024 * (kb))
9
+
10
+ #define MB(mb) (1024 * KB(mb))
11
+
8
12
  #define unlikely(x) __builtin_expect(!!(x), 0)
9
13
 
10
14
  #endif
@@ -1,9 +1,9 @@
1
1
  #ifndef HERB_PARSER_H
2
2
  #define HERB_PARSER_H
3
3
 
4
- #include "array.h"
5
4
  #include "ast_node.h"
6
5
  #include "lexer.h"
6
+ #include "util/hb_array.h"
7
7
 
8
8
  typedef enum {
9
9
  FOREIGN_CONTENT_UNKNOWN = 0,
@@ -19,21 +19,27 @@ typedef struct PARSER_OPTIONS_STRUCT {
19
19
  bool track_whitespace;
20
20
  } parser_options_T;
21
21
 
22
+ extern const parser_options_T HERB_DEFAULT_PARSER_OPTIONS;
23
+
22
24
  typedef struct PARSER_STRUCT {
23
25
  lexer_T* lexer;
24
26
  token_T* current_token;
25
- array_T* open_tags_stack;
27
+ hb_array_T* open_tags_stack;
26
28
  parser_state_T state;
27
29
  foreign_content_type_T foreign_content_type;
28
- parser_options_T* options;
30
+ parser_options_T options;
29
31
  } parser_T;
30
32
 
31
- parser_T* herb_parser_init(lexer_T* lexer, parser_options_T* options);
33
+ size_t parser_sizeof(void);
34
+
35
+ void herb_parser_init(parser_T* parser, lexer_T* lexer, parser_options_T options);
32
36
 
33
37
  AST_DOCUMENT_NODE_T* herb_parser_parse(parser_T* parser);
34
38
 
35
- size_t parser_sizeof(void);
39
+ void herb_parser_match_html_tags_post_analyze(AST_DOCUMENT_NODE_T* document);
40
+ void herb_parser_deinit(parser_T* parser);
36
41
 
37
- void parser_free(parser_T* parser);
42
+ void match_tags_in_node_array(hb_array_T* nodes, hb_array_T* errors);
43
+ bool match_tags_visitor(const AST_NODE_T* node, void* data);
38
44
 
39
45
  #endif
@@ -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,
22
- position_T* start
26
+ hb_buffer_T* buffer,
27
+ hb_array_T* children,
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
@@ -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
@@ -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
@@ -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