wpilog-parser 3.1.0 → 3.1.2
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/dist/{catalog-DstFMwwV.mjs → catalog-BRtbeKXA.mjs} +148 -247
- package/dist/cli.mjs +58 -39
- package/dist/index.mjs +1 -1
- package/package.json +2 -4
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineDiagnostics } from "nostics";
|
|
2
|
-
import { CstParser, Lexer, createToken } from "chevrotain";
|
|
3
2
|
// src/byte-offset.ts
|
|
4
3
|
var ByteOffset = class {
|
|
5
4
|
offset;
|
|
@@ -29,10 +28,6 @@ var ByteOffset = class {
|
|
|
29
28
|
// src/diagnostics.ts
|
|
30
29
|
/** Stable codes for errors callers can act on. */
|
|
31
30
|
const diagnostics = defineDiagnostics({ codes: {
|
|
32
|
-
WPILOG_C0001: {
|
|
33
|
-
why: (p) => `Unknown command \`${p.command}\``,
|
|
34
|
-
fix: "Run `wpilog --help` to see the available commands."
|
|
35
|
-
},
|
|
36
31
|
WPILOG_C0002: {
|
|
37
32
|
why: "Output flags cannot be combined",
|
|
38
33
|
fix: "Choose one of --json, --jsonl, --ndjson, or --csv."
|
|
@@ -207,35 +202,14 @@ function readTimestamp(view, offset, length) {
|
|
|
207
202
|
switch (length) {
|
|
208
203
|
case 1: return BigInt(view.getUint8(offset));
|
|
209
204
|
case 2: return BigInt(view.getUint16(offset, true));
|
|
210
|
-
case 3:
|
|
211
|
-
const b0 = BigInt(view.getUint8(offset));
|
|
212
|
-
const b1 = BigInt(view.getUint8(offset + 1));
|
|
213
|
-
return BigInt(view.getUint8(offset + 2)) << 16n | b1 << 8n | b0;
|
|
214
|
-
}
|
|
205
|
+
case 3: return BigInt(view.getUint16(offset, true) + view.getUint8(offset + 2) * 2 ** 16);
|
|
215
206
|
case 4: return BigInt(view.getUint32(offset, true));
|
|
216
|
-
case 5:
|
|
217
|
-
|
|
218
|
-
const b1 = BigInt(view.getUint8(offset + 1));
|
|
219
|
-
const b2 = BigInt(view.getUint8(offset + 2));
|
|
220
|
-
const b3 = BigInt(view.getUint8(offset + 3));
|
|
221
|
-
return BigInt(view.getUint8(offset + 4)) << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
|
|
222
|
-
}
|
|
223
|
-
case 6: {
|
|
224
|
-
const b0 = BigInt(view.getUint8(offset));
|
|
225
|
-
const b1 = BigInt(view.getUint8(offset + 1));
|
|
226
|
-
const b2 = BigInt(view.getUint8(offset + 2));
|
|
227
|
-
const b3 = BigInt(view.getUint8(offset + 3));
|
|
228
|
-
const b4 = BigInt(view.getUint8(offset + 4));
|
|
229
|
-
return BigInt(view.getUint8(offset + 5)) << 40n | b4 << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
|
|
230
|
-
}
|
|
207
|
+
case 5: return BigInt(view.getUint32(offset, true) + view.getUint8(offset + 4) * 2 ** 32);
|
|
208
|
+
case 6: return BigInt(view.getUint32(offset, true) + view.getUint16(offset + 4, true) * 2 ** 32);
|
|
231
209
|
case 7: {
|
|
232
|
-
const
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
const b3 = BigInt(view.getUint8(offset + 3));
|
|
236
|
-
const b4 = BigInt(view.getUint8(offset + 4));
|
|
237
|
-
const b5 = BigInt(view.getUint8(offset + 5));
|
|
238
|
-
return BigInt(view.getUint8(offset + 6)) << 48n | b5 << 40n | b4 << 32n | b3 << 24n | b2 << 16n | b1 << 8n | b0;
|
|
210
|
+
const low = view.getUint32(offset, true);
|
|
211
|
+
const high = view.getUint16(offset + 4, true) + view.getUint8(offset + 6) * 2 ** 16;
|
|
212
|
+
return BigInt(high) << 32n | BigInt(low);
|
|
239
213
|
}
|
|
240
214
|
case 8: return view.getBigUint64(offset, true);
|
|
241
215
|
default: throw new RangeError(`Invalid timestamp length ${length}`);
|
|
@@ -624,158 +598,11 @@ function compileStruct(registry, name) {
|
|
|
624
598
|
${sources.join("\n")}
|
|
625
599
|
return ${root};`)(new TextDecoder());
|
|
626
600
|
}
|
|
627
|
-
// src/struct/
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
const Semicolon = createToken({
|
|
633
|
-
name: "Semicolon",
|
|
634
|
-
pattern: ";"
|
|
635
|
-
});
|
|
636
|
-
const Colon = createToken({
|
|
637
|
-
name: "Colon",
|
|
638
|
-
pattern: ":"
|
|
639
|
-
});
|
|
640
|
-
const Equals = createToken({
|
|
641
|
-
name: "Equals",
|
|
642
|
-
pattern: "="
|
|
643
|
-
});
|
|
644
|
-
const WhiteSpace = createToken({
|
|
645
|
-
name: "WhiteSpace",
|
|
646
|
-
pattern: /\s+/
|
|
647
|
-
});
|
|
648
|
-
const Integer = createToken({
|
|
649
|
-
name: "Integer",
|
|
650
|
-
pattern: /0|[1-9]\d*/
|
|
651
|
-
});
|
|
652
|
-
const LeftSquareBrace = createToken({
|
|
653
|
-
name: "LeftSquareBrace",
|
|
654
|
-
pattern: "["
|
|
655
|
-
});
|
|
656
|
-
const RightSquareBrace = createToken({
|
|
657
|
-
name: "RightSquareBrace",
|
|
658
|
-
pattern: "]"
|
|
659
|
-
});
|
|
660
|
-
const EnumKeyword = createToken({
|
|
661
|
-
name: "EnumKeyword",
|
|
662
|
-
pattern: "enum"
|
|
663
|
-
});
|
|
664
|
-
const LeftCurlyBrace = createToken({
|
|
665
|
-
name: "LeftCurlyBrace",
|
|
666
|
-
pattern: "{"
|
|
667
|
-
});
|
|
668
|
-
const RightCurlyBrace = createToken({
|
|
669
|
-
name: "RightCurlyBrace",
|
|
670
|
-
pattern: "}"
|
|
671
|
-
});
|
|
672
|
-
const Identifier = createToken({
|
|
673
|
-
name: "Identifier",
|
|
674
|
-
pattern: /\w+/
|
|
675
|
-
});
|
|
676
|
-
const allTokens = [
|
|
677
|
-
WhiteSpace,
|
|
678
|
-
Semicolon,
|
|
679
|
-
Equals,
|
|
680
|
-
Comma,
|
|
681
|
-
Colon,
|
|
682
|
-
Integer,
|
|
683
|
-
LeftSquareBrace,
|
|
684
|
-
RightSquareBrace,
|
|
685
|
-
EnumKeyword,
|
|
686
|
-
LeftCurlyBrace,
|
|
687
|
-
RightCurlyBrace,
|
|
688
|
-
Identifier
|
|
689
|
-
];
|
|
690
|
-
const lexer = new Lexer(allTokens);
|
|
691
|
-
// src/struct/parser.ts
|
|
692
|
-
var StructParser = class extends CstParser {
|
|
693
|
-
structSpecification = this.RULE("structSpecification", () => {
|
|
694
|
-
this.MANY_SEP({
|
|
695
|
-
SEP: Semicolon,
|
|
696
|
-
DEF: () => this.OPTION(() => this.SUBRULE(this.declaration))
|
|
697
|
-
});
|
|
698
|
-
});
|
|
699
|
-
declaration = this.RULE("declaration", () => {
|
|
700
|
-
this.OPTION(() => this.SUBRULE(this.enumSpecification));
|
|
701
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
702
|
-
this.CONSUME(Identifier);
|
|
703
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
704
|
-
this.CONSUME1(Identifier);
|
|
705
|
-
this.OPTION1(() => this.OR({ DEF: [{ ALT: () => this.SUBRULE(this.bitFieldDeclaration) }, { ALT: () => this.SUBRULE(this.standardDeclarationArray) }] }));
|
|
706
|
-
});
|
|
707
|
-
standardDeclarationArray = this.RULE("standardDeclarationArray", () => {
|
|
708
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
709
|
-
this.SUBRULE(this.arraySize);
|
|
710
|
-
});
|
|
711
|
-
bitFieldDeclaration = this.RULE("bitFieldDeclaration", () => {
|
|
712
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
713
|
-
this.CONSUME(Colon);
|
|
714
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
715
|
-
this.CONSUME(Integer);
|
|
716
|
-
});
|
|
717
|
-
arraySize = this.RULE("arraySize", () => {
|
|
718
|
-
this.CONSUME(LeftSquareBrace);
|
|
719
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
720
|
-
this.CONSUME(Integer);
|
|
721
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
722
|
-
this.CONSUME(RightSquareBrace);
|
|
723
|
-
});
|
|
724
|
-
enumSpecification = this.RULE("enumSpecification", () => {
|
|
725
|
-
this.OPTION(() => this.CONSUME(EnumKeyword));
|
|
726
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
727
|
-
this.CONSUME(LeftCurlyBrace);
|
|
728
|
-
this.MANY_SEP({
|
|
729
|
-
SEP: Comma,
|
|
730
|
-
DEF: () => this.SUBRULE(this.enumMember)
|
|
731
|
-
});
|
|
732
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
733
|
-
this.CONSUME(RightCurlyBrace);
|
|
734
|
-
});
|
|
735
|
-
enumMember = this.RULE("enumMember", () => {
|
|
736
|
-
this.SUBRULE(this.optionalWhitespace);
|
|
737
|
-
this.CONSUME(Identifier);
|
|
738
|
-
this.SUBRULE1(this.optionalWhitespace);
|
|
739
|
-
this.CONSUME(Equals);
|
|
740
|
-
this.SUBRULE2(this.optionalWhitespace);
|
|
741
|
-
this.CONSUME(Integer);
|
|
742
|
-
this.SUBRULE3(this.optionalWhitespace);
|
|
743
|
-
});
|
|
744
|
-
optionalWhitespace = this.RULE("optionalWhitespace", () => {
|
|
745
|
-
this.OPTION(() => this.CONSUME(WhiteSpace));
|
|
746
|
-
});
|
|
747
|
-
constructor() {
|
|
748
|
-
super(allTokens);
|
|
749
|
-
this.performSelfAnalysis();
|
|
750
|
-
}
|
|
751
|
-
};
|
|
752
|
-
const parser = new StructParser();
|
|
753
|
-
parser.getBaseCstVisitorConstructor();
|
|
754
|
-
const BaseStructVisitorWithDefaults = parser.getBaseCstVisitorConstructorWithDefaults();
|
|
755
|
-
// src/struct/struct-ast-visitor.ts
|
|
756
|
-
var StructAstVisitor = class extends BaseStructVisitorWithDefaults {
|
|
757
|
-
constructor() {
|
|
758
|
-
super();
|
|
759
|
-
this.validateVisitor();
|
|
760
|
-
}
|
|
761
|
-
structSpecification(children) {
|
|
762
|
-
return children.declaration?.map((declaration) => this.declaration(declaration.children)) ?? [];
|
|
763
|
-
}
|
|
764
|
-
declaration(children) {
|
|
765
|
-
const [typeName, name] = children.Identifier;
|
|
766
|
-
const enumSpecification = children.enumSpecification ? this.enumSpecification(children.enumSpecification[0].children, typeName.image) : void 0;
|
|
767
|
-
const arraySize = children.standardDeclarationArray ? this.standardDeclarationArray(children.standardDeclarationArray[0].children) : void 0;
|
|
768
|
-
const bitWidth = children.bitFieldDeclaration ? this.bitFieldDeclaration(children.bitFieldDeclaration[0].children, typeName.image) : void 0;
|
|
769
|
-
return {
|
|
770
|
-
name: name.image,
|
|
771
|
-
value: typeName.image,
|
|
772
|
-
enumSpecification,
|
|
773
|
-
arraySize,
|
|
774
|
-
bitWidth
|
|
775
|
-
};
|
|
776
|
-
}
|
|
777
|
-
enumSpecification(children, dataType) {
|
|
778
|
-
switch (dataType) {
|
|
601
|
+
// src/struct/validate-declarations.ts
|
|
602
|
+
function validateDeclarations(declarations) {
|
|
603
|
+
for (const declaration of declarations) {
|
|
604
|
+
const { value, enumSpecification, bitWidth } = declaration;
|
|
605
|
+
if (enumSpecification) switch (value) {
|
|
779
606
|
case KnownStructTypeName.Int8:
|
|
780
607
|
case KnownStructTypeName.Uint8:
|
|
781
608
|
case KnownStructTypeName.Int16:
|
|
@@ -786,82 +613,156 @@ var StructAstVisitor = class extends BaseStructVisitorWithDefaults {
|
|
|
786
613
|
case KnownStructTypeName.Uint64: break;
|
|
787
614
|
default: throw diagnostics.WPILOG_R0009();
|
|
788
615
|
}
|
|
789
|
-
|
|
790
|
-
return new Map(entries);
|
|
616
|
+
if (bitWidth !== void 0) validateBitWidth(value, bitWidth);
|
|
791
617
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
618
|
+
return declarations;
|
|
619
|
+
}
|
|
620
|
+
function validateBitWidth(value, parsed) {
|
|
621
|
+
switch (value) {
|
|
622
|
+
case KnownStructTypeName.Boolean:
|
|
623
|
+
if (parsed !== 1) throw diagnostics.WPILOG_R0010({
|
|
624
|
+
type: value,
|
|
625
|
+
width: parsed,
|
|
626
|
+
maxBits: 1
|
|
627
|
+
});
|
|
628
|
+
break;
|
|
629
|
+
case KnownStructTypeName.Int8:
|
|
630
|
+
case KnownStructTypeName.Uint8:
|
|
631
|
+
if (parsed > 8) throw diagnostics.WPILOG_R0010({
|
|
632
|
+
type: value,
|
|
633
|
+
width: parsed,
|
|
634
|
+
maxBits: 8
|
|
635
|
+
});
|
|
636
|
+
break;
|
|
637
|
+
case KnownStructTypeName.Int16:
|
|
638
|
+
case KnownStructTypeName.Uint16:
|
|
639
|
+
if (parsed > 16) throw diagnostics.WPILOG_R0010({
|
|
640
|
+
type: value,
|
|
641
|
+
width: parsed,
|
|
642
|
+
maxBits: 16
|
|
643
|
+
});
|
|
644
|
+
break;
|
|
645
|
+
case KnownStructTypeName.Int32:
|
|
646
|
+
case KnownStructTypeName.Uint32:
|
|
647
|
+
if (parsed > 32) throw diagnostics.WPILOG_R0010({
|
|
648
|
+
type: value,
|
|
649
|
+
width: parsed,
|
|
650
|
+
maxBits: 32
|
|
651
|
+
});
|
|
652
|
+
break;
|
|
653
|
+
case KnownStructTypeName.Int64:
|
|
654
|
+
case KnownStructTypeName.Uint64:
|
|
655
|
+
if (parsed > 64) throw diagnostics.WPILOG_R0010({
|
|
656
|
+
type: value,
|
|
657
|
+
width: parsed,
|
|
658
|
+
maxBits: 64
|
|
659
|
+
});
|
|
660
|
+
break;
|
|
661
|
+
default: throw diagnostics.WPILOG_R0011();
|
|
796
662
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
663
|
+
}
|
|
664
|
+
// src/struct/parser.ts
|
|
665
|
+
const tokenPattern = /\s*([a-zA-Z_]\w*|\d+|[;,=:[\]{}])?/y;
|
|
666
|
+
const identifierStartPattern = /^[a-zA-Z_]/;
|
|
667
|
+
const integerStartPattern = /^\d/;
|
|
668
|
+
/** Parse a WPILib struct schema into field declarations. */
|
|
669
|
+
function parseStruct(source) {
|
|
670
|
+
return validateDeclarations(new SchemaParser(source).parse());
|
|
671
|
+
}
|
|
672
|
+
var SchemaParser = class {
|
|
673
|
+
source;
|
|
674
|
+
offset = 0;
|
|
675
|
+
token = "";
|
|
676
|
+
tokenOffset = 0;
|
|
677
|
+
constructor(source) {
|
|
678
|
+
this.source = source;
|
|
679
|
+
}
|
|
680
|
+
parse() {
|
|
681
|
+
const declarations = [];
|
|
682
|
+
this.advance();
|
|
683
|
+
while (this.token) {
|
|
684
|
+
if (this.at(";")) {
|
|
685
|
+
this.advance();
|
|
686
|
+
continue;
|
|
687
|
+
}
|
|
688
|
+
declarations.push(this.readDeclaration());
|
|
689
|
+
if (this.token) this.consume(";");
|
|
690
|
+
}
|
|
691
|
+
return declarations;
|
|
692
|
+
}
|
|
693
|
+
readDeclaration() {
|
|
694
|
+
const enumSpecification = this.at("enum") || this.at("{") ? this.readEnum() : void 0;
|
|
695
|
+
const value = this.readIdentifier();
|
|
696
|
+
const name = this.readIdentifier();
|
|
697
|
+
let arraySize;
|
|
698
|
+
let bitWidth;
|
|
699
|
+
if (this.at("[")) {
|
|
700
|
+
this.advance();
|
|
701
|
+
arraySize = Number(this.readInteger());
|
|
702
|
+
this.consume("]");
|
|
703
|
+
} else if (this.at(":")) {
|
|
704
|
+
this.advance();
|
|
705
|
+
bitWidth = Number(this.readInteger());
|
|
706
|
+
}
|
|
707
|
+
return {
|
|
708
|
+
name,
|
|
709
|
+
value,
|
|
710
|
+
enumSpecification,
|
|
711
|
+
arraySize,
|
|
712
|
+
bitWidth
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
readEnum() {
|
|
716
|
+
if (this.at("enum")) this.advance();
|
|
717
|
+
this.consume("{");
|
|
718
|
+
const members = /* @__PURE__ */ new Map();
|
|
719
|
+
if (!this.at("}")) while (true) {
|
|
720
|
+
const name = this.readIdentifier();
|
|
721
|
+
this.consume("=");
|
|
722
|
+
members.set(name, BigInt(this.readInteger()));
|
|
723
|
+
if (!this.at(",")) break;
|
|
724
|
+
this.advance();
|
|
841
725
|
}
|
|
842
|
-
|
|
726
|
+
this.consume("}");
|
|
727
|
+
return members;
|
|
728
|
+
}
|
|
729
|
+
readIdentifier() {
|
|
730
|
+
if (!identifierStartPattern.test(this.token)) this.fail("identifier");
|
|
731
|
+
const value = this.token;
|
|
732
|
+
this.advance();
|
|
733
|
+
return value;
|
|
734
|
+
}
|
|
735
|
+
readInteger() {
|
|
736
|
+
if (!integerStartPattern.test(this.token)) this.fail("integer");
|
|
737
|
+
const value = this.token;
|
|
738
|
+
this.advance();
|
|
739
|
+
return value;
|
|
740
|
+
}
|
|
741
|
+
at(expected) {
|
|
742
|
+
return this.token === expected;
|
|
743
|
+
}
|
|
744
|
+
consume(expected) {
|
|
745
|
+
if (!this.at(expected)) this.fail(JSON.stringify(expected));
|
|
746
|
+
this.advance();
|
|
843
747
|
}
|
|
844
|
-
|
|
845
|
-
|
|
748
|
+
advance() {
|
|
749
|
+
tokenPattern.lastIndex = this.offset;
|
|
750
|
+
this.token = tokenPattern.exec(this.source)[1] ?? "";
|
|
751
|
+
this.offset = tokenPattern.lastIndex;
|
|
752
|
+
this.tokenOffset = this.offset - this.token.length;
|
|
753
|
+
if (!this.token && this.offset < this.source.length) throw diagnostics.WPILOG_R0007({ cause: new AggregateError([/* @__PURE__ */ new SyntaxError(`Invalid character at offset ${this.offset}`)]) });
|
|
846
754
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
return Number(value.image);
|
|
755
|
+
fail(expected) {
|
|
756
|
+
throw diagnostics.WPILOG_R0008({ cause: new AggregateError([/* @__PURE__ */ new SyntaxError(`Expected ${expected} at offset ${this.tokenOffset}`)]) });
|
|
850
757
|
}
|
|
851
758
|
};
|
|
852
759
|
// src/struct/parse-struct.ts
|
|
853
|
-
const structAstVisitor = new StructAstVisitor();
|
|
854
760
|
const cache = /* @__PURE__ */ new Map();
|
|
855
761
|
/** Parse a WPILib struct specification string into declarations. */
|
|
856
762
|
function parseStructSpecification(declaration) {
|
|
857
763
|
const existing = cache.get(declaration);
|
|
858
764
|
if (existing) return existing;
|
|
859
|
-
const
|
|
860
|
-
if (lexingResult.errors.length > 0) throw diagnostics.WPILOG_R0007({ cause: new AggregateError(lexingResult.errors) });
|
|
861
|
-
parser.input = lexingResult.tokens;
|
|
862
|
-
const cstNode = parser.structSpecification();
|
|
863
|
-
if (parser.errors.length > 0) throw diagnostics.WPILOG_R0008({ cause: new AggregateError(parser.errors) });
|
|
864
|
-
const created = structAstVisitor.structSpecification(cstNode.children);
|
|
765
|
+
const created = parseStruct(declaration);
|
|
865
766
|
cache.set(declaration, created);
|
|
866
767
|
return created;
|
|
867
768
|
}
|
package/dist/cli.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { o as readRecords, t as catalogEntries, u as diagnostics } from "./catalog-
|
|
2
|
+
import { o as readRecords, t as catalogEntries, u as diagnostics } from "./catalog-BRtbeKXA.mjs";
|
|
3
3
|
import { Diagnostic, formatDiagnostic } from "nostics";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
4
|
+
import { RootCommand, script } from "@bomb.sh/tab";
|
|
5
|
+
import { boolean, command, commandsInfo, positional, run } from "@drizzle-team/brocli";
|
|
6
6
|
import oscStatus from "osc-status";
|
|
7
7
|
import { readFile } from "node:fs/promises";
|
|
8
8
|
import { encode } from "@toon-format/toon";
|
|
9
9
|
// package.json
|
|
10
|
-
var version = "3.1.
|
|
10
|
+
var version = "3.1.2";
|
|
11
|
+
var description = "Read WPILib wpilog data log files in TypeScript & JavaScript";
|
|
11
12
|
// src/cli/catalog.ts
|
|
12
13
|
async function catalogFile(filePath) {
|
|
13
14
|
let bytes;
|
|
@@ -57,42 +58,60 @@ function formatCatalog(entries, format = "toon") {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
// src/cli.ts
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
const completions = new RootCommand();
|
|
62
|
+
const commands = [command({
|
|
63
|
+
name: "catalog",
|
|
64
|
+
desc: "List the entries available in a WPILOG file",
|
|
65
|
+
options: {
|
|
66
|
+
file: positional().desc("WPILOG file to catalog").required(),
|
|
67
|
+
json: boolean().desc("Output as JSON"),
|
|
68
|
+
jsonl: boolean().desc("Output as newline-delimited JSON"),
|
|
69
|
+
ndjson: boolean().desc("Output as newline-delimited JSON"),
|
|
70
|
+
csv: boolean().desc("Output as CSV")
|
|
71
|
+
},
|
|
72
|
+
async handler(options) {
|
|
73
|
+
const format = selectCatalogFormat(options);
|
|
74
|
+
oscStatus.working({
|
|
75
|
+
app: "wpilog",
|
|
76
|
+
message: "Cataloging log"
|
|
77
|
+
});
|
|
78
|
+
const entries = await catalogFile(options.file);
|
|
79
|
+
console.log(formatCatalog(entries, format));
|
|
80
|
+
oscStatus.done({
|
|
81
|
+
app: "wpilog",
|
|
82
|
+
message: `Cataloged ${entries.length} entries`
|
|
83
|
+
});
|
|
82
84
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
}), command({
|
|
86
|
+
name: "complete",
|
|
87
|
+
desc: "Generate shell completion scripts",
|
|
88
|
+
options: { shell: positional().enum("zsh", "bash", "fish", "powershell").desc("Shell type") },
|
|
89
|
+
handler({ shell }) {
|
|
90
|
+
if (shell) script(shell, "wpilog", "wpilog");
|
|
91
|
+
else completions.parse([]);
|
|
87
92
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
oscStatus.error({
|
|
94
|
-
app: "wpilog",
|
|
95
|
-
message: "Command failed"
|
|
96
|
-
});
|
|
93
|
+
})];
|
|
94
|
+
for (const info of Object.values(commandsInfo(commands))) {
|
|
95
|
+
const completion = completions.command(info.name, info.desc ?? "");
|
|
96
|
+
for (const option of Object.values(info.options ?? {})) if (option.type === "positional") completion.argument(option.name);
|
|
97
|
+
else completion.option(option.name.replace(/^-+/, ""), option.description ?? "");
|
|
97
98
|
}
|
|
99
|
+
if (process.argv[2] === "complete" && process.argv[3] === "--") completions.parse(process.argv.slice(4));
|
|
100
|
+
else await run(commands, {
|
|
101
|
+
name: "wpilog",
|
|
102
|
+
description,
|
|
103
|
+
version,
|
|
104
|
+
theme(event) {
|
|
105
|
+
if (event.type !== "error") return false;
|
|
106
|
+
oscStatus.error({
|
|
107
|
+
app: "wpilog",
|
|
108
|
+
message: "Command failed"
|
|
109
|
+
});
|
|
110
|
+
if (event.violation === "unknown_error" && event.error instanceof Diagnostic) {
|
|
111
|
+
console.error(formatDiagnostic(event.error));
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
98
117
|
export {};
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { s as ControlRecordType, a as KnownStructTypeName, c as RecordType, t as catalogEntries, n as decodeRecords, l as isDataRecord, r as parseDataLog, i as parseStructSpecification, o as readRecords } from "./catalog-
|
|
1
|
+
export { s as ControlRecordType, a as KnownStructTypeName, c as RecordType, t as catalogEntries, n as decodeRecords, l as isDataRecord, r as parseDataLog, i as parseStructSpecification, o as readRecords } from "./catalog-BRtbeKXA.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wpilog-parser",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "Read WPILib wpilog data log files in TypeScript & JavaScript",
|
|
5
5
|
"homepage": "https://github.com/jonahsnider/wpilog-parser#readme",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
"build": "vp pack",
|
|
36
36
|
"check": "vp check",
|
|
37
37
|
"dev": "vp pack --watch",
|
|
38
|
-
"generate": "node ./src/struct/codegen.ts",
|
|
39
38
|
"preapi:check": "vp run build",
|
|
40
39
|
"preapi:update": "vp run build",
|
|
41
40
|
"prepare": "vp config",
|
|
@@ -45,9 +44,8 @@
|
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
46
|
"@bomb.sh/tab": "^0.0.22",
|
|
47
|
+
"@drizzle-team/brocli": "^0.12.1",
|
|
48
48
|
"@toon-format/toon": "^4.1.1",
|
|
49
|
-
"cac": "^7.0.0",
|
|
50
|
-
"chevrotain": "^13.0.0",
|
|
51
49
|
"nostics": "^1.3.0",
|
|
52
50
|
"osc-status": "^1.0.0"
|
|
53
51
|
},
|