herb 0.5.0 → 0.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afe14304b15d889956676e86746b1c644874c838107f2969850f2d6c8d52f02d
4
- data.tar.gz: b9fe773d58e2a83c28f6a226c6aea6de1b8ce6dc372c8fb24552c75b4ace74f4
3
+ metadata.gz: 4d5c39f15561e11ed266e3d57d080287c05f3d9109377d8744b12a089ecf95d7
4
+ data.tar.gz: b9e545a299e398a69aa75d15ae56d5743275a0cb45c4dc1645b8b444c863a069
5
5
  SHA512:
6
- metadata.gz: fcb85bd4f29941b854c6fc2dba8b2a7d0795702e4303d3401d8df475c66a27f432b0020fc67f5413e7ce5039ff0d2b42c5195afd0109d7f8a4448939440ebc06
7
- data.tar.gz: 232b1023973cf69349cd8b4a5aa9dff3ab21e0797945f9a54a748a2d9beced26e557b476accb148dbe933f08263c38a6843a8069acf5ad1b647ebf02dfa501c6
6
+ metadata.gz: 41f6050418f0a9c01adef13de22dc4a554d3bb4c5fd3532f5394948aabb2378dedff1e2c54b12dffd348a69cf9224e7150abf08a439bad5144c83ec09e3b85bb
7
+ data.tar.gz: 60782c6d4ec3587664b91fbc66b96b782e70373be331b78cd44d54ec44c1a520923be005673b55a791e5ecf0f2168ba715d100abf7e3bc2bea31760c70ae6e7f
data/Makefile CHANGED
@@ -76,7 +76,7 @@ ifeq ($(os),Darwin)
76
76
  clang_tidy = $(llvm_path)/bin/clang-tidy
77
77
  endif
78
78
 
79
- all: prism $(exec) $(lib_name) $(static_lib_name) test wasm
79
+ all: templates prism $(exec) $(lib_name) $(static_lib_name) test wasm
80
80
 
81
81
  $(exec): $(objects)
82
82
  $(cc) $(objects) $(flags) $(ldflags) $(prism_ldflags) -o $(exec)
@@ -88,10 +88,10 @@ $(lib_name): $(objects)
88
88
  $(static_lib_name): $(objects)
89
89
  ar rcs $(static_lib_name) $(objects)
90
90
 
91
- src/%.o: src/%.c
91
+ src/%.o: src/%.c templates
92
92
  $(cc) -c $(flags) -fPIC $< -o $@
93
93
 
94
- test/%.o: test/%.c
94
+ test/%.o: test/%.c templates
95
95
  $(cc) -c $(test_cflags) $(test_flags) $(prism_flags) $< -o $@
96
96
 
97
97
  test: $(test_objects) $(non_main_objects)
@@ -105,6 +105,9 @@ clean:
105
105
  bundle_install:
106
106
  bundle install
107
107
 
108
+ templates: bundle_install
109
+ bundle exec rake templates
110
+
108
111
  prism: bundle_install
109
112
  cd $(prism_path) && ruby templates/template.rb && make static && cd -
110
113
 
@@ -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.5.0/templates/ext/herb/error_helpers.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/ext/herb/error_helpers.c.erb
3
3
 
4
4
  #include <ruby.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.5.0/templates/ext/herb/error_helpers.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/ext/herb/error_helpers.h.erb
3
3
 
4
4
  #ifndef HERB_EXTENSION_ERROR_HELPERS_H
5
5
  #define HERB_EXTENSION_ERROR_HELPERS_H
data/ext/herb/extension.c CHANGED
@@ -40,10 +40,26 @@ static VALUE Herb_lex_file(VALUE self, VALUE path) {
40
40
  return result;
41
41
  }
42
42
 
