occam-parsers 22.0.62 → 22.0.64
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/example.js +268 -64
- package/lib/example/view.js +7 -13
- package/lib/node/nonTerminal.js +30 -2
- package/lib/node/terminal/epsilon.js +8 -8
- package/lib/node/terminal.js +25 -1
- package/lib/parseTree/ruleName.js +23 -3
- package/lib/parseTree/terminalNode.js +10 -2
- package/lib/state.js +2 -2
- package/lib/utilities/tokens.js +17 -14
- package/package.json +3 -3
- package/src/example/view.js +8 -16
- package/src/node/nonTerminal.js +33 -1
- package/src/node/terminal/epsilon.js +6 -6
- package/src/node/terminal.js +24 -0
- package/src/parseTree/ruleName.js +29 -9
- package/src/parseTree/terminalNode.js +15 -5
- package/src/state.js +1 -1
- package/src/utilities/tokens.js +16 -13
package/src/node/nonTerminal.js
CHANGED
|
@@ -5,7 +5,7 @@ import { specialSymbols } from "occam-lexers";
|
|
|
5
5
|
|
|
6
6
|
import NonTerminalNodeParseTree from "../parseTree/nonTerminalNode";
|
|
7
7
|
|
|
8
|
-
const { first, match,
|
|
8
|
+
const { first, match, backwardsSome, forwardsSome } = arrayUtilities,
|
|
9
9
|
{ opaque : opaqueSpecialSymbol , semiOpaque: semiOpaqueSpecialSymbol } = specialSymbols;
|
|
10
10
|
|
|
11
11
|
export default class NonTerminalNode {
|
|
@@ -118,6 +118,38 @@ export default class NonTerminalNode {
|
|
|
118
118
|
return lowerPrecedence;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
+
getFirstSignificantTokenIndex(tokens) {
|
|
122
|
+
let firstSignificantTokenIndex;
|
|
123
|
+
|
|
124
|
+
forwardsSome(this.childNodes, (childNode) => {
|
|
125
|
+
const node = childNode;
|
|
126
|
+
|
|
127
|
+
firstSignificantTokenIndex = node.getFirstSignificantTokenIndex(tokens);
|
|
128
|
+
|
|
129
|
+
if (firstSignificantTokenIndex !== -1) {
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
return firstSignificantTokenIndex;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getLastSignificantTokenIndex(tokens) {
|
|
138
|
+
let lastSignificantTokenIndex;
|
|
139
|
+
|
|
140
|
+
backwardsSome(this.childNodes, (childNode) => {
|
|
141
|
+
const node = childNode;
|
|
142
|
+
|
|
143
|
+
lastSignificantTokenIndex = node.getLastSignificantTokenIndex(tokens);
|
|
144
|
+
|
|
145
|
+
if (lastSignificantTokenIndex !== -1) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return lastSignificantTokenIndex;
|
|
151
|
+
}
|
|
152
|
+
|
|
121
153
|
isUnprecedented() {
|
|
122
154
|
let unprecedented = false;
|
|
123
155
|
|
|
@@ -8,12 +8,6 @@ import EpsilonNodeParseTree from "../../parseTree/epsilonNode";
|
|
|
8
8
|
const { epsilon } = specialSymbols;
|
|
9
9
|
|
|
10
10
|
export default class EpsilonNode extends TerminalNode {
|
|
11
|
-
isEpsilonNode() {
|
|
12
|
-
const epsilonNode = true;
|
|
13
|
-
|
|
14
|
-
return epsilonNode;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
11
|
getType() {
|
|
18
12
|
const type = null; ///
|
|
19
13
|
|
|
@@ -26,6 +20,12 @@ export default class EpsilonNode extends TerminalNode {
|
|
|
26
20
|
return content;
|
|
27
21
|
}
|
|
28
22
|
|
|
23
|
+
isEpsilonNode() {
|
|
24
|
+
const epsilonNode = true;
|
|
25
|
+
|
|
26
|
+
return epsilonNode;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
29
|
asParseTree(tokens) {
|
|
30
30
|
const epsilonNodeParseTree = EpsilonNodeParseTree.fromNothing(),
|
|
31
31
|
parseTree = epsilonNodeParseTree; ///
|
package/src/node/terminal.js
CHANGED
|
@@ -69,6 +69,30 @@ export default class TerminalNode {
|
|
|
69
69
|
return lowerPrecedence;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
getFirstSignificantTokenIndex(tokens) {
|
|
73
|
+
const significantTokenIndex = this.getSignificantTokenIndex(tokens),
|
|
74
|
+
firstSignificantTokenIndex = significantTokenIndex; ///
|
|
75
|
+
|
|
76
|
+
return firstSignificantTokenIndex;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getLastSignificantTokenIndex(tokens) {
|
|
80
|
+
const significantTokenIndex = this.getSignificantTokenIndex(tokens),
|
|
81
|
+
lastSignificantTokenIndex = significantTokenIndex; ///
|
|
82
|
+
|
|
83
|
+
return lastSignificantTokenIndex;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getSignificantTokenIndex(tokens) {
|
|
87
|
+
let significantTokenIndex = null;
|
|
88
|
+
|
|
89
|
+
if (this.significantToken !== null) {
|
|
90
|
+
significantTokenIndex = tokens.indexOf(this.significantToken);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return significantTokenIndex;
|
|
94
|
+
}
|
|
95
|
+
|
|
72
96
|
isIncludedIn(node) {
|
|
73
97
|
let includedIn = false;
|
|
74
98
|
|
|
@@ -4,7 +4,8 @@ import { characters} from "necessary";
|
|
|
4
4
|
|
|
5
5
|
import VerticalBranchParseTree from "./verticalBranch";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { EMPTY_STRING } from "../constants";
|
|
8
|
+
import { lineIndexFromTokenIndexAndTokens } from "../utilities/tokens";
|
|
8
9
|
|
|
9
10
|
const { SPACE_CHARACTER } = characters;
|
|
10
11
|
|
|
@@ -12,13 +13,32 @@ export default class RuleNameParseTree extends VerticalBranchParseTree {
|
|
|
12
13
|
static fromNonTerminalNodeAndTokens(nonTerminalNode, tokens) {
|
|
13
14
|
const ruleName = nonTerminalNode.getRuleName(),
|
|
14
15
|
opacity = nonTerminalNode.getOpacity(),
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
firstSignificantTokenIndex = nonTerminalNode.getFirstSignificantTokenIndex(tokens),
|
|
17
|
+
lastSignificantTokenIndex = nonTerminalNode.getLastSignificantTokenIndex(tokens),
|
|
18
|
+
firstLineIndex = lineIndexFromTokenIndexAndTokens(firstSignificantTokenIndex, tokens),
|
|
19
|
+
lastLineIndex = lineIndexFromTokenIndexAndTokens(lastSignificantTokenIndex, tokens);
|
|
20
|
+
|
|
21
|
+
let lineIndexes;
|
|
22
|
+
|
|
23
|
+
if (firstLineIndex === lastLineIndex) {
|
|
24
|
+
const lineIndex = firstLineIndex; ///
|
|
25
|
+
|
|
26
|
+
if (lineIndex === null) {
|
|
27
|
+
lineIndexes = EMPTY_STRING;
|
|
28
|
+
} else {
|
|
29
|
+
lineIndexes = ` [${lineIndex}]`;
|
|
30
|
+
}
|
|
31
|
+
} else {
|
|
32
|
+
if (false) {
|
|
33
|
+
///
|
|
34
|
+
} else if (firstLineIndex === null) {
|
|
35
|
+
lineIndexes = ` [${lastLineIndex}]`;
|
|
36
|
+
} else if (lastLineIndex === null) {
|
|
37
|
+
lineIndexes = ` [${firstLineIndex}]`;
|
|
38
|
+
} else {
|
|
39
|
+
lineIndexes = ` [${firstLineIndex}-${lastLineIndex}]`
|
|
40
|
+
}
|
|
41
|
+
}
|
|
22
42
|
|
|
23
43
|
let string = `${ruleName}`;
|
|
24
44
|
|
|
@@ -26,7 +46,7 @@ export default class RuleNameParseTree extends VerticalBranchParseTree {
|
|
|
26
46
|
string = `${string}${opacity}`;
|
|
27
47
|
}
|
|
28
48
|
|
|
29
|
-
string = `${string}
|
|
49
|
+
string = `${string}${lineIndexes}`;
|
|
30
50
|
|
|
31
51
|
let precedence = nonTerminalNode.getPrecedence();
|
|
32
52
|
|
|
@@ -2,15 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
import VerticalBranchParseTree from "./verticalBranch";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { EMPTY_STRING } from "../constants";
|
|
6
|
+
import { lineIndexFromTokenIndexAndTokens } from "../utilities/tokens";
|
|
6
7
|
|
|
7
8
|
export default class TerminalNodeParseTree extends VerticalBranchParseTree {
|
|
8
9
|
static fromTerminalNodeAndTokens(terminalNode, tokens) {
|
|
9
|
-
const
|
|
10
|
+
const type = terminalNode.getType(),
|
|
10
11
|
content = terminalNode.getContent(),
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
significantTokenIndex = terminalNode.getSignificantTokenIndex(tokens),
|
|
13
|
+
lineIndex = lineIndexFromTokenIndexAndTokens(significantTokenIndex, tokens);
|
|
14
|
+
|
|
15
|
+
let lineIndexes;
|
|
16
|
+
|
|
17
|
+
if (lineIndex === null) {
|
|
18
|
+
lineIndexes = EMPTY_STRING;
|
|
19
|
+
} else {
|
|
20
|
+
lineIndexes = ` [${lineIndex}]`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const string = `"${content}"[${type}]${lineIndexes}`,
|
|
14
24
|
stringLength = string.length,
|
|
15
25
|
verticalBranchParseTreeWidth = stringLength, ///
|
|
16
26
|
verticalBranchParseTree = VerticalBranchParseTree.fromWidth(verticalBranchParseTreeWidth),
|
package/src/state.js
CHANGED
package/src/utilities/tokens.js
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
export function
|
|
4
|
-
let
|
|
3
|
+
export function lineIndexFromTokenIndexAndTokens(tokenIndex, tokens) {
|
|
4
|
+
let lineIndex = null;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end = tokenIndex;
|
|
6
|
+
if (tokenIndex !== null) {
|
|
7
|
+
lineIndex = 0;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
const start = 0,
|
|
10
|
+
end = tokenIndex;
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
const tokenEndOfLineToken = token.isEndOfLineToken();
|
|
12
|
+
tokens = tokens.slice(start, end); ///
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
});
|
|
14
|
+
tokens.forEach((token) => {
|
|
15
|
+
const tokenEndOfLineToken = token.isEndOfLineToken();
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
if (tokenEndOfLineToken) {
|
|
18
|
+
lineIndex++;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return lineIndex;
|
|
21
24
|
}
|