Skip to content

Commit 9107ce2

Browse files
committed
fix: don't make annotations require a double-#
1 parent 49ccdbf commit 9107ce2

File tree

6 files changed

+74
-78
lines changed

6 files changed

+74
-78
lines changed

ipld-schema.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ BaseType
469469
/ "null"
470470
/ "any"
471471

472-
// Annotation is '## @name(value)' or '## @name', swallowing any trailing comments
473-
Annotation = [ \t]* "##" [ \t]* "@" name:StringName value:("(" value:[^)]* ")" { return value })? [^\r\n]* newline ws* {
472+
// Annotation is '# @name(value)' or '# @name', swallowing any trailing comments
473+
Annotation = [ \t]* "#" [ \t]* "@" name:StringName value:("(" value:[^)]* ")" { return value })? [^\r\n]* newline ws* {
474474
return { [name]: value ? value.join('') : '' }
475475
}
476476

@@ -496,7 +496,7 @@ _wsnl
496496

497497
wsnl = _wsnl*
498498

499-
comment = "#" !("#" [ \t]* "@" StringName) [^\r\n]*
499+
comment = "#" !([ \t]* "@" StringName) [^\r\n]*
500500

501501
ws = [ \t]
502502

lib/gen/go.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function generateGo (schema, options = {}) {
5353
let linecomment = ''
5454
if (comments) {
5555
if (comments.precomments) {
56-
for (const comment of comments.precomments.split('\n')) {
56+
for (const comment of comments.precomments.trim().split('\n')) {
5757
typesrc += `\t// ${comment}\n`
5858
}
5959
}

lib/gen/rust.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function generateRust (schema) {
7272
let linecomment = ''
7373
if (comments) {
7474
if (comments.precomments) {
75-
for (const comment of comments.precomments.split('\n')) {
75+
for (const comment of comments.precomments.trim().split('\n')) {
7676
typesrc += ` /// ${comment}\n`
7777
}
7878
}

lib/gen/typescript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function generateTypeScript (schema) {
5050
let linecomment = ''
5151
if (comments) {
5252
if (comments.precomments) {
53-
for (const comment of comments.precomments.split('\n')) {
53+
for (const comment of comments.precomments.trim().split('\n')) {
5454
typesrc += ` // ${comment}\n`
5555
}
5656
}

lib/parser.cjs

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,10 @@ function peg$parse(input, options) {
229229
var peg$c48 = "link";
230230
var peg$c49 = "null";
231231
var peg$c50 = "any";
232-
var peg$c51 = "##";
232+
var peg$c51 = "#";
233233
var peg$c52 = "@";
234-
var peg$c53 = "#";
235-
var peg$c54 = "\r";
236-
var peg$c55 = "\n";
234+
var peg$c53 = "\r";
235+
var peg$c54 = "\n";
237236

238237
var peg$r0 = /^[^"]/;
239238
var peg$r1 = /^[a-zA-Z]/;
@@ -299,13 +298,12 @@ function peg$parse(input, options) {
299298
var peg$e53 = peg$literalExpectation("null", false);
300299
var peg$e54 = peg$literalExpectation("any", false);
301300
var peg$e55 = peg$classExpectation([" ", "\t"], false, false);
302-
var peg$e56 = peg$literalExpectation("##", false);
301+
var peg$e56 = peg$literalExpectation("#", false);
303302
var peg$e57 = peg$literalExpectation("@", false);
304303
var peg$e58 = peg$classExpectation([")"], true, false);
305304
var peg$e59 = peg$classExpectation(["\r", "\n"], true, false);
306-
var peg$e60 = peg$literalExpectation("#", false);
307-
var peg$e61 = peg$literalExpectation("\r", false);
308-
var peg$e62 = peg$literalExpectation("\n", false);
305+
var peg$e60 = peg$literalExpectation("\r", false);
306+
var peg$e61 = peg$literalExpectation("\n", false);
309307

310308
var peg$f0 = function(roots) {
311309
// merge 'type' and 'advanced' structures into one {types:{}, advanced:{}}
@@ -3550,9 +3548,9 @@ function peg$parse(input, options) {
35503548
if (peg$silentFails === 0) { peg$fail(peg$e55); }
35513549
}
35523550
}
3553-
if (input.substr(peg$currPos, 2) === peg$c51) {
3551+
if (input.charCodeAt(peg$currPos) === 35) {
35543552
s2 = peg$c51;
3555-
peg$currPos += 2;
3553+
peg$currPos++;
35563554
} else {
35573555
s2 = peg$FAILED;
35583556
if (peg$silentFails === 0) { peg$fail(peg$e56); }
@@ -3867,62 +3865,50 @@ function peg$parse(input, options) {
38673865
}
38683866

38693867
function peg$parsecomment() {
3870-
var s0, s1, s2, s3, s4, s5, s6, s7;
3868+
var s0, s1, s2, s3, s4, s5, s6;
38713869

38723870
s0 = peg$currPos;
38733871
if (input.charCodeAt(peg$currPos) === 35) {
3874-
s1 = peg$c53;
3872+
s1 = peg$c51;
38753873
peg$currPos++;
38763874
} else {
38773875
s1 = peg$FAILED;
3878-
if (peg$silentFails === 0) { peg$fail(peg$e60); }
3876+
if (peg$silentFails === 0) { peg$fail(peg$e56); }
38793877
}
38803878
if (s1 !== peg$FAILED) {
38813879
s2 = peg$currPos;
38823880
peg$silentFails++;
38833881
s3 = peg$currPos;
3884-
if (input.charCodeAt(peg$currPos) === 35) {
3885-
s4 = peg$c53;
3882+
s4 = [];
3883+
s5 = input.charAt(peg$currPos);
3884+
if (peg$r4.test(s5)) {
38863885
peg$currPos++;
38873886
} else {
3888-
s4 = peg$FAILED;
3889-
if (peg$silentFails === 0) { peg$fail(peg$e60); }
3887+
s5 = peg$FAILED;
3888+
if (peg$silentFails === 0) { peg$fail(peg$e55); }
38903889
}
3891-
if (s4 !== peg$FAILED) {
3892-
s5 = [];
3893-
s6 = input.charAt(peg$currPos);
3894-
if (peg$r4.test(s6)) {
3890+
while (s5 !== peg$FAILED) {
3891+
s4.push(s5);
3892+
s5 = input.charAt(peg$currPos);
3893+
if (peg$r4.test(s5)) {
38953894
peg$currPos++;
38963895
} else {
3897-
s6 = peg$FAILED;
3896+
s5 = peg$FAILED;
38983897
if (peg$silentFails === 0) { peg$fail(peg$e55); }
38993898
}
3900-
while (s6 !== peg$FAILED) {
3901-
s5.push(s6);
3902-
s6 = input.charAt(peg$currPos);
3903-
if (peg$r4.test(s6)) {
3904-
peg$currPos++;
3905-
} else {
3906-
s6 = peg$FAILED;
3907-
if (peg$silentFails === 0) { peg$fail(peg$e55); }
3908-
}
3909-
}
3910-
if (input.charCodeAt(peg$currPos) === 64) {
3911-
s6 = peg$c52;
3912-
peg$currPos++;
3913-
} else {
3914-
s6 = peg$FAILED;
3915-
if (peg$silentFails === 0) { peg$fail(peg$e57); }
3916-
}
3899+
}
3900+
if (input.charCodeAt(peg$currPos) === 64) {
3901+
s5 = peg$c52;
3902+
peg$currPos++;
3903+
} else {
3904+
s5 = peg$FAILED;
3905+
if (peg$silentFails === 0) { peg$fail(peg$e57); }
3906+
}
3907+
if (s5 !== peg$FAILED) {
3908+
s6 = peg$parseStringName();
39173909
if (s6 !== peg$FAILED) {
3918-
s7 = peg$parseStringName();
3919-
if (s7 !== peg$FAILED) {
3920-
s4 = [s4, s5, s6, s7];
3921-
s3 = s4;
3922-
} else {
3923-
peg$currPos = s3;
3924-
s3 = peg$FAILED;
3925-
}
3910+
s4 = [s4, s5, s6];
3911+
s3 = s4;
39263912
} else {
39273913
peg$currPos = s3;
39283914
s3 = peg$FAILED;
@@ -3990,21 +3976,21 @@ function peg$parse(input, options) {
39903976

39913977
s0 = peg$currPos;
39923978
if (input.charCodeAt(peg$currPos) === 13) {
3993-
s1 = peg$c54;
3979+
s1 = peg$c53;
39943980
peg$currPos++;
39953981
} else {
39963982
s1 = peg$FAILED;
3997-
if (peg$silentFails === 0) { peg$fail(peg$e61); }
3983+
if (peg$silentFails === 0) { peg$fail(peg$e60); }
39983984
}
39993985
if (s1 === peg$FAILED) {
40003986
s1 = null;
40013987
}
40023988
if (input.charCodeAt(peg$currPos) === 10) {
4003-
s2 = peg$c55;
3989+
s2 = peg$c54;
40043990
peg$currPos++;
40053991
} else {
40063992
s2 = peg$FAILED;
4007-
if (peg$silentFails === 0) { peg$fail(peg$e62); }
3993+
if (peg$silentFails === 0) { peg$fail(peg$e61); }
40083994
}
40093995
if (s2 !== peg$FAILED) {
40103996
s1 = [s1, s2];

test/fixtures/gen/filecoin_miner_types.md

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@ This file is an input to a test case, using the [testmark](https://github.com/wa
1313
```ipldsch
1414
type RecoveryDeclaration struct {
1515
# The deadline to which the recovered sectors are assigned, in range [0..WPoStPeriodDeadlines)
16-
## @unsigned
16+
#
17+
# @unsigned
1718
Deadline Int
19+
1820
# Partition index within the deadline containing the recovered sectors.
19-
## @unsigned
21+
#
22+
# @unsigned
2023
Partition Int
24+
2125
# Sectors in the partition being declared recovered.
22-
## @gotype(github.com/filecoin-project/go-bitfield.BitField)
23-
## @rusttype(fvm_ipld_bitfield::BitField)
26+
#
27+
# @gotype(github.com/filecoin-project/go-bitfield.BitField)
28+
# @rusttype(fvm_ipld_bitfield::BitField)
2429
Sectors Bytes
2530
} representation tuple
2631
@@ -30,41 +35,46 @@ type DeclareFaultsRecoveredParams struct {
3035
3136
type FaultDeclaration struct {
3237
# The deadline to which the faulty sectors are assigned, in range [0..WPoStPeriodDeadlines)
33-
## @unsigned
38+
#
39+
# @unsigned
3440
Deadline Int
41+
3542
# Partition index within the deadline containing the faulty sectors.
36-
## @unsigned
43+
#
44+
# @unsigned
3745
Partition Int
46+
3847
# Sectors in the partition being declared faulty.
39-
## @gotype(github.com/filecoin-project/go-bitfield.BitField)
40-
## @rusttype(fvm_ipld_bitfield::BitField)
48+
#
49+
# @gotype(github.com/filecoin-project/go-bitfield.BitField)
50+
# @rusttype(fvm_ipld_bitfield::BitField)
4151
Sectors Bytes
4252
} representation tuple
4353
4454
type DeclareFaultsParams struct {
4555
Faults [FaultDeclaration]
4656
} representation tuple
4757
48-
## @rustderive(Debug, Clone, PartialEq, Eq)
58+
# @rustderive(Debug, Clone, PartialEq, Eq)
4959
type ReplicaUpdate struct {
50-
## @gotype(github.com/filecoin-project/go-state-types/abi.SectorNumber)
51-
## @gorename(SectorID) - for historical reasons
52-
## @rusttype(fvm_shared::sector::SectorNumber)
60+
# @gotype(github.com/filecoin-project/go-state-types/abi.SectorNumber)
61+
# @gorename(SectorID) - for historical reasons
62+
# @rusttype(fvm_shared::sector::SectorNumber)
5363
SectorNumber Int
54-
## @unsigned
64+
# @unsigned
5565
Deadline Int
56-
## @unsigned
66+
# @unsigned
5767
Partition Int
58-
## @gotag(`checked:"true"`)
59-
## @rustrename(new_sealed_cid)
68+
# @gotag(`checked:"true"`)
69+
# @rustrename(new_sealed_cid)
6070
NewSealedSectorCID Link
61-
## @gotype(github.com/filecoin-project/go-state-types/abi.DealID)
62-
## @rusttype(fvm_shared::deal::DealID)
71+
# @gotype(github.com/filecoin-project/go-state-types/abi.DealID)
72+
# @rusttype(fvm_shared::deal::DealID)
6373
Deals [Int]
64-
## @gotype(github.com/filecoin-project/go-state-types/abi.RegisteredUpdateProof)
65-
## @rusttype(fvm_shared::sector::RegisteredUpdateProof)
74+
# @gotype(github.com/filecoin-project/go-state-types/abi.RegisteredUpdateProof)
75+
# @rusttype(fvm_shared::sector::RegisteredUpdateProof)
6676
UpdateProofType Int
67-
## @rusttype(fvm_ipld_encoding::RawBytes)
77+
# @rusttype(fvm_ipld_encoding::RawBytes)
6878
ReplicaProof Bytes
6979
} representation tuple
7080
```

0 commit comments

Comments
 (0)