@herb-tools/node 0.8.4 → 0.8.6

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 (52) hide show
  1. package/binding.gyp +1 -0
  2. package/dist/herb-node.esm.js +1 -1
  3. package/extension/error_helpers.cpp +27 -1
  4. package/extension/error_helpers.h +2 -1
  5. package/extension/libherb/analyze.c +25 -4
  6. package/extension/libherb/analyze_helpers.c +179 -84
  7. package/extension/libherb/analyze_helpers.h +1 -0
  8. package/extension/libherb/analyze_missing_end.c +1 -1
  9. package/extension/libherb/analyze_transform.c +1 -1
  10. package/extension/libherb/analyzed_ruby.c +26 -25
  11. package/extension/libherb/analyzed_ruby.h +19 -18
  12. package/extension/libherb/ast_nodes.c +1 -1
  13. package/extension/libherb/ast_nodes.h +1 -1
  14. package/extension/libherb/ast_pretty_print.c +17 -16
  15. package/extension/libherb/ast_pretty_print.h +1 -1
  16. package/extension/libherb/errors.c +38 -1
  17. package/extension/libherb/errors.h +9 -1
  18. package/extension/libherb/extract.c +2 -1
  19. package/extension/libherb/include/analyze_helpers.h +1 -0
  20. package/extension/libherb/include/analyzed_ruby.h +19 -18
  21. package/extension/libherb/include/ast_nodes.h +1 -1
  22. package/extension/libherb/include/ast_pretty_print.h +1 -1
  23. package/extension/libherb/include/errors.h +9 -1
  24. package/extension/libherb/include/util/hb_narray.h +29 -0
  25. package/extension/libherb/include/version.h +1 -1
  26. package/extension/libherb/lexer.c +3 -3
  27. package/extension/libherb/parser.c +4 -2
  28. package/extension/libherb/parser_helpers.c +5 -5
  29. package/extension/libherb/parser_match_tags.c +1 -1
  30. package/extension/libherb/util/hb_narray.c +75 -0
  31. package/extension/libherb/util/hb_narray.h +29 -0
  32. package/extension/libherb/version.h +1 -1
  33. package/extension/libherb/visitor.c +1 -1
  34. package/extension/nodes.cpp +1 -1
  35. package/extension/nodes.h +1 -1
  36. package/extension/prism/include/prism/ast.h +54 -20
  37. package/extension/prism/include/prism/diagnostic.h +2 -0
  38. package/extension/prism/include/prism/options.h +8 -2
  39. package/extension/prism/include/prism/parser.h +3 -0
  40. package/extension/prism/include/prism/version.h +2 -2
  41. package/extension/prism/include/prism.h +1 -1
  42. package/extension/prism/src/diagnostic.c +5 -1
  43. package/extension/prism/src/encoding.c +172 -67
  44. package/extension/prism/src/node.c +9 -0
  45. package/extension/prism/src/options.c +17 -7
  46. package/extension/prism/src/prettyprint.c +16 -0
  47. package/extension/prism/src/prism.c +1192 -1895
  48. package/extension/prism/src/serialize.c +7 -1
  49. package/extension/prism/src/token_type.c +2 -2
  50. package/extension/prism/src/util/pm_constant_pool.c +1 -1
  51. package/package.json +4 -4
  52. package/CHANGELOG.md +0 -19
@@ -11,24 +11,25 @@ typedef struct ANALYZED_RUBY_STRUCT {
11
11
  pm_node_t* root;
12
12
  bool valid;
13
13
  bool parsed;
14
- bool has_if_node;
15
- bool has_elsif_node;
16
- bool has_else_node;
17
- bool has_end;
18
- bool has_block_closing;
19
- bool has_block_node;
20
- bool has_case_node;
21
- bool has_case_match_node;
22
- bool has_when_node;
23
- bool has_in_node;
24
- bool has_for_node;
25
- bool has_while_node;
26
- bool has_until_node;
27
- bool has_begin_node;
28
- bool has_rescue_node;
29
- bool has_ensure_node;
30
- bool has_unless_node;
31
- bool has_yield_node;
14
+ int if_node_count;
15
+ int elsif_node_count;
16
+ int else_node_count;
17
+ int end_count;
18
+ int block_closing_count;
19
+ int block_node_count;
20
+ int case_node_count;
21
+ int case_match_node_count;
22
+ int when_node_count;
23
+ int in_node_count;
24
+ int for_node_count;
25
+ int while_node_count;
26
+ int until_node_count;
27
+ int begin_node_count;
28
+ int rescue_node_count;
29
+ int ensure_node_count;
30
+ int unless_node_count;
31
+ int yield_node_count;
32
+ int unclosed_control_flow_count;
32
33
  } analyzed_ruby_T;
