@herb-tools/core 0.3.1 → 0.4.1
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.
- package/README.md +18 -6
- package/dist/herb-core.browser.js +135 -215
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +137 -214
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +135 -215
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +137 -214
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/diagnostic.d.ts +55 -0
- package/dist/types/errors.d.ts +14 -19
- package/dist/types/index.d.ts +1 -0
- package/dist/types/nodes.d.ts +5 -1
- package/dist/types/token-list.d.ts +1 -0
- package/package.json +1 -2
- package/src/diagnostic.ts +78 -0
- package/src/errors.ts +83 -238
- package/src/index.ts +1 -0
- package/src/nodes.ts +79 -33
- package/src/parse-result.ts +3 -3
- package/src/token-list.ts +4 -0
- package/src/visitor.ts +1 -1
package/dist/herb-core.umd.js
CHANGED
|
@@ -38,6 +38,22 @@
|
|
|
38
38
|
return object;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Converts a Diagnostic to Monaco/VSCode-compatible MonacoDiagnostic format
|
|
43
|
+
*/
|
|
44
|
+
function toMonacoDiagnostic(diagnostic) {
|
|
45
|
+
const { message, location } = diagnostic;
|
|
46
|
+
const severity = diagnostic.severity === "hint" ? "info" : diagnostic.severity;
|
|
47
|
+
return {
|
|
48
|
+
line: location.start.line,
|
|
49
|
+
column: location.start.column,
|
|
50
|
+
endLine: location.end.line,
|
|
51
|
+
endColumn: location.end.column,
|
|
52
|
+
message,
|
|
53
|
+
severity
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
41
57
|
class Position {
|
|
42
58
|
line;
|
|
43
59
|
column;
|
|
@@ -169,11 +185,16 @@
|
|
|
169
185
|
}
|
|
170
186
|
|
|
171
187
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
172
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/errors.ts.erb
|
|
188
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-4/templates/javascript/packages/core/src/errors.ts.erb
|
|
173
189
|
class HerbError {
|
|
174
190
|
type;
|
|
175
191
|
message;
|
|
176
192
|
location;
|
|
193
|
+
severity = "error";
|
|
194
|
+
source = "parser";
|
|
195
|
+
get code() {
|
|
196
|
+
return this.type;
|
|
197
|
+
}
|
|
177
198
|
static from(error) {
|
|
178
199
|
return fromSerializedError(error);
|
|
179
200
|
}
|
|
@@ -222,21 +243,15 @@
|
|
|
222
243
|
found: this.found,
|
|
223
244
|
};
|
|
224
245
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
];
|
|
236
|
-
// no-op for description
|
|
237
|
-
// no-op for expected
|
|
238
|
-
// no-op for found
|
|
239
|
-
return diagnostics;
|
|
246
|
+
toMonacoDiagnostic() {
|
|
247
|
+
return {
|
|
248
|
+
line: this.location.start.line,
|
|
249
|
+
column: this.location.start.column,
|
|
250
|
+
endLine: this.location.end.line,
|
|
251
|
+
endColumn: this.location.end.column,
|
|
252
|
+
message: this.message,
|
|
253
|
+
severity: 'error'
|
|
254
|
+
};
|
|
240
255
|
}
|
|
241
256
|
treeInspect() {
|
|
242
257
|
let output = "";
|
|
@@ -273,29 +288,15 @@
|
|
|
273
288
|
found: this.found ? this.found.toJSON() : null,
|
|
274
289
|
};
|
|
275
290
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
];
|
|
287
|
-
// no-op for expected_type
|
|
288
|
-
if (this.found) {
|
|
289
|
-
diagnostics.push({
|
|
290
|
-
line: this.found.location.start.line,
|
|
291
|
-
column: this.found.location.start.column,
|
|
292
|
-
endLine: this.found.location.end.line,
|
|
293
|
-
endColumn: this.found.location.end.column,
|
|
294
|
-
message: `found "${(this.found.value)}" is here`,
|
|
295
|
-
severity: 'info'
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
return diagnostics;
|
|
291
|
+
toMonacoDiagnostic() {
|
|
292
|
+
return {
|
|
293
|
+
line: this.location.start.line,
|
|
294
|
+
column: this.location.start.column,
|
|
295
|
+
endLine: this.location.end.line,
|
|
296
|
+
endColumn: this.location.end.column,
|
|
297
|
+
message: this.message,
|
|
298
|
+
severity: 'error'
|
|
299
|
+
};
|
|
299
300
|
}
|
|
300
301
|
treeInspect() {
|
|
301
302
|
let output = "";
|
|
@@ -327,28 +328,15 @@
|
|
|
327
328
|
closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
|
|
328
329
|
};
|
|
329
330
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
}
|
|
340
|
-
];
|
|
341
|
-
if (this.closing_tag) {
|
|
342
|
-
diagnostics.push({
|
|
343
|
-
line: this.closing_tag.location.start.line,
|
|
344
|
-
column: this.closing_tag.location.start.column,
|
|
345
|
-
endLine: this.closing_tag.location.end.line,
|
|
346
|
-
endColumn: this.closing_tag.location.end.column,
|
|
347
|
-
message: `closing_tag "${(this.closing_tag.value)}" is here`,
|
|
348
|
-
severity: 'info'
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
return diagnostics;
|
|
331
|
+
toMonacoDiagnostic() {
|
|
332
|
+
return {
|
|
333
|
+
line: this.location.start.line,
|
|
334
|
+
column: this.location.start.column,
|
|
335
|
+
endLine: this.location.end.line,
|
|
336
|
+
endColumn: this.location.end.column,
|
|
337
|
+
message: this.message,
|
|
338
|
+
severity: 'error'
|
|
339
|
+
};
|
|
352
340
|
}
|
|
353
341
|
treeInspect() {
|
|
354
342
|
let output = "";
|
|
@@ -379,28 +367,15 @@
|
|
|
379
367
|
opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
|
|
380
368
|
};
|
|
381
369
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
}
|
|
392
|
-
];
|
|
393
|
-
if (this.opening_tag) {
|
|
394
|
-
diagnostics.push({
|
|
395
|
-
line: this.opening_tag.location.start.line,
|
|
396
|
-
column: this.opening_tag.location.start.column,
|
|
397
|
-
endLine: this.opening_tag.location.end.line,
|
|
398
|
-
endColumn: this.opening_tag.location.end.column,
|
|
399
|
-
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
400
|
-
severity: 'info'
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
return diagnostics;
|
|
370
|
+
toMonacoDiagnostic() {
|
|
371
|
+
return {
|
|
372
|
+
line: this.location.start.line,
|
|
373
|
+
column: this.location.start.column,
|
|
374
|
+
endLine: this.location.end.line,
|
|
375
|
+
endColumn: this.location.end.column,
|
|
376
|
+
message: this.message,
|
|
377
|
+
severity: 'error'
|
|
378
|
+
};
|
|
404
379
|
}
|
|
405
380
|
treeInspect() {
|
|
406
381
|
let output = "";
|
|
@@ -435,38 +410,15 @@
|
|
|
435
410
|
closing_tag: this.closing_tag ? this.closing_tag.toJSON() : null,
|
|
436
411
|
};
|
|
437
412
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
}
|
|
448
|
-
];
|
|
449
|
-
if (this.opening_tag) {
|
|
450
|
-
diagnostics.push({
|
|
451
|
-
line: this.opening_tag.location.start.line,
|
|
452
|
-
column: this.opening_tag.location.start.column,
|
|
453
|
-
endLine: this.opening_tag.location.end.line,
|
|
454
|
-
endColumn: this.opening_tag.location.end.column,
|
|
455
|
-
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
456
|
-
severity: 'info'
|
|
457
|
-
});
|
|
458
|
-
}
|
|
459
|
-
if (this.closing_tag) {
|
|
460
|
-
diagnostics.push({
|
|
461
|
-
line: this.closing_tag.location.start.line,
|
|
462
|
-
column: this.closing_tag.location.start.column,
|
|
463
|
-
endLine: this.closing_tag.location.end.line,
|
|
464
|
-
endColumn: this.closing_tag.location.end.column,
|
|
465
|
-
message: `closing_tag "${(this.closing_tag.value)}" is here`,
|
|
466
|
-
severity: 'info'
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
return diagnostics;
|
|
413
|
+
toMonacoDiagnostic() {
|
|
414
|
+
return {
|
|
415
|
+
line: this.location.start.line,
|
|
416
|
+
column: this.location.start.column,
|
|
417
|
+
endLine: this.location.end.line,
|
|
418
|
+
endColumn: this.location.end.column,
|
|
419
|
+
message: this.message,
|
|
420
|
+
severity: 'error'
|
|
421
|
+
};
|
|
470
422
|
}
|
|
471
423
|
treeInspect() {
|
|
472
424
|
let output = "";
|
|
@@ -502,38 +454,15 @@
|
|
|
502
454
|
closing_quote: this.closing_quote ? this.closing_quote.toJSON() : null,
|
|
503
455
|
};
|
|
504
456
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
];
|
|
516
|
-
if (this.opening_quote) {
|
|
517
|
-
diagnostics.push({
|
|
518
|
-
line: this.opening_quote.location.start.line,
|
|
519
|
-
column: this.opening_quote.location.start.column,
|
|
520
|
-
endLine: this.opening_quote.location.end.line,
|
|
521
|
-
endColumn: this.opening_quote.location.end.column,
|
|
522
|
-
message: `opening_quote "${(this.opening_quote.value)}" is here`,
|
|
523
|
-
severity: 'info'
|
|
524
|
-
});
|
|
525
|
-
}
|
|
526
|
-
if (this.closing_quote) {
|
|
527
|
-
diagnostics.push({
|
|
528
|
-
line: this.closing_quote.location.start.line,
|
|
529
|
-
column: this.closing_quote.location.start.column,
|
|
530
|
-
endLine: this.closing_quote.location.end.line,
|
|
531
|
-
endColumn: this.closing_quote.location.end.column,
|
|
532
|
-
message: `closing_quote "${(this.closing_quote.value)}" is here`,
|
|
533
|
-
severity: 'info'
|
|
534
|
-
});
|
|
535
|
-
}
|
|
536
|
-
return diagnostics;
|
|
457
|
+
toMonacoDiagnostic() {
|
|
458
|
+
return {
|
|
459
|
+
line: this.location.start.line,
|
|
460
|
+
column: this.location.start.column,
|
|
461
|
+
endLine: this.location.end.line,
|
|
462
|
+
endColumn: this.location.end.column,
|
|
463
|
+
message: this.message,
|
|
464
|
+
severity: 'error'
|
|
465
|
+
};
|
|
537
466
|
}
|
|
538
467
|
treeInspect() {
|
|
539
468
|
let output = "";
|
|
@@ -573,30 +502,15 @@
|
|
|
573
502
|
found: this.found,
|
|
574
503
|
};
|
|
575
504
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
586
|
-
];
|
|
587
|
-
if (this.tag_name) {
|
|
588
|
-
diagnostics.push({
|
|
589
|
-
line: this.tag_name.location.start.line,
|
|
590
|
-
column: this.tag_name.location.start.column,
|
|
591
|
-
endLine: this.tag_name.location.end.line,
|
|
592
|
-
endColumn: this.tag_name.location.end.column,
|
|
593
|
-
message: `tag_name "${(this.tag_name.value)}" is here`,
|
|
594
|
-
severity: 'info'
|
|
595
|
-
});
|
|
596
|
-
}
|
|
597
|
-
// no-op for expected
|
|
598
|
-
// no-op for found
|
|
599
|
-
return diagnostics;
|
|
505
|
+
toMonacoDiagnostic() {
|
|
506
|
+
return {
|
|
507
|
+
line: this.location.start.line,
|
|
508
|
+
column: this.location.start.column,
|
|
509
|
+
endLine: this.location.end.line,
|
|
510
|
+
endColumn: this.location.end.column,
|
|
511
|
+
message: this.message,
|
|
512
|
+
severity: 'error'
|
|
513
|
+
};
|
|
600
514
|
}
|
|
601
515
|
treeInspect() {
|
|
602
516
|
let output = "";
|
|
@@ -629,28 +543,15 @@
|
|
|
629
543
|
opening_tag: this.opening_tag ? this.opening_tag.toJSON() : null,
|
|
630
544
|
};
|
|
631
545
|
}
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
];
|
|
643
|
-
if (this.opening_tag) {
|
|
644
|
-
diagnostics.push({
|
|
645
|
-
line: this.opening_tag.location.start.line,
|
|
646
|
-
column: this.opening_tag.location.start.column,
|
|
647
|
-
endLine: this.opening_tag.location.end.line,
|
|
648
|
-
endColumn: this.opening_tag.location.end.column,
|
|
649
|
-
message: `opening_tag "${(this.opening_tag.value)}" is here`,
|
|
650
|
-
severity: 'info'
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
return diagnostics;
|
|
546
|
+
toMonacoDiagnostic() {
|
|
547
|
+
return {
|
|
548
|
+
line: this.location.start.line,
|
|
549
|
+
column: this.location.start.column,
|
|
550
|
+
endLine: this.location.end.line,
|
|
551
|
+
endColumn: this.location.end.column,
|
|
552
|
+
message: this.message,
|
|
553
|
+
severity: 'error'
|
|
554
|
+
};
|
|
654
555
|
}
|
|
655
556
|
treeInspect() {
|
|
656
557
|
let output = "";
|
|
@@ -689,21 +590,15 @@
|
|
|
689
590
|
level: this.level,
|
|
690
591
|
};
|
|
691
592
|
}
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
}
|
|
702
|
-
];
|
|
703
|
-
// no-op for error_message
|
|
704
|
-
// no-op for diagnostic_id
|
|
705
|
-
// no-op for level
|
|
706
|
-
return diagnostics;
|
|
593
|
+
toMonacoDiagnostic() {
|
|
594
|
+
return {
|
|
595
|
+
line: this.location.start.line,
|
|
596
|
+
column: this.location.start.column,
|
|
597
|
+
endLine: this.location.end.line,
|
|
598
|
+
endColumn: this.location.end.column,
|
|
599
|
+
message: this.message,
|
|
600
|
+
severity: 'error'
|
|
601
|
+
};
|
|
707
602
|
}
|
|
708
603
|
treeInspect() {
|
|
709
604
|
let output = "";
|
|
@@ -732,7 +627,7 @@
|
|
|
732
627
|
}
|
|
733
628
|
|
|
734
629
|
var name = "@herb-tools/core";
|
|
735
|
-
var version = "0.
|
|
630
|
+
var version = "0.4.1";
|
|
736
631
|
var packageJSON = {
|
|
737
632
|
name: name,
|
|
738
633
|
version: version};
|
|
@@ -788,6 +683,9 @@
|
|
|
788
683
|
get length() {
|
|
789
684
|
return this.list.length;
|
|
790
685
|
}
|
|
686
|
+
get tokens() {
|
|
687
|
+
return this.list;
|
|
688
|
+
}
|
|
791
689
|
[Symbol.iterator]() {
|
|
792
690
|
return this.list[Symbol.iterator]();
|
|
793
691
|
}
|
|
@@ -881,7 +779,7 @@
|
|
|
881
779
|
}
|
|
882
780
|
|
|
883
781
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
884
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/nodes.ts.erb
|
|
782
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-4/templates/javascript/packages/core/src/nodes.ts.erb
|
|
885
783
|
class Node {
|
|
886
784
|
type;
|
|
887
785
|
location;
|
|
@@ -2874,6 +2772,28 @@
|
|
|
2874
2772
|
throw new Error(`Unknown node type: ${node.type}`);
|
|
2875
2773
|
}
|
|
2876
2774
|
}
|
|
2775
|
+
const ERBNodeClasses = [
|
|
2776
|
+
ERBContentNode,
|
|
2777
|
+
ERBEndNode,
|
|
2778
|
+
ERBElseNode,
|
|
2779
|
+
ERBIfNode,
|
|
2780
|
+
ERBBlockNode,
|
|
2781
|
+
ERBWhenNode,
|
|
2782
|
+
ERBCaseNode,
|
|
2783
|
+
ERBCaseMatchNode,
|
|
2784
|
+
ERBWhileNode,
|
|
2785
|
+
ERBUntilNode,
|
|
2786
|
+
ERBForNode,
|
|
2787
|
+
ERBRescueNode,
|
|
2788
|
+
ERBEnsureNode,
|
|
2789
|
+
ERBBeginNode,
|
|
2790
|
+
ERBUnlessNode,
|
|
2791
|
+
ERBYieldNode,
|
|
2792
|
+
ERBInNode,
|
|
2793
|
+
];
|
|
2794
|
+
function isERBNode(node) {
|
|
2795
|
+
return node.constructor.name.startsWith("ERB");
|
|
2796
|
+
}
|
|
2877
2797
|
|
|
2878
2798
|
/**
|
|
2879
2799
|
* Represents the result of a parsing operation, extending the base `Result` class.
|
|
@@ -2906,15 +2826,15 @@
|
|
|
2906
2826
|
* @returns `true` if there are errors, otherwise `false`.
|
|
2907
2827
|
*/
|
|
2908
2828
|
get failed() {
|
|
2909
|
-
//
|
|
2910
|
-
return this.
|
|
2829
|
+
// Consider errors on this result and recursively in the document tree
|
|
2830
|
+
return this.recursiveErrors().length > 0;
|
|
2911
2831
|
}
|
|
2912
2832
|
/**
|
|
2913
2833
|
* Determines if the parsing was successful.
|
|
2914
2834
|
* @returns `true` if there are no errors, otherwise `false`.
|
|
2915
2835
|
*/
|
|
2916
2836
|
get successful() {
|
|
2917
|
-
return this.
|
|
2837
|
+
return !this.failed;
|
|
2918
2838
|
}
|
|
2919
2839
|
/**
|
|
2920
2840
|
* Returns a pretty-printed JSON string of the errors.
|
|
@@ -3060,7 +2980,7 @@
|
|
|
3060
2980
|
}
|
|
3061
2981
|
|
|
3062
2982
|
// NOTE: This file is generated by the templates/template.rb script and should not
|
|
3063
|
-
// be modified manually. See /Users/marcoroth/Development/herb-release/templates/javascript/packages/core/src/visitor.ts.erb
|
|
2983
|
+
// be modified manually. See /Users/marcoroth/Development/herb-release-4/templates/javascript/packages/core/src/visitor.ts.erb
|
|
3064
2984
|
class Visitor {
|
|
3065
2985
|
visit(node) {
|
|
3066
2986
|
if (!node)
|
|
@@ -3177,6 +3097,7 @@
|
|
|
3177
3097
|
exports.ERBForNode = ERBForNode;
|
|
3178
3098
|
exports.ERBIfNode = ERBIfNode;
|
|
3179
3099
|
exports.ERBInNode = ERBInNode;
|
|
3100
|
+
exports.ERBNodeClasses = ERBNodeClasses;
|
|
3180
3101
|
exports.ERBRescueNode = ERBRescueNode;
|
|
3181
3102
|
exports.ERBUnlessNode = ERBUnlessNode;
|
|
3182
3103
|
exports.ERBUntilNode = ERBUntilNode;
|
|
@@ -3223,7 +3144,9 @@
|
|
|
3223
3144
|
exports.ensureString = ensureString;
|
|
3224
3145
|
exports.fromSerializedError = fromSerializedError;
|
|
3225
3146
|
exports.fromSerializedNode = fromSerializedNode;
|
|
3147
|
+
exports.isERBNode = isERBNode;
|
|
3226
3148
|
exports.isLibHerbBackend = isLibHerbBackend;
|
|
3149
|
+
exports.toMonacoDiagnostic = toMonacoDiagnostic;
|
|
3227
3150
|
|
|
3228
3151
|
}));
|
|
3229
3152
|
//# sourceMappingURL=herb-core.umd.js.map
|