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/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
- indentationStack.push(spaces.length);
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
- return spaces.length >= indentationStack[indentationStack.length - 1];
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 = _ links:links eof { return links; }
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
- PUSH_INDENTATION = spaces:" "* &{ return spaces.length > getCurrentIndentation(); } { pushIndentation(spaces); }
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';