33
34
 
34
35
  analyzed_ruby_T* init_analyzed_ruby(hb_string_T source);
@@ -1,5 +1,5 @@
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.8.4/templates/src/ast_nodes.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/ast_nodes.c.erb
3
3
 
4
4
  #include <stdio.h>
5
5
  #include <stdbool.h>
@@ -1,5 +1,5 @@
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.8.4/templates/src/include/ast_nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/include/ast_nodes.h.erb
3
3
 
4
4
  #ifndef HERB_AST_NODES_H
5
5
  #define HERB_AST_NODES_H
@@ -1,6 +1,7 @@
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.8.4/templates/src/ast_pretty_print.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/ast_pretty_print.c.erb
3
3
 
4
+ #include "include/analyze_helpers.h"
4
5
  #include "include/ast_node.h"
5
6
  #include "include/ast_nodes.h"
6
7
  #include "include/errors.h"
@@ -214,21 +215,21 @@ void ast_pretty_print_node(AST_NODE_T* node, const size_t indent, const size_t r
214
215
  pretty_print_token_property(erb_content_node->content, hb_string("content"), indent, relative_indent, false, buffer);
215
216
  pretty_print_token_property(erb_content_node->tag_closing, hb_string("tag_closing"), indent, relative_indent, false, buffer);
216
217
  if (erb_content_node->analyzed_ruby) {
217
- pretty_print_boolean_property(hb_string("if_node"), erb_content_node->analyzed_ruby->has_if_node, indent, relative_indent, false, buffer);
218
- pretty_print_boolean_property(hb_string("elsif_node"), erb_content_node->analyzed_ruby->has_elsif_node, indent, relative_indent, false, buffer);
219
- pretty_print_boolean_property(hb_string("else_node"), erb_content_node->analyzed_ruby->has_else_node, indent, relative_indent, false, buffer);
220
- pretty_print_boolean_property(hb_string("end"), erb_content_node->analyzed_ruby->has_end, indent, relative_indent, false, buffer);
221
- pretty_print_boolean_property(hb_string("block_node"), erb_content_node->analyzed_ruby->has_block_node, indent, relative_indent, false, buffer);
222
- pretty_print_boolean_property(hb_string("block_closing"), erb_content_node->analyzed_ruby->has_block_closing, indent, relative_indent, false, buffer);
223
- pretty_print_boolean_property(hb_string("case_node"), erb_content_node->analyzed_ruby->has_case_node, indent, relative_indent, false, buffer);
224
- pretty_print_boolean_property(hb_string("when_node"), erb_content_node->analyzed_ruby->has_when_node, indent, relative_indent, false, buffer);
225
- pretty_print_boolean_property(hb_string("for_node"), erb_content_node->analyzed_ruby->has_for_node, indent, relative_indent, false, buffer);
226
- pretty_print_boolean_property(hb_string("while_node"), erb_content_node->analyzed_ruby->has_while_node, indent, relative_indent, false, buffer);
227
- pretty_print_boolean_property(hb_string("until_node"), erb_content_node->analyzed_ruby->has_until_node, indent, relative_indent, false, buffer);
228
- pretty_print_boolean_property(hb_string("begin_node"), erb_content_node->analyzed_ruby->has_begin_node, indent, relative_indent, false, buffer);
229
- pretty_print_boolean_property(hb_string("rescue_node"), erb_content_node->analyzed_ruby->has_rescue_node, indent, relative_indent, false, buffer);
230
- pretty_print_boolean_property(hb_string("ensure_node"), erb_content_node->analyzed_ruby->has_ensure_node, indent, relative_indent, false, buffer);
231
- pretty_print_boolean_property(hb_string("unless_node"), erb_content_node->analyzed_ruby->has_unless_node, indent, relative_indent, false, buffer);
218
+ pretty_print_boolean_property(hb_string("if_node"), has_if_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
219
+ pretty_print_boolean_property(hb_string("elsif_node"), has_elsif_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
220
+ pretty_print_boolean_property(hb_string("else_node"), has_else_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
221
+ pretty_print_boolean_property(hb_string("end"), has_end(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
222
+ pretty_print_boolean_property(hb_string("block_node"), has_block_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
223
+ pretty_print_boolean_property(hb_string("block_closing"), has_block_closing(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
224
+ pretty_print_boolean_property(hb_string("case_node"), has_case_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
225
+ pretty_print_boolean_property(hb_string("when_node"), has_when_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
226
+ pretty_print_boolean_property(hb_string("for_node"), has_for_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
227
+ pretty_print_boolean_property(hb_string("while_node"), has_while_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
228
+ pretty_print_boolean_property(hb_string("until_node"), has_until_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
229
+ pretty_print_boolean_property(hb_string("begin_node"), has_begin_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
230
+ pretty_print_boolean_property(hb_string("rescue_node"), has_rescue_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
231
+ pretty_print_boolean_property(hb_string("ensure_node"), has_ensure_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
232
+ pretty_print_boolean_property(hb_string("unless_node"), has_unless_node(erb_content_node->analyzed_ruby), indent, relative_indent, false, buffer);
232
233
  } else {
233
234
  pretty_print_label(hb_string("analyzed_ruby"), indent, relative_indent, false, buffer);
234
235
  hb_buffer_append(buffer, " ∅\n");
@@ -1,5 +1,5 @@
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.8.4/templates/src/include/ast_pretty_print.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/include/ast_pretty_print.h.erb
3
3
 
4
4
  #ifndef HERB_AST_PRETTY_PRINT_H
5
5
  #define HERB_AST_PRETTY_PRINT_H
@@ -1,5 +1,5 @@
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.8.4/templates/src/errors.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/errors.c.erb
3
3
 
4
4
  #include "include/errors.h"
5
5
  #include "include/location.h"
@@ -497,6 +497,20 @@ void append_missingerb_end_tag_error(const char* keyword, position_T start, posi
497
497
  hb_array_append(errors, missingerb_end_tag_error_init(keyword, start, end));
498
498
  }
499
499
 
500
+ ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* erb_multiple_blocks_in_tag_error_init(position_T start, position_T end) {
501
+ ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* erb_multiple_blocks_in_tag_error = malloc(sizeof(ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T));
502
+
503
+ error_init(&erb_multiple_blocks_in_tag_error->base, ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR, start, end);
504
+
505
+ erb_multiple_blocks_in_tag_error->base.message = herb_strdup("Multiple unclosed control flow blocks in a single ERB tag. Split each block into its own ERB tag, or close all blocks within the same tag.");
506
+
507
+ return erb_multiple_blocks_in_tag_error;
508
+ }
509
+
510
+ void append_erb_multiple_blocks_in_tag_error(position_T start, position_T end, hb_array_T* errors) {
511
+ hb_array_append(errors, erb_multiple_blocks_in_tag_error_init(start, end));
512
+ }
513
+
500
514
  const char* error_type_to_string(ERROR_T* error) {
501
515
  switch (error->type) {
502
516
  case UNEXPECTED_ERROR: return "UNEXPECTED_ERROR";
@@ -510,6 +524,7 @@ const char* error_type_to_string(ERROR_T* error) {
510
524
  case RUBY_PARSE_ERROR: return "RUBY_PARSE_ERROR";
511
525
  case ERB_CONTROL_FLOW_SCOPE_ERROR: return "ERB_CONTROL_FLOW_SCOPE_ERROR";
512
526
  case MISSINGERB_END_TAG_ERROR: return "MISSINGERB_END_TAG_ERROR";
527
+ case ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR: return "ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR";
513
528
  }
514
529
 
515
530
  return "Unknown error_type_T";
@@ -528,6 +543,7 @@ const char* error_human_type(ERROR_T* error) {
528
543
  case RUBY_PARSE_ERROR: return "RubyParseError";
529
544
  case ERB_CONTROL_FLOW_SCOPE_ERROR: return "ERBControlFlowScopeError";
530
545
  case MISSINGERB_END_TAG_ERROR: return "MissingERBEndTagError";
546
+ case ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR: return "ERBMultipleBlocksInTagError";
531
547
  }
532
548
 
533
549
  return "Unknown error_type_T";
@@ -616,6 +632,12 @@ static void error_free_missingerb_end_tag_error(MISSINGERB_END_TAG_ERROR_T* miss
616
632
  error_free_base_error(&missingerb_end_tag_error->base);
617
633
  }
618
634
 
635
+ static void error_free_erb_multiple_blocks_in_tag_error(ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* erb_multiple_blocks_in_tag_error) {
636
+ /* no ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T specific fields to free up */
637
+
638
+ error_free_base_error(&erb_multiple_blocks_in_tag_error->base);
639
+ }
640
+
619
641
  void error_free(ERROR_T* error) {
620
642
  if (!error) { return; }
621
643
 
@@ -631,6 +653,7 @@ void error_free(ERROR_T* error) {
631
653
  case RUBY_PARSE_ERROR: error_free_ruby_parse_error((RUBY_PARSE_ERROR_T*) error); break;
632
654
  case ERB_CONTROL_FLOW_SCOPE_ERROR: error_free_erb_control_flow_scope_error((ERB_CONTROL_FLOW_SCOPE_ERROR_T*) error); break;
633
655
  case MISSINGERB_END_TAG_ERROR: error_free_missingerb_end_tag_error((MISSINGERB_END_TAG_ERROR_T*) error); break;
656
+ case ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR: error_free_erb_multiple_blocks_in_tag_error((ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T*) error); break;
634
657
  }
635
658
  }
636
659
 
@@ -841,6 +864,19 @@ static void error_pretty_print_missingerb_end_tag_error(MISSINGERB_END_TAG_ERROR
841
864
  pretty_print_quoted_property(hb_string("keyword"), hb_string(error->keyword), indent, relative_indent, true, buffer);
842
865
  }
843
866
 
867
+ static void error_pretty_print_erb_multiple_blocks_in_tag_error(ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* error, const size_t indent, const size_t relative_indent, hb_buffer_T* buffer) {
868
+ if (!error) { return; }
869
+
870
+ hb_buffer_append(buffer, "@ ");
871
+ hb_buffer_append(buffer, error_human_type((ERROR_T*) error));
872
+ hb_buffer_append(buffer, " ");
873
+
874
+ pretty_print_location(error->base.location, buffer);
875
+ hb_buffer_append(buffer, "\n");
876
+
877
+ pretty_print_quoted_property(hb_string("message"), hb_string(error->base.message), indent, relative_indent, true, buffer);
878
+ }
879
+
844
880
  void error_pretty_print(ERROR_T* error, const size_t indent, const size_t relative_indent, hb_buffer_T* buffer) {
845
881
  if (!error) { return; }
846
882
 
@@ -856,5 +892,6 @@ void error_pretty_print(ERROR_T* error, const size_t indent, const size_t relati
856
892
  case RUBY_PARSE_ERROR: error_pretty_print_ruby_parse_error((RUBY_PARSE_ERROR_T*) error, indent, relative_indent, buffer); break;
857
893
  case ERB_CONTROL_FLOW_SCOPE_ERROR: error_pretty_print_erb_control_flow_scope_error((ERB_CONTROL_FLOW_SCOPE_ERROR_T*) error, indent, relative_indent, buffer); break;
858
894
  case MISSINGERB_END_TAG_ERROR: error_pretty_print_missingerb_end_tag_error((MISSINGERB_END_TAG_ERROR_T*) error, indent, relative_indent, buffer); break;
895
+ case ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR: error_pretty_print_erb_multiple_blocks_in_tag_error((ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T*) error, indent, relative_indent, buffer); break;
859
896
  }
860
897
  }
@@ -1,5 +1,5 @@
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.8.4/templates/src/include/errors.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/include/errors.h.erb
3
3
 
4
4
  #ifndef HERB_ERRORS_H
5
5
  #define HERB_ERRORS_H
@@ -23,6 +23,7 @@ typedef enum {
23
23
  RUBY_PARSE_ERROR,
24
24
  ERB_CONTROL_FLOW_SCOPE_ERROR,
25
25
  MISSINGERB_END_TAG_ERROR,
26
+ ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR,
26
27
  } error_type_T;
27
28
 
28
29
  typedef struct ERROR_STRUCT {
@@ -96,6 +97,11 @@ typedef struct {
96
97
  const char* keyword;
97
98
  } MISSINGERB_END_TAG_ERROR_T;
98
99
 
100
+ typedef struct {
101
+ ERROR_T base;
102
+ /* no additional fields */
103
+ } ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T;
104
+
99
105
  UNEXPECTED_ERROR_T* unexpected_error_init(const char* description, const char* expected, const char* found, position_T start, position_T end);
100
106
  void append_unexpected_error(const char* description, const char* expected, const char* found, position_T start, position_T end, hb_array_T* errors);
101
107
  UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T start, position_T end);
@@ -118,6 +124,8 @@ ERB_CONTROL_FLOW_SCOPE_ERROR_T* erb_control_flow_scope_error_init(const char* ke
118
124
  void append_erb_control_flow_scope_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
119
125
  MISSINGERB_END_TAG_ERROR_T* missingerb_end_tag_error_init(const char* keyword, position_T start, position_T end);
120
126
  void append_missingerb_end_tag_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
127
+ ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* erb_multiple_blocks_in_tag_error_init(position_T start, position_T end);
128
+ void append_erb_multiple_blocks_in_tag_error(position_T start, position_T end, hb_array_T* errors);
121
129
 
122
130
  void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end);
123
131
 
@@ -25,7 +25,8 @@ void herb_extract_ruby_to_buffer(const char* source, hb_buffer_T* output) {
25
25
  if (strcmp(token->value, "<%#") == 0) {
26
26
  skip_erb_content = true;
27
27
  is_comment_tag = true;
28
- } else if (strcmp(token->value, "<%%") == 0 || strcmp(token->value, "<%%=") == 0) {
28
+ } else if (strcmp(token->value, "<%%") == 0 || strcmp(token->value, "<%%=") == 0
29
+ || strcmp(token->value, "<%graphql") == 0) {
29
30
  skip_erb_content = true;
30
31
  is_comment_tag = false;
31
32
  } else {
@@ -46,6 +46,7 @@ bool search_in_nodes(analyzed_ruby_T* analyzed);
46
46
  bool search_rescue_nodes(analyzed_ruby_T* analyzed);
47
47
  bool search_ensure_nodes(analyzed_ruby_T* analyzed);
48
48
  bool search_yield_nodes(const pm_node_t* node, void* data);
49
+ bool search_unclosed_control_flows(const pm_node_t* node, void* data);
49
50
 
50
51
  void check_erb_node_for_missing_end(const AST_NODE_T* node);
51
52
 
@@ -11,24 +11,25 @@ typedef struct ANALYZED_RUBY_STRUCT {
11
11
  pm_node_t* root;
12
12
  bool valid;
13
13
  bool parsed;
14
- bool has_if_node;
15
- bool has_elsif_node;
16
- bool has_else_node;
17
- bool has_end;
18
- bool has_block_closing;
19
- bool has_block_node;
20
- bool has_case_node;
21
- bool has_case_match_node;
22
- bool has_when_node;
23
- bool has_in_node;
24
- bool has_for_node;
25
- bool has_while_node;
26
- bool has_until_node;
27
- bool has_begin_node;
28
- bool has_rescue_node;
29
- bool has_ensure_node;
30
- bool has_unless_node;
31
- bool has_yield_node;
14
+ int if_node_count;
15
+ int elsif_node_count;
16
+ int else_node_count;
17
+ int end_count;
18
+ int block_closing_count;
19
+ int block_node_count;
20
+ int case_node_count;
21
+ int case_match_node_count;
22
+ int when_node_count;
23
+ int in_node_count;
24
+ int for_node_count;
25
+ int while_node_count;
26
+ int until_node_count;
27
+ int begin_node_count;
28
+ int rescue_node_count;
29
+ int ensure_node_count;
30
+ int unless_node_count;
31
+ int yield_node_count;
32
+ int unclosed_control_flow_count;
32
33
  } analyzed_ruby_T;
33
34
 
34
35
  analyzed_ruby_T* init_analyzed_ruby(hb_string_T source);
@@ -1,5 +1,5 @@
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.8.4/templates/src/include/ast_nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/include/ast_nodes.h.erb
3
3
 
4
4
  #ifndef HERB_AST_NODES_H
5
5
  #define HERB_AST_NODES_H
@@ -1,5 +1,5 @@
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.8.4/templates/src/include/ast_pretty_print.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/include/ast_pretty_print.h.erb
3
3
 
4
4
  #ifndef HERB_AST_PRETTY_PRINT_H
5
5
  #define HERB_AST_PRETTY_PRINT_H
@@ -1,5 +1,5 @@
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.8.4/templates/src/include/errors.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/include/errors.h.erb
3
3
 
4
4
  #ifndef HERB_ERRORS_H
5
5
  #define HERB_ERRORS_H
@@ -23,6 +23,7 @@ typedef enum {
23
23
  RUBY_PARSE_ERROR,
24
24
  ERB_CONTROL_FLOW_SCOPE_ERROR,
25
25
  MISSINGERB_END_TAG_ERROR,
26
+ ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR,
26
27
  } error_type_T;
27
28
 
28
29
  typedef struct ERROR_STRUCT {
@@ -96,6 +97,11 @@ typedef struct {
96
97
  const char* keyword;
97
98
  } MISSINGERB_END_TAG_ERROR_T;
98
99
 
100
+ typedef struct {
101
+ ERROR_T base;
102
+ /* no additional fields */
103
+ } ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T;
104
+
99
105
  UNEXPECTED_ERROR_T* unexpected_error_init(const char* description, const char* expected, const char* found, position_T start, position_T end);
100
106
  void append_unexpected_error(const char* description, const char* expected, const char* found, position_T start, position_T end, hb_array_T* errors);
101
107
  UNEXPECTED_TOKEN_ERROR_T* unexpected_token_error_init(token_type_T expected_type, token_T* found, position_T start, position_T end);
@@ -118,6 +124,8 @@ ERB_CONTROL_FLOW_SCOPE_ERROR_T* erb_control_flow_scope_error_init(const char* ke
118
124
  void append_erb_control_flow_scope_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
119
125
  MISSINGERB_END_TAG_ERROR_T* missingerb_end_tag_error_init(const char* keyword, position_T start, position_T end);
120
126
  void append_missingerb_end_tag_error(const char* keyword, position_T start, position_T end, hb_array_T* errors);
127
+ ERB_MULTIPLE_BLOCKS_IN_TAG_ERROR_T* erb_multiple_blocks_in_tag_error_init(position_T start, position_T end);
128
+ void append_erb_multiple_blocks_in_tag_error(position_T start, position_T end, hb_array_T* errors);
121
129
 
122
130
  void error_init(ERROR_T* error, error_type_T type, position_T start, position_T end);
123
131
 
@@ -0,0 +1,29 @@
1
+ #ifndef HERB_NARRAY_H
2
+ #define HERB_NARRAY_H
3
+
4
+ #include <stdint.h>
5
+ #include <stdlib.h>
6
+ #include <stdbool.h>
7
+
8
+ typedef struct HB_NARRAY_STRUCT {
9
+ uint8_t* items;
10
+ size_t item_size;
11
+ size_t size;
12
+ size_t capacity;
13
+ } hb_narray_T;
14
+
15
+ void hb_narray_init(hb_narray_T* array, size_t item_size, size_t initial_capacity);
16
+ #define hb_narray_pointer_init(array, initial_capacity) (hb_narray_init(array, sizeof(void*), initial_capacity))
17
+
18
+ void* hb_narray_get(const hb_narray_T* array, size_t index);
19
+ void* hb_narray_first(hb_narray_T* array);
20
+ void* hb_narray_last(hb_narray_T* array);
21
+
22
+ void hb_narray_append(hb_narray_T* array, void* item);
23
+ void hb_narray_remove(hb_narray_T* array, size_t index);
24
+ void hb_narray_deinit(hb_narray_T* array);
25
+
26
+ #define hb_narray_push(array, item) (hb_narray_append(array, item))
27
+ bool hb_narray_pop(hb_narray_T* array, void* item);
28
+
29
+ #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.8.4"
4
+ #define HERB_VERSION "0.8.6"
5
5
 
6
6
  #endif
@@ -185,8 +185,8 @@ static token_T* lexer_parse_identifier(lexer_T* lexer) {
185
185
  // ===== ERB Parsing
186
186
 
187
187
  static token_T* lexer_parse_erb_open(lexer_T* lexer) {
188
- hb_string_T erb_patterns[] = { hb_string("<%=="), hb_string("<%%="), hb_string("<%="), hb_string("<%#"),
189
- hb_string("<%-"), hb_string("<%%"), hb_string("<%") };
188
+ hb_string_T erb_patterns[] = { hb_string("<%=="), hb_string("<%%="), hb_string("<%="), hb_string("<%#"),
189
+ hb_string("<%-"), hb_string("<%%"), hb_string("<%graphql"), hb_string("<%") };
190
190
 
191
191
  lexer->state = STATE_ERB_CONTENT;
192
192
 
@@ -278,7 +278,7 @@ token_T* lexer_next_token(lexer_T* lexer) {
278
278
  return lexer_advance_with_next(lexer, strlen("<![CDATA["), TOKEN_CDATA_START);
279
279
  }
280
280
 
281
- if (isalnum(lexer_peek(lexer, 1))) { return lexer_advance_current(lexer, TOKEN_HTML_TAG_START); }
281
+ if (isalpha(lexer_peek(lexer, 1))) { return lexer_advance_current(lexer, TOKEN_HTML_TAG_START); }
282
282
 
283
283
  if (lexer_peek_for_html_comment_start(lexer, 0)) {
284
284
  return lexer_advance_with(lexer, hb_string("<!--"), TOKEN_HTML_COMMENT_START);
@@ -1115,7 +1115,9 @@ static void parser_parse_in_data_state(parser_T* parser, hb_array_T* children, h
1115
1115
  TOKEN_DASH,
1116
1116
  TOKEN_EQUALS,
1117
1117
  TOKEN_EXCLAMATION,
1118
+ TOKEN_HTML_TAG_END,
1118
1119
  TOKEN_IDENTIFIER,
1120
+ TOKEN_LT,
1119
1121
  TOKEN_NBSP,
1120
1122
  TOKEN_NEWLINE,
1121
1123
  TOKEN_PERCENT,
@@ -1149,11 +1151,11 @@ static size_t find_matching_close_tag(hb_array_T* nodes, size_t start_idx, hb_st
1149
1151
  if (node->type == AST_HTML_OPEN_TAG_NODE) {
1150
1152
  AST_HTML_OPEN_TAG_NODE_T* open = (AST_HTML_OPEN_TAG_NODE_T*) node;
1151
1153
 
1152
- if (hb_string_equals(hb_string(open->tag_name->value), tag_name)) { depth++; }
1154
+ if (hb_string_equals_case_insensitive(hb_string(open->tag_name->value), tag_name)) { depth++; }
1153
1155
  } else if (node->type == AST_HTML_CLOSE_TAG_NODE) {
1154
1156
  AST_HTML_CLOSE_TAG_NODE_T* close = (AST_HTML_CLOSE_TAG_NODE_T*) node;
1155
1157
 
1156
- if (hb_string_equals(hb_string(close->tag_name->value), tag_name)) {
1158
+ if (hb_string_equals_case_insensitive(hb_string(close->tag_name->value), tag_name)) {
1157
1159
  if (depth == 0) { return i; }
1158
1160
  depth--;
1159
1161
  }
@@ -24,7 +24,7 @@ bool parser_check_matching_tag(const parser_T* parser, hb_string_T tag_name) {
24
24
  token_T* top_token = hb_array_last(parser->open_tags_stack);
25
25
  if (top_token == NULL || top_token->value == NULL) { return false; };
26
26
 
27
- return hb_string_equals(hb_string(top_token->value), tag_name);
27
+ return hb_string_equals_case_insensitive(hb_string(top_token->value), tag_name);
28
28
  }
29
29
 
30
30
  token_T* parser_pop_open_tag(const parser_T* parser) {
@@ -49,7 +49,7 @@ bool parser_in_svg_context(const parser_T* parser) {
49
49
 
50
50
  if (tag && tag->value) {
51
51
  hb_string_T tag_value_string = hb_string(tag->value);
52
- if (hb_string_equals(tag_value_string, hb_string("svg"))) { return true; }
52
+ if (hb_string_equals_case_insensitive(tag_value_string, hb_string("svg"))) { return true; }
53
53
  }
54
54
  }
55
55
 
@@ -61,8 +61,8 @@ bool parser_in_svg_context(const parser_T* parser) {
61
61
  foreign_content_type_T parser_get_foreign_content_type(hb_string_T tag_name) {
62
62
  if (hb_string_is_empty(tag_name)) { return FOREIGN_CONTENT_UNKNOWN; }
63
63
 
64
- if (hb_string_equals(tag_name, hb_string("script"))) { return FOREIGN_CONTENT_SCRIPT; }
65
- if (hb_string_equals(tag_name, hb_string("style"))) { return FOREIGN_CONTENT_STYLE; }
64
+ if (hb_string_equals_case_insensitive(tag_name, hb_string("script"))) { return FOREIGN_CONTENT_SCRIPT; }
65
+ if (hb_string_equals_case_insensitive(tag_name, hb_string("style"))) { return FOREIGN_CONTENT_STYLE; }
66
66
 
67
67
  return FOREIGN_CONTENT_UNKNOWN;
68
68
  }
@@ -217,5 +217,5 @@ bool parser_is_expected_closing_tag_name(hb_string_T tag_name, foreign_content_t
217
217
 
218
218
  if (hb_string_is_empty(tag_name) || hb_string_is_empty(expected_tag_name)) { return false; }
219
219
 
220
- return hb_string_equals(expected_tag_name, tag_name);
220
+ return hb_string_equals_case_insensitive(expected_tag_name, tag_name);
221
221
  }
@@ -1,5 +1,5 @@
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.8.4/templates/src/parser_match_tags.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/parser_match_tags.c.erb
3
3
 
4
4
  #include "include/parser.h"
5
5
  #include "include/ast_nodes.h"
@@ -0,0 +1,75 @@
1
+ #include "../include/util/hb_narray.h"
2
+
3
+ #include <assert.h>
4
+ #include <stdbool.h>
5
+ #include <string.h>
6
+
7
+ void hb_narray_init(hb_narray_T* array, size_t item_size, size_t initial_capacity) {
8
+ assert(initial_capacity != 0);
9
+
10
+ array->item_size = item_size;
11
+ array->capacity = initial_capacity;
12
+ array->size = 0;
13
+ array->items = malloc(array->capacity * array->item_size);
14
+ }
15
+
16
+ void hb_narray_append(hb_narray_T* array, void* item) {
17
+ if (array->size + 1 > array->capacity) {
18
+ array->capacity *= 2;
19
+ void* new_buffer = realloc(array->items, array->capacity * array->item_size);
20
+ assert(new_buffer != NULL);
21
+ array->items = new_buffer;
22
+ }
23
+
24
+ memcpy(array->items + (array->size * array->item_size), item, array->item_size);
25
+ array->size += 1;
26
+ }
27
+
28
+ static inline uint8_t* hb_narray_memory_position(const hb_narray_T* array, size_t index) {
29
+ return array->items + (array->item_size * index);
30
+ }
31
+
32
+ void hb_narray_remove(hb_narray_T* array, size_t index) {
33
+ assert(index < array->size);
34
+
35
+ if (array->size - 1 > index) {
36
+ size_t elements_to_shift = (array->size - 1) - index;
37
+ size_t bytes_to_shift = array->item_size * elements_to_shift;
38
+
39
+ memcpy(hb_narray_memory_position(array, index), hb_narray_memory_position(array, index + 1), bytes_to_shift);
40
+ }
41
+
42
+ array->size -= 1;
43
+ }
44
+
45
+ void* hb_narray_get(const hb_narray_T* array, size_t index) {
46
+ assert(index < array->size);
47
+
48
+ return hb_narray_memory_position(array, index);
49
+ }
50
+
51
+ void* hb_narray_first(hb_narray_T* array) {
52
+ if (array->size == 0) { return NULL; }
53
+
54
+ return hb_narray_get(array, 0);
55
+ }
56
+
57
+ void* hb_narray_last(hb_narray_T* array) {
58
+ if (array->size == 0) { return NULL; }
59
+ return hb_narray_get(array, array->size - 1);
60
+ }
61
+
62
+ bool hb_narray_pop(hb_narray_T* array, void* item) {
63
+ if (array->size == 0) { return false; }
64
+ memcpy(item, hb_narray_last(array), array->item_size);
65
+ array->size -= 1;
66
+
67
+ return true;
68
+ }
69
+
70
+ void hb_narray_deinit(hb_narray_T* array) {
71
+ array->item_size = 0;
72
+ array->capacity = 0;
73
+ array->size = 0;
74
+ free(array->items);
75
+ }
@@ -0,0 +1,29 @@
1
+ #ifndef HERB_NARRAY_H
2
+ #define HERB_NARRAY_H
3
+
4
+ #include <stdint.h>
5
+ #include <stdlib.h>
6
+ #include <stdbool.h>
7
+
8
+ typedef struct HB_NARRAY_STRUCT {
9
+ uint8_t* items;
10
+ size_t item_size;
11
+ size_t size;
12
+ size_t capacity;
13
+ } hb_narray_T;
14
+
15
+ void hb_narray_init(hb_narray_T* array, size_t item_size, size_t initial_capacity);
16
+ #define hb_narray_pointer_init(array, initial_capacity) (hb_narray_init(array, sizeof(void*), initial_capacity))
17
+
18
+ void* hb_narray_get(const hb_narray_T* array, size_t index);
19
+ void* hb_narray_first(hb_narray_T* array);
20
+ void* hb_narray_last(hb_narray_T* array);
21
+
22
+ void hb_narray_append(hb_narray_T* array, void* item);
23
+ void hb_narray_remove(hb_narray_T* array, size_t index);
24
+ void hb_narray_deinit(hb_narray_T* array);
25
+
26
+ #define hb_narray_push(array, item) (hb_narray_append(array, item))
27
+ bool hb_narray_pop(hb_narray_T* array, void* item);
28
+
29
+ #endif
@@ -1,6 +1,6 @@
1
1
  #ifndef HERB_VERSION_H
2
2
  #define HERB_VERSION_H
3
3
 
4
- #define HERB_VERSION "0.8.4"
4
+ #define HERB_VERSION "0.8.6"
5
5
 
6
6
  #endif
@@ -1,5 +1,5 @@
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.8.4/templates/src/visitor.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/src/visitor.c.erb
3
3
 
4
4
  #include <stdio.h>
5
5
 
@@ -1,5 +1,5 @@
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.8.4/templates/javascript/packages/node/extension/nodes.cpp.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/javascript/packages/node/extension/nodes.cpp.erb
3
3
 
4
4
  #include <node_api.h>
5
5
  #include "error_helpers.h"
package/extension/nodes.h CHANGED
@@ -1,5 +1,5 @@
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.8.4/templates/javascript/packages/node/extension/nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.8.6/templates/javascript/packages/node/extension/nodes.h.erb
3
3
 
4
4
  #ifndef HERB_EXTENSION_NODES_H
5
5
  #define HERB_EXTENSION_NODES_H