@stxt-lang/core 0.8.1 → 0.9.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/out/core/Line.d.ts +4 -1
- package/out/core/LineParser.d.ts +4 -1
- package/out/core/LineParser.js +18 -3
- package/out/core/Parser.js +2 -0
- package/package.json +1 -1
package/out/core/Line.d.ts
CHANGED
|
@@ -8,7 +8,10 @@ export declare class Line {
|
|
|
8
8
|
readonly level: number;
|
|
9
9
|
/** Content of the line with the indentation already removed. */
|
|
10
10
|
readonly content: string;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* True if the line is a comment (`#`). Its indentation has already been validated like a
|
|
13
|
+
* node's (spec 9), but it produces no node and never moves the hierarchy.
|
|
14
|
+
*/
|
|
12
15
|
readonly isComment: boolean;
|
|
13
16
|
/** True if the line is a text line belonging to an open BLOCK node (`>>`). */
|
|
14
17
|
readonly isBlock: boolean;
|
package/out/core/LineParser.d.ts
CHANGED
|
@@ -5,7 +5,10 @@ import { Line } from "./Line";
|
|
|
5
5
|
*
|
|
6
6
|
* Indentation is one level per tab or per {@link Constants.TAB_SPACES} spaces; mixing both, using
|
|
7
7
|
* a number of spaces that is not a multiple of four or going more than one level deeper than the
|
|
8
|
-
* previous node are errors (spec 8.1 and 8.3).
|
|
8
|
+
* previous node are errors (spec 8.1 and 8.3). Comment lines are validated exactly like node lines
|
|
9
|
+
* (spec 9 and 11): they produce no node and never move the hierarchy, but their indentation must
|
|
10
|
+
* be homogeneous, a multiple of four when spaces, and at most one level deeper than the last node.
|
|
11
|
+
* Only empty lines are exempt.
|
|
9
12
|
*
|
|
10
13
|
* @param line source line, with its indentation.
|
|
11
14
|
* @param lastNodeBlock true if the node currently open is a BLOCK text node.
|
package/out/core/LineParser.js
CHANGED
|
@@ -11,7 +11,10 @@ const Line_1 = require("./Line");
|
|
|
11
11
|
*
|
|
12
12
|
* Indentation is one level per tab or per {@link Constants.TAB_SPACES} spaces; mixing both, using
|
|
13
13
|
* a number of spaces that is not a multiple of four or going more than one level deeper than the
|
|
14
|
-
* previous node are errors (spec 8.1 and 8.3).
|
|
14
|
+
* previous node are errors (spec 8.1 and 8.3). Comment lines are validated exactly like node lines
|
|
15
|
+
* (spec 9 and 11): they produce no node and never move the hierarchy, but their indentation must
|
|
16
|
+
* be homogeneous, a multiple of four when spaces, and at most one level deeper than the last node.
|
|
17
|
+
* Only empty lines are exempt.
|
|
15
18
|
*
|
|
16
19
|
* @param line source line, with its indentation.
|
|
17
20
|
* @param lastNodeBlock true if the node currently open is a BLOCK text node.
|
|
@@ -28,6 +31,7 @@ function parseLine(line, lastNodeBlock, lastLevel, numLine, validate = true) {
|
|
|
28
31
|
let pointer = 0;
|
|
29
32
|
let sawSpace = false;
|
|
30
33
|
let sawTab = false;
|
|
34
|
+
let isComment = false;
|
|
31
35
|
while (pointer < line.length) {
|
|
32
36
|
const c = line.charAt(pointer);
|
|
33
37
|
if (c === Constants_1.Constants.SPACE) {
|
|
@@ -44,7 +48,13 @@ function parseLine(line, lastNodeBlock, lastLevel, numLine, validate = true) {
|
|
|
44
48
|
spaces = 0;
|
|
45
49
|
}
|
|
46
50
|
else if (c === Constants_1.Constants.COMMENT_CHAR) {
|
|
47
|
-
|
|
51
|
+
// Comment line: produces no node, but its indentation is validated below exactly like
|
|
52
|
+
// a node's (spec 9). Reached only when the line is not block text (a '#' deeper than an
|
|
53
|
+
// open block is caught as text by the check below, before getting here), so inside an
|
|
54
|
+
// open block a comment always has indent <= the block node: the Parser closes the block
|
|
55
|
+
// (spec 9.1) and hands the comment over to the observers.
|
|
56
|
+
isComment = true;
|
|
57
|
+
break;
|
|
48
58
|
}
|
|
49
59
|
else {
|
|
50
60
|
// First character that is not space/tab/comment => end of indentation
|
|
@@ -79,10 +89,15 @@ function parseLine(line, lastNodeBlock, lastLevel, numLine, validate = true) {
|
|
|
79
89
|
if (validate && spaces > 0) {
|
|
80
90
|
throw new ParseException_1.ParseException(numLine, "INVALID_NUMBER_SPACES", `There are ${spaces} spaces before node`);
|
|
81
91
|
}
|
|
82
|
-
// Validate the level
|
|
92
|
+
// Validate the level (spec 11.3). Comments included (spec 9): lastLevel is the level of the
|
|
93
|
+
// last NODE, a comment never becomes the reference.
|
|
83
94
|
if (validate && level > lastLevel + 1) {
|
|
84
95
|
throw new ParseException_1.ParseException(numLine, "INDENTATION_LEVEL_NOT_VALID", `Level of indent incorrect: ${level}`);
|
|
85
96
|
}
|
|
97
|
+
// Comment: the text after '#', verbatim
|
|
98
|
+
if (isComment) {
|
|
99
|
+
return new Line_1.Line(level, line.substring(pointer + 1), true, false, pointer);
|
|
100
|
+
}
|
|
86
101
|
// General case: return the line without the indentation already consumed
|
|
87
102
|
// Blank-only trim (spec 4): an NBSP after the value is part of it
|
|
88
103
|
return new Line_1.Line(level, StringUtils_1.StringUtils.trim(line.substring(pointer)), false, false, pointer);
|
package/out/core/Parser.js
CHANGED
|
@@ -90,6 +90,8 @@ 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
|
+
// Its indentation was validated by parseLine like a node's (spec 9), but it never
|
|
94
|
+
// becomes the reference level: the stack (and so lastLevel) is only moved by nodes.
|
|
93
95
|
// A comment at the level of an open block node (or shallower) closes the block
|
|
94
96
|
// (spec 6.1 and 9.1): a block is a literal and cannot be commented from inside.
|
|
95
97
|
// Only the block closes; the comment does not touch the rest of the hierarchy.
|