herb 0.7.4-aarch64-linux-gnu → 0.8.0-aarch64-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 (176) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +8 -5
  3. data/config.yml +40 -20
  4. data/ext/herb/error_helpers.c +57 -3
  5. data/ext/herb/error_helpers.h +1 -1
  6. data/ext/herb/extconf.rb +1 -0
  7. data/ext/herb/extension.c +10 -24
  8. data/ext/herb/extension_helpers.c +12 -18
  9. data/ext/herb/extension_helpers.h +4 -4
  10. data/ext/herb/nodes.c +72 -37
  11. data/herb.gemspec +0 -2
  12. data/lib/herb/3.0/herb.so +0 -0
  13. data/lib/herb/3.1/herb.so +0 -0
  14. data/lib/herb/3.2/herb.so +0 -0
  15. data/lib/herb/3.3/herb.so +0 -0
  16. data/lib/herb/3.4/herb.so +0 -0
  17. data/lib/herb/ast/helpers.rb +11 -0
  18. data/lib/herb/ast/node.rb +15 -6
  19. data/lib/herb/ast/nodes.rb +609 -392
  20. data/lib/herb/cli.rb +31 -0
  21. data/lib/herb/colors.rb +82 -0
  22. data/lib/herb/engine/compiler.rb +140 -14
  23. data/lib/herb/engine/debug_visitor.rb +1 -5
  24. data/lib/herb/engine/parser_error_overlay.rb +1 -1
  25. data/lib/herb/engine.rb +18 -20
  26. data/lib/herb/errors.rb +166 -56
  27. data/lib/herb/location.rb +2 -2
  28. data/lib/herb/project.rb +86 -21
  29. data/lib/herb/token.rb +14 -2
  30. data/lib/herb/version.rb +1 -1
  31. data/lib/herb.rb +1 -0
  32. data/sig/herb/ast/helpers.rbs +3 -0
  33. data/sig/herb/ast/node.rbs +12 -5
  34. data/sig/herb/ast/nodes.rbs +124 -62
  35. data/sig/herb/colors.rbs +35 -0
  36. data/sig/herb/engine/compiler.rbs +23 -1
  37. data/sig/herb/errors.rbs +74 -20
  38. data/sig/herb/token.rbs +8 -0
  39. data/sig/herb_c_extension.rbs +1 -1
  40. data/sig/serialized_ast_errors.rbs +8 -0
  41. data/src/analyze.c +461 -249
  42. data/src/analyze_helpers.c +5 -0
  43. data/src/analyze_missing_end.c +147 -0
  44. data/src/analyze_transform.c +196 -0
  45. data/src/analyzed_ruby.c +23 -2
  46. data/src/ast_node.c +14 -17
  47. data/src/ast_nodes.c +179 -181
  48. data/src/ast_pretty_print.c +232 -232
  49. data/src/element_source.c +7 -6
  50. data/src/errors.c +272 -152
  51. data/src/extract.c +92 -34
  52. data/src/herb.c +37 -49
  53. data/src/html_util.c +34 -96
  54. data/src/include/analyze.h +10 -2
  55. data/src/include/analyze_helpers.h +3 -0
  56. data/src/include/analyzed_ruby.h +4 -2
  57. data/src/include/ast_node.h +4 -4
  58. data/src/include/ast_nodes.h +68 -67
  59. data/src/include/ast_pretty_print.h +2 -2
  60. data/src/include/element_source.h +3 -1
  61. data/src/include/errors.h +42 -26
  62. data/src/include/extract.h +4 -4
  63. data/src/include/herb.h +6 -7
  64. data/src/include/html_util.h +4 -5
  65. data/src/include/lexer.h +1 -3
  66. data/src/include/lexer_peek_helpers.h +21 -19
  67. data/src/include/lexer_struct.h +12 -10
  68. data/src/include/location.h +10 -13
  69. data/src/include/macros.h +4 -0
  70. data/src/include/parser.h +12 -6
  71. data/src/include/parser_helpers.h +26 -16
  72. data/src/include/position.h +3 -14
  73. data/src/include/pretty_print.h +38 -28
  74. data/src/include/prism_helpers.h +1 -1
  75. data/src/include/range.h +4 -13
  76. data/src/include/token.h +5 -11
  77. data/src/include/token_struct.h +2 -2
  78. data/src/include/utf8.h +3 -2
  79. data/src/include/util/hb_arena.h +31 -0
  80. data/src/include/util/hb_arena_debug.h +8 -0
  81. data/src/include/util/hb_array.h +33 -0
  82. data/src/include/util/hb_buffer.h +34 -0
  83. data/src/include/util/hb_string.h +29 -0
  84. data/src/include/util/hb_system.h +9 -0
  85. data/src/include/util.h +3 -14
  86. data/src/include/version.h +1 -1
  87. data/src/include/visitor.h +1 -1
  88. data/src/io.c +7 -4
  89. data/src/lexer.c +62 -88
  90. data/src/lexer_peek_helpers.c +42 -38
  91. data/src/location.c +9 -37
  92. data/src/main.c +19 -23
  93. data/src/parser.c +373 -313
  94. data/src/parser_helpers.c +60 -54
  95. data/src/parser_match_tags.c +316 -0
  96. data/src/pretty_print.c +88 -117
  97. data/src/prism_helpers.c +7 -7
  98. data/src/range.c +2 -35
  99. data/src/token.c +36 -87
  100. data/src/utf8.c +4 -4
  101. data/src/util/hb_arena.c +179 -0
  102. data/src/util/hb_arena_debug.c +237 -0
  103. data/src/{array.c → util/hb_array.c} +26 -27
  104. data/src/util/hb_buffer.c +203 -0
  105. data/src/util/hb_string.c +85 -0
  106. data/src/util/hb_system.c +30 -0
  107. data/src/util.c +29 -99
  108. data/src/visitor.c +54 -54
  109. data/templates/ext/herb/error_helpers.c.erb +3 -3
  110. data/templates/ext/herb/error_helpers.h.erb +1 -1
  111. data/templates/ext/herb/nodes.c.erb +11 -6
  112. data/templates/java/error_helpers.c.erb +75 -0
  113. data/templates/java/error_helpers.h.erb +20 -0
  114. data/templates/java/nodes.c.erb +97 -0
  115. data/templates/java/nodes.h.erb +23 -0
  116. data/templates/java/org/herb/ast/Errors.java.erb +121 -0
  117. data/templates/java/org/herb/ast/NodeVisitor.java.erb +14 -0
  118. data/templates/java/org/herb/ast/Nodes.java.erb +220 -0
  119. data/templates/java/org/herb/ast/Visitor.java.erb +56 -0
  120. data/templates/javascript/packages/core/src/visitor.ts.erb +29 -1
  121. data/templates/javascript/packages/node/extension/error_helpers.cpp.erb +8 -8
  122. data/templates/javascript/packages/node/extension/error_helpers.h.erb +1 -1
  123. data/templates/javascript/packages/node/extension/nodes.cpp.erb +9 -9
  124. data/templates/javascript/packages/node/extension/nodes.h.erb +1 -1
  125. data/templates/lib/herb/ast/nodes.rb.erb +28 -16
  126. data/templates/lib/herb/errors.rb.erb +17 -12
  127. data/templates/rust/src/ast/nodes.rs.erb +220 -0
  128. data/templates/rust/src/errors.rs.erb +216 -0
  129. data/templates/rust/src/nodes.rs.erb +374 -0
  130. data/templates/src/analyze_missing_end.c.erb +36 -0
  131. data/templates/src/analyze_transform.c.erb +24 -0
  132. data/templates/src/ast_nodes.c.erb +14 -16
  133. data/templates/src/ast_pretty_print.c.erb +36 -36
  134. data/templates/src/errors.c.erb +36 -38
  135. data/templates/src/include/ast_nodes.h.erb +11 -10
  136. data/templates/src/include/ast_pretty_print.h.erb +2 -2
  137. data/templates/src/include/errors.h.erb +9 -9
  138. data/templates/src/parser_match_tags.c.erb +38 -0
  139. data/templates/src/visitor.c.erb +4 -4
  140. data/templates/template.rb +22 -3
  141. data/templates/wasm/error_helpers.cpp.erb +9 -9
  142. data/templates/wasm/error_helpers.h.erb +1 -1
  143. data/templates/wasm/nodes.cpp.erb +9 -9
  144. data/templates/wasm/nodes.h.erb +1 -1
  145. data/vendor/prism/Rakefile +4 -1
  146. data/vendor/prism/config.yml +2 -1
  147. data/vendor/prism/include/prism/ast.h +31 -1
  148. data/vendor/prism/include/prism/diagnostic.h +1 -0
  149. data/vendor/prism/include/prism/version.h +3 -3
  150. data/vendor/prism/src/diagnostic.c +3 -1
  151. data/vendor/prism/src/prism.c +130 -71
  152. data/vendor/prism/src/util/pm_string.c +6 -8
  153. data/vendor/prism/templates/include/prism/ast.h.erb +2 -0
  154. data/vendor/prism/templates/java/org/prism/Loader.java.erb +2 -2
  155. data/vendor/prism/templates/javascript/src/deserialize.js.erb +2 -2
  156. data/vendor/prism/templates/lib/prism/serialize.rb.erb +2 -2
  157. data/vendor/prism/templates/sig/prism.rbs.erb +4 -0
  158. data/vendor/prism/templates/src/diagnostic.c.erb +1 -0
  159. metadata +34 -21
  160. data/lib/herb/libherb/array.rb +0 -51
  161. data/lib/herb/libherb/ast_node.rb +0 -50
  162. data/lib/herb/libherb/buffer.rb +0 -56
  163. data/lib/herb/libherb/extract_result.rb +0 -20
  164. data/lib/herb/libherb/lex_result.rb +0 -32
  165. data/lib/herb/libherb/libherb.rb +0 -52
  166. data/lib/herb/libherb/parse_result.rb +0 -20
  167. data/lib/herb/libherb/token.rb +0 -46
  168. data/lib/herb/libherb.rb +0 -35
  169. data/src/buffer.c +0 -232
  170. data/src/include/array.h +0 -33
  171. data/src/include/buffer.h +0 -39
  172. data/src/include/json.h +0 -28
  173. data/src/include/memory.h +0 -12
  174. data/src/json.c +0 -205
  175. data/src/memory.c +0 -53
  176. data/src/position.c +0 -33
