Skip to content

Commit 41e9659

Browse files
committed
nit: rename range pattern
1 parent 364a14b commit 41e9659

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const keyValuePairPattern = /([-\w]+)=(?:'([^']*)'|"([^"]*)"|\`([^`]*)\`)/;
55

66
const WhiteSpace = createToken({ name: "WhiteSpace", pattern: /\s+/, group: Lexer.SKIPPED });
77
const Range0 = createToken({ name: "Range0", pattern: /\w*{\d+}/, label: "range" });
8-
const Range2Dotted = createToken({ name: "Range2Dotted", pattern: /\w*{\d+\.\.\d+}/, label: "range" });
8+
const Range2 = createToken({ name: "Range2", pattern: /\w*{\d+\.\.\d+}/, label: "range" });
99
const Ranges = createToken({ name: "Ranges", pattern: /\w*{(?:\d+|\d+\.\.\d+)(?:,\s*(?:\d+|\d+\.\.\d+))*}/, label: "range" });
1010
const KeyValuePair = createToken({ name: "KeyValuePair", pattern: keyValuePairPattern, label: "pair" });
1111

1212
const tokens = [
1313
WhiteSpace,
1414
Range0,
15-
Range2Dotted,
15+
Range2,
1616
Ranges,
1717
KeyValuePair
1818
];
@@ -53,14 +53,14 @@ export default class FenceParser {
5353
switch(type) {
5454
case "Range0":
5555
return { key, value: [Number(value)], label };
56-
case "Range2Dotted":
57-
const [ dottedB0, dottedB1 ] = value.split("..").map((bound) => Number(bound));
58-
const dottedRangeStart = Math.min(dottedB0, dottedB1);
59-
const dottedRangeStop = Math.max(dottedB0, dottedB1);
60-
const dottedRangeSize = dottedRangeStop - dottedRangeStart + 1;
56+
case "Range2":
57+
const [ b0, b1 ] = value.split("..").map((bound) => Number(bound));
58+
const start = Math.min(b0, b1);
59+
const stop = Math.max(b0, b1);
60+
const size = stop - start + 1;
6161
return {
6262
key,
63-
value: Array.from({ length: dottedRangeSize }, (_, i) => i + dottedRangeStart),
63+
value: Array.from({ length: size }, (_, i) => i + start),
6464
label
6565
};
6666
case "Ranges":

0 commit comments

Comments
 (0)