occam-parsers 23.0.161 → 23.1.1
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 +2 -2
- package/example.js +157 -464
- package/lib/basic/bnf.js +2 -2
- package/lib/bnf/bnf.js +2 -2
- package/lib/bnf/parser.js +4 -4
- package/lib/definition/callAheadModifierRule.js +4 -4
- package/lib/definition/choiceOfParts.js +6 -6
- package/lib/definition/definitions.js +4 -4
- package/lib/definition/noWhitespacePart.js +4 -4
- package/lib/definition/opacityModifierRule.js +9 -9
- package/lib/definition/precedence.js +5 -5
- package/lib/definition/quantifierRule.js +4 -4
- package/lib/definition/rule.js +7 -7
- package/lib/definition/sequenceOfParts.js +5 -5
- package/lib/definition/startOfContentPart.js +4 -4
- package/lib/definition/{terminalSymbol.js → stringLiteral.js} +14 -14
- package/lib/example/view/basic.js +7 -8
- package/lib/example/view/div/sizeable.js +2 -2
- package/lib/node/bnf/{terminalSymbol.js → stringLiteral.js} +13 -13
- package/lib/nonTerminalNodeMap.js +3 -3
- package/lib/parseTree/terminalNode.js +16 -2
- package/lib/part/terminal/{terminalSymbol.js → stringLiteral.js} +11 -11
- package/lib/parts.js +13 -13
- package/lib/rule/bnf/endOfLine.js +4 -4
- package/lib/rule/bnf/epsilon.js +4 -4
- package/lib/rule/bnf/{terminalSymbol.js → stringLiteral.js} +12 -12
- package/lib/rule/bnf/terminalPart.js +4 -4
- package/lib/rule/bnf/wildcard.js +4 -4
- package/lib/ruleNames.js +5 -5
- package/package.json +2 -2
- package/src/basic/bnf.js +1 -1
- package/src/bnf/bnf.js +2 -2
- package/src/bnf/parser.js +3 -3
- package/src/definition/callAheadModifierRule.js +3 -3
- package/src/definition/choiceOfParts.js +10 -10
- package/src/definition/definitions.js +3 -3
- package/src/definition/noWhitespacePart.js +3 -3
- package/src/definition/opacityModifierRule.js +9 -9
- package/src/definition/precedence.js +7 -7
- package/src/definition/quantifierRule.js +3 -3
- package/src/definition/rule.js +7 -7
- package/src/definition/sequenceOfParts.js +7 -7
- package/src/definition/startOfContentPart.js +3 -3
- package/src/definition/stringLiteral.js +17 -0
- package/src/example/view/basic.js +6 -7
- package/src/example/view/div/sizeable.js +1 -1
- package/src/node/bnf/{terminalSymbol.js → stringLiteral.js} +5 -5
- package/src/nonTerminalNodeMap.js +3 -3
- package/src/parseTree/terminalNode.js +21 -1
- package/src/part/terminal/{terminalSymbol.js → stringLiteral.js} +3 -3
- package/src/parts.js +12 -12
- package/src/rule/bnf/endOfLine.js +3 -3
- package/src/rule/bnf/epsilon.js +3 -3
- package/src/rule/bnf/{terminalSymbol.js → stringLiteral.js} +5 -5
- package/src/rule/bnf/terminalPart.js +4 -4
- package/src/rule/bnf/wildcard.js +3 -3
- package/src/ruleNames.js +1 -1
- package/src/definition/terminalSymbol.js +0 -17
|
@@ -3,20 +3,20 @@
|
|
|
3
3
|
import { arrayUtilities } from "necessary";
|
|
4
4
|
|
|
5
5
|
import NonTerminalNode from "../../node/nonTerminal";
|
|
6
|
-
import
|
|
6
|
+
import StringLiteralPart from "../../part/terminal/stringLiteral";
|
|
7
7
|
|
|
8
8
|
import { ESCAPED_BACKSLASH, ESCAPED_DOUBLE_QUOTE } from "../../constants";
|
|
9
9
|
|
|
10
10
|
const { first, second } = arrayUtilities;
|
|
11
11
|
|
|
12
|
-
export default class
|
|
12
|
+
export default class StringLiteralBNFNode extends NonTerminalNode {
|
|
13
13
|
regularExpression = /^"((?:\\.|[^"\\])*)"$/;
|
|
14
14
|
|
|
15
15
|
generatePart(callAhead) {
|
|
16
16
|
const content = this.getContent(),
|
|
17
|
-
|
|
17
|
+
stringLiteralPart = StringLiteralPart.fromContent(content);
|
|
18
18
|
|
|
19
|
-
return
|
|
19
|
+
return stringLiteralPart;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
getContent() {
|
|
@@ -35,7 +35,7 @@ export default class TerminalSymbolBNFNode extends NonTerminalNode {
|
|
|
35
35
|
return content;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return NonTerminalNode.fromRuleNameChildNodesOpacityAndPrecedence(
|
|
38
|
+
static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return NonTerminalNode.fromRuleNameChildNodesOpacityAndPrecedence(StringLiteralBNFNode, ruleName, childNodes, opacity, precedence); }
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function sanitiseContent(content) {
|
|
@@ -16,7 +16,7 @@ import DefinitionBNFNode from "./node/bnf/definition";
|
|
|
16
16
|
import DefinitionsBNFNode from "./node/bnf/definitions";
|
|
17
17
|
import TerminalPartBNFNode from "./node/bnf/terminalPart";
|
|
18
18
|
import ChoiceOfPartsBNFNode from "./node/bnf/choiceOfParts";
|
|
19
|
-
import
|
|
19
|
+
import StringLiteralBNFNode from "./node/bnf/stringLiteral";
|
|
20
20
|
import BonTerminalPartBNFNode from "./node/bnf/nonTerminalPart";
|
|
21
21
|
import SequenceOfPartsBNFNode from "./node/bnf/sequenceOfParts";
|
|
22
22
|
import OpacityModifierBNFNode from "./node/bnf/opacityModifier";
|
|
@@ -44,8 +44,8 @@ import { NAME_RULE_NAME,
|
|
|
44
44
|
PART_CHOICE_RULE_NAME,
|
|
45
45
|
DEFINITIONS_RULE_NAME,
|
|
46
46
|
TERMINAL_PART_RULE_NAME,
|
|
47
|
+
STRING_LITERAL_RULE_NAME,
|
|
47
48
|
CHOICE_OF_PARTS_RULE_NAME,
|
|
48
|
-
TERMINAL_SYMBOL_RULE_NAME,
|
|
49
49
|
OPACITY_MODIFIER_RULE_NAME,
|
|
50
50
|
NON_TERMINAL_PART_RULE_NAME,
|
|
51
51
|
SEQUENCE_OF_PARTS_RULE_NAME,
|
|
@@ -74,8 +74,8 @@ const NonTerminalNodeMap = {
|
|
|
74
74
|
[PART_CHOICE_RULE_NAME]: PartChoiceBNFNode,
|
|
75
75
|
[DEFINITIONS_RULE_NAME]: DefinitionsBNFNode,
|
|
76
76
|
[TERMINAL_PART_RULE_NAME]: TerminalPartBNFNode,
|
|
77
|
+
[STRING_LITERAL_RULE_NAME]: StringLiteralBNFNode,
|
|
77
78
|
[CHOICE_OF_PARTS_RULE_NAME]: ChoiceOfPartsBNFNode,
|
|
78
|
-
[TERMINAL_SYMBOL_RULE_NAME]: TerminalSymbolBNFNode,
|
|
79
79
|
[OPACITY_MODIFIER_RULE_NAME]: OpacityModifierBNFNode,
|
|
80
80
|
[NON_TERMINAL_PART_RULE_NAME]: BonTerminalPartBNFNode,
|
|
81
81
|
[SEQUENCE_OF_PARTS_RULE_NAME]: SequenceOfPartsBNFNode,
|
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
import { characters } from "necessary";
|
|
4
|
+
|
|
3
5
|
import VerticalBranchParseTree from "./verticalBranch";
|
|
4
6
|
|
|
5
7
|
import { EMPTY_STRING } from "../constants";
|
|
6
8
|
import { lineIndexFromTokenIndexAndTokens } from "../utilities/tokens";
|
|
7
9
|
|
|
10
|
+
const { NEW_LINE_CHARACTER, CARRIAGE_RETURN_CHARACTER } = characters;
|
|
11
|
+
|
|
8
12
|
export default class TerminalNodeParseTree extends VerticalBranchParseTree {
|
|
9
13
|
static fromTerminalNodeAndTokens(terminalNode, tokens) {
|
|
14
|
+
let content;
|
|
15
|
+
|
|
16
|
+
content = terminalNode.getContent();
|
|
17
|
+
|
|
18
|
+
content = content.replace(/[\r\n]/g, (match) => {
|
|
19
|
+
switch (match) {
|
|
20
|
+
case CARRIAGE_RETURN_CHARACTER:
|
|
21
|
+
return "\\r";
|
|
22
|
+
|
|
23
|
+
case NEW_LINE_CHARACTER:
|
|
24
|
+
return "\\n";
|
|
25
|
+
|
|
26
|
+
default:
|
|
27
|
+
return match;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
10
31
|
const type = terminalNode.getType(),
|
|
11
|
-
content = terminalNode.getContent(),
|
|
12
32
|
significantTokenIndex = terminalNode.getSignificantTokenIndex(tokens),
|
|
13
33
|
lineIndex = lineIndexFromTokenIndexAndTokens(significantTokenIndex, tokens);
|
|
14
34
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import TerminalPart from "../../part/terminal";
|
|
4
4
|
import TerminalNode from "../../node/terminal";
|
|
5
5
|
|
|
6
|
-
export default class
|
|
6
|
+
export default class StringLiteralPart extends TerminalPart {
|
|
7
7
|
constructor(content) {
|
|
8
8
|
super();
|
|
9
9
|
|
|
@@ -54,8 +54,8 @@ export default class TerminalSymbolPart extends TerminalPart {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
static fromContent(content) {
|
|
57
|
-
const
|
|
57
|
+
const stringLiteralPart = new StringLiteralPart(content);
|
|
58
58
|
|
|
59
|
-
return
|
|
59
|
+
return stringLiteralPart;
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/parts.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import EpsilonPart from "./part/terminal/epsilon";
|
|
4
|
+
import RuleNamePart from "./part/nonTerminal/ruleName";
|
|
4
5
|
import WildcardPart from "./part/terminal/wildcard";
|
|
5
6
|
import EndOfLinePart from "./part/terminal/endOfLine";
|
|
6
|
-
import TerminalSymbolPart from "./part/terminal/terminalSymbol";
|
|
7
|
-
import RegularExpressionPart from "./part/terminal/regularExpression";
|
|
8
|
-
import SignificantTokenTypePart from "./part/terminal/significantTokenType";
|
|
9
|
-
import RuleNamePart from "./part/nonTerminal/ruleName";
|
|
10
7
|
import OptionalPartPart from "./part/nonTerminal/optionalPart";
|
|
11
|
-
import
|
|
8
|
+
import StringLiteralPart from "./part/terminal/stringLiteral";
|
|
9
|
+
import ChoiceOfPartsPart from "./part/nonTerminal/choiceOfParts";
|
|
12
10
|
import OneOrMorePartsPart from "./part/nonTerminal/oneOrMoreParts";
|
|
13
11
|
import SequenceOfPartsPart from "./part/nonTerminal/sequenceOfParts";
|
|
14
|
-
import
|
|
12
|
+
import ZeroOrMorePartsPart from "./part/nonTerminal/zeroOrMoreParts";
|
|
13
|
+
import RegularExpressionPart from "./part/terminal/regularExpression";
|
|
14
|
+
import SignificantTokenTypePart from "./part/terminal/significantTokenType";
|
|
15
15
|
|
|
16
16
|
export default {
|
|
17
17
|
EpsilonPart,
|
|
18
|
+
RuleNamePart,
|
|
18
19
|
WildcardPart,
|
|
19
20
|
EndOfLinePart,
|
|
20
|
-
TerminalSymbolPart,
|
|
21
|
-
RegularExpressionPart,
|
|
22
|
-
SignificantTokenTypePart,
|
|
23
|
-
RuleNamePart,
|
|
24
21
|
OptionalPartPart,
|
|
25
|
-
|
|
22
|
+
ChoiceOfPartsPart,
|
|
23
|
+
StringLiteralPart,
|
|
26
24
|
OneOrMorePartsPart,
|
|
27
25
|
SequenceOfPartsPart,
|
|
28
|
-
|
|
26
|
+
ZeroOrMorePartsPart,
|
|
27
|
+
RegularExpressionPart,
|
|
28
|
+
SignificantTokenTypePart
|
|
29
29
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { specialSymbols } from "occam-lexers";
|
|
4
4
|
|
|
5
5
|
import Rule from "../../rule";
|
|
6
|
-
import
|
|
6
|
+
import StringLiteralDefinition from "../../definition/stringLiteral";
|
|
7
7
|
|
|
8
8
|
import { END_OF_LINE_RULE_NAME } from "../../ruleNames";
|
|
9
9
|
|
|
@@ -12,11 +12,11 @@ const { endOfLine } = specialSymbols;
|
|
|
12
12
|
export default class EndOfLineBNFRule extends Rule {
|
|
13
13
|
static fromNothing() {
|
|
14
14
|
const content = endOfLine,
|
|
15
|
-
|
|
15
|
+
endOfLineStringLiteralDefinition = StringLiteralDefinition.fromContent(content),
|
|
16
16
|
name = END_OF_LINE_RULE_NAME, ///
|
|
17
17
|
opacity = null,
|
|
18
18
|
definitions = [
|
|
19
|
-
|
|
19
|
+
endOfLineStringLiteralDefinition
|
|
20
20
|
],
|
|
21
21
|
endOfLineRule = new EndOfLineBNFRule(name, opacity, definitions);
|
|
22
22
|
|
package/src/rule/bnf/epsilon.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { specialSymbols } from "occam-lexers";
|
|
4
4
|
|
|
5
5
|
import Rule from "../../rule";
|
|
6
|
-
import
|
|
6
|
+
import StringLiteralDefinition from "../../definition/stringLiteral";
|
|
7
7
|
|
|
8
8
|
import { EPSILON_RULE_NAME } from "../../ruleNames";
|
|
9
9
|
|
|
@@ -12,11 +12,11 @@ const { epsilon } = specialSymbols;
|
|
|
12
12
|
export default class EpsilonBNFRule extends Rule {
|
|
13
13
|
static fromNothing() {
|
|
14
14
|
const content = epsilon, ///
|
|
15
|
-
|
|
15
|
+
epsilonStringLiteralDefinition = StringLiteralDefinition.fromContent(content),
|
|
16
16
|
name = EPSILON_RULE_NAME, ///
|
|
17
17
|
opacity = null,
|
|
18
18
|
definitions = [
|
|
19
|
-
|
|
19
|
+
epsilonStringLiteralDefinition
|
|
20
20
|
],
|
|
21
21
|
epsilonRule = new EpsilonBNFRule(name, opacity, definitions);
|
|
22
22
|
|
|
@@ -5,21 +5,21 @@ import { types } from "occam-lexers";
|
|
|
5
5
|
import Rule from "../../rule";
|
|
6
6
|
import SignificantTokenTypeDefinition from "../../definition/significantTokenType";
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { STRING_LITERAL_RULE_NAME } from "../../ruleNames";
|
|
9
9
|
|
|
10
10
|
const { stringLiteralType } = types;
|
|
11
11
|
|
|
12
|
-
export default class
|
|
12
|
+
export default class StringLiteralBNFRule extends Rule {
|
|
13
13
|
static fromNothing() {
|
|
14
14
|
const significantTokenType = stringLiteralType, ///
|
|
15
15
|
stringLiteralSignificantTokenTypeDefinition = SignificantTokenTypeDefinition.fromSignificantTokenType(significantTokenType),
|
|
16
|
-
name =
|
|
16
|
+
name = STRING_LITERAL_RULE_NAME, ///
|
|
17
17
|
opacity = null,
|
|
18
18
|
definitions = [
|
|
19
19
|
stringLiteralSignificantTokenTypeDefinition
|
|
20
20
|
],
|
|
21
|
-
|
|
21
|
+
stringLiteralRule = new StringLiteralBNFRule(name, opacity, definitions);
|
|
22
22
|
|
|
23
|
-
return
|
|
23
|
+
return stringLiteralRule;
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -7,7 +7,7 @@ import { EPSILON_RULE_NAME,
|
|
|
7
7
|
WILDCARD_RULE_NAME,
|
|
8
8
|
END_OF_LINE_RULE_NAME,
|
|
9
9
|
TERMINAL_PART_RULE_NAME,
|
|
10
|
-
|
|
10
|
+
STRING_LITERAL_RULE_NAME,
|
|
11
11
|
NO_WHITESPACE_PART_RULE_NAME,
|
|
12
12
|
REGULAR_EXPRESSION_RULE_NAME,
|
|
13
13
|
START_OF_CONTENT_PART_RULE_NAME,
|
|
@@ -31,9 +31,9 @@ export default class TerminalPartBNFRule extends Rule {
|
|
|
31
31
|
|
|
32
32
|
const endOfLineRuleNameDefinition = RuleNameDefinition.fromRuleName(ruleName);
|
|
33
33
|
|
|
34
|
-
ruleName =
|
|
34
|
+
ruleName = STRING_LITERAL_RULE_NAME;
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const stringLiteralRuleNameDefinition = RuleNameDefinition.fromRuleName(ruleName);
|
|
37
37
|
|
|
38
38
|
ruleName = NO_WHITESPACE_PART_RULE_NAME;
|
|
39
39
|
|
|
@@ -54,7 +54,7 @@ export default class TerminalPartBNFRule extends Rule {
|
|
|
54
54
|
definitions = [
|
|
55
55
|
significantTokenTypeRuleNameDefinition,
|
|
56
56
|
regularExpressionRuleNameDefinition,
|
|
57
|
-
|
|
57
|
+
stringLiteralRuleNameDefinition,
|
|
58
58
|
endOfLineRuleNameDefinition,
|
|
59
59
|
wildcardRuleNameDefinition,
|
|
60
60
|
epsilonRuleNameDefinition,
|
package/src/rule/bnf/wildcard.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { specialSymbols } from "occam-lexers";
|
|
4
4
|
|
|
5
5
|
import Rule from "../../rule";
|
|
6
|
-
import
|
|
6
|
+
import StringLiteralDefinition from "../../definition/stringLiteral";
|
|
7
7
|
|
|
8
8
|
import { WILDCARD_RULE_NAME } from "../../ruleNames";
|
|
9
9
|
|
|
@@ -12,11 +12,11 @@ const { wildcard } = specialSymbols;
|
|
|
12
12
|
export default class WildcardBNFRule extends Rule {
|
|
13
13
|
static fromNothing() {
|
|
14
14
|
const content = wildcard, ///
|
|
15
|
-
|
|
15
|
+
wildcardStringLiteralDefinition = StringLiteralDefinition.fromContent(content),
|
|
16
16
|
name = WILDCARD_RULE_NAME, ///
|
|
17
17
|
opacity = null,
|
|
18
18
|
definitions = [
|
|
19
|
-
|
|
19
|
+
wildcardStringLiteralDefinition
|
|
20
20
|
],
|
|
21
21
|
wildcardRule = new WildcardBNFRule(name, opacity, definitions);
|
|
22
22
|
|
package/src/ruleNames.js
CHANGED
|
@@ -15,8 +15,8 @@ export const END_OF_LINE_RULE_NAME = "endOfLine";
|
|
|
15
15
|
export const PART_CHOICE_RULE_NAME = "partChoice";
|
|
16
16
|
export const DEFINITIONS_RULE_NAME = "definitions";
|
|
17
17
|
export const TERMINAL_PART_RULE_NAME = "terminalPart";
|
|
18
|
+
export const STRING_LITERAL_RULE_NAME = "stringLiteral";
|
|
18
19
|
export const CHOICE_OF_PARTS_RULE_NAME = "choiceOfParts";
|
|
19
|
-
export const TERMINAL_SYMBOL_RULE_NAME = "terminalSymbol";
|
|
20
20
|
export const OPACITY_MODIFIER_RULE_NAME = "opacityModifier";
|
|
21
21
|
export const NON_TERMINAL_PART_RULE_NAME = "nonTerminalPart";
|
|
22
22
|
export const SEQUENCE_OF_PARTS_RULE_NAME = "sequenceOfParts";
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import Definition from "../definition";
|
|
4
|
-
import TerminalSymbolPart from "../part/terminal/terminalSymbol";
|
|
5
|
-
|
|
6
|
-
export default class TerminalSymbolDefinition extends Definition {
|
|
7
|
-
static fromContent(content) {
|
|
8
|
-
const terminalSymbolPart = TerminalSymbolPart.fromContent(content),
|
|
9
|
-
parts = [
|
|
10
|
-
terminalSymbolPart
|
|
11
|
-
],
|
|
12
|
-
precedence = null,
|
|
13
|
-
terminalSymbolDefinition = new TerminalSymbolDefinition(parts, precedence);
|
|
14
|
-
|
|
15
|
-
return terminalSymbolDefinition;
|
|
16
|
-
}
|
|
17
|
-
}
|