herb 0.1.1-x86-linux-gnu → 0.2.0-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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +20 -2
  3. data/ext/herb/extension.c +46 -14
  4. data/ext/herb/extension.h +9 -0
  5. data/ext/herb/extension_helpers.c +9 -27
  6. data/ext/herb/nodes.c +104 -1
  7. data/herb.gemspec +2 -1
  8. data/lib/herb/3.0/herb.so +0 -0
  9. data/lib/herb/3.1/herb.so +0 -0
  10. data/lib/herb/3.2/herb.so +0 -0
  11. data/lib/herb/3.3/herb.so +0 -0
  12. data/lib/herb/3.4/herb.so +0 -0
  13. data/lib/herb/ast/node.rb +40 -4
  14. data/lib/herb/ast/nodes.rb +892 -140
  15. data/lib/herb/ast.rb +1 -0
  16. data/lib/herb/cli.rb +4 -1
  17. data/lib/herb/errors.rb +84 -33
  18. data/lib/herb/lex_result.rb +4 -1
  19. data/lib/herb/libherb/array.rb +3 -0
  20. data/lib/herb/libherb/ast_node.rb +3 -0
  21. data/lib/herb/libherb/buffer.rb +3 -0
  22. data/lib/herb/libherb/extract_result.rb +3 -0
  23. data/lib/herb/libherb/lex_result.rb +3 -0
  24. data/lib/herb/libherb/libherb.rb +3 -0
  25. data/lib/herb/libherb/parse_result.rb +3 -0
  26. data/lib/herb/libherb/token.rb +3 -0
  27. data/lib/herb/libherb.rb +3 -0
  28. data/lib/herb/location.rb +15 -6
  29. data/lib/herb/parse_result.rb +10 -1
  30. data/lib/herb/position.rb +17 -8
  31. data/lib/herb/project.rb +13 -4
  32. data/lib/herb/range.rb +18 -8
  33. data/lib/herb/result.rb +7 -1
  34. data/lib/herb/token.rb +14 -4
  35. data/lib/herb/token_list.rb +10 -1
  36. data/lib/herb/version.rb +2 -1
  37. data/lib/herb/visitor.rb +175 -0
  38. data/lib/herb/warnings.rb +43 -0
  39. data/lib/herb.rb +6 -1
  40. data/sig/herb/ast/node.rbs +48 -0
  41. data/sig/herb/ast/nodes.rbs +941 -0
  42. data/sig/herb/ast.rbs +6 -0
  43. data/sig/herb/errors.rbs +193 -0
  44. data/sig/herb/lex_result.rbs +16 -0
  45. data/sig/herb/location.rbs +30 -0
  46. data/sig/herb/parse_result.rbs +22 -0
  47. data/sig/herb/position.rbs +30 -0
  48. data/sig/herb/range.rbs +33 -0
  49. data/sig/herb/result.rbs +20 -0
  50. data/sig/herb/token.rbs +31 -0
  51. data/sig/herb/token_list.rbs +13 -0
  52. data/sig/herb/version.rbs +5 -0
  53. data/sig/herb/visitor.rbs +104 -0
  54. data/sig/herb/warnings.rbs +28 -0
  55. data/sig/herb.rbs +4 -0
  56. data/sig/serialized.rbs +9 -0
  57. data/sig/serialized_ast_errors.rbs +53 -0
  58. data/sig/serialized_ast_nodes.rbs +221 -0
  59. data/src/analyze.c +138 -43
  60. data/src/analyze_helpers.c +44 -1
  61. data/src/analyzed_ruby.c +10 -1
  62. data/src/ast_nodes.c +103 -1
  63. data/src/ast_pretty_print.c +60 -0
  64. data/src/buffer.c +60 -27
  65. data/src/extract.c +57 -20
  66. data/src/include/analyze.h +3 -0
  67. data/src/include/analyze_helpers.h +6 -0
  68. data/src/include/analyzed_ruby.h +3 -0
  69. data/src/include/ast_nodes.h +32 -0
  70. data/src/include/buffer.h +5 -2
  71. data/src/include/lexer_peek_helpers.h +2 -2
  72. data/src/include/macros.h +2 -2
  73. data/src/include/version.h +1 -1
  74. data/src/lexer.c +1 -1
  75. data/src/parser.c +17 -7
  76. data/src/token.c +1 -1
  77. data/src/util.c +3 -1
  78. data/src/visitor.c +36 -0
  79. metadata +24 -3
  80. /data/{License.txt → LICENSE.txt} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75cad17d367e32029ace08418c524393db0115c5621f55e250ac43ff2b8ca443