43
- static VALUE Herb_parse(VALUE self, VALUE source) {
43
+ static VALUE Herb_parse(int argc, VALUE* argv, VALUE self) {
44
+ VALUE source, options;
45
+ rb_scan_args(argc, argv, "1:", &source, &options);
46
+
44
47
  char* string = (char*) check_string(source);
45
48
 
46
- AST_DOCUMENT_NODE_T* root = herb_parse(string);
49
+ parser_options_T* parser_options = NULL;
50
+ parser_options_T opts = { 0 };
51
+
52
+ if (!NIL_P(options)) {
53
+ VALUE track_whitespace = rb_hash_lookup(options, rb_str_new_cstr("track_whitespace"));
54
+ if (NIL_P(track_whitespace)) { track_whitespace = rb_hash_lookup(options, ID2SYM(rb_intern("track_whitespace"))); }
55
+
56
+ if (!NIL_P(track_whitespace) && RTEST(track_whitespace)) {
57
+ opts.track_whitespace = true;
58
+ parser_options = &opts;
59
+ }
60
+ }
61
+
62
+ AST_DOCUMENT_NODE_T* root = herb_parse(string, parser_options);
47
63
 
48
64
  herb_analyze_parse_tree(root, string);
49
65
 
@@ -60,7 +76,7 @@ static VALUE Herb_parse_file(VALUE self, VALUE path) {
60
76
  VALUE source_value = read_file_to_ruby_string(file_path);
61
77
  char* string = (char*) check_string(source_value);
62
78
 
63
- AST_DOCUMENT_NODE_T* root = herb_parse(string);
79
+ AST_DOCUMENT_NODE_T* root = herb_parse(string, NULL);
64
80
 
65
81
  VALUE result = create_parse_result(root, source_value);
66
82
 
@@ -131,7 +147,7 @@ void Init_herb(void) {
131
147
  cLexResult = rb_define_class_under(mHerb, "LexResult", cResult);
132
148
  cParseResult = rb_define_class_under(mHerb, "ParseResult", cResult);
133
149
 
134
- rb_define_singleton_method(mHerb, "parse", Herb_parse, 1);
150
+ rb_define_singleton_method(mHerb, "parse", Herb_parse, -1);
135
151
  rb_define_singleton_method(mHerb, "lex", Herb_lex, 1);
136
152
  rb_define_singleton_method(mHerb, "parse_file", Herb_parse_file, 1);
137
153
  rb_define_singleton_method(mHerb, "lex_file", Herb_lex_file, 1);
data/ext/herb/nodes.c 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.5.0/templates/ext/herb/nodes.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/ext/herb/nodes.c.erb
3
3
 
4
4
  #include <ruby.h>
5
5
 
@@ -116,52 +116,20 @@ static VALUE rb_html_close_tag_node_from_c_struct(AST_HTML_CLOSE_TAG_NODE_T* htm
116
116
 
117
117
  VALUE html_close_tag_node_tag_opening = rb_token_from_c_struct(html_close_tag_node->tag_opening);
118
118
  VALUE html_close_tag_node_tag_name = rb_token_from_c_struct(html_close_tag_node->tag_name);
119
+ VALUE html_close_tag_node_children = rb_nodes_array_from_c_array(html_close_tag_node->children);
119
120
  VALUE html_close_tag_node_tag_closing = rb_token_from_c_struct(html_close_tag_node->tag_closing);
120
121
 
121
- VALUE args[6] = {
122
+ VALUE args[7] = {
122
123
  type,
123
124
  location,
124
125
  errors,
125
126
  html_close_tag_node_tag_opening,
126
127
  html_close_tag_node_tag_name,
128
+ html_close_tag_node_children,
127
129
  html_close_tag_node_tag_closing
128
130
  };
129
131
 
130
- return rb_class_new_instance(6, args, HTMLCloseTagNode);
131
- };
132
-
133
- static VALUE rb_html_self_close_tag_node_from_c_struct(AST_HTML_SELF_CLOSE_TAG_NODE_T* html_self_close_tag_node) {
134
- if (html_self_close_tag_node == NULL) { return Qnil; }
135
-
136
- AST_NODE_T* node = &html_self_close_tag_node->base;
137
-
138
- VALUE Herb = rb_define_module("Herb");
139
- VALUE AST = rb_define_module_under(Herb, "AST");
140
- VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
141
- VALUE HTMLSelfCloseTagNode = rb_define_class_under(AST, "HTMLSelfCloseTagNode", Node);
142
-
143
- VALUE type = rb_str_new_cstr(ast_node_type_to_string(node));
144
- VALUE location = rb_location_from_c_struct(node->location);
145
- VALUE errors = rb_errors_array_from_c_array(node->errors);
146
-
147
- VALUE html_self_close_tag_node_tag_opening = rb_token_from_c_struct(html_self_close_tag_node->tag_opening);
148
- VALUE html_self_close_tag_node_tag_name = rb_token_from_c_struct(html_self_close_tag_node->tag_name);
149
- VALUE html_self_close_tag_node_attributes = rb_nodes_array_from_c_array(html_self_close_tag_node->attributes);
150
- VALUE html_self_close_tag_node_tag_closing = rb_token_from_c_struct(html_self_close_tag_node->tag_closing);
151
- VALUE html_self_close_tag_node_is_void = (html_self_close_tag_node->is_void) ? Qtrue : Qfalse;
152
-
153
- VALUE args[8] = {
154
- type,
155
- location,
156
- errors,
157
- html_self_close_tag_node_tag_opening,
158
- html_self_close_tag_node_tag_name,
159
- html_self_close_tag_node_attributes,
160
- html_self_close_tag_node_tag_closing,
161
- html_self_close_tag_node_is_void
162
- };
163
-
164
- return rb_class_new_instance(8, args, HTMLSelfCloseTagNode);
132
+ return rb_class_new_instance(7, args, HTMLCloseTagNode);
165
133
  };
166
134
 
167
135
  static VALUE rb_html_element_node_from_c_struct(AST_HTML_ELEMENT_NODE_T* html_element_node) {
@@ -244,13 +212,13 @@ static VALUE rb_html_attribute_name_node_from_c_struct(AST_HTML_ATTRIBUTE_NAME_N
244
212
  VALUE location = rb_location_from_c_struct(node->location);
245
213
  VALUE errors = rb_errors_array_from_c_array(node->errors);
246
214
 
247
- VALUE html_attribute_name_node_name = rb_token_from_c_struct(html_attribute_name_node->name);
215
+ VALUE html_attribute_name_node_children = rb_nodes_array_from_c_array(html_attribute_name_node->children);
248
216
 
249
217
  VALUE args[4] = {
250
218
  type,
251
219
  location,
252
220
  errors,
253
- html_attribute_name_node_name
221
+ html_attribute_name_node_children
254
222
  };
255
223
 
256
224
  return rb_class_new_instance(4, args, HTMLAttributeNameNode);
@@ -372,6 +340,66 @@ static VALUE rb_html_doctype_node_from_c_struct(AST_HTML_DOCTYPE_NODE_T* html_do
372
340
  return rb_class_new_instance(6, args, HTMLDoctypeNode);
373
341
  };
374
342
 
343
+ static VALUE rb_xml_declaration_node_from_c_struct(AST_XML_DECLARATION_NODE_T* xml_declaration_node) {
344
+ if (xml_declaration_node == NULL) { return Qnil; }
345
+
346
+ AST_NODE_T* node = &xml_declaration_node->base;
347
+
348
+ VALUE Herb = rb_define_module("Herb");
349
+ VALUE AST = rb_define_module_under(Herb, "AST");
350
+ VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
351
+ VALUE XMLDeclarationNode = rb_define_class_under(AST, "XMLDeclarationNode", Node);
352
+
353
+ VALUE type = rb_str_new_cstr(ast_node_type_to_string(node));
354
+ VALUE location = rb_location_from_c_struct(node->location);
355
+ VALUE errors = rb_errors_array_from_c_array(node->errors);
356
+
357
+ VALUE xml_declaration_node_tag_opening = rb_token_from_c_struct(xml_declaration_node->tag_opening);
358
+ VALUE xml_declaration_node_children = rb_nodes_array_from_c_array(xml_declaration_node->children);
359
+ VALUE xml_declaration_node_tag_closing = rb_token_from_c_struct(xml_declaration_node->tag_closing);
360
+
361
+ VALUE args[6] = {
362
+ type,
363
+ location,
364
+ errors,
365
+ xml_declaration_node_tag_opening,
366
+ xml_declaration_node_children,
367
+ xml_declaration_node_tag_closing
368
+ };
369
+
370
+ return rb_class_new_instance(6, args, XMLDeclarationNode);
371
+ };
372
+
373
+ static VALUE rb_cdata_node_from_c_struct(AST_CDATA_NODE_T* cdata_node) {
374
+ if (cdata_node == NULL) { return Qnil; }
375
+
376
+ AST_NODE_T* node = &cdata_node->base;
377
+
378
+ VALUE Herb = rb_define_module("Herb");
379
+ VALUE AST = rb_define_module_under(Herb, "AST");
380
+ VALUE Node = rb_define_class_under(AST, "Node", rb_cObject);
381
+ VALUE CDATANode = rb_define_class_under(AST, "CDATANode", Node);
382
+
383
+ VALUE type = rb_str_new_cstr(ast_node_type_to_string(node));
384
+ VALUE location = rb_location_from_c_struct(node->location);
385
+ VALUE errors = rb_errors_array_from_c_array(node->errors);
386
+
387
+ VALUE cdata_node_tag_opening = rb_token_from_c_struct(cdata_node->tag_opening);
388
+ VALUE cdata_node_children = rb_nodes_array_from_c_array(cdata_node->children);
389
+ VALUE cdata_node_tag_closing = rb_token_from_c_struct(cdata_node->tag_closing);
390
+
391
+ VALUE args[6] = {
392
+ type,
393
+ location,
394
+ errors,
395
+ cdata_node_tag_opening,
396
+ cdata_node_children,
397
+ cdata_node_tag_closing
398
+ };
399
+
400
+ return rb_class_new_instance(6, args, CDATANode);
401
+ };
402
+
375
403
  static VALUE rb_whitespace_node_from_c_struct(AST_WHITESPACE_NODE_T* whitespace_node) {
376
404
  if (whitespace_node == NULL) { return Qnil; }
377
405
 
@@ -415,7 +443,7 @@ static VALUE rb_erb_content_node_from_c_struct(AST_ERB_CONTENT_NODE_T* erb_conte
415
443
  VALUE erb_content_node_tag_opening = rb_token_from_c_struct(erb_content_node->tag_opening);
416
444
  VALUE erb_content_node_content = rb_token_from_c_struct(erb_content_node->content);
417
445
  VALUE erb_content_node_tag_closing = rb_token_from_c_struct(erb_content_node->tag_closing);
418
- /* #<Herb::Template::AnalyzedRubyField:0x00007ffffed68688 @name="analyzed_ruby", @options={kind: nil}> */
446
+ /* #<Herb::Template::AnalyzedRubyField:0x00007ffffed727f0 @name="analyzed_ruby", @options={kind: nil}> */
419
447
  VALUE erb_content_node_analyzed_ruby = Qnil;
420
448
  VALUE erb_content_node_parsed = (erb_content_node->parsed) ? Qtrue : Qfalse;
421
449
  VALUE erb_content_node_valid = (erb_content_node->valid) ? Qtrue : Qfalse;
@@ -990,7 +1018,6 @@ VALUE rb_node_from_c_struct(AST_NODE_T* node) {
990
1018
  case AST_LITERAL_NODE: return rb_literal_node_from_c_struct((AST_LITERAL_NODE_T*) node); break;
991
1019
  case AST_HTML_OPEN_TAG_NODE: return rb_html_open_tag_node_from_c_struct((AST_HTML_OPEN_TAG_NODE_T*) node); break;
992
1020
  case AST_HTML_CLOSE_TAG_NODE: return rb_html_close_tag_node_from_c_struct((AST_HTML_CLOSE_TAG_NODE_T*) node); break;
993
- case AST_HTML_SELF_CLOSE_TAG_NODE: return rb_html_self_close_tag_node_from_c_struct((AST_HTML_SELF_CLOSE_TAG_NODE_T*) node); break;
994
1021
  case AST_HTML_ELEMENT_NODE: return rb_html_element_node_from_c_struct((AST_HTML_ELEMENT_NODE_T*) node); break;
995
1022
  case AST_HTML_ATTRIBUTE_VALUE_NODE: return rb_html_attribute_value_node_from_c_struct((AST_HTML_ATTRIBUTE_VALUE_NODE_T*) node); break;
996
1023
  case AST_HTML_ATTRIBUTE_NAME_NODE: return rb_html_attribute_name_node_from_c_struct((AST_HTML_ATTRIBUTE_NAME_NODE_T*) node); break;
@@ -998,6 +1025,8 @@ VALUE rb_node_from_c_struct(AST_NODE_T* node) {
998
1025
  case AST_HTML_TEXT_NODE: return rb_html_text_node_from_c_struct((AST_HTML_TEXT_NODE_T*) node); break;
999
1026
  case AST_HTML_COMMENT_NODE: return rb_html_comment_node_from_c_struct((AST_HTML_COMMENT_NODE_T*) node); break;
1000
1027
  case AST_HTML_DOCTYPE_NODE: return rb_html_doctype_node_from_c_struct((AST_HTML_DOCTYPE_NODE_T*) node); break;
1028
+ case AST_XML_DECLARATION_NODE: return rb_xml_declaration_node_from_c_struct((AST_XML_DECLARATION_NODE_T*) node); break;
1029
+ case AST_CDATA_NODE: return rb_cdata_node_from_c_struct((AST_CDATA_NODE_T*) node); break;
1001
1030
  case AST_WHITESPACE_NODE: return rb_whitespace_node_from_c_struct((AST_WHITESPACE_NODE_T*) node); break;
1002
1031
  case AST_ERB_CONTENT_NODE: return rb_erb_content_node_from_c_struct((AST_ERB_CONTENT_NODE_T*) node); break;
1003
1032
  case AST_ERB_END_NODE: return rb_erb_end_node_from_c_struct((AST_ERB_END_NODE_T*) node); break;
data/ext/herb/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.5.0/templates/ext/herb/nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/ext/herb/nodes.h.erb
3
3
 
4
4
  #ifndef HERB_EXTENSION_NODES_H
5
5
  #define HERB_EXTENSION_NODES_H
@@ -2,7 +2,7 @@
2
2
  # typed: true
3
3
 
4
4
  # NOTE: This file is generated by the templates/template.rb script and should not be
5
- # modified manually. See /Users/marcoroth/Development/herb-release-0.5.0/templates/lib/herb/ast/nodes.rb.erb
5
+ # modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/lib/herb/ast/nodes.rb.erb
6
6
 
7
7
  module Herb
8
8
  module AST
@@ -194,13 +194,15 @@ module Herb
194
194
  class HTMLCloseTagNode < Node
195
195
  attr_reader :tag_opening #: Herb::Token
196
196
  attr_reader :tag_name #: Herb::Token
197
+ attr_reader :children #: Array[Herb::AST::Node]
197
198
  attr_reader :tag_closing #: Herb::Token
198
199
 
199
- #: (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Herb::Token) -> void
200
- def initialize(type, location, errors, tag_opening, tag_name, tag_closing)
200
+ #: (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
201
+ def initialize(type, location, errors, tag_opening, tag_name, children, tag_closing)
201
202
  super(type, location, errors)
202
203
  @tag_opening = tag_opening
203
204
  @tag_name = tag_name
205
+ @children = children
204
206
  @tag_closing = tag_closing
205
207
  end
206
208
 
@@ -209,6 +211,7 @@ module Herb
209
211
  super.merge({
210
212
  tag_opening: tag_opening,
211
213
  tag_name: tag_name,
214
+ children: children,
212
215
  tag_closing: tag_closing,
213
216
  }) #: Herb::serialized_html_close_tag_node
214
217
  end
@@ -220,7 +223,7 @@ module Herb
220
223
 
221
224
  #: () -> Array[Herb::AST::Node?]
222
225
  def child_nodes
223
- []
226
+ [*children]
224
227
  end
225
228
 
226
229
  #: () -> Array[Herb::AST::Node]
@@ -249,6 +252,8 @@ module Herb
249
252
  output += "├── tag_name: "
250
253
  output += tag_name ? tag_name.tree_inspect : "∅"
251
254
  output += "\n"
255
+ output += "├── children: "
256
+ output += inspect_array(children, prefix: "│ ")
252
257
  output += "└── tag_closing: "
253
258
  output += tag_closing ? tag_closing.tree_inspect : "∅"
254
259
  output += "\n"
@@ -258,84 +263,6 @@ module Herb
258
263
  end
259
264
  end
260
265
 
261
- class HTMLSelfCloseTagNode < Node
262
- attr_reader :tag_opening #: Herb::Token
263
- attr_reader :tag_name #: Herb::Token
264
- attr_reader :attributes #: Array[Herb::AST::HTMLAttributeNode]
265
- attr_reader :tag_closing #: Herb::Token
266
- attr_reader :is_void #: bool
267
-
268
- #: (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Array[Herb::AST::HTMLAttributeNode], Herb::Token, bool) -> void
269
- def initialize(type, location, errors, tag_opening, tag_name, attributes, tag_closing, is_void)
270
- super(type, location, errors)
271
- @tag_opening = tag_opening
272
- @tag_name = tag_name
273
- @attributes = attributes
274
- @tag_closing = tag_closing
275
- @is_void = is_void
276
- end
277
-
278
- #: () -> serialized_html_self_close_tag_node
279
- def to_hash
280
- super.merge({
281
- tag_opening: tag_opening,
282
- tag_name: tag_name,
283
- attributes: attributes,
284
- tag_closing: tag_closing,
285
- is_void: is_void,
286
- }) #: Herb::serialized_html_self_close_tag_node
287
- end
288
-
289
- #: (Visitor) -> void
290
- def accept(visitor)
291
- visitor.visit_html_self_close_tag_node(self)
292
- end
293
-
294
- #: () -> Array[Herb::AST::Node?]
295
- def child_nodes
296
- [*attributes]
297
- end
298
-
299
- #: () -> Array[Herb::AST::Node]
300
- def compact_child_nodes
301
- child_nodes.compact
302
- end
303
-
304
- #: () -> String
305
- def inspect
306
- tree_inspect.rstrip.gsub(/\s+$/, "")
307
- end
308
-
309
- #: (?Integer) -> String
310
- def tree_inspect(indent = 0)
311
- output = +""
312
-
313
- output += "@ #{node_name} "
314
- output += location.tree_inspect
315
- output += "\n"
316
-
317
- output += inspect_errors(prefix: "│ ")
318
-
319
- output += "├── tag_opening: "
320
- output += tag_opening ? tag_opening.tree_inspect : "∅"
321
- output += "\n"
322
- output += "├── tag_name: "
323
- output += tag_name ? tag_name.tree_inspect : "∅"
324
- output += "\n"
325
- output += "├── attributes: "
326
- output += inspect_array(attributes, prefix: "│ ")
327
- output += "├── tag_closing: "
328
- output += tag_closing ? tag_closing.tree_inspect : "∅"
329
- output += "\n"
330
- output += "└── is_void: "
331
- output += [true, false].include?(is_void) ? is_void.to_s : "∅"
332
- output += "\n"
333
- output += "\n"
334
-
335
- output.gsub(/^/, " " * indent)
336
- end
337
- end
338
-
339
266
  class HTMLElementNode < Node
340
267
  attr_reader :open_tag #: Herb::AST::HTMLOpenTagNode
341
268
  attr_reader :tag_name #: Herb::Token
@@ -497,18 +424,18 @@ module Herb
497
424
  end
498
425
 
499
426
  class HTMLAttributeNameNode < Node
500
- attr_reader :name #: Herb::Token
427
+ attr_reader :children #: Array[Herb::AST::Node]
501
428
 
502
- #: (String, Location, Array[Herb::Errors::Error], Herb::Token) -> void
503
- def initialize(type, location, errors, name)
429
+ #: (String, Location, Array[Herb::Errors::Error], Array[Herb::AST::Node]) -> void
430
+ def initialize(type, location, errors, children)
504
431
  super(type, location, errors)
505
- @name = name
432
+ @children = children
506
433
  end
507
434
 
508
435
  #: () -> serialized_html_attribute_name_node
509
436
  def to_hash
510
437
  super.merge({
511
- name: name,
438
+ children: children,
512
439
  }) #: Herb::serialized_html_attribute_name_node
513
440
  end
514
441
 
@@ -519,7 +446,7 @@ module Herb
519
446
 
520
447
  #: () -> Array[Herb::AST::Node?]
521
448
  def child_nodes
522
- []
449
+ [*children]
523
450
  end
524
451
 
525
452
  #: () -> Array[Herb::AST::Node]
@@ -542,9 +469,8 @@ module Herb
542
469
 
543
470
  output += inspect_errors(prefix: "│ ")
544
471
 
545
- output += "└── name: "
546
- output += name ? name.tree_inspect : ""
547
- output += "\n"
472
+ output += "└── children: "
473
+ output += inspect_array(children, prefix: " ")
548
474
  output += "\n"
549
475
 
550
476
  output.gsub(/^/, " " * indent)
@@ -813,6 +739,138 @@ module Herb
813
739
  end
814
740
  end
815
741
 
742
+ class XMLDeclarationNode < Node
743
+ attr_reader :tag_opening #: Herb::Token
744
+ attr_reader :children #: Array[Herb::AST::Node]
745
+ attr_reader :tag_closing #: Herb::Token
746
+
747
+ #: (String, Location, Array[Herb::Errors::Error], Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
748
+ def initialize(type, location, errors, tag_opening, children, tag_closing)
749
+ super(type, location, errors)
750
+ @tag_opening = tag_opening
751
+ @children = children
752
+ @tag_closing = tag_closing
753
+ end
754
+
755
+ #: () -> serialized_xml_declaration_node
756
+ def to_hash
757
+ super.merge({
758
+ tag_opening: tag_opening,
759
+ children: children,
760
+ tag_closing: tag_closing,
761
+ }) #: Herb::serialized_xml_declaration_node
762
+ end
763
+
764
+ #: (Visitor) -> void
765
+ def accept(visitor)
766
+ visitor.visit_xml_declaration_node(self)
767
+ end
768
+
769
+ #: () -> Array[Herb::AST::Node?]
770
+ def child_nodes
771
+ [*children]
772
+ end
773
+
774
+ #: () -> Array[Herb::AST::Node]
775
+ def compact_child_nodes
776
+ child_nodes.compact
777
+ end
778
+
779
+ #: () -> String
780
+ def inspect
781
+ tree_inspect.rstrip.gsub(/\s+$/, "")
782
+ end
783
+
784
+ #: (?Integer) -> String
785
+ def tree_inspect(indent = 0)
786
+ output = +""
787
+
788
+ output += "@ #{node_name} "
789
+ output += location.tree_inspect
790
+ output += "\n"
791
+
792
+ output += inspect_errors(prefix: "│ ")
793
+
794
+ output += "├── tag_opening: "
795
+ output += tag_opening ? tag_opening.tree_inspect : "∅"
796
+ output += "\n"
797
+ output += "├── children: "
798
+ output += inspect_array(children, prefix: "│ ")
799
+ output += "└── tag_closing: "
800
+ output += tag_closing ? tag_closing.tree_inspect : "∅"
801
+ output += "\n"
802
+ output += "\n"
803
+
804
+ output.gsub(/^/, " " * indent)
805
+ end
806
+ end
807
+
808
+ class CDATANode < Node
809
+ attr_reader :tag_opening #: Herb::Token
810
+ attr_reader :children #: Array[Herb::AST::Node]
811
+ attr_reader :tag_closing #: Herb::Token
812
+
813
+ #: (String, Location, Array[Herb::Errors::Error], Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
814
+ def initialize(type, location, errors, tag_opening, children, tag_closing)
815
+ super(type, location, errors)
816
+ @tag_opening = tag_opening
817
+ @children = children
818
+ @tag_closing = tag_closing
819
+ end
820
+
821
+ #: () -> serialized_cdata_node
822
+ def to_hash
823
+ super.merge({
824
+ tag_opening: tag_opening,
825
+ children: children,
826
+ tag_closing: tag_closing,
827
+ }) #: Herb::serialized_cdata_node
828
+ end
829
+
830
+ #: (Visitor) -> void
831
+ def accept(visitor)
832
+ visitor.visit_cdata_node(self)
833
+ end
834
+
835
+ #: () -> Array[Herb::AST::Node?]
836
+ def child_nodes
837
+ [*children]
838
+ end
839
+
840
+ #: () -> Array[Herb::AST::Node]
841
+ def compact_child_nodes
842
+ child_nodes.compact
843
+ end
844
+
845
+ #: () -> String
846
+ def inspect
847
+ tree_inspect.rstrip.gsub(/\s+$/, "")
848
+ end
849
+
850
+ #: (?Integer) -> String
851
+ def tree_inspect(indent = 0)
852
+ output = +""
853
+
854
+ output += "@ #{node_name} "
855
+ output += location.tree_inspect
856
+ output += "\n"
857
+
858
+ output += inspect_errors(prefix: "│ ")
859
+
860
+ output += "├── tag_opening: "
861
+ output += tag_opening ? tag_opening.tree_inspect : "∅"
862
+ output += "\n"
863
+ output += "├── children: "
864
+ output += inspect_array(children, prefix: "│ ")
865
+ output += "└── tag_closing: "
866
+ output += tag_closing ? tag_closing.tree_inspect : "∅"
867
+ output += "\n"
868
+ output += "\n"
869
+
870
+ output.gsub(/^/, " " * indent)
871
+ end
872
+ end
873
+
816
874
  class WhitespaceNode < Node
817
875
  attr_reader :value #: Herb::Token
818
876
 
data/lib/herb/cli.rb CHANGED
@@ -6,7 +6,7 @@
6
6
  require "optparse"
7
7
 
8
8
  class Herb::CLI
9
- attr_accessor :json, :silent, :no_interactive, :no_log_file, :no_timing
9
+ attr_accessor :json, :silent, :no_interactive, :no_log_file, :no_timing, :local
10
10
 
11
11
  def initialize(args)
12
12
  @args = args
@@ -125,12 +125,21 @@ class Herb::CLI
125
125
  when "playground"
126
126
  require "lz_string"
127
127
 
128
- if Dir.pwd.include?("/herb")
129
- system(%(npx concurrently "nx dev playground" "sleep 1 && open http://localhost:5173##{LZString::UriSafe.compress(file_content)}"))
130
- exit(0)
128
+ hash = LZString::UriSafe.compress(file_content)
129
+ local_url = "http://localhost:5173"
130
+ url = "https://herb-tools.dev/playground"
131
+
132
+ if local
133
+ if Dir.pwd.include?("/herb")
134
+ system(%(npx concurrently "nx dev playground" "sleep 1 && open #{local_url}##{hash}"))
135
+ exit(0)
136
+ else
137
+ puts "This command can currently only be run within the herb repo itself"
138
+ exit(1)
139
+ end
131
140
  else
132
- puts "This command can currently only be run within the herb repo itself"
133
- exit(1)
141
+ system(%(open "#{url}##{hash}"))
142
+ exit(0)
134
143
  end
135
144
  when "help"
136
145
  help
@@ -178,6 +187,10 @@ class Herb::CLI
178
187
  parser.on("--no-timing", "Disable timing output") do
179
188
  self.no_timing = true
180
189
  end
190
+
191
+ parser.on("--local", "Use localhost for playground command instead of herb-tools.dev") do
192
+ self.local = true
193
+ end
181
194
  end
182
195
  end
183
196
 
data/lib/herb/errors.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # typed: true
3
3
 
4
4
  # NOTE: This file is generated by the templates/template.rb script and should not be
5
- # modified manually. See /Users/marcoroth/Development/herb-release-0.5.0/templates/lib/herb/errors.rb.erb
5
+ # modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/lib/herb/errors.rb.erb
6
6
 
7
7
  module Herb
8
8
  module Errors
data/lib/herb/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # typed: true
3
3
 
4
4
  module Herb
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end