links-notation 0.11.0 → 0.12.0
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/bun.lock +1 -0
- package/dist/index.js +484 -143
- package/examples/debug_indentation.js +16 -0
- package/examples/test_leading_spaces.js +33 -0
- package/package.json +1 -1
- package/src/FormatConfig.js +19 -0
- package/src/FormatOptions.js +52 -0
- package/src/Link.js +287 -25
- package/src/Parser.js +43 -8
- package/src/grammar.pegjs +30 -10
- package/src/index.js +3 -1
- package/src/parser-generated.js +276 -123
- package/tests/ApiTests.test.js +104 -7
- package/tests/EdgeCaseParser.test.js +9 -9
- package/tests/FormatConfig.test.js +126 -0
- package/tests/IndentationConsistency.test.js +128 -0
- package/tests/IndentedIdSyntax.test.js +2 -2
- package/tests/Link.test.js +1 -1
- package/tests/LinksGroup.test.js +28 -1
- package/tests/MixedIndentationModes.test.js +5 -5
- package/tests/MultilineParser.test.js +5 -5
- package/tests/NestedParser.test.js +31 -4
- package/tests/NestedSelfReference.test.js +102 -0
- package/tests/SingleLineParser.test.js +86 -6
package/src/grammar.pegjs
CHANGED
|
@@ -1,31 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
let indentationStack = [0];
|
|
3
|
-
|
|
3
|
+
let baseIndentation = null;
|
|
4
|
+
|
|
5
|
+
function setBaseIndentation(spaces) {
|
|
6
|
+
if (baseIndentation === null) {
|
|
7
|
+
baseIndentation = spaces.length;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function normalizeIndentation(spaces) {
|
|
12
|
+
if (baseIndentation === null) {
|
|
13
|
+
return spaces.length;
|
|
14
|
+
}
|
|
15
|
+
return Math.max(0, spaces.length - baseIndentation);
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
function pushIndentation(spaces) {
|
|
5
|
-
|
|
19
|
+
const normalized = normalizeIndentation(spaces);
|
|
20
|
+
indentationStack.push(normalized);
|
|
6
21
|
}
|
|
7
|
-
|
|
22
|
+
|
|
8
23
|
function popIndentation() {
|
|
9
24
|
if (indentationStack.length > 1) {
|
|
10
25
|
indentationStack.pop();
|
|
11
26
|
}
|
|
12
27
|
}
|
|
13
|
-
|
|
28
|
+
|
|
14
29
|
function checkIndentation(spaces) {
|
|
15
|
-
|
|
30
|
+
const normalized = normalizeIndentation(spaces);
|
|
31
|
+
return normalized >= indentationStack[indentationStack.length - 1];
|
|
16
32
|
}
|
|
17
|
-
|
|
33
|
+
|
|
18
34
|
function getCurrentIndentation() {
|
|
19
35
|
return indentationStack[indentationStack.length - 1];
|
|
20
36
|
}
|
|
21
37
|
}
|
|
22
38
|
|
|
23
|
-
document =
|
|
24
|
-
/ _ eof { return []; }
|
|
39
|
+
document = &{ indentationStack = [0]; baseIndentation = null; return true; } skipEmptyLines links:links _ eof { return links; }
|
|
40
|
+
/ &{ indentationStack = [0]; baseIndentation = null; return true; } _ eof { return []; }
|
|
41
|
+
|
|
42
|
+
skipEmptyLines = ([ \t]* [\r\n])*
|
|
25
43
|
|
|
26
44
|
links = fl:firstLine list:line* { popIndentation(); return [fl].concat(list || []); }
|
|
27
45
|
|
|
28
|
-
firstLine = l:element { return l; }
|
|
46
|
+
firstLine = SET_BASE_INDENTATION l:element { return l; }
|
|
29
47
|
|
|
30
48
|
line = CHECK_INDENTATION l:element { return l; }
|
|
31
49
|
|
|
@@ -69,7 +87,9 @@ doubleQuotedReference = '"' r:[^"]+ '"' { return r.join(''); }
|
|
|
69
87
|
|
|
70
88
|
singleQuotedReference = "'" r:[^']+ "'" { return r.join(''); }
|
|
71
89
|
|
|
72
|
-
|
|
90
|
+
SET_BASE_INDENTATION = spaces:" "* { setBaseIndentation(spaces); }
|
|
91
|
+
|
|
92
|
+
PUSH_INDENTATION = spaces:" "* &{ return normalizeIndentation(spaces) > getCurrentIndentation(); } { pushIndentation(spaces); }
|
|
73
93
|
|
|
74
94
|
CHECK_INDENTATION = spaces:" "* &{ return checkIndentation(spaces); }
|
|
75
95
|
|
package/src/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { Link, formatLinks } from './Link.js';
|
|
2
2
|
export { LinksGroup } from './LinksGroup.js';
|
|
3
|
-
export { Parser } from './Parser.js';
|
|
3
|
+
export { Parser } from './Parser.js';
|
|
4
|
+
export { FormatConfig } from './FormatConfig.js';
|
|
5
|
+
export { FormatOptions } from './FormatOptions.js';
|