links-notation 0.16.1 → 0.17.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/README.md CHANGED
@@ -223,6 +223,35 @@ parent
223
223
  grandchild2
224
224
  ```
225
225
 
226
+ ### Multi-line Groups
227
+
228
+ A parenthesized group opens a _nested context_: its body starts fresh at
229
+ indentation level zero and follows the same rules as the root document, so a
230
+ line break inside parentheses is structure rather than decoration.
231
+
232
+ ```lino
233
+ value (
234
+ id "1"
235
+ label "one"
236
+ )
237
+ ```
238
+
239
+ The document above parses to `(value ((id 1) (label one)))` - two children, each
240
+ a link of its own - rather than to one flat list in which the boundary between
241
+ `id` and `label` would be lost. A body that stays on a single line still
242
+ collapses to a single link, so `(a b c)` is unchanged.
243
+
244
+ ```javascript
245
+ import { Parser, formatLinks } from 'links-notation';
246
+
247
+ const links = new Parser().parse(`value (
248
+ id "1"
249
+ label "one"
250
+ )`);
251
+
252
+ console.log(formatLinks(links)); // (value ((id 1) (label one)))
253
+ ```
254
+
226
255
  ## API Reference
227
256
 
228
257
  ### Classes
@@ -315,5 +344,4 @@ fail the format check.
315
344
  ## Package Information
316
345
 
317
346
  - Package: `links-notation`
318
- - Version: 0.1.0
319
- - License: MIT
347
+ - License: Unlicense (see [LICENSE](../LICENSE))
package/README.ru.md CHANGED
@@ -142,6 +142,35 @@ console.log(group.format());
142
142
  внук2
143
143
  ```
144
144
 
145
+ ### Многострочные группы
146
+
147
+ Скобочная группа открывает _вложенный контекст_: её тело начинается заново с
148
+ нулевого уровня отступа и подчиняется тем же правилам, что и корень документа,
149
+ поэтому перенос строки внутри скобок — это структура, а не оформление.
150
+
151
+ ```lino
152
+ value (
153
+ id "1"
154
+ label "one"
155
+ )
156
+ ```
157
+
158
+ Документ выше разбирается в `(value ((id 1) (label one)))` — два потомка,
159
+ каждый из которых сам является связью, — а не в один плоский список, в котором
160
+ граница между `id` и `label` была бы потеряна. Тело, умещающееся в одну строку,
161
+ по-прежнему сворачивается в одну связь, так что `(a b c)` не меняется.
162
+
163
+ ```javascript
164
+ import { Parser, formatLinks } from 'links-notation';
165
+
166
+ const links = new Parser().parse(`value (
167
+ id "1"
168
+ label "one"
169
+ )`);
170
+
171
+ console.log(formatLinks(links)); // (value ((id 1) (label one)))
172
+ ```
173
+
145
174
  ## Справочник API
146
175
 
147
176
  ### Классы
@@ -186,5 +215,4 @@ console.log(group.format());
186
215
  ## Информация о пакете
187
216
 
188
217
  - Пакет: `links-notation`
