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.
data/lib/herb/visitor.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/visitor.rb.erb
5
+ # modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/lib/herb/visitor.rb.erb
6
6
 
7
7
  module Herb
8
8
  class Visitor
@@ -41,11 +41,6 @@ module Herb
41
41
  visit_child_nodes(node)
42
42
  end
43
43
 
44
- #: (Herb::AST::HTMLSelfCloseTagNode) -> void
45
- def visit_html_self_close_tag_node(node)
46
- visit_child_nodes(node)
47
- end
48
-
49
44
  #: (Herb::AST::HTMLElementNode) -> void
50
45
  def visit_html_element_node(node)
51
46
  visit_child_nodes(node)
@@ -81,6 +76,16 @@ module Herb
81
76
  visit_child_nodes(node)
82
77
  end
83
78
 
79
+ #: (Herb::AST::XMLDeclarationNode) -> void
80
+ def visit_xml_declaration_node(node)
81
+ visit_child_nodes(node)
82
+ end
83
+
84
+ #: (Herb::AST::CDATANode) -> void
85
+ def visit_cdata_node(node)
86
+ visit_child_nodes(node)
87
+ end
88
+
84
89
  #: (Herb::AST::WhitespaceNode) -> void
85
90
  def visit_whitespace_node(node)
86
91
  visit_child_nodes(node)
@@ -90,10 +90,12 @@ module Herb
90
90
 
91
91
  attr_reader tag_name: Herb::Token
92
92
 
93
+ attr_reader children: Array[Herb::AST::Node]
94
+
93
95
  attr_reader tag_closing: Herb::Token
94
96
 
