occam-parsers 22.0.61 → 22.0.63

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.
@@ -5,7 +5,7 @@ import { specialSymbols } from "occam-lexers";
5
5
 
6
6
  import NonTerminalNodeParseTree from "../parseTree/nonTerminalNode";
7
7
 
8
- const { first, match, forwardsSome, backwardsSome } = arrayUtilities,
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; ///
@@ -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 { tokenLineIndexFromTokenAndTokens } from "../utilities/tokens";
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
- firstSignificantToken = nonTerminalNode.getFirstSignificantToken(),
16
- lastSignificantToken = nonTerminalNode.getLastSignificantToken(),
17
- firstSignificantTokenLineIndex = tokenLineIndexFromTokenAndTokens(firstSignificantToken, tokens),
18
- lastSignificantTokenLineIndex = tokenLineIndexFromTokenAndTokens(lastSignificantToken, tokens),
19
- tokenLineIndexes = (firstSignificantTokenLineIndex !== lastSignificantTokenLineIndex) ?
20
- `${firstSignificantTokenLineIndex}-${lastSignificantTokenLineIndex}` :
21
- `${firstSignificantTokenLineIndex}`;
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} [${tokenLineIndexes}]`;
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 { tokenLineIndexFromTokenAndTokens } from "../utilities/tokens";
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 significantToken = terminalNode.getSignificantToken(),
10
+ const type = terminalNode.getType(),
10
11
  content = terminalNode.getContent(),
11
- type = significantToken.getType(),
12
- significantTokenLineIndex = tokenLineIndexFromTokenAndTokens(significantToken, tokens),
13
- string = `"${content}"[${type}] [${significantTokenLineIndex}]`,
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
@@ -119,7 +119,7 @@ export default class State {
119
119
 
120
120
  tokens = Class; ///
121
121
 
122
- Class = State;
122
+ Class = State; ///
123
123
  }
124
124
 
125
125
  const index = 0,
@@ -1,21 +1,24 @@
1
1
  "use strict";
2
2
 
3
- export function tokenLineIndexFromTokenAndTokens(token, tokens) {
4
- let tokenLineIndex = 0;
3
+ export function lineIndexFromTokenIndexAndTokens(tokenIndex, tokens) {
4
+ let lineIndex = null;
5
5
 
6
- const tokenIndex = tokens.indexOf(token),
7
- start = 0,
8
- end = tokenIndex;
6
+ if (tokenIndex !== null) {
7
+ lineIndex = 0;
9
8
 
10
- tokens = tokens.slice(start, end); ///
9
+ const start = 0,
10
+ end = tokenIndex;
11
11
 
12
- tokens.forEach((token) => {
13
- const tokenEndOfLineToken = token.isEndOfLineToken();
12
+ tokens = tokens.slice(start, end); ///
14
13
 
15
- if (tokenEndOfLineToken) {
16
- tokenLineIndex++;
17
- }
18
- });
14
+ tokens.forEach((token) => {
15
+ const tokenEndOfLineToken = token.isEndOfLineToken();
19
16
 
20
- return tokenLineIndex;
17
+ if (tokenEndOfLineToken) {
18
+ lineIndex++;
19
+ }
20
+ });
21
+ }
22
+
23
+ return lineIndex;
21
24
  }