4
- data.tar.gz: 18bea6391d7d26ddc92c877521866c1bd593ea6892bc0f134e7bab4ed81d060c
3
+ metadata.gz: 6057887b415fcab355abaee6d221b8485bd26cab4bea36954b396cc1041e5dca
4
+ data.tar.gz: 417ba20abcc762eefd122e86686285bdff911bec16ef6994192c9285cd6897b0
5
5
  SHA512:
6
- metadata.gz: 825f8dcfd459710d29c327ed7da74e3cefe19b238330db0c4d9dea664fc2c628ceeaac7013baf1be87fcdd41c735a8e18585046aff69e0c95112b68cc3af6b2c
7
- data.tar.gz: 4917b27cc6580f57bcf31e16a073c212a305ea965ada749244802b4ec165ae4b2c5aa5a8525a4e6f3ea0ad2bb5c4a42427fd85729222c70df7d0d562c33f15af
6
+ metadata.gz: 0f58f16240608e315917c3ec8295ad75b247d7c3b6ccaf9ad1d902875fae546a1d166723011d69b28995ccfda97d68a3e4683d6e5cc86473a435b80899e9a45e
7
+ data.tar.gz: d235f68088a5e0fa380c7e9f07c8d2e69cf07a7c6c166a54064b4ba4edca80966c23dcea1b24b8bf3a707375a212889e7a527269f4888318d39075f16630730b
data/Rakefile CHANGED
@@ -59,7 +59,7 @@ begin
59
59
 
60
60
  task "gem:native" do
61
61
  require "rake_compiler_dock"
62
- # sh "bundle config set cache_all true"
62
+ sh "bundle config set cache_all true"
63
63
 
64
64
  PLATFORMS.each do |platform|
65
65
  RakeCompilerDock.sh "bundle && rake native:#{platform} gem", platform: platform
@@ -75,7 +75,7 @@ begin
75
75
  require "rake_compiler_dock"
76
76
  require "io/console"
77
77
 
78
- # sh "bundle config set cache_all true"
78
+ sh "bundle config set cache_all true"
79
79
  sh "cp ~/.gem/gem-*.pem build/gem/ || true"
80
80
 
81
81
  gemspec_path = File.expand_path("./herb.gemspec", __dir__)
@@ -181,4 +181,22 @@ namespace :parse do
181
181
  end
182
182
  end
183
183
 
184
+ task :rbs_inline do
185
+ require "open3"
186
+
187
+ command = "bundle exec rbs-inline --opt-out --output=sig/ lib/"
188
+
189
+ _stdout, stderr, status = Open3.capture3(command)
190
+
191
+ puts "Running `#{command}`"
192
+
193
+ if stderr.strip == "🎉 Generated 0 RBS files under sig/"
194
+ puts "RBS files in sig/ are up to date"
195
+ exit status.exitstatus
196
+ else
197
+ puts "RBS files in sig/ are not up to date"
198
+ exit 1
199
+ end
200
+ end
201
+
184
202
  task default: [:templates, :make, :compile, :test]
data/ext/herb/extension.c CHANGED
@@ -1,17 +1,31 @@
1
1
  #include <ruby.h>
2
2
 