95
- # : (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Herb::Token) -> void
96
- def initialize: (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Herb::Token) -> void
97
+ # : (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
98
+ def initialize: (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
97
99
 
98
100
  # : () -> serialized_html_close_tag_node
99
101
  def to_hash: () -> serialized_html_close_tag_node
@@ -114,39 +116,6 @@ module Herb
114
116
  def tree_inspect: (?Integer) -> String
115
117
  end
116
118
 
117
- class HTMLSelfCloseTagNode < Node
118
- attr_reader tag_opening: Herb::Token
119
-
120
- attr_reader tag_name: Herb::Token
121
-
122
- attr_reader attributes: Array[Herb::AST::HTMLAttributeNode]
123
-
124
- attr_reader tag_closing: Herb::Token
125
-
126
- attr_reader is_void: bool
127
-
128
- # : (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Array[Herb::AST::HTMLAttributeNode], Herb::Token, bool) -> void
129
- def initialize: (String, Location, Array[Herb::Errors::Error], Herb::Token, Herb::Token, Array[Herb::AST::HTMLAttributeNode], Herb::Token, bool) -> void
130
-
131
- # : () -> serialized_html_self_close_tag_node
132
- def to_hash: () -> serialized_html_self_close_tag_node
133
-
134
- # : (Visitor) -> void
135
- def accept: (Visitor) -> void
136
-
137
- # : () -> Array[Herb::AST::Node?]
138
- def child_nodes: () -> Array[Herb::AST::Node?]
139
-
140
- # : () -> Array[Herb::AST::Node]
141
- def compact_child_nodes: () -> Array[Herb::AST::Node]
142
-
143
- # : () -> String
144
- def inspect: () -> String
145
-
146
- # : (?Integer) -> String
147
- def tree_inspect: (?Integer) -> String
148
- end
149
-
150
119
  class HTMLElementNode < Node
151
120
  attr_reader open_tag: Herb::AST::HTMLOpenTagNode
152
121
 
@@ -212,10 +181,10 @@ module Herb
212
181
  end
213
182
 
214
183
  class HTMLAttributeNameNode < Node
215
- attr_reader name: Herb::Token
184
+ attr_reader children: Array[Herb::AST::Node]
216
185
 
217
- # : (String, Location, Array[Herb::Errors::Error], Herb::Token) -> void
218
- def initialize: (String, Location, Array[Herb::Errors::Error], Herb::Token) -> void
186
+ # : (String, Location, Array[Herb::Errors::Error], Array[Herb::AST::Node]) -> void
187
+ def initialize: (String, Location, Array[Herb::Errors::Error], Array[Herb::AST::Node]) -> void
219
188
 
220
189
  # : () -> serialized_html_attribute_name_node
221
190
  def to_hash: () -> serialized_html_attribute_name_node
@@ -348,6 +317,64 @@ module Herb
348
317
  def tree_inspect: (?Integer) -> String
349
318
  end
350
319
 
320
+ class XMLDeclarationNode < Node
321
+ attr_reader tag_opening: Herb::Token
322
+
323
+ attr_reader children: Array[Herb::AST::Node]
324
+
325
+ attr_reader tag_closing: Herb::Token
326
+
327
+ # : (String, Location, Array[Herb::Errors::Error], Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
328
+ def initialize: (String, Location, Array[Herb::Errors::Error], Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
329
+
330
+ # : () -> serialized_xml_declaration_node
331
+ def to_hash: () -> serialized_xml_declaration_node
332
+
333
+ # : (Visitor) -> void
334
+ def accept: (Visitor) -> void
335
+
336
+ # : () -> Array[Herb::AST::Node?]
337
+ def child_nodes: () -> Array[Herb::AST::Node?]
338
+
339
+ # : () -> Array[Herb::AST::Node]
340
+ def compact_child_nodes: () -> Array[Herb::AST::Node]
341
+
342
+ # : () -> String
343
+ def inspect: () -> String
344
+
345
+ # : (?Integer) -> String
346
+ def tree_inspect: (?Integer) -> String
347
+ end
348
+
349
+ class CDATANode < Node
350
+ attr_reader tag_opening: Herb::Token
351
+
352
+ attr_reader children: Array[Herb::AST::Node]
353
+
354
+ attr_reader tag_closing: Herb::Token
355
+
356
+ # : (String, Location, Array[Herb::Errors::Error], Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
357
+ def initialize: (String, Location, Array[Herb::Errors::Error], Herb::Token, Array[Herb::AST::Node], Herb::Token) -> void
358
+
359
+ # : () -> serialized_cdata_node
360
+ def to_hash: () -> serialized_cdata_node
361
+
362
+ # : (Visitor) -> void
363
+ def accept: (Visitor) -> void
364
+
365
+ # : () -> Array[Herb::AST::Node?]
366
+ def child_nodes: () -> Array[Herb::AST::Node?]
367
+
368
+ # : () -> Array[Herb::AST::Node]
369
+ def compact_child_nodes: () -> Array[Herb::AST::Node]
370
+
371
+ # : () -> String
372
+ def inspect: () -> String
373
+
374
+ # : (?Integer) -> String
375
+ def tree_inspect: (?Integer) -> String
376
+ end
377
+
351
378
  class WhitespaceNode < Node
352
379
  attr_reader value: Herb::Token
353
380
 
data/sig/herb/visitor.rbs CHANGED
@@ -23,9 +23,6 @@ module Herb
23
23
  # : (Herb::AST::HTMLCloseTagNode) -> void
24
24
  def visit_html_close_tag_node: (Herb::AST::HTMLCloseTagNode) -> void
25
25
 
26
- # : (Herb::AST::HTMLSelfCloseTagNode) -> void
27
- def visit_html_self_close_tag_node: (Herb::AST::HTMLSelfCloseTagNode) -> void
28
-
29
26
  # : (Herb::AST::HTMLElementNode) -> void
30
27
  def visit_html_element_node: (Herb::AST::HTMLElementNode) -> void
31
28
 
@@ -47,6 +44,12 @@ module Herb
47
44
  # : (Herb::AST::HTMLDoctypeNode) -> void
48
45
  def visit_html_doctype_node: (Herb::AST::HTMLDoctypeNode) -> void
49
46
 
47
+ # : (Herb::AST::XMLDeclarationNode) -> void
48
+ def visit_xml_declaration_node: (Herb::AST::XMLDeclarationNode) -> void
49
+
50
+ # : (Herb::AST::CDATANode) -> void
51
+ def visit_cdata_node: (Herb::AST::CDATANode) -> void
52
+
50
53
  # : (Herb::AST::WhitespaceNode) -> void
51
54
  def visit_whitespace_node: (Herb::AST::WhitespaceNode) -> void
52
55
 
@@ -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/sig/serialized_ast_errors.rbs.erb
5
+ # modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/sig/serialized_ast_errors.rbs.erb
6
6
 
7
7
  module Herb
8
8
  type serialized_unexpected_error = serialized_error & {
@@ -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/sig/serialized_ast_nodes.rbs.erb
5
+ # modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/sig/serialized_ast_nodes.rbs.erb
6
6
 
7
7
  module Herb
8
8
  type serialized_document_node = serialized_node & {
@@ -24,17 +24,10 @@ module Herb
24
24
  type serialized_html_close_tag_node = serialized_node & {
25
25
  tag_opening: Herb::Token,
26
26
  tag_name: Herb::Token,
27
+ children: Array[Herb::AST::Node],
27
28
  tag_closing: Herb::Token,
28
29
  }
29
30
 
30
- type serialized_html_self_close_tag_node = serialized_node & {
31
- tag_opening: Herb::Token,
32
- tag_name: Herb::Token,
33
- attributes: Array[Herb::AST::HTMLAttributeNode],
34
- tag_closing: Herb::Token,
35
- is_void: bool,
36
- }
37
-
38
31
  type serialized_html_element_node = serialized_node & {
39
32
  open_tag: Herb::AST::HTMLOpenTagNode,
40
33
  tag_name: Herb::Token,
@@ -51,7 +44,7 @@ module Herb
51
44
  }
52
45
 
53
46
  type serialized_html_attribute_name_node = serialized_node & {
54
- name: Herb::Token,
47
+ children: Array[Herb::AST::Node],
55
48
  }
56
49
 
57
50
  type serialized_html_attribute_node = serialized_node & {
@@ -76,6 +69,18 @@ module Herb
76
69
  tag_closing: Herb::Token,
77
70
  }
78
71
 
72
+ type serialized_xml_declaration_node = serialized_node & {
73
+ tag_opening: Herb::Token,
74
+ children: Array[Herb::AST::Node],
75
+ tag_closing: Herb::Token,
76
+ }
77
+
78
+ type serialized_cdata_node = serialized_node & {
79
+ tag_opening: Herb::Token,
80
+ children: Array[Herb::AST::Node],
81
+ tag_closing: Herb::Token,
82
+ }
83
+
79
84
  type serialized_whitespace_node = serialized_node & {
80
85
  value: Herb::Token,
81
86
  }
data/src/ast_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/src/ast_nodes.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/src/ast_nodes.c.erb
3
3
 
4
4
  #include <stdio.h>
5
5
  #include <stdbool.h>
@@ -49,32 +49,19 @@ AST_HTML_OPEN_TAG_NODE_T* ast_html_open_tag_node_init(token_T* tag_opening, toke
49
49
  return html_open_tag_node;
50
50
  }
51
51
 
52
- AST_HTML_CLOSE_TAG_NODE_T* ast_html_close_tag_node_init(token_T* tag_opening, token_T* tag_name, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors) {
52
+ AST_HTML_CLOSE_TAG_NODE_T* ast_html_close_tag_node_init(token_T* tag_opening, token_T* tag_name, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors) {
53
53
  AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node = malloc(sizeof(AST_HTML_CLOSE_TAG_NODE_T));
54
54
 
55
55
  ast_node_init(&html_close_tag_node->base, AST_HTML_CLOSE_TAG_NODE, start_position, end_position, errors);
56
56
 
57
57
  html_close_tag_node->tag_opening = token_copy(tag_opening);
58
58
  html_close_tag_node->tag_name = token_copy(tag_name);
59
+ html_close_tag_node->children = children;
59
60
  html_close_tag_node->tag_closing = token_copy(tag_closing);
60
61
 
61
62
  return html_close_tag_node;
62
63
  }
63
64
 
64
- AST_HTML_SELF_CLOSE_TAG_NODE_T* ast_html_self_close_tag_node_init(token_T* tag_opening, token_T* tag_name, array_T* attributes, token_T* tag_closing, bool is_void, position_T* start_position, position_T* end_position, array_T* errors) {
65
- AST_HTML_SELF_CLOSE_TAG_NODE_T* html_self_close_tag_node = malloc(sizeof(AST_HTML_SELF_CLOSE_TAG_NODE_T));
66
-
67
- ast_node_init(&html_self_close_tag_node->base, AST_HTML_SELF_CLOSE_TAG_NODE, start_position, end_position, errors);
68
-
69
- html_self_close_tag_node->tag_opening = token_copy(tag_opening);
70
- html_self_close_tag_node->tag_name = token_copy(tag_name);
71
- html_self_close_tag_node->attributes = attributes;
72
- html_self_close_tag_node->tag_closing = token_copy(tag_closing);
73
- html_self_close_tag_node->is_void = is_void;
74
-
75
- return html_self_close_tag_node;
76
- }
77
-
78
65
  AST_HTML_ELEMENT_NODE_T* ast_html_element_node_init(struct AST_HTML_OPEN_TAG_NODE_STRUCT* open_tag, token_T* tag_name, array_T* body, struct AST_HTML_CLOSE_TAG_NODE_STRUCT* close_tag, bool is_void, position_T* start_position, position_T* end_position, array_T* errors) {
79
66
  AST_HTML_ELEMENT_NODE_T* html_element_node = malloc(sizeof(AST_HTML_ELEMENT_NODE_T));
80
67
 
@@ -102,12 +89,12 @@ AST_HTML_ATTRIBUTE_VALUE_NODE_T* ast_html_attribute_value_node_init(token_T* ope
102
89
  return html_attribute_value_node;
103
90
  }
104
91
 
105
- AST_HTML_ATTRIBUTE_NAME_NODE_T* ast_html_attribute_name_node_init(token_T* name, position_T* start_position, position_T* end_position, array_T* errors) {
92
+ AST_HTML_ATTRIBUTE_NAME_NODE_T* ast_html_attribute_name_node_init(array_T* children, position_T* start_position, position_T* end_position, array_T* errors) {
106
93
  AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = malloc(sizeof(AST_HTML_ATTRIBUTE_NAME_NODE_T));
107
94
 
108
95
  ast_node_init(&html_attribute_name_node->base, AST_HTML_ATTRIBUTE_NAME_NODE, start_position, end_position, errors);
109
96
 
110
- html_attribute_name_node->name = token_copy(name);
97
+ html_attribute_name_node->children = children;
111
98
 
112
99
  return html_attribute_name_node;
113
100
  }
@@ -158,6 +145,30 @@ AST_HTML_DOCTYPE_NODE_T* ast_html_doctype_node_init(token_T* tag_opening, array_
158
145
  return html_doctype_node;
159
146
  }
160
147
 
148
+ AST_XML_DECLARATION_NODE_T* ast_xml_declaration_node_init(token_T* tag_opening, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors) {
149
+ AST_XML_DECLARATION_NODE_T* xml_declaration_node = malloc(sizeof(AST_XML_DECLARATION_NODE_T));
150
+
151
+ ast_node_init(&xml_declaration_node->base, AST_XML_DECLARATION_NODE, start_position, end_position, errors);
152
+
153
+ xml_declaration_node->tag_opening = token_copy(tag_opening);
154
+ xml_declaration_node->children = children;
155
+ xml_declaration_node->tag_closing = token_copy(tag_closing);
156
+
157
+ return xml_declaration_node;
158
+ }
159
+
160
+ AST_CDATA_NODE_T* ast_cdata_node_init(token_T* tag_opening, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors) {
161
+ AST_CDATA_NODE_T* cdata_node = malloc(sizeof(AST_CDATA_NODE_T));
162
+
163
+ ast_node_init(&cdata_node->base, AST_CDATA_NODE, start_position, end_position, errors);
164
+
165
+ cdata_node->tag_opening = token_copy(tag_opening);
166
+ cdata_node->children = children;
167
+ cdata_node->tag_closing = token_copy(tag_closing);
168
+
169
+ return cdata_node;
170
+ }
171
+
161
172
  AST_WHITESPACE_NODE_T* ast_whitespace_node_init(token_T* value, position_T* start_position, position_T* end_position, array_T* errors) {
162
173
  AST_WHITESPACE_NODE_T* whitespace_node = malloc(sizeof(AST_WHITESPACE_NODE_T));
163
174
 
@@ -414,7 +425,6 @@ const char* ast_node_type_to_string(AST_NODE_T* node) {
414
425
  case AST_LITERAL_NODE: return "AST_LITERAL_NODE";
415
426
  case AST_HTML_OPEN_TAG_NODE: return "AST_HTML_OPEN_TAG_NODE";
416
427
  case AST_HTML_CLOSE_TAG_NODE: return "AST_HTML_CLOSE_TAG_NODE";
417
- case AST_HTML_SELF_CLOSE_TAG_NODE: return "AST_HTML_SELF_CLOSE_TAG_NODE";
418
428
  case AST_HTML_ELEMENT_NODE: return "AST_HTML_ELEMENT_NODE";
419
429
  case AST_HTML_ATTRIBUTE_VALUE_NODE: return "AST_HTML_ATTRIBUTE_VALUE_NODE";
420
430
  case AST_HTML_ATTRIBUTE_NAME_NODE: return "AST_HTML_ATTRIBUTE_NAME_NODE";
@@ -422,6 +432,8 @@ const char* ast_node_type_to_string(AST_NODE_T* node) {
422
432
  case AST_HTML_TEXT_NODE: return "AST_HTML_TEXT_NODE";
423
433
  case AST_HTML_COMMENT_NODE: return "AST_HTML_COMMENT_NODE";
424
434
  case AST_HTML_DOCTYPE_NODE: return "AST_HTML_DOCTYPE_NODE";
435
+ case AST_XML_DECLARATION_NODE: return "AST_XML_DECLARATION_NODE";
436
+ case AST_CDATA_NODE: return "AST_CDATA_NODE";
425
437
  case AST_WHITESPACE_NODE: return "AST_WHITESPACE_NODE";
426
438
  case AST_ERB_CONTENT_NODE: return "AST_ERB_CONTENT_NODE";
427
439
  case AST_ERB_END_NODE: return "AST_ERB_END_NODE";
@@ -451,7 +463,6 @@ const char* ast_node_human_type(AST_NODE_T* node) {
451
463
  case AST_LITERAL_NODE: return "LiteralNode";
452
464
  case AST_HTML_OPEN_TAG_NODE: return "HTMLOpenTagNode";
453
465
  case AST_HTML_CLOSE_TAG_NODE: return "HTMLCloseTagNode";
454
- case AST_HTML_SELF_CLOSE_TAG_NODE: return "HTMLSelfCloseTagNode";
455
466
  case AST_HTML_ELEMENT_NODE: return "HTMLElementNode";
456
467
  case AST_HTML_ATTRIBUTE_VALUE_NODE: return "HTMLAttributeValueNode";
457
468
  case AST_HTML_ATTRIBUTE_NAME_NODE: return "HTMLAttributeNameNode";
@@ -459,6 +470,8 @@ const char* ast_node_human_type(AST_NODE_T* node) {
459
470
  case AST_HTML_TEXT_NODE: return "HTMLTextNode";
460
471
  case AST_HTML_COMMENT_NODE: return "HTMLCommentNode";
461
472
  case AST_HTML_DOCTYPE_NODE: return "HTMLDoctypeNode";
473
+ case AST_XML_DECLARATION_NODE: return "XMLDeclarationNode";
474
+ case AST_CDATA_NODE: return "CDATANode";
462
475
  case AST_WHITESPACE_NODE: return "WhitespaceNode";
463
476
  case AST_ERB_CONTENT_NODE: return "ERBContentNode";
464
477
  case AST_ERB_END_NODE: return "ERBEndNode";
@@ -538,25 +551,17 @@ static void ast_free_html_open_tag_node(AST_HTML_OPEN_TAG_NODE_T* html_open_tag_
538
551
  static void ast_free_html_close_tag_node(AST_HTML_CLOSE_TAG_NODE_T* html_close_tag_node) {
539
552
  if (html_close_tag_node->tag_opening != NULL) { token_free(html_close_tag_node->tag_opening); }
540
553
  if (html_close_tag_node->tag_name != NULL) { token_free(html_close_tag_node->tag_name); }
541
- if (html_close_tag_node->tag_closing != NULL) { token_free(html_close_tag_node->tag_closing); }
542
-
543
- ast_free_base_node(&html_close_tag_node->base);
544
- }
545
-
546
- static void ast_free_html_self_close_tag_node(AST_HTML_SELF_CLOSE_TAG_NODE_T* html_self_close_tag_node) {
547
- if (html_self_close_tag_node->tag_opening != NULL) { token_free(html_self_close_tag_node->tag_opening); }
548
- if (html_self_close_tag_node->tag_name != NULL) { token_free(html_self_close_tag_node->tag_name); }
549
- if (html_self_close_tag_node->attributes != NULL) {
550
- for (size_t i = 0; i < array_size(html_self_close_tag_node->attributes); i++) {
551
- AST_NODE_T* child = array_get(html_self_close_tag_node->attributes, i);
554
+ if (html_close_tag_node->children != NULL) {
555
+ for (size_t i = 0; i < array_size(html_close_tag_node->children); i++) {
556
+ AST_NODE_T* child = array_get(html_close_tag_node->children, i);
552
557
  if (child) { ast_node_free(child); }
553
558
  }
554
559
 
555
- array_free(&html_self_close_tag_node->attributes);
560
+ array_free(&html_close_tag_node->children);
556
561
  }
557
- if (html_self_close_tag_node->tag_closing != NULL) { token_free(html_self_close_tag_node->tag_closing); }
562
+ if (html_close_tag_node->tag_closing != NULL) { token_free(html_close_tag_node->tag_closing); }
558
563
 
559
- ast_free_base_node(&html_self_close_tag_node->base);
564
+ ast_free_base_node(&html_close_tag_node->base);
560
565
  }
561
566
 
562
567
  static void ast_free_html_element_node(AST_HTML_ELEMENT_NODE_T* html_element_node) {
@@ -591,7 +596,14 @@ static void ast_free_html_attribute_value_node(AST_HTML_ATTRIBUTE_VALUE_NODE_T*
591
596
  }
592
597
 
593
598
  static void ast_free_html_attribute_name_node(AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node) {
594
- if (html_attribute_name_node->name != NULL) { token_free(html_attribute_name_node->name); }
599
+ if (html_attribute_name_node->children != NULL) {
600
+ for (size_t i = 0; i < array_size(html_attribute_name_node->children); i++) {
601
+ AST_NODE_T* child = array_get(html_attribute_name_node->children, i);
602
+ if (child) { ast_node_free(child); }
603
+ }
604
+
605
+ array_free(&html_attribute_name_node->children);
606
+ }
595
607
 
596
608
  ast_free_base_node(&html_attribute_name_node->base);
597
609
  }
@@ -640,6 +652,36 @@ static void ast_free_html_doctype_node(AST_HTML_DOCTYPE_NODE_T* html_doctype_nod
640
652
  ast_free_base_node(&html_doctype_node->base);
641
653
  }
642
654
 
655
+ static void ast_free_xml_declaration_node(AST_XML_DECLARATION_NODE_T* xml_declaration_node) {
656
+ if (xml_declaration_node->tag_opening != NULL) { token_free(xml_declaration_node->tag_opening); }
657
+ if (xml_declaration_node->children != NULL) {
658
+ for (size_t i = 0; i < array_size(xml_declaration_node->children); i++) {
659
+ AST_NODE_T* child = array_get(xml_declaration_node->children, i);
660
+ if (child) { ast_node_free(child); }
661
+ }
662
+
663
+ array_free(&xml_declaration_node->children);
664
+ }
665
+ if (xml_declaration_node->tag_closing != NULL) { token_free(xml_declaration_node->tag_closing); }
666
+
667
+ ast_free_base_node(&xml_declaration_node->base);
668
+ }
669
+
670
+ static void ast_free_cdata_node(AST_CDATA_NODE_T* cdata_node) {
671
+ if (cdata_node->tag_opening != NULL) { token_free(cdata_node->tag_opening); }
672
+ if (cdata_node->children != NULL) {
673
+ for (size_t i = 0; i < array_size(cdata_node->children); i++) {
674
+ AST_NODE_T* child = array_get(cdata_node->children, i);
675
+ if (child) { ast_node_free(child); }
676
+ }
677
+
678
+ array_free(&cdata_node->children);
679
+ }
680
+ if (cdata_node->tag_closing != NULL) { token_free(cdata_node->tag_closing); }
681
+
682
+ ast_free_base_node(&cdata_node->base);
683
+ }
684
+
643
685
  static void ast_free_whitespace_node(AST_WHITESPACE_NODE_T* whitespace_node) {
644
686
  if (whitespace_node->value != NULL) { token_free(whitespace_node->value); }
645
687
 
@@ -938,7 +980,6 @@ void ast_node_free(AST_NODE_T* node) {
938
980
  case AST_LITERAL_NODE: ast_free_literal_node((AST_LITERAL_NODE_T*) node); break;
939
981
  case AST_HTML_OPEN_TAG_NODE: ast_free_html_open_tag_node((AST_HTML_OPEN_TAG_NODE_T*) node); break;
940
982
  case AST_HTML_CLOSE_TAG_NODE: ast_free_html_close_tag_node((AST_HTML_CLOSE_TAG_NODE_T*) node); break;
941
- case AST_HTML_SELF_CLOSE_TAG_NODE: ast_free_html_self_close_tag_node((AST_HTML_SELF_CLOSE_TAG_NODE_T*) node); break;
942
983
  case AST_HTML_ELEMENT_NODE: ast_free_html_element_node((AST_HTML_ELEMENT_NODE_T*) node); break;
943
984
  case AST_HTML_ATTRIBUTE_VALUE_NODE: ast_free_html_attribute_value_node((AST_HTML_ATTRIBUTE_VALUE_NODE_T*) node); break;
944
985
  case AST_HTML_ATTRIBUTE_NAME_NODE: ast_free_html_attribute_name_node((AST_HTML_ATTRIBUTE_NAME_NODE_T*) node); break;
@@ -946,6 +987,8 @@ void ast_node_free(AST_NODE_T* node) {
946
987
  case AST_HTML_TEXT_NODE: ast_free_html_text_node((AST_HTML_TEXT_NODE_T*) node); break;
947
988
  case AST_HTML_COMMENT_NODE: ast_free_html_comment_node((AST_HTML_COMMENT_NODE_T*) node); break;
948
989
  case AST_HTML_DOCTYPE_NODE: ast_free_html_doctype_node((AST_HTML_DOCTYPE_NODE_T*) node); break;
990
+ case AST_XML_DECLARATION_NODE: ast_free_xml_declaration_node((AST_XML_DECLARATION_NODE_T*) node); break;
991
+ case AST_CDATA_NODE: ast_free_cdata_node((AST_CDATA_NODE_T*) node); break;
949
992
  case AST_WHITESPACE_NODE: ast_free_whitespace_node((AST_WHITESPACE_NODE_T*) node); break;
950
993
  case AST_ERB_CONTENT_NODE: ast_free_erb_content_node((AST_ERB_CONTENT_NODE_T*) node); break;
951
994
  case AST_ERB_END_NODE: ast_free_erb_end_node((AST_ERB_END_NODE_T*) node); break;
@@ -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/src/ast_pretty_print.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/src/ast_pretty_print.c.erb
3
3
 
4
4
  #include "include/ast_node.h"
5
5
  #include "include/ast_nodes.h"
@@ -58,20 +58,10 @@ void ast_pretty_print_node(AST_NODE_T* node, const size_t indent, const size_t r
58
58
  pretty_print_errors(node, indent, relative_indent, false, buffer);
59
59
  pretty_print_token_property(html_close_tag_node->tag_opening, "tag_opening", indent, relative_indent, false, buffer);
60
60
  pretty_print_token_property(html_close_tag_node->tag_name, "tag_name", indent, relative_indent, false, buffer);
61
+ pretty_print_array("children", html_close_tag_node->children, indent, relative_indent, false, buffer);
61
62
  pretty_print_token_property(html_close_tag_node->tag_closing, "tag_closing", indent, relative_indent, true, buffer);
62
63
  } break;
63
64
 
64
- case AST_HTML_SELF_CLOSE_TAG_NODE: {
65
- const AST_HTML_SELF_CLOSE_TAG_NODE_T* html_self_close_tag_node = (AST_HTML_SELF_CLOSE_TAG_NODE_T*) node;
66
-
67
- pretty_print_errors(node, indent, relative_indent, false, buffer);
68
- pretty_print_token_property(html_self_close_tag_node->tag_opening, "tag_opening", indent, relative_indent, false, buffer);
69
- pretty_print_token_property(html_self_close_tag_node->tag_name, "tag_name", indent, relative_indent, false, buffer);
70
- pretty_print_array("attributes", html_self_close_tag_node->attributes, indent, relative_indent, false, buffer);
71
- pretty_print_token_property(html_self_close_tag_node->tag_closing, "tag_closing", indent, relative_indent, false, buffer);
72
- pretty_print_boolean_property("is_void", html_self_close_tag_node->is_void, indent, relative_indent, true, buffer);
73
- } break;
74
-
75
65
  case AST_HTML_ELEMENT_NODE: {
76
66
  const AST_HTML_ELEMENT_NODE_T* html_element_node = (AST_HTML_ELEMENT_NODE_T*) node;
77
67
 
@@ -125,7 +115,7 @@ void ast_pretty_print_node(AST_NODE_T* node, const size_t indent, const size_t r
125
115
  const AST_HTML_ATTRIBUTE_NAME_NODE_T* html_attribute_name_node = (AST_HTML_ATTRIBUTE_NAME_NODE_T*) node;
126
116
 
127
117
  pretty_print_errors(node, indent, relative_indent, false, buffer);
128
- pretty_print_token_property(html_attribute_name_node->name, "name", indent, relative_indent, true, buffer);
118
+ pretty_print_array("children", html_attribute_name_node->children, indent, relative_indent, true, buffer);
129
119
  } break;
130
120
 
131
121
  case AST_HTML_ATTRIBUTE_NODE: {
@@ -190,6 +180,24 @@ void ast_pretty_print_node(AST_NODE_T* node, const size_t indent, const size_t r
190
180
  pretty_print_token_property(html_doctype_node->tag_closing, "tag_closing", indent, relative_indent, true, buffer);
191
181
  } break;
192
182
 
183
+ case AST_XML_DECLARATION_NODE: {
184
+ const AST_XML_DECLARATION_NODE_T* xml_declaration_node = (AST_XML_DECLARATION_NODE_T*) node;
185
+
186
+ pretty_print_errors(node, indent, relative_indent, false, buffer);
187
+ pretty_print_token_property(xml_declaration_node->tag_opening, "tag_opening", indent, relative_indent, false, buffer);
188
+ pretty_print_array("children", xml_declaration_node->children, indent, relative_indent, false, buffer);
189
+ pretty_print_token_property(xml_declaration_node->tag_closing, "tag_closing", indent, relative_indent, true, buffer);
190
+ } break;
191
+
192
+ case AST_CDATA_NODE: {
193
+ const AST_CDATA_NODE_T* cdata_node = (AST_CDATA_NODE_T*) node;
194
+
195
+ pretty_print_errors(node, indent, relative_indent, false, buffer);
196
+ pretty_print_token_property(cdata_node->tag_opening, "tag_opening", indent, relative_indent, false, buffer);
197
+ pretty_print_array("children", cdata_node->children, indent, relative_indent, false, buffer);
198
+ pretty_print_token_property(cdata_node->tag_closing, "tag_closing", indent, relative_indent, true, buffer);
199
+ } break;
200
+
193
201
  case AST_WHITESPACE_NODE: {
194
202
  const AST_WHITESPACE_NODE_T* whitespace_node = (AST_WHITESPACE_NODE_T*) node;
195
203
 
data/src/errors.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/src/errors.c.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/src/errors.c.erb
3
3
 
4
4
  #include "include/array.h"
5
5
  #include "include/errors.h"
data/src/herb.c CHANGED
@@ -27,9 +27,9 @@ array_T* herb_lex(const char* source) {
27
27
  return tokens;
28
28
  }
29
29
 
30
- AST_DOCUMENT_NODE_T* herb_parse(const char* source) {
30
+ AST_DOCUMENT_NODE_T* herb_parse(const char* source, parser_options_T* options) {
31
31
  lexer_T* lexer = lexer_init(source);
32
- parser_T* parser = parser_init(lexer);
32
+ parser_T* parser = parser_init(lexer, options);
33
33
 
34
34
  AST_DOCUMENT_NODE_T* document = parser_parse(parser);
35
35
 
@@ -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/src/include/ast_nodes.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/templates/src/include/ast_nodes.h.erb
3
3
 
4
4
  #ifndef HERB_AST_NODES_H
5
5
  #define HERB_AST_NODES_H
@@ -19,7 +19,6 @@ typedef enum {
19
19
  AST_LITERAL_NODE,
20
20
  AST_HTML_OPEN_TAG_NODE,
21
21
  AST_HTML_CLOSE_TAG_NODE,
22
- AST_HTML_SELF_CLOSE_TAG_NODE,
23
22
  AST_HTML_ELEMENT_NODE,
24
23
  AST_HTML_ATTRIBUTE_VALUE_NODE,
25
24
  AST_HTML_ATTRIBUTE_NAME_NODE,
@@ -27,6 +26,8 @@ typedef enum {
27
26
  AST_HTML_TEXT_NODE,
28
27
  AST_HTML_COMMENT_NODE,
29
28
  AST_HTML_DOCTYPE_NODE,
29
+ AST_XML_DECLARATION_NODE,
30
+ AST_CDATA_NODE,
30
31
  AST_WHITESPACE_NODE,
31
32
  AST_ERB_CONTENT_NODE,
32
33
  AST_ERB_END_NODE,
@@ -78,18 +79,10 @@ typedef struct AST_HTML_CLOSE_TAG_NODE_STRUCT {
78
79
  AST_NODE_T base;
79
80
  token_T* tag_opening;
80
81
  token_T* tag_name;
82
+ array_T* children;
81
83
  token_T* tag_closing;
82
84
  } AST_HTML_CLOSE_TAG_NODE_T;
83
85
 
84
- typedef struct AST_HTML_SELF_CLOSE_TAG_NODE_STRUCT {
85
- AST_NODE_T base;
86
- token_T* tag_opening;
87
- token_T* tag_name;
88
- array_T* attributes;
89
- token_T* tag_closing;
90
- bool is_void;
91
- } AST_HTML_SELF_CLOSE_TAG_NODE_T;
92
-
93
86
  typedef struct AST_HTML_ELEMENT_NODE_STRUCT {
94
87
  AST_NODE_T base;
95
88
  struct AST_HTML_OPEN_TAG_NODE_STRUCT* open_tag;
@@ -109,7 +102,7 @@ typedef struct AST_HTML_ATTRIBUTE_VALUE_NODE_STRUCT {
109
102
 
110
103
  typedef struct AST_HTML_ATTRIBUTE_NAME_NODE_STRUCT {
111
104
  AST_NODE_T base;
112
- token_T* name;
105
+ array_T* children;
113
106
  } AST_HTML_ATTRIBUTE_NAME_NODE_T;
114
107
 
115
108
  typedef struct AST_HTML_ATTRIBUTE_NODE_STRUCT {
@@ -138,6 +131,20 @@ typedef struct AST_HTML_DOCTYPE_NODE_STRUCT {
138
131
  token_T* tag_closing;
139
132
  } AST_HTML_DOCTYPE_NODE_T;
140
133
 
134
+ typedef struct AST_XML_DECLARATION_NODE_STRUCT {
135
+ AST_NODE_T base;
136
+ token_T* tag_opening;
137
+ array_T* children;
138
+ token_T* tag_closing;
139
+ } AST_XML_DECLARATION_NODE_T;
140
+
141
+ typedef struct AST_CDATA_NODE_STRUCT {
142
+ AST_NODE_T base;
143
+ token_T* tag_opening;
144
+ array_T* children;
145
+ token_T* tag_closing;
146
+ } AST_CDATA_NODE_T;
147
+
141
148
  typedef struct AST_WHITESPACE_NODE_STRUCT {
142
149
  AST_NODE_T base;
143
150
  token_T* value;
@@ -301,15 +308,16 @@ typedef struct AST_ERB_IN_NODE_STRUCT {
301
308
  AST_DOCUMENT_NODE_T* ast_document_node_init(array_T* children, position_T* start_position, position_T* end_position, array_T* errors);
302
309
  AST_LITERAL_NODE_T* ast_literal_node_init(const char* content, position_T* start_position, position_T* end_position, array_T* errors);
303
310
  AST_HTML_OPEN_TAG_NODE_T* ast_html_open_tag_node_init(token_T* tag_opening, token_T* tag_name, token_T* tag_closing, array_T* children, bool is_void, position_T* start_position, position_T* end_position, array_T* errors);
304
- AST_HTML_CLOSE_TAG_NODE_T* ast_html_close_tag_node_init(token_T* tag_opening, token_T* tag_name, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
305
- AST_HTML_SELF_CLOSE_TAG_NODE_T* ast_html_self_close_tag_node_init(token_T* tag_opening, token_T* tag_name, array_T* attributes, token_T* tag_closing, bool is_void, position_T* start_position, position_T* end_position, array_T* errors);
311
+ AST_HTML_CLOSE_TAG_NODE_T* ast_html_close_tag_node_init(token_T* tag_opening, token_T* tag_name, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
306
312
  AST_HTML_ELEMENT_NODE_T* ast_html_element_node_init(struct AST_HTML_OPEN_TAG_NODE_STRUCT* open_tag, token_T* tag_name, array_T* body, struct AST_HTML_CLOSE_TAG_NODE_STRUCT* close_tag, bool is_void, position_T* start_position, position_T* end_position, array_T* errors);
307
313
  AST_HTML_ATTRIBUTE_VALUE_NODE_T* ast_html_attribute_value_node_init(token_T* open_quote, array_T* children, token_T* close_quote, bool quoted, position_T* start_position, position_T* end_position, array_T* errors);
308
- AST_HTML_ATTRIBUTE_NAME_NODE_T* ast_html_attribute_name_node_init(token_T* name, position_T* start_position, position_T* end_position, array_T* errors);
314
+ AST_HTML_ATTRIBUTE_NAME_NODE_T* ast_html_attribute_name_node_init(array_T* children, position_T* start_position, position_T* end_position, array_T* errors);
309
315
  AST_HTML_ATTRIBUTE_NODE_T* ast_html_attribute_node_init(struct AST_HTML_ATTRIBUTE_NAME_NODE_STRUCT* name, token_T* equals, struct AST_HTML_ATTRIBUTE_VALUE_NODE_STRUCT* value, position_T* start_position, position_T* end_position, array_T* errors);
310
316
  AST_HTML_TEXT_NODE_T* ast_html_text_node_init(const char* content, position_T* start_position, position_T* end_position, array_T* errors);
311
317
  AST_HTML_COMMENT_NODE_T* ast_html_comment_node_init(token_T* comment_start, array_T* children, token_T* comment_end, position_T* start_position, position_T* end_position, array_T* errors);
312
318
  AST_HTML_DOCTYPE_NODE_T* ast_html_doctype_node_init(token_T* tag_opening, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
319
+ AST_XML_DECLARATION_NODE_T* ast_xml_declaration_node_init(token_T* tag_opening, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
320
+ AST_CDATA_NODE_T* ast_cdata_node_init(token_T* tag_opening, array_T* children, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
313
321
  AST_WHITESPACE_NODE_T* ast_whitespace_node_init(token_T* value, position_T* start_position, position_T* end_position, array_T* errors);
314
322
  AST_ERB_CONTENT_NODE_T* ast_erb_content_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, analyzed_ruby_T* analyzed_ruby, bool parsed, bool valid, position_T* start_position, position_T* end_position, array_T* errors);
315
323
  AST_ERB_END_NODE_T* ast_erb_end_node_init(token_T* tag_opening, token_T* content, token_T* tag_closing, position_T* start_position, position_T* end_position, array_T* errors);
@@ -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/src/include/ast_pretty_print.h.erb
2
+ // be modified manually. See /Users/marcoroth/Development/herb-release-0.6.0/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