189
- - Версия: 0.1.0
190
- - Лицензия: MIT
218
+ - Лицензия: Unlicense (см. [LICENSE](../LICENSE))
package/dist/index.js CHANGED
@@ -149,13 +149,13 @@ class Link {
149
149
  if (options.shouldIndentByRefCount(this.values.length)) {
150
150
  shouldIndent = true;
151
151
  } else {
152
- const valuesStr2 = this.values.map((v) => this.formatValue(v)).join(" ");
152
+ const valuesStr = this.values.map((v) => this.formatValue(v)).join(" ");
153
153
  let testLine;
154
154
  if (this.id !== null) {
155
- const idStr2 = Link.escapeReference(this.id);
156
- testLine = options.lessParentheses ? `${idStr2}: ${valuesStr2}` : `(${idStr2}: ${valuesStr2})`;
155
+ const idStr = Link.escapeReference(this.id);
156
+ testLine = options.lessParentheses ? `${idStr}: ${valuesStr}` : `(${idStr}: ${valuesStr})`;
157
157
  } else {
158
- testLine = options.lessParentheses ? valuesStr2 : `(${valuesStr2})`;
158
+ testLine = options.lessParentheses ? valuesStr : `(${valuesStr})`;
159
159
  }
160
160
  if (options.shouldIndentByLength(testLine)) {
161
161
  shouldIndent = true;
@@ -181,8 +181,8 @@ class Link {
181
181
  }
182
182
  _formatIndented(options) {
183
183
  if (this.id === null) {
184
- const lines2 = this.values.map((v) => options.indentString + this.formatValue(v));
185
- return lines2.join(`
184
+ const lines = this.values.map((v) => options.indentString + this.formatValue(v));
185
+ return lines.join(`
186
186
  `);
187
187
  }
188
188
  const idStr = Link.escapeReference(this.id);
@@ -282,7 +282,7 @@ class peg$SyntaxError extends SyntaxError {
282
282
  let str = "Error: " + this.message;
283
283
  if (this.location) {
284
284
  let src = null;
285
- const st = sources.find((s2) => s2.source === this.location.source);
285
+ const st = sources.find((s) => s.source === this.location.source);
286
286
  if (st) {
287
287
  src = st.text.split(/\r\n|\n|\r/g);
288
288
  }
@@ -345,8 +345,8 @@ class peg$SyntaxError extends SyntaxError {
345
345
  function describeExpectation(expectation) {
346
346
  return DESCRIBE_EXPECTATION_FNS[expectation.type](expectation);
347
347
  }
348
- function describeExpected(expected2) {
349
- const descriptions = expected2.map(describeExpectation);
348
+ function describeExpected(expected) {
349
+ const descriptions = expected.map(describeExpectation);
350
350
  descriptions.sort();
351
351
  if (descriptions.length > 0) {
352
352
  let j = 1;
@@ -367,8 +367,8 @@ class peg$SyntaxError extends SyntaxError {
367
367
  return descriptions.slice(0, -1).join(", ") + ", or " + descriptions[descriptions.length - 1];
368
368
  }
369
369
  }
370
- function describeFound(found2) {
371
- return found2 ? '"' + literalEscape(found2) + '"' : "end of input";
370
+ function describeFound(found) {
371
+ return found ? '"' + literalEscape(found) + '"' : "end of input";
372
372
  }
373
373
  return "Expected " + describeExpected(expected) + " but " + describeFound(found) + " found.";
374
374
  }
@@ -597,13 +597,13 @@ function peg$parse(input, options) {
597
597
  function location() {
598
598
  return peg$computeLocation(peg$savedPos, peg$currPos);
599
599
  }
600
- function expected(description, location2) {
601
- location2 = location2 !== undefined ? location2 : peg$computeLocation(peg$savedPos, peg$currPos);
602
- throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location2);
600
+ function expected(description, location) {
601
+ location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos);
602
+ throw peg$buildStructuredError([peg$otherExpectation(description)], input.substring(peg$savedPos, peg$currPos), location);
603
603
  }
604
- function error(message, location2) {
605
- location2 = location2 !== undefined ? location2 : peg$computeLocation(peg$savedPos, peg$currPos);
606
- throw peg$buildSimpleError(message, location2);
604
+ function error(message, location) {
605
+ location = location !== undefined ? location : peg$computeLocation(peg$savedPos, peg$currPos);
606
+ throw peg$buildSimpleError(message, location);
607
607
  }
608
608
  function peg$getUnicode(pos = peg$currPos) {
609
609
  const cp = input.codePointAt(pos);
@@ -612,8 +612,8 @@ function peg$parse(input, options) {
612
612
  }
613
613
  return String.fromCodePoint(cp);
614
614
  }
615
- function peg$literalExpectation(text2, ignoreCase) {
616
- return { type: "literal", text: text2, ignoreCase };
615
+ function peg$literalExpectation(text, ignoreCase) {
616
+ return { type: "literal", text, ignoreCase };
617
617
  }
618
618
  function peg$classExpectation(parts, inverted, ignoreCase, unicode) {
619
619
  return { type: "class", parts, inverted, ignoreCase, unicode };
@@ -657,7 +657,7 @@ function peg$parse(input, options) {
657
657
  return details;
658
658
  }
659
659
  }
660
- function peg$computeLocation(startPos, endPos, offset2) {
660
+ function peg$computeLocation(startPos, endPos, offset) {
661
661
  const startPosDetails = peg$computePosDetails(startPos);
662
662
  const endPosDetails = peg$computePosDetails(endPos);
663
663
  const res = {
@@ -673,13 +673,13 @@ function peg$parse(input, options) {
673
673
  column: endPosDetails.column
674
674
  }
675
675
  };
676
- if (offset2 && peg$source && typeof peg$source.offset === "function") {
676
+ if (offset && peg$source && typeof peg$source.offset === "function") {
677
677
  res.start = peg$source.offset(res.start);
678
678
  res.end = peg$source.offset(res.end);
679
679
  }
680
680
  return res;
681
681
  }
682
- function peg$fail(expected2) {
682
+ function peg$fail(expected) {
683
683
  if (peg$currPos < peg$maxFailPos) {
684
684
  return;
685
685
  }
@@ -687,13 +687,13 @@ function peg$parse(input, options) {
687
687
  peg$maxFailPos = peg$currPos;
688
688
  peg$maxFailExpected = [];
689
689
  }
690
- peg$maxFailExpected.push(expected2);
690
+ peg$maxFailExpected.push(expected);
691
691
  }
692
- function peg$buildSimpleError(message, location2) {
693
- return new peg$SyntaxError(message, null, null, location2);
692
+ function peg$buildSimpleError(message, location) {
693
+ return new peg$SyntaxError(message, null, null, location);
694
694
  }
695
- function peg$buildStructuredError(expected2, found, location2) {
696
- return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected2, found), expected2, found, location2);
695
+ function peg$buildStructuredError(expected, found, location) {
696
+ return new peg$SyntaxError(peg$SyntaxError.buildMessage(expected, found), expected, found, location);
697
697
  }
698
698
  function peg$parsedocument() {
699
699
  let s0, s1, s2, s3, s4, s5;
@@ -2086,9 +2086,9 @@ class Parser {
2086
2086
  if (pathElements.length === 0)
2087
2087
  return current;
2088
2088
  if (pathElements.length === 1) {
2089
- const combined2 = new Link(null, [pathElements[0], current]);
2090
- combined2._isFromPathCombination = true;
2091
- return combined2;
2089
+ const combined = new Link(null, [pathElements[0], current]);
2090
+ combined._isFromPathCombination = true;
2091
+ return combined;
2092
2092
  }
2093
2093
  const parentPath = pathElements.slice(0, -1);
2094
2094
  const lastElement = pathElements[pathElements.length - 1];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "links-notation",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "description": "Links Notation parser for JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "types": "index.d.ts",