@@ -7,6 +7,8 @@
7
7
  module Herb
8
8
  module AST
9
9
  class DocumentNode < Node
10
+ include Colors
11
+
10
12
  attr_reader :children #: Array[Herb::AST::Node]
11
13
 
12
14
  #: (String, Location, Array[Herb::Errors::Error], Array[Herb::AST::Node]) -> void
@@ -42,18 +44,23 @@ module Herb
42
44
  tree_inspect.rstrip.gsub(/\s+$/, "")
43
45
  end
44
46
 
45
- #: (?Integer) -> String
46
- def tree_inspect(indent = 0)
47
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
48
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
47
49
  output = +""
48
50
 
49
- output += "@ #{node_name} "
50
- output += location.tree_inspect
51
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
51
52
  output += "\n"
52
53
 
54
+ if depth >= depth_limit
55
+ output += dimmed("└── [depth limit reached ...]\n\n")
56
+
57
+ return output.gsub(/^/, " " * indent)
58
+ end
59
+
53
60
  output += inspect_errors(prefix: "│ ")
54
61
 
55
- output += "└── children: "
56
- output += inspect_array(children, prefix: " ")
62
+ output += white("└── children: ")
63
+ output += inspect_array(children, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
57
64
  output += "\n"
58
65
 
59
66
  output.gsub(/^/, " " * indent)
@@ -61,6 +68,8 @@ module Herb
61
68
  end
62
69
 
63
70
  class LiteralNode < Node
71
+ include Colors
72
+
64
73
  attr_reader :content #: String
65
74
 
66
75
  #: (String, Location, Array[Herb::Errors::Error], String) -> void
@@ -96,17 +105,22 @@ module Herb
96
105
  tree_inspect.rstrip.gsub(/\s+$/, "")
97
106
  end
98
107
 
99
- #: (?Integer) -> String
100
- def tree_inspect(indent = 0)
108
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
109
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
101
110
  output = +""
102
111
 
103
- output += "@ #{node_name} "
104
- output += location.tree_inspect
112
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
105
113
  output += "\n"
106
114
 
115
+ if depth >= depth_limit
116
+ output += dimmed("└── [depth limit reached ...]\n\n")
117
+
118
+ return output.gsub(/^/, " " * indent)
119
+ end
120
+
107
121
  output += inspect_errors(prefix: "│ ")
108
122
 
109
- output += %(└── content: #{content.inspect}\n)
123
+ output += white("└── content: ") + green("#{content.inspect}\n")
110
124
  output += "\n"
111
125
 
112
126
  output.gsub(/^/, " " * indent)
@@ -114,6 +128,8 @@ module Herb
114
128
  end
115
129
 
116
130
  class HTMLOpenTagNode < Node
131
+ include Colors
132
+
117
133
  attr_reader :tag_opening #: Herb::Token
118
134
  attr_reader :tag_name #: Herb::Token
119
135
  attr_reader :tag_closing #: Herb::Token
@@ -161,29 +177,34 @@ module Herb
161
177
  tree_inspect.rstrip.gsub(/\s+$/, "")
162
178
  end
163
179
 
164
- #: (?Integer) -> String
165
- def tree_inspect(indent = 0)
180
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
181
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
166
182
  output = +""
167
183
 
168
- output += "@ #{node_name} "
169
- output += location.tree_inspect
184
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
170
185
  output += "\n"
171
186
 
187
+ if depth >= depth_limit
188
+ output += dimmed("└── [depth limit reached ...]\n\n")
189
+
190
+ return output.gsub(/^/, " " * indent)
191
+ end
192
+
172
193
  output += inspect_errors(prefix: "│ ")
173
194
 
174
- output += "├── tag_opening: "
175
- output += tag_opening ? tag_opening.tree_inspect : "∅"
195
+ output += white("├── tag_opening: ")
196
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
176
197
  output += "\n"
177
- output += "├── tag_name: "
178
- output += tag_name ? tag_name.tree_inspect : "∅"
198
+ output += white("├── tag_name: ")
199
+ output += tag_name ? tag_name.tree_inspect : magenta("∅")
179
200
  output += "\n"
180
- output += "├── tag_closing: "
181
- output += tag_closing ? tag_closing.tree_inspect : "∅"
201
+ output += white("├── tag_closing: ")
202
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
182
203
  output += "\n"
183
- output += "├── children: "
184
- output += inspect_array(children, prefix: "│ ")
185
- output += "└── is_void: "
186
- output += [true, false].include?(is_void) ? is_void.to_s : "∅"
204
+ output += white("├── children: ")
205
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
206
+ output += white("└── is_void: ")
207
+ output += [true, false].include?(is_void) ? bold(magenta(is_void.to_s)) : magenta("∅")
187
208
  output += "\n"
188
209
  output += "\n"
189
210
 
@@ -192,6 +213,8 @@ module Herb
192
213
  end
193
214
 
194
215
  class HTMLCloseTagNode < Node
216
+ include Colors
217
+
195
218
  attr_reader :tag_opening #: Herb::Token
196
219
  attr_reader :tag_name #: Herb::Token
197
220
  attr_reader :children #: Array[Herb::AST::Node]
@@ -236,26 +259,31 @@ module Herb
236
259
  tree_inspect.rstrip.gsub(/\s+$/, "")
237
260
  end
238
261
 
239
- #: (?Integer) -> String
240
- def tree_inspect(indent = 0)
262
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
263
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
241
264
  output = +""
242
265
 
243
- output += "@ #{node_name} "
244
- output += location.tree_inspect
266
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
245
267
  output += "\n"
246
268
 
269
+ if depth >= depth_limit
270
+ output += dimmed("└── [depth limit reached ...]\n\n")
271
+
272
+ return output.gsub(/^/, " " * indent)
273
+ end
274
+
247
275
  output += inspect_errors(prefix: "│ ")
248
276
 
249
- output += "├── tag_opening: "
250
- output += tag_opening ? tag_opening.tree_inspect : "∅"
277
+ output += white("├── tag_opening: ")
278
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
251
279
  output += "\n"
252
- output += "├── tag_name: "
253
- output += tag_name ? tag_name.tree_inspect : "∅"
280
+ output += white("├── tag_name: ")
281
+ output += tag_name ? tag_name.tree_inspect : magenta("∅")
254
282
  output += "\n"
255
- output += "├── children: "
256
- output += inspect_array(children, prefix: "│ ")
257
- output += "└── tag_closing: "
258
- output += tag_closing ? tag_closing.tree_inspect : "∅"
283
+ output += white("├── children: ")
284
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
285
+ output += white("└── tag_closing: ")
286
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
259
287
  output += "\n"
260
288
  output += "\n"
261
289
 
@@ -264,6 +292,8 @@ module Herb
264
292
  end
265
293
 
266
294
  class HTMLElementNode < Node
295
+ include Colors
296
+
267
297
  attr_reader :open_tag #: Herb::AST::HTMLOpenTagNode
268
298
  attr_reader :tag_name #: Herb::Token
269
299
  attr_reader :body #: Array[Herb::AST::Node]
@@ -314,41 +344,46 @@ module Herb
314
344
  tree_inspect.rstrip.gsub(/\s+$/, "")
315
345
  end
316
346
 
317
- #: (?Integer) -> String
318
- def tree_inspect(indent = 0)
347
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
348
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
319
349
  output = +""
320
350
 
321
- output += "@ #{node_name} "
322
- output += location.tree_inspect
351
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
323
352
  output += "\n"
324
353
 
354
+ if depth >= depth_limit
355
+ output += dimmed("└── [depth limit reached ...]\n\n")
356
+
357
+ return output.gsub(/^/, " " * indent)
358
+ end
359
+
325
360
  output += inspect_errors(prefix: "│ ")
326
361
 
327
- output += "├── open_tag: "
362
+ output += white("├── open_tag: ")
328
363
  if open_tag
329
364
  output += "\n"
330
365
  output += "│ └── "
331
- output += open_tag.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
366
+ output += open_tag.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
332
367
  else
333
- output += "∅\n"
368
+ output += magenta("∅\n")
334
369
  end
335
- output += "├── tag_name: "
336
- output += tag_name ? tag_name.tree_inspect : "∅"
370
+ output += white("├── tag_name: ")
371
+ output += tag_name ? tag_name.tree_inspect : magenta("∅")
337
372
  output += "\n"
338
- output += "├── body: "
339
- output += inspect_array(body, prefix: "│ ")
340
- output += "├── close_tag: "
373
+ output += white("├── body: ")
374
+ output += inspect_array(body, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
375
+ output += white("├── close_tag: ")
341
376
  if close_tag
342
377
  output += "\n"
343
378
  output += "│ └── "
344
- output += close_tag.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
379
+ output += close_tag.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
345
380
  else
346
- output += "∅\n"
381
+ output += magenta("∅\n")
347
382
  end
348
- output += "├── is_void: "
349
- output += [true, false].include?(is_void) ? is_void.to_s : "∅"
383
+ output += white("├── is_void: ")
384
+ output += [true, false].include?(is_void) ? bold(magenta(is_void.to_s)) : magenta("∅")
350
385
  output += "\n"
351
- output += %(└── source: #{source.inspect}\n)
386
+ output += white("└── source: #{green(source.inspect)}\n")
352
387
  output += "\n"
353
388
 
354
389
  output.gsub(/^/, " " * indent)
@@ -356,6 +391,8 @@ module Herb
356
391
  end
357
392
 
358
393
  class HTMLAttributeValueNode < Node
394
+ include Colors
395
+
359
396
  attr_reader :open_quote #: Herb::Token
360
397
  attr_reader :children #: Array[Herb::AST::Node]
361
398
  attr_reader :close_quote #: Herb::Token
@@ -400,26 +437,31 @@ module Herb
400
437
  tree_inspect.rstrip.gsub(/\s+$/, "")
401
438
  end
402
439
 
403
- #: (?Integer) -> String
404
- def tree_inspect(indent = 0)
440
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
441
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
405
442
  output = +""
406
443
 
407
- output += "@ #{node_name} "
408
- output += location.tree_inspect
444
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
409
445
  output += "\n"
410
446
 
447
+ if depth >= depth_limit
448
+ output += dimmed("└── [depth limit reached ...]\n\n")
449
+
450
+ return output.gsub(/^/, " " * indent)
451
+ end
452
+
411
453
  output += inspect_errors(prefix: "│ ")
412
454
 
413
- output += "├── open_quote: "
414
- output += open_quote ? open_quote.tree_inspect : "∅"
455
+ output += white("├── open_quote: ")
456
+ output += open_quote ? open_quote.tree_inspect : magenta("∅")
415
457
  output += "\n"
416
- output += "├── children: "
417
- output += inspect_array(children, prefix: "│ ")
418
- output += "├── close_quote: "
419
- output += close_quote ? close_quote.tree_inspect : "∅"
458
+ output += white("├── children: ")
459
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
460
+ output += white("├── close_quote: ")
461
+ output += close_quote ? close_quote.tree_inspect : magenta("∅")
420
462
  output += "\n"
421
- output += "└── quoted: "
422
- output += [true, false].include?(quoted) ? quoted.to_s : "∅"
463
+ output += white("└── quoted: ")
464
+ output += [true, false].include?(quoted) ? bold(magenta(quoted.to_s)) : magenta("∅")
423
465
  output += "\n"
424
466
  output += "\n"
425
467
 
@@ -428,6 +470,8 @@ module Herb
428
470
  end
429
471
 
430
472
  class HTMLAttributeNameNode < Node
473
+ include Colors
474
+
431
475
  attr_reader :children #: Array[Herb::AST::Node]
432
476
 
433
477
  #: (String, Location, Array[Herb::Errors::Error], Array[Herb::AST::Node]) -> void
@@ -463,18 +507,23 @@ module Herb
463
507
  tree_inspect.rstrip.gsub(/\s+$/, "")
464
508
  end
465
509
 
466
- #: (?Integer) -> String
467
- def tree_inspect(indent = 0)
510
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
511
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
468
512
  output = +""
469
513
 
470
- output += "@ #{node_name} "
471
- output += location.tree_inspect
514
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
472
515
  output += "\n"
473
516
 
517
+ if depth >= depth_limit
518
+ output += dimmed("└── [depth limit reached ...]\n\n")
519
+
520
+ return output.gsub(/^/, " " * indent)
521
+ end
522
+
474
523
  output += inspect_errors(prefix: "│ ")
475
524
 
476
- output += "└── children: "
477
- output += inspect_array(children, prefix: " ")
525
+ output += white("└── children: ")
526
+ output += inspect_array(children, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
478
527
  output += "\n"
479
528
 
480
529
  output.gsub(/^/, " " * indent)
@@ -482,6 +531,8 @@ module Herb
482
531
  end
483
532
 
484
533
  class HTMLAttributeNode < Node
534
+ include Colors
535
+
485
536
  attr_reader :name #: Herb::AST::HTMLAttributeNameNode
486
537
  attr_reader :equals #: Herb::Token
487
538
  attr_reader :value #: Herb::AST::HTMLAttributeValueNode
@@ -523,34 +574,39 @@ module Herb
523
574
  tree_inspect.rstrip.gsub(/\s+$/, "")
524
575
  end
525
576
 
526
- #: (?Integer) -> String
527
- def tree_inspect(indent = 0)
577
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
578
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
528
579
  output = +""
529
580
 
530
- output += "@ #{node_name} "
531
- output += location.tree_inspect
581
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
532
582
  output += "\n"
533
583
 
584
+ if depth >= depth_limit
585
+ output += dimmed("└── [depth limit reached ...]\n\n")
586
+
587
+ return output.gsub(/^/, " " * indent)
588
+ end
589
+
534
590
  output += inspect_errors(prefix: "│ ")
535
591
 
536
- output += "├── name: "
592
+ output += white("├── name: ")
537
593
  if name
538
594
  output += "\n"
539
595
  output += "│ └── "
540
- output += name.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
596
+ output += name.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
541
597
  else
542
- output += "∅\n"
598
+ output += magenta("∅\n")
543
599
  end
544
- output += "├── equals: "
545
- output += equals ? equals.tree_inspect : "∅"
600
+ output += white("├── equals: ")
601
+ output += equals ? equals.tree_inspect : magenta("∅")
546
602
  output += "\n"
547
- output += "└── value: "
603
+ output += white("└── value: ")
548
604
  if value
549
605
  output += "\n"
550
606
  output += " └── "
551
- output += value.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
607
+ output += value.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
552
608
  else
553
- output += "∅\n"
609
+ output += magenta("∅\n")
554
610
  end
555
611
  output += "\n"
556
612
 
@@ -559,6 +615,8 @@ module Herb
559
615
  end
560
616
 
561
617
  class HTMLTextNode < Node
618
+ include Colors
619
+
562
620
  attr_reader :content #: String
563
621
 
564
622
  #: (String, Location, Array[Herb::Errors::Error], String) -> void
@@ -594,17 +652,22 @@ module Herb
594
652
  tree_inspect.rstrip.gsub(/\s+$/, "")
595
653
  end
596
654
 
597
- #: (?Integer) -> String
598
- def tree_inspect(indent = 0)
655
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
656
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
599
657
  output = +""
600
658
 
601
- output += "@ #{node_name} "
602
- output += location.tree_inspect
659
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
603
660
  output += "\n"
604
661
 
662
+ if depth >= depth_limit
663
+ output += dimmed("└── [depth limit reached ...]\n\n")
664
+
665
+ return output.gsub(/^/, " " * indent)
666
+ end
667
+
605
668
  output += inspect_errors(prefix: "│ ")
606
669
 
607
- output += %(└── content: #{content.inspect}\n)
670
+ output += white("└── content: ") + green("#{content.inspect}\n")
608
671
  output += "\n"
609
672
 
610
673
  output.gsub(/^/, " " * indent)
@@ -612,6 +675,8 @@ module Herb
612
675
  end
613
676
 
614
677
  class HTMLCommentNode < Node
678
+ include Colors
679
+
615
680
  attr_reader :comment_start #: Herb::Token
616
681
  attr_reader :children #: Array[Herb::AST::Node]
617
682
  attr_reader :comment_end #: Herb::Token
@@ -653,23 +718,28 @@ module Herb
653
718
  tree_inspect.rstrip.gsub(/\s+$/, "")
654
719
  end
655
720
 
656
- #: (?Integer) -> String
657
- def tree_inspect(indent = 0)
721
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
722
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
658
723
  output = +""
659
724
 
660
- output += "@ #{node_name} "
661
- output += location.tree_inspect
725
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
662
726
  output += "\n"
663
727
 
728
+ if depth >= depth_limit
729
+ output += dimmed("└── [depth limit reached ...]\n\n")
730
+
731
+ return output.gsub(/^/, " " * indent)
732
+ end
733
+
664
734
  output += inspect_errors(prefix: "│ ")
665
735
 
666
- output += "├── comment_start: "
667
- output += comment_start ? comment_start.tree_inspect : "∅"
736
+ output += white("├── comment_start: ")
737
+ output += comment_start ? comment_start.tree_inspect : magenta("∅")
668
738
  output += "\n"
669
- output += "├── children: "
670
- output += inspect_array(children, prefix: "│ ")
671
- output += "└── comment_end: "
672
- output += comment_end ? comment_end.tree_inspect : "∅"
739
+ output += white("├── children: ")
740
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
741
+ output += white("└── comment_end: ")
742
+ output += comment_end ? comment_end.tree_inspect : magenta("∅")
673
743
  output += "\n"
674
744
  output += "\n"
675
745
 
@@ -678,6 +748,8 @@ module Herb
678
748
  end
679
749
 
680
750
  class HTMLDoctypeNode < Node
751
+ include Colors
752
+
681
753
  attr_reader :tag_opening #: Herb::Token
682
754
  attr_reader :children #: Array[Herb::AST::Node]
683
755
  attr_reader :tag_closing #: Herb::Token
@@ -719,23 +791,28 @@ module Herb
719
791
  tree_inspect.rstrip.gsub(/\s+$/, "")
720
792
  end
721
793
 
722
- #: (?Integer) -> String
723
- def tree_inspect(indent = 0)
794
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
795
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
724
796
  output = +""
725
797
 
726
- output += "@ #{node_name} "
727
- output += location.tree_inspect
798
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
728
799
  output += "\n"
729
800
 
801
+ if depth >= depth_limit
802
+ output += dimmed("└── [depth limit reached ...]\n\n")
803
+
804
+ return output.gsub(/^/, " " * indent)
805
+ end
806
+
730
807
  output += inspect_errors(prefix: "│ ")
731
808
 
732
- output += "├── tag_opening: "
733
- output += tag_opening ? tag_opening.tree_inspect : "∅"
809
+ output += white("├── tag_opening: ")
810
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
734
811
  output += "\n"
735
- output += "├── children: "
736
- output += inspect_array(children, prefix: "│ ")
737
- output += "└── tag_closing: "
738
- output += tag_closing ? tag_closing.tree_inspect : "∅"
812
+ output += white("├── children: ")
813
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
814
+ output += white("└── tag_closing: ")
815
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
739
816
  output += "\n"
740
817
  output += "\n"
741
818
 
@@ -744,6 +821,8 @@ module Herb
744
821
  end
745
822
 
746
823
  class XMLDeclarationNode < Node
824
+ include Colors
825
+
747
826
  attr_reader :tag_opening #: Herb::Token
748
827
  attr_reader :children #: Array[Herb::AST::Node]
749
828
  attr_reader :tag_closing #: Herb::Token
@@ -785,23 +864,28 @@ module Herb
785
864
  tree_inspect.rstrip.gsub(/\s+$/, "")
786
865
  end
787
866
 
788
- #: (?Integer) -> String
789
- def tree_inspect(indent = 0)
867
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
868
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
790
869
  output = +""
791
870
 
792
- output += "@ #{node_name} "
793
- output += location.tree_inspect
871
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
794
872
  output += "\n"
795
873
 
874
+ if depth >= depth_limit
875
+ output += dimmed("└── [depth limit reached ...]\n\n")
876
+
877
+ return output.gsub(/^/, " " * indent)
878
+ end
879
+
796
880
  output += inspect_errors(prefix: "│ ")
797
881
 
798
- output += "├── tag_opening: "
799
- output += tag_opening ? tag_opening.tree_inspect : "∅"
882
+ output += white("├── tag_opening: ")
883
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
800
884
  output += "\n"
801
- output += "├── children: "
802
- output += inspect_array(children, prefix: "│ ")
803
- output += "└── tag_closing: "
804
- output += tag_closing ? tag_closing.tree_inspect : "∅"
885
+ output += white("├── children: ")
886
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
887
+ output += white("└── tag_closing: ")
888
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
805
889
  output += "\n"
806
890
  output += "\n"
807
891
 
@@ -810,6 +894,8 @@ module Herb
810
894
  end
811
895
 
812
896
  class CDATANode < Node
897
+ include Colors
898
+
813
899
  attr_reader :tag_opening #: Herb::Token
814
900
  attr_reader :children #: Array[Herb::AST::Node]
815
901
  attr_reader :tag_closing #: Herb::Token
@@ -851,23 +937,28 @@ module Herb
851
937
  tree_inspect.rstrip.gsub(/\s+$/, "")
852
938
  end
853
939
 
854
- #: (?Integer) -> String
855
- def tree_inspect(indent = 0)
940
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
941
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
856
942
  output = +""
857
943
 
858
- output += "@ #{node_name} "
859
- output += location.tree_inspect
944
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
860
945
  output += "\n"
861
946
 
947
+ if depth >= depth_limit
948
+ output += dimmed("└── [depth limit reached ...]\n\n")
949
+
950
+ return output.gsub(/^/, " " * indent)
951
+ end
952
+
862
953
  output += inspect_errors(prefix: "│ ")
863
954
 
864
- output += "├── tag_opening: "
865
- output += tag_opening ? tag_opening.tree_inspect : "∅"
955
+ output += white("├── tag_opening: ")
956
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
866
957
  output += "\n"
867
- output += "├── children: "
868
- output += inspect_array(children, prefix: "│ ")
869
- output += "└── tag_closing: "
870
- output += tag_closing ? tag_closing.tree_inspect : "∅"
958
+ output += white("├── children: ")
959
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
960
+ output += white("└── tag_closing: ")
961
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
871
962
  output += "\n"
872
963
  output += "\n"
873
964
 
@@ -876,6 +967,8 @@ module Herb
876
967
  end
877
968
 
878
969
  class WhitespaceNode < Node
970
+ include Colors
971
+
879
972
  attr_reader :value #: Herb::Token
880
973
 
881
974
  #: (String, Location, Array[Herb::Errors::Error], Herb::Token) -> void
@@ -911,18 +1004,23 @@ module Herb
911
1004
  tree_inspect.rstrip.gsub(/\s+$/, "")
912
1005
  end
913
1006
 
914
- #: (?Integer) -> String
915
- def tree_inspect(indent = 0)
1007
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1008
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
916
1009
  output = +""
917
1010
 
918
- output += "@ #{node_name} "
919
- output += location.tree_inspect
1011
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
920
1012
  output += "\n"
921
1013
 
1014
+ if depth >= depth_limit
1015
+ output += dimmed("└── [depth limit reached ...]\n\n")
1016
+
1017
+ return output.gsub(/^/, " " * indent)
1018
+ end
1019
+
922
1020
  output += inspect_errors(prefix: "│ ")
923
1021
 
924
- output += "└── value: "
925
- output += value ? value.tree_inspect : "∅"
1022
+ output += white("└── value: ")
1023
+ output += value ? value.tree_inspect : magenta("∅")
926
1024
  output += "\n"
927
1025
  output += "\n"
928
1026
 
@@ -931,6 +1029,8 @@ module Herb
931
1029
  end
932
1030
 
933
1031
  class ERBContentNode < Node
1032
+ include Colors
1033
+
934
1034
  attr_reader :tag_opening #: Herb::Token
935
1035
  attr_reader :content #: Herb::Token
936
1036
  attr_reader :tag_closing #: Herb::Token
@@ -981,31 +1081,36 @@ module Herb
981
1081
  tree_inspect.rstrip.gsub(/\s+$/, "")
982
1082
  end
983
1083
 
984
- #: (?Integer) -> String
985
- def tree_inspect(indent = 0)
1084
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1085
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
986
1086
  output = +""
987
1087
 
988
- output += "@ #{node_name} "
989
- output += location.tree_inspect
1088
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
990
1089
  output += "\n"
991
1090
 
1091
+ if depth >= depth_limit
1092
+ output += dimmed("└── [depth limit reached ...]\n\n")
1093
+
1094
+ return output.gsub(/^/, " " * indent)
1095
+ end
1096
+
992
1097
  output += inspect_errors(prefix: "│ ")
993
1098
 
994
- output += "├── tag_opening: "
995
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1099
+ output += white("├── tag_opening: ")
1100
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
996
1101
  output += "\n"
997
- output += "├── content: "
998
- output += content ? content.tree_inspect : "∅"
1102
+ output += white("├── content: ")
1103
+ output += content ? content.tree_inspect : magenta("∅")
999
1104
  output += "\n"
1000
- output += "├── tag_closing: "
1001
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1105
+ output += white("├── tag_closing: ")
1106
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1002
1107
  output += "\n"
1003
1108
  # no-op for analyzed_ruby
1004
- output += "├── parsed: "
1005
- output += [true, false].include?(parsed) ? parsed.to_s : "∅"
1109
+ output += white("├── parsed: ")
1110
+ output += [true, false].include?(parsed) ? bold(magenta(parsed.to_s)) : magenta("∅")
1006
1111
  output += "\n"
1007
- output += "└── valid: "
1008
- output += [true, false].include?(valid) ? valid.to_s : "∅"
1112
+ output += white("└── valid: ")
1113
+ output += [true, false].include?(valid) ? bold(magenta(valid.to_s)) : magenta("∅")
1009
1114
  output += "\n"
1010
1115
  output += "\n"
1011
1116
 
@@ -1014,6 +1119,8 @@ module Herb
1014
1119
  end
1015
1120
 
1016
1121
  class ERBEndNode < Node
1122
+ include Colors
1123
+
1017
1124
  attr_reader :tag_opening #: Herb::Token
1018
1125
  attr_reader :content #: Herb::Token
1019
1126
  attr_reader :tag_closing #: Herb::Token
@@ -1055,24 +1162,29 @@ module Herb
1055
1162
  tree_inspect.rstrip.gsub(/\s+$/, "")
1056
1163
  end
1057
1164
 
1058
- #: (?Integer) -> String
1059
- def tree_inspect(indent = 0)
1165
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1166
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1060
1167
  output = +""
1061
1168
 
1062
- output += "@ #{node_name} "
1063
- output += location.tree_inspect
1169
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1064
1170
  output += "\n"
1065
1171
 
1172
+ if depth >= depth_limit
1173
+ output += dimmed("└── [depth limit reached ...]\n\n")
1174
+
1175
+ return output.gsub(/^/, " " * indent)
1176
+ end
1177
+
1066
1178
  output += inspect_errors(prefix: "│ ")
1067
1179
 
1068
- output += "├── tag_opening: "
1069
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1180
+ output += white("├── tag_opening: ")
1181
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1070
1182
  output += "\n"
1071
- output += "├── content: "
1072
- output += content ? content.tree_inspect : "∅"
1183
+ output += white("├── content: ")
1184
+ output += content ? content.tree_inspect : magenta("∅")
1073
1185
  output += "\n"
1074
- output += "└── tag_closing: "
1075
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1186
+ output += white("└── tag_closing: ")
1187
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1076
1188
  output += "\n"
1077
1189
  output += "\n"
1078
1190
 
@@ -1081,6 +1193,8 @@ module Herb
1081
1193
  end
1082
1194
 
1083
1195
  class ERBElseNode < Node
1196
+ include Colors
1197
+
1084
1198
  attr_reader :tag_opening #: Herb::Token
1085
1199
  attr_reader :content #: Herb::Token
1086
1200
  attr_reader :tag_closing #: Herb::Token
@@ -1125,27 +1239,32 @@ module Herb
1125
1239
  tree_inspect.rstrip.gsub(/\s+$/, "")
1126
1240
  end
1127
1241
 
1128
- #: (?Integer) -> String
1129
- def tree_inspect(indent = 0)
1242
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1243
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1130
1244
  output = +""
1131
1245
 
1132
- output += "@ #{node_name} "
1133
- output += location.tree_inspect
1246
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1134
1247
  output += "\n"
1135
1248
 
1249
+ if depth >= depth_limit
1250
+ output += dimmed("└── [depth limit reached ...]\n\n")
1251
+
1252
+ return output.gsub(/^/, " " * indent)
1253
+ end
1254
+
1136
1255
  output += inspect_errors(prefix: "│ ")
1137
1256
 
1138
- output += "├── tag_opening: "
1139
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1257
+ output += white("├── tag_opening: ")
1258
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1140
1259
  output += "\n"
1141
- output += "├── content: "
1142
- output += content ? content.tree_inspect : "∅"
1260
+ output += white("├── content: ")
1261
+ output += content ? content.tree_inspect : magenta("∅")
1143
1262
  output += "\n"
1144
- output += "├── tag_closing: "
1145
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1263
+ output += white("├── tag_closing: ")
1264
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1146
1265
  output += "\n"
1147
- output += "└── statements: "
1148
- output += inspect_array(statements, prefix: " ")
1266
+ output += white("└── statements: ")
1267
+ output += inspect_array(statements, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1149
1268
  output += "\n"
1150
1269
 
1151
1270
  output.gsub(/^/, " " * indent)
@@ -1153,6 +1272,8 @@ module Herb
1153
1272
  end
1154
1273
 
1155
1274
  class ERBIfNode < Node
1275
+ include Colors
1276
+
1156
1277
  attr_reader :tag_opening #: Herb::Token
1157
1278
  attr_reader :content #: Herb::Token
1158
1279
  attr_reader :tag_closing #: Herb::Token
@@ -1203,42 +1324,47 @@ module Herb
1203
1324
  tree_inspect.rstrip.gsub(/\s+$/, "")
1204
1325
  end
1205
1326
 
1206
- #: (?Integer) -> String
1207
- def tree_inspect(indent = 0)
1327
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1328
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1208
1329
  output = +""
1209
1330
 
1210
- output += "@ #{node_name} "
1211
- output += location.tree_inspect
1331
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1212
1332
  output += "\n"
1213
1333
 
1334
+ if depth >= depth_limit
1335
+ output += dimmed("└── [depth limit reached ...]\n\n")
1336
+
1337
+ return output.gsub(/^/, " " * indent)
1338
+ end
1339
+
1214
1340
  output += inspect_errors(prefix: "│ ")
1215
1341
 
1216
- output += "├── tag_opening: "
1217
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1342
+ output += white("├── tag_opening: ")
1343
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1218
1344
  output += "\n"
1219
- output += "├── content: "
1220
- output += content ? content.tree_inspect : "∅"
1345
+ output += white("├── content: ")
1346
+ output += content ? content.tree_inspect : magenta("∅")
1221
1347
  output += "\n"
1222
- output += "├── tag_closing: "
1223
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1348
+ output += white("├── tag_closing: ")
1349
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1224
1350
  output += "\n"
1225
- output += "├── statements: "
1226
- output += inspect_array(statements, prefix: "│ ")
1227
- output += "├── subsequent: "
1351
+ output += white("├── statements: ")
1352
+ output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1353
+ output += white("├── subsequent: ")
1228
1354
  if subsequent
1229
1355
  output += "\n"
1230
1356
  output += "│ └── "
1231
- output += subsequent.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
1357
+ output += subsequent.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
1232
1358
  else
1233
- output += "∅\n"
1359
+ output += magenta("∅\n")
1234
1360
  end
1235
- output += "└── end_node: "
1361
+ output += white("└── end_node: ")
1236
1362
  if end_node
1237
1363
  output += "\n"
1238
1364
  output += " └── "
1239
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1365
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1240
1366
  else
1241
- output += "∅\n"
1367
+ output += magenta("∅\n")
1242
1368
  end
1243
1369
  output += "\n"
1244
1370
 
@@ -1247,6 +1373,8 @@ module Herb
1247
1373
  end
1248
1374
 
1249
1375
  class ERBBlockNode < Node
1376
+ include Colors
1377
+
1250
1378
  attr_reader :tag_opening #: Herb::Token
1251
1379
  attr_reader :content #: Herb::Token
1252
1380
  attr_reader :tag_closing #: Herb::Token
@@ -1294,34 +1422,39 @@ module Herb
1294
1422
  tree_inspect.rstrip.gsub(/\s+$/, "")
1295
1423
  end
1296
1424
 
1297
- #: (?Integer) -> String
1298
- def tree_inspect(indent = 0)
1425
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1426
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1299
1427
  output = +""
1300
1428
 
1301
- output += "@ #{node_name} "
1302
- output += location.tree_inspect
1429
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1303
1430
  output += "\n"
1304
1431
 
1432
+ if depth >= depth_limit
1433
+ output += dimmed("└── [depth limit reached ...]\n\n")
1434
+
1435
+ return output.gsub(/^/, " " * indent)
1436
+ end
1437
+
1305
1438
  output += inspect_errors(prefix: "│ ")
1306
1439
 
1307
- output += "├── tag_opening: "
1308
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1440
+ output += white("├── tag_opening: ")
1441
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1309
1442
  output += "\n"
1310
- output += "├── content: "
1311
- output += content ? content.tree_inspect : "∅"
1443
+ output += white("├── content: ")
1444
+ output += content ? content.tree_inspect : magenta("∅")
1312
1445
  output += "\n"
1313
- output += "├── tag_closing: "
1314
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1446
+ output += white("├── tag_closing: ")
1447
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1315
1448
  output += "\n"
1316
- output += "├── body: "
1317
- output += inspect_array(body, prefix: "│ ")
1318
- output += "└── end_node: "
1449
+ output += white("├── body: ")
1450
+ output += inspect_array(body, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1451
+ output += white("└── end_node: ")
1319
1452
  if end_node
1320
1453
  output += "\n"
1321
1454
  output += " └── "
1322
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1455
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1323
1456
  else
1324
- output += "∅\n"
1457
+ output += magenta("∅\n")
1325
1458
  end
1326
1459
  output += "\n"
1327
1460
 
@@ -1330,6 +1463,8 @@ module Herb
1330
1463
  end
1331
1464
 
1332
1465
  class ERBWhenNode < Node
1466
+ include Colors
1467
+
1333
1468
  attr_reader :tag_opening #: Herb::Token
1334
1469
  attr_reader :content #: Herb::Token
1335
1470
  attr_reader :tag_closing #: Herb::Token
@@ -1374,27 +1509,32 @@ module Herb
1374
1509
  tree_inspect.rstrip.gsub(/\s+$/, "")
1375
1510
  end
1376
1511
 
1377
- #: (?Integer) -> String
1378
- def tree_inspect(indent = 0)
1512
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1513
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1379
1514
  output = +""
1380
1515
 
1381
- output += "@ #{node_name} "
1382
- output += location.tree_inspect
1516
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1383
1517
  output += "\n"
1384
1518
 
1519
+ if depth >= depth_limit
1520
+ output += dimmed("└── [depth limit reached ...]\n\n")
1521
+
1522
+ return output.gsub(/^/, " " * indent)
1523
+ end
1524
+
1385
1525
  output += inspect_errors(prefix: "│ ")
1386
1526
 
1387
- output += "├── tag_opening: "
1388
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1527
+ output += white("├── tag_opening: ")
1528
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1389
1529
  output += "\n"
1390
- output += "├── content: "
1391
- output += content ? content.tree_inspect : "∅"
1530
+ output += white("├── content: ")
1531
+ output += content ? content.tree_inspect : magenta("∅")
1392
1532
  output += "\n"
1393
- output += "├── tag_closing: "
1394
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1533
+ output += white("├── tag_closing: ")
1534
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1395
1535
  output += "\n"
1396
- output += "└── statements: "
1397
- output += inspect_array(statements, prefix: " ")
1536
+ output += white("└── statements: ")
1537
+ output += inspect_array(statements, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1398
1538
  output += "\n"
1399
1539
 
1400
1540
  output.gsub(/^/, " " * indent)
@@ -1402,6 +1542,8 @@ module Herb
1402
1542
  end
1403
1543
 
1404
1544
  class ERBCaseNode < Node
1545
+ include Colors
1546
+
1405
1547
  attr_reader :tag_opening #: Herb::Token
1406
1548
  attr_reader :content #: Herb::Token
1407
1549
  attr_reader :tag_closing #: Herb::Token
@@ -1455,44 +1597,49 @@ module Herb
1455
1597
  tree_inspect.rstrip.gsub(/\s+$/, "")
1456
1598
  end
1457
1599
 
1458
- #: (?Integer) -> String
1459
- def tree_inspect(indent = 0)
1600
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1601
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1460
1602
  output = +""
1461
1603
 
1462
- output += "@ #{node_name} "
1463
- output += location.tree_inspect
1604
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1464
1605
  output += "\n"
1465
1606
 
1607
+ if depth >= depth_limit
1608
+ output += dimmed("└── [depth limit reached ...]\n\n")
1609
+
1610
+ return output.gsub(/^/, " " * indent)
1611
+ end
1612
+
1466
1613
  output += inspect_errors(prefix: "│ ")
1467
1614
 
1468
- output += "├── tag_opening: "
1469
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1615
+ output += white("├── tag_opening: ")
1616
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1470
1617
  output += "\n"
1471
- output += "├── content: "
1472
- output += content ? content.tree_inspect : "∅"
1618
+ output += white("├── content: ")
1619
+ output += content ? content.tree_inspect : magenta("∅")
1473
1620
  output += "\n"
1474
- output += "├── tag_closing: "
1475
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1621
+ output += white("├── tag_closing: ")
1622
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1476
1623
  output += "\n"
1477
- output += "├── children: "
1478
- output += inspect_array(children, prefix: "│ ")
1479
- output += "├── conditions: "
1480
- output += inspect_array(conditions, prefix: "│ ")
1481
- output += "├── else_clause: "
1624
+ output += white("├── children: ")
1625
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1626
+ output += white("├── conditions: ")
1627
+ output += inspect_array(conditions, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1628
+ output += white("├── else_clause: ")
1482
1629
  if else_clause
1483
1630
  output += "\n"
1484
1631
  output += "│ └── "
1485
- output += else_clause.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
1632
+ output += else_clause.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
1486
1633
  else
1487
- output += "∅\n"
1634
+ output += magenta("∅\n")
1488
1635
  end
1489
- output += "└── end_node: "
1636
+ output += white("└── end_node: ")
1490
1637
  if end_node
1491
1638
  output += "\n"
1492
1639
  output += " └── "
1493
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1640
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1494
1641
  else
1495
- output += "∅\n"
1642
+ output += magenta("∅\n")
1496
1643
  end
1497
1644
  output += "\n"
1498
1645
 
@@ -1501,6 +1648,8 @@ module Herb
1501
1648
  end
1502
1649
 
1503
1650
  class ERBCaseMatchNode < Node
1651
+ include Colors
1652
+
1504
1653
  attr_reader :tag_opening #: Herb::Token
1505
1654
  attr_reader :content #: Herb::Token
1506
1655
  attr_reader :tag_closing #: Herb::Token
@@ -1554,44 +1703,49 @@ module Herb
1554
1703
  tree_inspect.rstrip.gsub(/\s+$/, "")
1555
1704
  end
1556
1705
 
1557
- #: (?Integer) -> String
1558
- def tree_inspect(indent = 0)
1706
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1707
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1559
1708
  output = +""
1560
1709
 
1561
- output += "@ #{node_name} "
1562
- output += location.tree_inspect
1710
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1563
1711
  output += "\n"
1564
1712
 
1713
+ if depth >= depth_limit
1714
+ output += dimmed("└── [depth limit reached ...]\n\n")
1715
+
1716
+ return output.gsub(/^/, " " * indent)
1717
+ end
1718
+
1565
1719
  output += inspect_errors(prefix: "│ ")
1566
1720
 
1567
- output += "├── tag_opening: "
1568
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1721
+ output += white("├── tag_opening: ")
1722
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1569
1723
  output += "\n"
1570
- output += "├── content: "
1571
- output += content ? content.tree_inspect : "∅"
1724
+ output += white("├── content: ")
1725
+ output += content ? content.tree_inspect : magenta("∅")
1572
1726
  output += "\n"
1573
- output += "├── tag_closing: "
1574
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1727
+ output += white("├── tag_closing: ")
1728
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1575
1729
  output += "\n"
1576
- output += "├── children: "
1577
- output += inspect_array(children, prefix: "│ ")
1578
- output += "├── conditions: "
1579
- output += inspect_array(conditions, prefix: "│ ")
1580
- output += "├── else_clause: "
1730
+ output += white("├── children: ")
1731
+ output += inspect_array(children, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1732
+ output += white("├── conditions: ")
1733
+ output += inspect_array(conditions, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1734
+ output += white("├── else_clause: ")
1581
1735
  if else_clause
1582
1736
  output += "\n"
1583
1737
  output += "│ └── "
1584
- output += else_clause.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
1738
+ output += else_clause.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
1585
1739
  else
1586
- output += "∅\n"
1740
+ output += magenta("∅\n")
1587
1741
  end
1588
- output += "└── end_node: "
1742
+ output += white("└── end_node: ")
1589
1743
  if end_node
1590
1744
  output += "\n"
1591
1745
  output += " └── "
1592
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1746
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1593
1747
  else
1594
- output += "∅\n"
1748
+ output += magenta("∅\n")
1595
1749
  end
1596
1750
  output += "\n"
1597
1751
 
@@ -1600,6 +1754,8 @@ module Herb
1600
1754
  end
1601
1755
 
1602
1756
  class ERBWhileNode < Node
1757
+ include Colors
1758
+
1603
1759
  attr_reader :tag_opening #: Herb::Token
1604
1760
  attr_reader :content #: Herb::Token
1605
1761
  attr_reader :tag_closing #: Herb::Token
@@ -1647,34 +1803,39 @@ module Herb
1647
1803
  tree_inspect.rstrip.gsub(/\s+$/, "")
1648
1804
  end
1649
1805
 
1650
- #: (?Integer) -> String
1651
- def tree_inspect(indent = 0)
1806
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1807
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1652
1808
  output = +""
1653
1809
 
1654
- output += "@ #{node_name} "
1655
- output += location.tree_inspect
1810
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1656
1811
  output += "\n"
1657
1812
 
1813
+ if depth >= depth_limit
1814
+ output += dimmed("└── [depth limit reached ...]\n\n")
1815
+
1816
+ return output.gsub(/^/, " " * indent)
1817
+ end
1818
+
1658
1819
  output += inspect_errors(prefix: "│ ")
1659
1820
 
1660
- output += "├── tag_opening: "
1661
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1821
+ output += white("├── tag_opening: ")
1822
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1662
1823
  output += "\n"
1663
- output += "├── content: "
1664
- output += content ? content.tree_inspect : "∅"
1824
+ output += white("├── content: ")
1825
+ output += content ? content.tree_inspect : magenta("∅")
1665
1826
  output += "\n"
1666
- output += "├── tag_closing: "
1667
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1827
+ output += white("├── tag_closing: ")
1828
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1668
1829
  output += "\n"
1669
- output += "├── statements: "
1670
- output += inspect_array(statements, prefix: "│ ")
1671
- output += "└── end_node: "
1830
+ output += white("├── statements: ")
1831
+ output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1832
+ output += white("└── end_node: ")
1672
1833
  if end_node
1673
1834
  output += "\n"
1674
1835
  output += " └── "
1675
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1836
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1676
1837
  else
1677
- output += "∅\n"
1838
+ output += magenta("∅\n")
1678
1839
  end
1679
1840
  output += "\n"
1680
1841
 
@@ -1683,6 +1844,8 @@ module Herb
1683
1844
  end
1684
1845
 
1685
1846
  class ERBUntilNode < Node
1847
+ include Colors
1848
+
1686
1849
  attr_reader :tag_opening #: Herb::Token
1687
1850
  attr_reader :content #: Herb::Token
1688
1851
  attr_reader :tag_closing #: Herb::Token
@@ -1730,34 +1893,39 @@ module Herb
1730
1893
  tree_inspect.rstrip.gsub(/\s+$/, "")
1731
1894
  end
1732
1895
 
1733
- #: (?Integer) -> String
1734
- def tree_inspect(indent = 0)
1896
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1897
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1735
1898
  output = +""
1736
1899
 
1737
- output += "@ #{node_name} "
1738
- output += location.tree_inspect
1900
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1739
1901
  output += "\n"
1740
1902
 
1903
+ if depth >= depth_limit
1904
+ output += dimmed("└── [depth limit reached ...]\n\n")
1905
+
1906
+ return output.gsub(/^/, " " * indent)
1907
+ end
1908
+
1741
1909
  output += inspect_errors(prefix: "│ ")
1742
1910
 
1743
- output += "├── tag_opening: "
1744
- output += tag_opening ? tag_opening.tree_inspect : "∅"
1911
+ output += white("├── tag_opening: ")
1912
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1745
1913
  output += "\n"
1746
- output += "├── content: "
1747
- output += content ? content.tree_inspect : "∅"
1914
+ output += white("├── content: ")
1915
+ output += content ? content.tree_inspect : magenta("∅")
1748
1916
  output += "\n"
1749
- output += "├── tag_closing: "
1750
- output += tag_closing ? tag_closing.tree_inspect : "∅"
1917
+ output += white("├── tag_closing: ")
1918
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1751
1919
  output += "\n"
1752
- output += "├── statements: "
1753
- output += inspect_array(statements, prefix: "│ ")
1754
- output += "└── end_node: "
1920
+ output += white("├── statements: ")
1921
+ output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
1922
+ output += white("└── end_node: ")
1755
1923
  if end_node
1756
1924
  output += "\n"
1757
1925
  output += " └── "
1758
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1926
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1759
1927
  else
1760
- output += "∅\n"
1928
+ output += magenta("∅\n")
1761
1929
  end
1762
1930
  output += "\n"
1763
1931
 
@@ -1766,6 +1934,8 @@ module Herb
1766
1934
  end
1767
1935
 
1768
1936
  class ERBForNode < Node
1937
+ include Colors
1938
+
1769
1939
  attr_reader :tag_opening #: Herb::Token
1770
1940
  attr_reader :content #: Herb::Token
1771
1941
  attr_reader :tag_closing #: Herb::Token
@@ -1813,34 +1983,39 @@ module Herb
1813
1983
  tree_inspect.rstrip.gsub(/\s+$/, "")
1814
1984
  end
1815
1985
 
1816
- #: (?Integer) -> String
1817
- def tree_inspect(indent = 0)
1986
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
1987
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1818
1988
  output = +""
1819
1989
 
1820
- output += "@ #{node_name} "
1821
- output += location.tree_inspect
1990
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1822
1991
  output += "\n"
1823
1992
 
1993
+ if depth >= depth_limit
1994
+ output += dimmed("└── [depth limit reached ...]\n\n")
1995
+
1996
+ return output.gsub(/^/, " " * indent)
1997
+ end
1998
+
1824
1999
  output += inspect_errors(prefix: "│ ")
1825
2000
 
1826
- output += "├── tag_opening: "
1827
- output += tag_opening ? tag_opening.tree_inspect : "∅"
2001
+ output += white("├── tag_opening: ")
2002
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1828
2003
  output += "\n"
1829
- output += "├── content: "
1830
- output += content ? content.tree_inspect : "∅"
2004
+ output += white("├── content: ")
2005
+ output += content ? content.tree_inspect : magenta("∅")
1831
2006
  output += "\n"
1832
- output += "├── tag_closing: "
1833
- output += tag_closing ? tag_closing.tree_inspect : "∅"
2007
+ output += white("├── tag_closing: ")
2008
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1834
2009
  output += "\n"
1835
- output += "├── statements: "
1836
- output += inspect_array(statements, prefix: "│ ")
1837
- output += "└── end_node: "
2010
+ output += white("├── statements: ")
2011
+ output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
2012
+ output += white("└── end_node: ")
1838
2013
  if end_node
1839
2014
  output += "\n"
1840
2015
  output += " └── "
1841
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
2016
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1842
2017
  else
1843
- output += "∅\n"
2018
+ output += magenta("∅\n")
1844
2019
  end
1845
2020
  output += "\n"
1846
2021
 
@@ -1849,6 +2024,8 @@ module Herb
1849
2024
  end
1850
2025
 
1851
2026
  class ERBRescueNode < Node
2027
+ include Colors
2028
+
1852
2029
  attr_reader :tag_opening #: Herb::Token
1853
2030
  attr_reader :content #: Herb::Token
1854
2031
  attr_reader :tag_closing #: Herb::Token
@@ -1896,34 +2073,39 @@ module Herb
1896
2073
  tree_inspect.rstrip.gsub(/\s+$/, "")
1897
2074
  end
1898
2075
 
1899
- #: (?Integer) -> String
1900
- def tree_inspect(indent = 0)
2076
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2077
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1901
2078
  output = +""
1902
2079
 
1903
- output += "@ #{node_name} "
1904
- output += location.tree_inspect
2080
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1905
2081
  output += "\n"
1906
2082
 
2083
+ if depth >= depth_limit
2084
+ output += dimmed("└── [depth limit reached ...]\n\n")
2085
+
2086
+ return output.gsub(/^/, " " * indent)
2087
+ end
2088
+
1907
2089
  output += inspect_errors(prefix: "│ ")
1908
2090
 
1909
- output += "├── tag_opening: "
1910
- output += tag_opening ? tag_opening.tree_inspect : "∅"
2091
+ output += white("├── tag_opening: ")
2092
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1911
2093
  output += "\n"
1912
- output += "├── content: "
1913
- output += content ? content.tree_inspect : "∅"
2094
+ output += white("├── content: ")
2095
+ output += content ? content.tree_inspect : magenta("∅")
1914
2096
  output += "\n"
1915
- output += "├── tag_closing: "
1916
- output += tag_closing ? tag_closing.tree_inspect : "∅"
2097
+ output += white("├── tag_closing: ")
2098
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1917
2099
  output += "\n"
1918
- output += "├── statements: "
1919
- output += inspect_array(statements, prefix: "│ ")
1920
- output += "└── subsequent: "
2100
+ output += white("├── statements: ")
2101
+ output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
2102
+ output += white("└── subsequent: ")
1921
2103
  if subsequent
1922
2104
  output += "\n"
1923
2105
  output += " └── "
1924
- output += subsequent.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
2106
+ output += subsequent.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
1925
2107
  else
1926
- output += "∅\n"
2108
+ output += magenta("∅\n")
1927
2109
  end
1928
2110
  output += "\n"
1929
2111
 
@@ -1932,6 +2114,8 @@ module Herb
1932
2114
  end
1933
2115
 
1934
2116
  class ERBEnsureNode < Node
2117
+ include Colors
2118
+
1935
2119
  attr_reader :tag_opening #: Herb::Token
1936
2120
  attr_reader :content #: Herb::Token
1937
2121
  attr_reader :tag_closing #: Herb::Token
@@ -1976,27 +2160,32 @@ module Herb
1976
2160
  tree_inspect.rstrip.gsub(/\s+$/, "")
1977
2161
  end
1978
2162
 
1979
- #: (?Integer) -> String
1980
- def tree_inspect(indent = 0)
2163
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2164
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
1981
2165
  output = +""
1982
2166
 
1983
- output += "@ #{node_name} "
1984
- output += location.tree_inspect
2167
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
1985
2168
  output += "\n"
1986
2169
 
2170
+ if depth >= depth_limit
2171
+ output += dimmed("└── [depth limit reached ...]\n\n")
2172
+
2173
+ return output.gsub(/^/, " " * indent)
2174
+ end
2175
+
1987
2176
  output += inspect_errors(prefix: "│ ")
1988
2177
 
1989
- output += "├── tag_opening: "
1990
- output += tag_opening ? tag_opening.tree_inspect : "∅"
2178
+ output += white("├── tag_opening: ")
2179
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
1991
2180
  output += "\n"
1992
- output += "├── content: "
1993
- output += content ? content.tree_inspect : "∅"
2181
+ output += white("├── content: ")
2182
+ output += content ? content.tree_inspect : magenta("∅")
1994
2183
  output += "\n"
1995
- output += "├── tag_closing: "
1996
- output += tag_closing ? tag_closing.tree_inspect : "∅"
2184
+ output += white("├── tag_closing: ")
2185
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
1997
2186
  output += "\n"
1998
- output += "└── statements: "
1999
- output += inspect_array(statements, prefix: " ")
2187
+ output += white("└── statements: ")
2188
+ output += inspect_array(statements, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
2000
2189
  output += "\n"
2001
2190
 
2002
2191
  output.gsub(/^/, " " * indent)
@@ -2004,6 +2193,8 @@ module Herb
2004
2193
  end
2005
2194
 
2006
2195
  class ERBBeginNode < Node
2196
+ include Colors
2197
+
2007
2198
  attr_reader :tag_opening #: Herb::Token
2008
2199
  attr_reader :content #: Herb::Token
2009
2200
  attr_reader :tag_closing #: Herb::Token
@@ -2060,58 +2251,63 @@ module Herb
2060
2251
  tree_inspect.rstrip.gsub(/\s+$/, "")
2061
2252
  end
2062
2253
 
2063
- #: (?Integer) -> String
2064
- def tree_inspect(indent = 0)
2254
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2255
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
2065
2256
  output = +""
2066
2257
 
2067
- output += "@ #{node_name} "
2068
- output += location.tree_inspect
2258
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
2069
2259
  output += "\n"
2070
2260
 
2261
+ if depth >= depth_limit
2262
+ output += dimmed("└── [depth limit reached ...]\n\n")
2263
+
2264
+ return output.gsub(/^/, " " * indent)
2265
+ end
2266
+
2071
2267
  output += inspect_errors(prefix: "│ ")
2072
2268
 
2073
- output += "├── tag_opening: "
2074
- output += tag_opening ? tag_opening.tree_inspect : "∅"
2269
+ output += white("├── tag_opening: ")
2270
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
2075
2271
  output += "\n"
2076
- output += "├── content: "
2077
- output += content ? content.tree_inspect : "∅"
2272
+ output += white("├── content: ")
2273
+ output += content ? content.tree_inspect : magenta("∅")
2078
2274
  output += "\n"
2079
- output += "├── tag_closing: "
2080
- output += tag_closing ? tag_closing.tree_inspect : "∅"
2275
+ output += white("├── tag_closing: ")
2276
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
2081
2277
  output += "\n"
2082
- output += "├── statements: "
2083
- output += inspect_array(statements, prefix: "│ ")
2084
- output += "├── rescue_clause: "
2278
+ output += white("├── statements: ")
2279
+ output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
2280
+ output += white("├── rescue_clause: ")
2085
2281
  if rescue_clause
2086
2282
  output += "\n"
2087
2283
  output += "│ └── "
2088
- output += rescue_clause.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2284
+ output += rescue_clause.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2089
2285
  else
2090
- output += "∅\n"
2286
+ output += magenta("∅\n")
2091
2287
  end
2092
- output += "├── else_clause: "
2288
+ output += white("├── else_clause: ")
2093
2289
  if else_clause
2094
2290
  output += "\n"
2095
2291
  output += "│ └── "
2096
- output += else_clause.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2292
+ output += else_clause.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2097
2293
  else
2098
- output += "∅\n"
2294
+ output += magenta("∅\n")
2099
2295
  end
2100
- output += "├── ensure_clause: "
2296
+ output += white("├── ensure_clause: ")
2101
2297
  if ensure_clause
2102
2298
  output += "\n"
2103
2299
  output += "│ └── "
2104
- output += ensure_clause.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2300
+ output += ensure_clause.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2105
2301
  else
2106
- output += "∅\n"
2302
+ output += magenta("∅\n")
2107
2303
  end
2108
- output += "└── end_node: "
2304
+ output += white("└── end_node: ")
2109
2305
  if end_node
2110
2306
  output += "\n"
2111
2307
  output += " └── "
2112
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
2308
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
2113
2309
  else
2114
- output += "∅\n"
2310
+ output += magenta("∅\n")
2115
2311
  end
2116
2312
  output += "\n"
2117
2313
 
@@ -2120,6 +2316,8 @@ module Herb
2120
2316
  end
2121
2317
 
2122
2318
  class ERBUnlessNode < Node
2319
+ include Colors
2320
+
2123
2321
  attr_reader :tag_opening #: Herb::Token
2124
2322
  attr_reader :content #: Herb::Token
2125
2323
  attr_reader :tag_closing #: Herb::Token
@@ -2170,42 +2368,47 @@ module Herb
2170
2368
  tree_inspect.rstrip.gsub(/\s+$/, "")
2171
2369
  end
2172
2370
 
2173
- #: (?Integer) -> String
2174
- def tree_inspect(indent = 0)
2371
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2372
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
2175
2373
  output = +""
2176
2374
 
2177
- output += "@ #{node_name} "
2178
- output += location.tree_inspect
2375
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
2179
2376
  output += "\n"
2180
2377
 
2378
+ if depth >= depth_limit
2379
+ output += dimmed("└── [depth limit reached ...]\n\n")
2380
+
2381
+ return output.gsub(/^/, " " * indent)
2382
+ end
2383
+
2181
2384
  output += inspect_errors(prefix: "│ ")
2182
2385
 
2183
- output += "├── tag_opening: "
2184
- output += tag_opening ? tag_opening.tree_inspect : "∅"
2386
+ output += white("├── tag_opening: ")
2387
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
2185
2388
  output += "\n"
2186
- output += "├── content: "
2187
- output += content ? content.tree_inspect : "∅"
2389
+ output += white("├── content: ")
2390
+ output += content ? content.tree_inspect : magenta("∅")
2188
2391
  output += "\n"
2189
- output += "├── tag_closing: "
2190
- output += tag_closing ? tag_closing.tree_inspect : "∅"
2392
+ output += white("├── tag_closing: ")
2393
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
2191
2394
  output += "\n"
2192
- output += "├── statements: "
2193
- output += inspect_array(statements, prefix: "│ ")
2194
- output += "├── else_clause: "
2395
+ output += white("├── statements: ")
2396
+ output += inspect_array(statements, prefix: "│ ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
2397
+ output += white("├── else_clause: ")
2195
2398
  if else_clause
2196
2399
  output += "\n"
2197
2400
  output += "│ └── "
2198
- output += else_clause.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2401
+ output += else_clause.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, "│ ").delete_prefix("│ ")
2199
2402
  else
2200
- output += "∅\n"
2403
+ output += magenta("∅\n")
2201
2404
  end
2202
- output += "└── end_node: "
2405
+ output += white("└── end_node: ")
2203
2406
  if end_node
2204
2407
  output += "\n"
2205
2408
  output += " └── "
2206
- output += end_node.tree_inspect(indent).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
2409
+ output += end_node.tree_inspect(indent: indent, depth: depth + 1, depth_limit: depth_limit).gsub(/^/, " " * (indent + 1)).lstrip.gsub(/^/, " ").delete_prefix(" ")
2207
2410
  else
2208
- output += "∅\n"
2411
+ output += magenta("∅\n")
2209
2412
  end
2210
2413
  output += "\n"
2211
2414
 
@@ -2214,6 +2417,8 @@ module Herb
2214
2417
  end
2215
2418
 
2216
2419
  class ERBYieldNode < Node
2420
+ include Colors
2421
+
2217
2422
  attr_reader :tag_opening #: Herb::Token
2218
2423
  attr_reader :content #: Herb::Token
2219
2424
  attr_reader :tag_closing #: Herb::Token
@@ -2255,24 +2460,29 @@ module Herb
2255
2460
  tree_inspect.rstrip.gsub(/\s+$/, "")
2256
2461
  end
2257
2462
 
2258
- #: (?Integer) -> String
2259
- def tree_inspect(indent = 0)
2463
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2464
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
2260
2465
  output = +""
2261
2466
 
2262
- output += "@ #{node_name} "
2263
- output += location.tree_inspect
2467
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
2264
2468
  output += "\n"
2265
2469
 
2470
+ if depth >= depth_limit
2471
+ output += dimmed("└── [depth limit reached ...]\n\n")
2472
+
2473
+ return output.gsub(/^/, " " * indent)
2474
+ end
2475
+
2266
2476
  output += inspect_errors(prefix: "│ ")
2267
2477
 
2268
- output += "├── tag_opening: "
2269
- output += tag_opening ? tag_opening.tree_inspect : "∅"
2478
+ output += white("├── tag_opening: ")
2479
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
2270
2480
  output += "\n"
2271
- output += "├── content: "
2272
- output += content ? content.tree_inspect : "∅"
2481
+ output += white("├── content: ")
2482
+ output += content ? content.tree_inspect : magenta("∅")
2273
2483
  output += "\n"
2274
- output += "└── tag_closing: "
2275
- output += tag_closing ? tag_closing.tree_inspect : "∅"
2484
+ output += white("└── tag_closing: ")
2485
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
2276
2486
  output += "\n"
2277
2487
  output += "\n"
2278
2488
 
@@ -2281,6 +2491,8 @@ module Herb
2281
2491
  end
2282
2492
 
2283
2493
  class ERBInNode < Node
2494
+ include Colors
2495
+
2284
2496
  attr_reader :tag_opening #: Herb::Token
2285
2497
  attr_reader :content #: Herb::Token
2286
2498
  attr_reader :tag_closing #: Herb::Token
@@ -2325,27 +2537,32 @@ module Herb
2325
2537
  tree_inspect.rstrip.gsub(/\s+$/, "")
2326
2538
  end
2327
2539
 
2328
- #: (?Integer) -> String
2329
- def tree_inspect(indent = 0)
2540
+ #: (?indent: Integer, ?depth: Integer, ?depth_limit: Integer) -> String
2541
+ def tree_inspect(indent: 0, depth: 0, depth_limit: 10)
2330
2542
  output = +""
2331
2543
 
2332
- output += "@ #{node_name} "
2333
- output += location.tree_inspect
2544
+ output += white("@ #{bold(yellow(node_name.to_s))} #{dimmed("(location: #{location.tree_inspect})")}")
2334
2545
  output += "\n"
2335
2546
 
2547
+ if depth >= depth_limit
2548
+ output += dimmed("└── [depth limit reached ...]\n\n")
2549
+
2550
+ return output.gsub(/^/, " " * indent)
2551
+ end
2552
+
2336
2553
  output += inspect_errors(prefix: "│ ")
2337
2554
 
2338
- output += "├── tag_opening: "
2339
- output += tag_opening ? tag_opening.tree_inspect : "∅"
2555
+ output += white("├── tag_opening: ")
2556
+ output += tag_opening ? tag_opening.tree_inspect : magenta("∅")
2340
2557
  output += "\n"
2341
- output += "├── content: "
2342
- output += content ? content.tree_inspect : "∅"
2558
+ output += white("├── content: ")
2559
+ output += content ? content.tree_inspect : magenta("∅")
2343
2560
  output += "\n"
2344
- output += "├── tag_closing: "
2345
- output += tag_closing ? tag_closing.tree_inspect : "∅"
2561
+ output += white("├── tag_closing: ")
2562
+ output += tag_closing ? tag_closing.tree_inspect : magenta("∅")
2346
2563
  output += "\n"
2347
- output += "└── statements: "
2348
- output += inspect_array(statements, prefix: " ")
2564
+ output += white("└── statements: ")
2565
+ output += inspect_array(statements, prefix: " ", indent: indent, depth: depth + 1, depth_limit: depth_limit)
2349
2566
  output += "\n"
2350
2567
 
2351
2568
  output.gsub(/^/, " " * indent)