@stxt-lang/core 0.7.0 → 0.8.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
@@ -7,6 +7,7 @@ STXT is a plain-text format for writing structured, semantic documents: no brace
7
7
  - Website and language reference: <https://stxt.dev>
8
8
  - VSCode extension: [STXT - Semantic Text](https://marketplace.visualstudio.com/items?itemName=stxt-lang.stxt)
9
9
  - Java implementation: [`dev.stxt:stxt-core`](https://central.sonatype.com/artifact/dev.stxt/stxt-core) on Maven Central
10
+ - Python implementation: [`stxt`](https://pypi.org/project/stxt/) on PyPI
10
11
 
11
12
  ## What STXT looks like
12
13
 
@@ -149,7 +150,7 @@ for (const error of result.getErrors()) {
149
150
  }
150
151
  ```
151
152
 
152
- Available value types: `INLINE`, `BLOCK`, `TEXT`, `BOOLEAN`, `INTEGER`, `NATURAL`, `NUMBER`, `DATE`, `TIMESTAMP`, `EMAIL`, `URL`, `HEXADECIMAL`, `BASE64`, `GROUP`, `ENUM`.
153
+ Available value types: `INLINE`, `BLOCK`, `TEXT`, `MARKDOWN`, `BOOLEAN`, `INTEGER`, `NATURAL`, `NUMBER`, `DATE`, `TIME`, `TIMESTAMP`, `UUID`, `EMAIL`, `URL`, `HEXADECIMAL`, `BINARY`, `BASE64`, `GROUP`, `ENUM`.
153
154
 
154
155
  ## Finding the schemas: discovery
155
156
 
@@ -90,6 +90,12 @@ class Parser {
90
90
  // Parse the line
91
91
  const line = (0, LineParser_1.parseLine)(lineString, lastNodeText, lastLevel, lineNumber);
92
92
  if (line.isComment) {
93
+ // A comment at the level of an open block node (or shallower) closes the block
94
+ // (spec 6.1 and 9.1): a block is a literal and cannot be commented from inside.
95
+ // Only the block closes; the comment does not touch the rest of the hierarchy.
96
+ if (lastNodeText) {
97
+ this.closeToLevel(stack, stack.length - 1, result);
98
+ }
93
99
  // Hand it over to the observers
94
100
  this.observers.forEach(observer => {
95
101
  observer.onComment(lineNumber, lineString);
@@ -1,6 +1,7 @@
1
1
  /** String normalization helpers used for names, namespaces and values. */
2
2
  export declare class StringUtils {
3
3
  private static readonly NODE_NAME;
4
+ private static readonly NODE_NAME_LETTER_OR_DIGIT;
4
5
  private constructor();
5
6
  /**
6
7
  * Removes the trailing whitespace of a string.
@@ -62,7 +62,7 @@ class StringUtils {
62
62
  */
63
63
  static isValidNodeName(input) {
64
64
  const nfc = this.compactSpaces(input).normalize("NFC");
65
- return this.NODE_NAME.test(nfc) && this.normalize(nfc).length > 0;
65
+ return this.NODE_NAME.test(nfc) && this.NODE_NAME_LETTER_OR_DIGIT.test(nfc);
66
66
  }
67
67
  // Used for the normalized name of the nodes (STXT-SPEC 4.3): NFC + lower case,
68
68
  // keeping diacritics and non-Latin alphabets (IDN model)
@@ -87,7 +87,9 @@ class StringUtils {
87
87
  }
88
88
  }
89
89
  exports.StringUtils = StringUtils;
90
- // STXT-SPEC 4.2 / 4.3: validate the logical name after NFC so that a
90
+ // STXT-SPEC 4.2 / 4.3: letters, decimal digits, combining marks (Mn, Mc) and the three
91
+ // separators, with at least one letter or digit. Validated after NFC so that a
91
92
  // decomposed spelling such as "e" + combining acute is accepted as "é".
92
- StringUtils.NODE_NAME = /^[\p{L}\p{Nd}\-_ ]+$/u;
93
+ StringUtils.NODE_NAME = /^[\p{L}\p{Nd}\p{Mn}\p{Mc}\-_ ]+$/u;
94
+ StringUtils.NODE_NAME_LETTER_OR_DIGIT = /[\p{L}\p{Nd}]/u;
93
95
  //# sourceMappingURL=StringUtils.js.map
@@ -5,6 +5,10 @@ import { ValidationException } from "../exceptions/ValidationException";
5
5
  /**
6
6
  * Wrapper around a {@link SchemaValidator} that only validates namespaced nodes, so that a
7
7
  * document mixing schema-bound and free nodes does not report the free ones as unknown.
8
+ *
9
+ * @deprecated since 0.8.0: {@link SchemaValidator} applies this rule itself (STXT-SCHEMA-SPEC 5,
10
+ * the empty namespace is never validated), so the wrapper adds nothing. Register the
11
+ * `SchemaValidator` directly. Kept for compatibility; to be removed in 1.0.
8
12
  */
9
13
  export declare class ConditionalValidator implements Validator {
10
14
  private readonly schemaValidator;
@@ -4,6 +4,10 @@ exports.ConditionalValidator = void 0;
4
4
  /**
5
5
  * Wrapper around a {@link SchemaValidator} that only validates namespaced nodes, so that a
6
6
  * document mixing schema-bound and free nodes does not report the free ones as unknown.
7
+ *
8
+ * @deprecated since 0.8.0: {@link SchemaValidator} applies this rule itself (STXT-SCHEMA-SPEC 5,
9
+ * the empty namespace is never validated), so the wrapper adds nothing. Register the
10
+ * `SchemaValidator` directly. Kept for compatibility; to be removed in 1.0.
7
11
  */
8
12
  class ConditionalValidator {
9
13
  /**
@@ -26,6 +26,18 @@ class SchemaValidator {
26
26
  const errors = [];
27
27
  // Get the namespace
28
28
  const namespace = node.getNamespace();
29
+ // The empty namespace is never validated (STXT-SCHEMA-SPEC 5): a node that neither
30
+ // declares nor inherits a namespace is valid by definition, no schema is looked up for
31
+ // it and SCHEMA_NOT_FOUND is never reported for it. Its children are still walked when
32
+ // recursive, because one of them may declare a namespace of its own.
33
+ if (namespace === "") {
34
+ if (this.recursiveValidation && node instanceof InlineNode_1.InlineNode) {
35
+ for (const childNode of node.getChildren()) {
36
+ errors.push(...this.validate(childNode));
37
+ }
38
+ }
39
+ return errors;
40
+ }
29
41
  const schema = this.schemaProvider.getSchema(namespace);
30
42
  if (!schema) {
31
43
  errors.push(new ValidationException_1.ValidationException(node.getLine(), "SCHEMA_NOT_FOUND", `Not found schema: ${namespace}`));
@@ -1,2 +1,8 @@
1
- /** `EMAIL` type: checks that the value looks like an e-mail address. */
1
+ /**
2
+ * `EMAIL` type: checks that the value is an e-mail address, in either of the two forms of
3
+ * STXT-SCHEMA-SPEC 9.4: the bare address (`user@domain.tld`) or a display name followed by the
4
+ * address between angle brackets (`Joan Costa <joan@example.com>`). The display name is any
5
+ * non-empty text without `<` or `>` (quotes are not interpreted) and the space before `<` is
6
+ * optional; `<`/`>` without a name, unbalanced or followed by anything are rejected.
7
+ */
2
8
  export declare const EMAIL: import("../Type").Type;
@@ -2,6 +2,21 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EMAIL = void 0;
4
4
  const regexType_1 = require("./regexType");
5
- /** `EMAIL` type: checks that the value looks like an e-mail address. */
6
- exports.EMAIL = (0, regexType_1.regexType)("EMAIL", /^(?=.{1,256}$)(?=.{1,64}@.{1,255}$)(?=.{1,64}@.{1,63}\..{1,63}$)[A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/, "Invalid email");
5
+ /**
6
+ * The address proper, `local@domain` with the usual length limits, as it reads when it ends the
7
+ * value (bare form)...
8
+ */
9
+ const ADDRESS = "(?=.{1,256}$)(?=.{1,64}@.{1,255}$)(?=.{1,64}@.{1,63}\\..{1,63}$)"
10
+ + "[A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}";
11
+ /** ...and the same address as it reads between `<` and `>` (the lookaheads stop at the `>`). */
12
+ const BRACKETED = "(?=[^>]{1,256}>$)(?=[^>]{1,64}@[^>]{1,255}>$)(?=[^>]{1,64}@[^>]{1,63}\\.[^>]{1,63}>$)"
13
+ + "[A-Za-z0-9!#$%&'*+/=?^_`{|}~.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}";
14
+ /**
15
+ * `EMAIL` type: checks that the value is an e-mail address, in either of the two forms of
16
+ * STXT-SCHEMA-SPEC 9.4: the bare address (`user@domain.tld`) or a display name followed by the
17
+ * address between angle brackets (`Joan Costa <joan@example.com>`). The display name is any
18
+ * non-empty text without `<` or `>` (quotes are not interpreted) and the space before `<` is
19
+ * optional; `<`/`>` without a name, unbalanced or followed by anything are rejected.
20
+ */
21
+ exports.EMAIL = (0, regexType_1.regexType)("EMAIL", new RegExp(`^(?:[^<>]*[^<>\\s]\\s*<${BRACKETED}>|${ADDRESS})$`), "Invalid email");
7
22
  //# sourceMappingURL=EMAIL.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stxt-lang/core",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Parser and schema validator for STXT, an indentation-based structured-text format.",
5
5
  "main": "out/all.js",
6
6
  "types": "out/all.d.ts",