3
3
  #include "error_helpers.h"
4
+ #include "extension.h"
4
5
  #include "extension_helpers.h"
5
6
  #include "nodes.h"
6
7
 
7
8
  #include "../../src/include/analyze.h"
8
9
 
10
+ VALUE mHerb;
11
+ VALUE cPosition;
12
+ VALUE cLocation;
13
+ VALUE cRange;
14
+ VALUE cToken;
15
+ VALUE cResult;
16
+ VALUE cLexResult;
17
+ VALUE cParseResult;
18
+
9
19
  static VALUE Herb_lex(VALUE self, VALUE source) {
10
20
  char* string = (char*) check_string(source);
11
21
 
12
22
  array_T* tokens = herb_lex(string);
13
23
 
14
- return create_lex_result(tokens, source);
24
+ VALUE result = create_lex_result(tokens, source);
25
+
26
+ herb_free_tokens(&tokens);
27
+
28
+ return result;
15
29
  }
16
30
 
17
31
  static VALUE Herb_lex_file(VALUE self, VALUE path) {
@@ -19,8 +33,11 @@ static VALUE Herb_lex_file(VALUE self, VALUE path) {
19
33
  array_T* tokens = herb_lex_file(file_path);
20
34
 
21
35
  VALUE source_value = read_file_to_ruby_string(file_path);
36
+ VALUE result = create_lex_result(tokens, source_value);
37
+
38
+ herb_free_tokens(&tokens);
22
39
 
23
- return create_lex_result(tokens, source_value);
40
+ return result;
24
41
  }
25
42
 
26
43
  static VALUE Herb_parse(VALUE self, VALUE source) {
@@ -30,7 +47,11 @@ static VALUE Herb_parse(VALUE self, VALUE source) {
30
47
 
31
48
  herb_analyze_parse_tree(root, string);
32
49
 
33
- return create_parse_result(root, source);
50
+ VALUE result = create_parse_result(root, source);
51
+
52
+ ast_node_free((AST_NODE_T*) root);
53
+
54
+ return result;
34
55
  }
35
56
 
36
57
  static VALUE Herb_parse_file(VALUE self, VALUE path) {
@@ -41,7 +62,11 @@ static VALUE Herb_parse_file(VALUE self, VALUE path) {
41
62
 
42
63
  AST_DOCUMENT_NODE_T* root = herb_parse(string);
43
64
 
44
- return create_parse_result(root, source_value);
65
+ VALUE result = create_parse_result(root, source_value);
66
+
67
+ ast_node_free((AST_NODE_T*) root);
68
+
69
+ return result;
45
70
  }
46
71
 
47
72
  static VALUE Herb_lex_to_json(VALUE self, VALUE source) {
@@ -97,14 +122,21 @@ static VALUE Herb_version(VALUE self) {
97
122
  }
98
123
 
99
124
  void Init_herb(void) {
100
- VALUE Herb = rb_define_module("Herb");
101
-
102
- rb_define_singleton_method(Herb, "parse", Herb_parse, 1);
103
- rb_define_singleton_method(Herb, "lex", Herb_lex, 1);
104
- rb_define_singleton_method(Herb, "parse_file", Herb_parse_file, 1);
105
- rb_define_singleton_method(Herb, "lex_file", Herb_lex_file, 1);
106
- rb_define_singleton_method(Herb, "lex_to_json", Herb_lex_to_json, 1);
107
- rb_define_singleton_method(Herb, "extract_ruby", Herb_extract_ruby, 1);
108
- rb_define_singleton_method(Herb, "extract_html", Herb_extract_html, 1);
109
- rb_define_singleton_method(Herb, "version", Herb_version, 0);
125
+ mHerb = rb_define_module("Herb");
126
+ cPosition = rb_define_class_under(mHerb, "Position", rb_cObject);
127
+ cLocation = rb_define_class_under(mHerb, "Location", rb_cObject);
128
+ cRange = rb_define_class_under(mHerb, "Range", rb_cObject);
129
+ cToken = rb_define_class_under(mHerb, "Token", rb_cObject);
130
+ cResult = rb_define_class_under(mHerb, "Result", rb_cObject);
131
+ cLexResult = rb_define_class_under(mHerb, "LexResult", cResult);
132
+ cParseResult = rb_define_class_under(mHerb, "ParseResult", cResult);
133
+
134
+ rb_define_singleton_method(mHerb, "parse", Herb_parse, 1);
135
+ rb_define_singleton_method(mHerb, "lex", Herb_lex, 1);
136
+ rb_define_singleton_method(mHerb, "parse_file", Herb_parse_file, 1);
137
+ rb_define_singleton_method(mHerb, "lex_file", Herb_lex_file, 1);
138
+ rb_define_singleton_method(mHerb, "lex_to_json", Herb_lex_to_json, 1);
139
+ rb_define_singleton_method(mHerb, "extract_ruby", Herb_extract_ruby, 1);
140
+ rb_define_singleton_method(mHerb, "extract_html", Herb_extract_html, 1);
141
+ rb_define_singleton_method(mHerb, "version", Herb_version, 0);
110
142
  }
data/ext/herb/extension.h CHANGED
@@ -3,4 +3,13 @@
3
3
 
4
4
  void Init_herb(void);
5
5
 
6
+ extern VALUE mHerb;
7
+ extern VALUE cPosition;
8
+ extern VALUE cLocation;
9
+ extern VALUE cRange;
10
+ extern VALUE cToken;
11
+ extern VALUE cResult;
12
+ extern VALUE cLexResult;
13
+ extern VALUE cParseResult;
14
+
6
15
  #endif
@@ -1,5 +1,6 @@
1
1
  #include <ruby.h>
2
2
 
3
+ #include "extension.h"
3
4
  #include "extension_helpers.h"
4
5
  #include "nodes.h"
5
6
 
@@ -26,10 +27,7 @@ VALUE rb_position_from_c_struct(position_T* position) {
26
27
  args[0] = SIZET2NUM(position->line);
27
28
  args[1] = SIZET2NUM(position->column);
28
29
 
29
- VALUE Herb = rb_define_module("Herb");
30
- VALUE Position = rb_define_class_under(Herb, "Position", rb_cObject);
31
-
32
- return rb_class_new_instance(2, args, Position);
30
+ return rb_class_new_instance(2, args, cPosition);
33
31
  }
34
32
 
35
33
  VALUE rb_location_from_c_struct(location_T* location) {
@@ -39,10 +37,7 @@ VALUE rb_location_from_c_struct(location_T* location) {
39
37
  args[0] = rb_position_from_c_struct(location->start);
40
38
  args[1] = rb_position_from_c_struct(location->end);
41
39
 
42
- VALUE Herb = rb_define_module("Herb");
43
- VALUE Location = rb_define_class_under(Herb, "Location", rb_cObject);
44
-
45
- return rb_class_new_instance(2, args, Location);
40
+ return rb_class_new_instance(2, args, cLocation);
46
41
  }
47
42
 
48
43
  VALUE rb_range_from_c_struct(range_T* range) {
@@ -52,10 +47,7 @@ VALUE rb_range_from_c_struct(range_T* range) {
52
47
  args[0] = SIZET2NUM(range->from);
53
48
  args[1] = SIZET2NUM(range->to);
54
49
 
55
- VALUE Herb = rb_define_module("Herb");
56
- VALUE Range = rb_define_class_under(Herb, "Range", rb_cObject);
57
-
58
- return rb_class_new_instance(2, args, Range);
50
+ return rb_class_new_instance(2, args, cRange);
59
51
  }
60
52
 
61
53
  VALUE rb_token_from_c_struct(token_T* token) {
@@ -69,10 +61,7 @@ VALUE rb_token_from_c_struct(token_T* token) {
69
61
 
70
62
  VALUE args[4] = { value, range, location, type };
71
63
 
72
- VALUE Herb = rb_define_module("Herb");
73
- VALUE Token = rb_define_class_under(Herb, "Token", rb_cObject);
74
-
75
- return rb_class_new_instance(4, args, Token);
64
+ return rb_class_new_instance(4, args, cToken);
76
65
  }
77
66
 
78
67
  VALUE create_lex_result(array_T* tokens, VALUE source) {
@@ -85,13 +74,9 @@ VALUE create_lex_result(array_T* tokens, VALUE source) {
85
74
  if (token != NULL) { rb_ary_push(value, rb_token_from_c_struct(token)); }
86
75
  }
87
76
 
88
- VALUE Herb = rb_define_module("Herb");
89
- VALUE Result = rb_define_class_under(Herb, "Result", rb_cObject);
90
- VALUE LexResult = rb_define_class_under(Herb, "LexResult", Result);
91
-
92
- herb_free_tokens(&tokens);
93
77
  VALUE args[4] = { value, source, warnings, errors };
94
- return rb_class_new_instance(4, args, LexResult);
78
+
79
+ return rb_class_new_instance(4, args, cLexResult);
95
80
  }
96
81
 
97
82
  VALUE create_parse_result(AST_DOCUMENT_NODE_T* root, VALUE source) {
@@ -99,12 +84,9 @@ VALUE create_parse_result(AST_DOCUMENT_NODE_T* root, VALUE source) {
99
84
  VALUE warnings = rb_ary_new();
100
85
  VALUE errors = rb_ary_new();
101
86
 
102
- VALUE Herb = rb_define_module("Herb");
103
- VALUE Result = rb_define_class_under(Herb, "Result", rb_cObject);
104
- VALUE ParseResult = rb_define_class_under(Herb, "ParseResult", Result);
105
-
106
87
  VALUE args[4] = { value, source, warnings, errors };
107
- return rb_class_new_instance(4, args, ParseResult);
88
+
89
+ return rb_class_new_instance(4, args, cParseResult);
108
90
  }
109
91
 
110
92
  VALUE read_file_to_ruby_string(const char* file_path) {
data/ext/herb/nodes.c CHANGED
@@ -415,7 +415,7 @@ static VALUE rb_erb_content_node_from_c_struct(AST_ERB_CONTENT_NODE_T* erb_conte
415
415
  VALUE erb_content_node_tag_opening = rb_token_from_c_struct(erb_content_node->tag_opening);
416
416
  VALUE erb_content_node_content = rb_token_from_c_struct(erb_content_node->content);
417
417
  VALUE erb_content_node_tag_closing = rb_token_from_c_struct(erb_content_node->tag_closing);
418
- /* #<Herb::Template::AnalyzedRubyField:0x00007fffe32e8a20 @name="analyzed_ruby", @options={kind: nil}> */
418
+ /* #<Herb::Template::AnalyzedRubyField:0x00007ffffed61860 @name="analyzed_ruby", @options={kind: nil}> */
419
419
  VALUE erb_content_node_analyzed_ruby = Qnil;
420
420
  VALUE erb_content_node_parsed = (erb_content_node->parsed) ? Qtrue : Qfalse;
421
421
  VALUE erb_content_node_valid = (erb_content_node->valid) ? Qtrue : Qfalse;
@@ -637,6 +637,44 @@ static VALUE rb_erb_case_node_from_c_struct(AST_ERB_CASE_NODE_T* erb_case_node)
637
637
  return rb_class_new_instance(10, args, ERBCaseNode);
638
638
  };
639
639
 
640
+ static VALUE rb_erb_case_match_node_from_c_struct(AST_ERB_CASE_MATCH_NODE_T* erb_case_match_node) {
641
+ if (erb_case_match_node == NULL) { return Qnil; }
642
+
643
+ AST_NODE_T* node = &erb_case_match_node->base;
644
+
645
+ VALUE Herb = rb_define_module("Herb");
646
+ VALUE AST = rb_define_module_under(Herb, "AST");
647
+ VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
648
+ VALUE ERBCaseMatchNode = rb_define_class_under(AST, "ERBCaseMatchNode", Node);
649
+
650
+ VALUE type = rb_str_new_cstr(ast_node_type_to_string(node));
651
+ VALUE location = rb_location_from_c_struct(node->location);
652
+ VALUE errors = rb_errors_array_from_c_array(node->errors);
653
+
654
+ VALUE erb_case_match_node_tag_opening = rb_token_from_c_struct(erb_case_match_node->tag_opening);
655
+ VALUE erb_case_match_node_content = rb_token_from_c_struct(erb_case_match_node->content);
656
+ VALUE erb_case_match_node_tag_closing = rb_token_from_c_struct(erb_case_match_node->tag_closing);
657
+ VALUE erb_case_match_node_children = rb_nodes_array_from_c_array(erb_case_match_node->children);
658
+ VALUE erb_case_match_node_conditions = rb_nodes_array_from_c_array(erb_case_match_node->conditions);
659
+ VALUE erb_case_match_node_else_clause = rb_node_from_c_struct((AST_NODE_T*) erb_case_match_node->else_clause);
660
+ VALUE erb_case_match_node_end_node = rb_node_from_c_struct((AST_NODE_T*) erb_case_match_node->end_node);
661
+
662
+ VALUE args[10] = {
663
+ type,
664
+ location,
665
+ errors,
666
+ erb_case_match_node_tag_opening,
667
+ erb_case_match_node_content,
668
+ erb_case_match_node_tag_closing,
669
+ erb_case_match_node_children,
670
+ erb_case_match_node_conditions,
671
+ erb_case_match_node_else_clause,
672
+ erb_case_match_node_end_node
673
+ };
674
+
675
+ return rb_class_new_instance(10, args, ERBCaseMatchNode);
676
+ };
677
+
640
678
  static VALUE rb_erb_while_node_from_c_struct(AST_ERB_WHILE_NODE_T* erb_while_node) {
641
679
  if (erb_while_node == NULL) { return Qnil; }
642
680
 
@@ -881,6 +919,68 @@ static VALUE rb_erb_unless_node_from_c_struct(AST_ERB_UNLESS_NODE_T* erb_unless_
881
919
  return rb_class_new_instance(9, args, ERBUnlessNode);
882
920
  };
883
921
 
922
+ static VALUE rb_erb_yield_node_from_c_struct(AST_ERB_YIELD_NODE_T* erb_yield_node) {
923
+ if (erb_yield_node == NULL) { return Qnil; }
924
+
925
+ AST_NODE_T* node = &erb_yield_node->base;
926
+
927
+ VALUE Herb = rb_define_module("Herb");
928
+ VALUE AST = rb_define_module_under(Herb, "AST");
929
+ VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
930
+ VALUE ERBYieldNode = rb_define_class_under(AST, "ERBYieldNode", Node);
931
+
932
+ VALUE type = rb_str_new_cstr(ast_node_type_to_string(node));
933
+ VALUE location = rb_location_from_c_struct(node->location);
934
+ VALUE errors = rb_errors_array_from_c_array(node->errors);
935
+
936
+ VALUE erb_yield_node_tag_opening = rb_token_from_c_struct(erb_yield_node->tag_opening);
937
+ VALUE erb_yield_node_content = rb_token_from_c_struct(erb_yield_node->content);
938
+ VALUE erb_yield_node_tag_closing = rb_token_from_c_struct(erb_yield_node->tag_closing);
939
+
940
+ VALUE args[6] = {
941
+ type,
942
+ location,
943
+ errors,
944
+ erb_yield_node_tag_opening,
945
+ erb_yield_node_content,
946
+ erb_yield_node_tag_closing
947
+ };
948
+
949
+ return rb_class_new_instance(6, args, ERBYieldNode);
950
+ };
951
+
952
+ static VALUE rb_erb_in_node_from_c_struct(AST_ERB_IN_NODE_T* erb_in_node) {
953
+ if (erb_in_node == NULL) { return Qnil; }
954
+
955
+ AST_NODE_T* node = &erb_in_node->base;
956
+
957
+ VALUE Herb = rb_define_module("Herb");
958
+ VALUE AST = rb_define_module_under(Herb, "AST");
959
+ VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
960
+ VALUE ERBInNode = rb_define_class_under(AST, "ERBInNode", Node);
961
+
962
+ VALUE type = rb_str_new_cstr(ast_node_type_to_string(node));
963
+ VALUE location = rb_location_from_c_struct(node->location);
964
+ VALUE errors = rb_errors_array_from_c_array(node->errors);
965
+
966
+ VALUE erb_in_node_tag_opening = rb_token_from_c_struct(erb_in_node->tag_opening);
967
+ VALUE erb_in_node_content = rb_token_from_c_struct(erb_in_node->content);
968
+ VALUE erb_in_node_tag_closing = rb_token_from_c_struct(erb_in_node->tag_closing);
969
+ VALUE erb_in_node_statements = rb_nodes_array_from_c_array(erb_in_node->statements);
970
+
971
+ VALUE args[7] = {
972
+ type,
973
+ location,
974
+ errors,
975
+ erb_in_node_tag_opening,
976
+ erb_in_node_content,
977
+ erb_in_node_tag_closing,
978
+ erb_in_node_statements
979
+ };
980
+
981
+ return rb_class_new_instance(7, args, ERBInNode);
982
+ };
983
+
884
984
 
885
985
  VALUE rb_node_from_c_struct(AST_NODE_T* node) {
886
986
  if (!node) { return Qnil; }
@@ -906,6 +1006,7 @@ VALUE rb_node_from_c_struct(AST_NODE_T* node) {
906
1006
  case AST_ERB_BLOCK_NODE: return rb_erb_block_node_from_c_struct((AST_ERB_BLOCK_NODE_T*) node); break;
907
1007
  case AST_ERB_WHEN_NODE: return rb_erb_when_node_from_c_struct((AST_ERB_WHEN_NODE_T*) node); break;
908
1008
  case AST_ERB_CASE_NODE: return rb_erb_case_node_from_c_struct((AST_ERB_CASE_NODE_T*) node); break;
1009
+ case AST_ERB_CASE_MATCH_NODE: return rb_erb_case_match_node_from_c_struct((AST_ERB_CASE_MATCH_NODE_T*) node); break;
909
1010
  case AST_ERB_WHILE_NODE: return rb_erb_while_node_from_c_struct((AST_ERB_WHILE_NODE_T*) node); break;
910
1011
  case AST_ERB_UNTIL_NODE: return rb_erb_until_node_from_c_struct((AST_ERB_UNTIL_NODE_T*) node); break;
911
1012
  case AST_ERB_FOR_NODE: return rb_erb_for_node_from_c_struct((AST_ERB_FOR_NODE_T*) node); break;
@@ -913,6 +1014,8 @@ VALUE rb_node_from_c_struct(AST_NODE_T* node) {
913
1014
  case AST_ERB_ENSURE_NODE: return rb_erb_ensure_node_from_c_struct((AST_ERB_ENSURE_NODE_T*) node); break;
914
1015
  case AST_ERB_BEGIN_NODE: return rb_erb_begin_node_from_c_struct((AST_ERB_BEGIN_NODE_T*) node); break;
915
1016
  case AST_ERB_UNLESS_NODE: return rb_erb_unless_node_from_c_struct((AST_ERB_UNLESS_NODE_T*) node); break;
1017
+ case AST_ERB_YIELD_NODE: return rb_erb_yield_node_from_c_struct((AST_ERB_YIELD_NODE_T*) node); break;
1018
+ case AST_ERB_IN_NODE: return rb_erb_in_node_from_c_struct((AST_ERB_IN_NODE_T*) node); break;
916
1019
  }
917
1020
 
918
1021
  return Qnil;
data/herb.gemspec CHANGED
@@ -22,11 +22,12 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.files = Dir[
24
24
  "herb.gemspec",
25
- "License.txt",
25
+ "LICENSE.txt",
26
26
  "Makefile",
27
27
  "Rakefile",
28
28
  "README.md",
29
29
  "lib/**/*.rb",
30
+ "sig/**/*.rbs",
30
31
  "src/**/*.{c,h}",
31
32
  "ext/**/*.{c,h}",
32
33
  "exe/*"
data/lib/herb/3.0/herb.so CHANGED
Binary file
data/lib/herb/3.1/herb.so CHANGED
Binary file
data/lib/herb/3.2/herb.so CHANGED
Binary file
data/lib/herb/3.3/herb.so CHANGED
Binary file
data/lib/herb/3.4/herb.so CHANGED
Binary file
data/lib/herb/ast/node.rb CHANGED
@@ -1,16 +1,21 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  module Herb
4
5
  module AST
5
6
  class Node
6
- attr_reader :type, :location, :errors
7
+ attr_reader :type #: String
8
+ attr_reader :location #: Location
9
+ attr_reader :errors #: Array[Herb::Errors::Error]
7
10
 
11
+ #: (String, Location, Array[Herb::Errors::Error]) -> void
8
12
  def initialize(type, location, errors = [])
9
13
  @type = type
10
14
  @location = location
11
15
  @errors = errors
12
16
  end
13
17
 
18
+ #: () -> serialized_node
14
19
  def to_hash
15
20
  {
16
21
  type: type,
@@ -19,20 +24,29 @@ module Herb
19
24
  }
20
25
  end
21
26
 
27
+ #: () -> String
28
+ def class_name
29
+ self.class.name || "Node"
30
+ end
31
+
32
+ #: () -> String
22
33
  def node_name
23
- self.class.name.split("::").last
34
+ class_name.split("::").last || "Node"
24
35
  end
25
36
 
26
- def to_json(*args)
27
- to_hash.to_json(*args)
37
+ #: (?untyped) -> String
38
+ def to_json(state = nil)
39
+ to_hash.to_json(state)
28
40
  end
29
41
 
42
+ #: (?prefix: String) -> String
30
43
  def inspect_errors(prefix: " ")
31
44
  return "" if errors.empty?
32
45
 
33
46
  "├── errors: #{inspect_array(errors, item_name: "error", prefix: prefix)}"
34
47
  end
35
48
 
49
+ #: (Array[Herb::AST::Node|Herb::Errors::Error], ?item_name: String, ?prefix: String) -> String
36
50
  def inspect_array(array, item_name: "item", prefix: " ")
37
51
  output = +""
38
52
 
@@ -56,6 +70,28 @@ module Herb
56
70
 
57
71
  output
58
72
  end
73
+
74
+ #: (?Integer) -> String
75
+ def tree_inspect(_indent = 0)
76
+ raise NotImplementedError
77
+ end
78
+
79
+ #: (Visitor) -> void
80
+ def accept(_visitor)
81
+ raise NoMethodError, "undefined method `accept' for #{inspect}"
82
+ end
83
+
84
+ #: () -> Array[Herb::AST::Node?]
85
+ def child_nodes
86
+ raise NoMethodError, "undefined method `child_nodes' for #{inspect}"
87
+ end
88
+
89
+ alias deconstruct child_nodes
90
+
91
+ #: () -> Array[Herb::AST::Node]
92
+ def compact_child_nodes
93
+ child_nodes.compact
94
+ end
59
95
  end
60
96
  end
61
97
  end