occam-verify-cli 0.0.505 → 0.0.507

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.
Files changed (50) hide show
  1. package/lib/conclusion.js +5 -160
  2. package/lib/consequence.js +3 -81
  3. package/lib/matcher/conclusion.js +194 -0
  4. package/lib/matcher/consequence.js +194 -0
  5. package/lib/matcher/premise.js +199 -0
  6. package/lib/matcher/supposition.js +199 -0
  7. package/lib/matcher.js +36 -0
  8. package/lib/metaMatcher/conclusion.js +194 -0
  9. package/lib/metaMatcher/premise.js +199 -0
  10. package/lib/metaMatcher.js +36 -0
  11. package/lib/metaSubstitution.js +7 -6
  12. package/lib/mixins/matcher.js +109 -0
  13. package/lib/premise.js +14 -183
  14. package/lib/ruleNames.js +5 -1
  15. package/lib/step/metaproof.js +6 -6
  16. package/lib/substitution.js +7 -6
  17. package/lib/supposition.js +5 -92
  18. package/lib/theorem.js +3 -3
  19. package/lib/utilities/substitution.js +61 -0
  20. package/lib/verify/metaproof.js +3 -3
  21. package/lib/verify/proof.js +3 -3
  22. package/lib/verify/ruleProof.js +5 -5
  23. package/package.json +1 -1
  24. package/src/conclusion.js +6 -277
  25. package/src/consequence.js +3 -141
  26. package/src/matcher/conclusion.js +86 -0
  27. package/src/matcher/consequence.js +89 -0
  28. package/src/matcher/premise.js +94 -0
  29. package/src/matcher/supposition.js +97 -0
  30. package/src/matcher.js +9 -0
  31. package/src/metaMatcher/conclusion.js +86 -0
  32. package/src/metaMatcher/premise.js +94 -0
  33. package/src/metaMatcher.js +9 -0
  34. package/src/metaSubstitution.js +4 -3
  35. package/src/mixins/matcher.js +81 -0
  36. package/src/premise.js +24 -312
  37. package/src/ruleNames.js +1 -0
  38. package/src/step/metaproof.js +2 -2
  39. package/src/substitution.js +3 -2
  40. package/src/supposition.js +12 -159
  41. package/src/theorem.js +1 -1
  42. package/src/utilities/{node.js → substitution.js} +4 -74
  43. package/src/verify/metaproof.js +2 -2
  44. package/src/verify/proof.js +2 -2
  45. package/src/verify/ruleProof.js +3 -3
  46. package/lib/metaSupposition.js +0 -167
  47. package/lib/utilities/node.js +0 -106
  48. package/lib/verify/metaSupposition.js +0 -41
  49. package/src/metaSupposition.js +0 -196
  50. package/src/verify/metaSupposition.js +0 -44
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ import Matcher from "../matcher";
4
+ import Substitution from "../substitution";
5
+
6
+ import { first } from "../utilities/array";
7
+ import { metavariableNameFromMetavariableNode } from "../utilities/query";
8
+ import { STATEMENT_RULE_NAME, METAVARIABLE_RULE_NAME, METASTATEMENT_RULE_NAME} from "../ruleNames";
9
+
10
+ class PremiseMatcher extends Matcher {
11
+ matchNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, substitutions) {
12
+ let nonTerminalNodeMatches = false;
13
+
14
+ const ruleName = nonTerminalNode.getRuleName(),
15
+ premiseNonTerminalNodeRuleName = premiseNonTerminalNode.getRuleName(),
16
+ ruleNameStatementRuleName = (ruleName === STATEMENT_RULE_NAME),
17
+ premiseNonTerminalNodeRuleNameMetastatementRuleName = (premiseNonTerminalNodeRuleName === METASTATEMENT_RULE_NAME);
18
+
19
+ if (ruleNameStatementRuleName && premiseNonTerminalNodeRuleNameMetastatementRuleName) {
20
+ const statementNode = nonTerminalNode, ///
21
+ premiseMetastatementNode = premiseNonTerminalNode, ///
22
+ metastatementNodeMatches = this.matchMetastatementNode(premiseMetastatementNode, statementNode, substitutions);
23
+
24
+ if (metastatementNodeMatches) {
25
+ nonTerminalNodeMatches = true;
26
+ } else {
27
+ nonTerminalNodeMatches = super.matchNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, substitutions);
28
+ }
29
+ } else if (ruleName === premiseNonTerminalNodeRuleName) {
30
+ nonTerminalNodeMatches = super.matchNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, substitutions);
31
+ }
32
+
33
+ return nonTerminalNodeMatches;
34
+ }
35
+
36
+ matchMetavariableNode(premiseMetavariableNode, statementNode, substitutions) {
37
+ let metavariableNodeMatches;
38
+
39
+ const premiseMetavariableName = metavariableNameFromMetavariableNode(premiseMetavariableNode),
40
+ substitution = substitutions.find((substitution) => {
41
+ const metavariableName = substitution.getMetavariableName();
42
+
43
+ if (metavariableName === premiseMetavariableName) {
44
+ return true;
45
+ }
46
+ }) || null;
47
+
48
+ if (substitution !== null) {
49
+ const substitutionNodesMatch = substitution.matchStatementNode(statementNode);
50
+
51
+ metavariableNodeMatches = substitutionNodesMatch; ///
52
+ } else {
53
+ const metavariableName = premiseMetavariableName, ///
54
+ substitution = Substitution.fromMetavariableNameAndStatementNode(metavariableName, statementNode);
55
+
56
+ substitutions.push(substitution);
57
+
58
+ metavariableNodeMatches = true;
59
+ }
60
+
61
+ return metavariableNodeMatches;
62
+ }
63
+
64
+ matchMetastatementNode(premiseMetastatementNode, statementNode, substitutions) {
65
+ let metastatementNodeMatches = false;
66
+
67
+ const premiseNonTerminalNode = premiseMetastatementNode, ///
68
+ premiseNonTerminalNodeChildNodes = premiseNonTerminalNode.getChildNodes(),
69
+ premiseNonTerminalNodeChildNodesLength = premiseNonTerminalNodeChildNodes.length;
70
+
71
+ if (premiseNonTerminalNodeChildNodesLength === 1) {
72
+ const firstPremiseChildNode = first(premiseNonTerminalNodeChildNodes),
73
+ premiseChildNode = firstPremiseChildNode, ///
74
+ premiseChildNodeNonTerminalNode = premiseChildNode.isNonTerminalNode();
75
+
76
+ if (premiseChildNodeNonTerminalNode) {
77
+ const premiseNonTerminalChildNode = premiseChildNode, ///
78
+ premiseNonTerminalChildNodeRuleName = premiseNonTerminalChildNode.getRuleName(),
79
+ premiseNonTerminalChildNodeRuleNameMetavariableRuleName = (premiseNonTerminalChildNodeRuleName === METAVARIABLE_RULE_NAME);
80
+
81
+ if (premiseNonTerminalChildNodeRuleNameMetavariableRuleName) {
82
+ const premiseMetavariableNode = premiseNonTerminalChildNode, ///
83
+ metaVariableNodeMatches = this.matchMetavariableNode(premiseMetavariableNode, statementNode, substitutions);
84
+
85
+ metastatementNodeMatches = metaVariableNodeMatches; ///
86
+ }
87
+ }
88
+ }
89
+
90
+ return metastatementNodeMatches;
91
+ }
92
+ }
93
+
94
+ export const premiseMatcher = new PremiseMatcher();
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ import Matcher from "../matcher";
4
+ import Substitution from "../substitution";
5
+
6
+ import { first } from "../utilities/array";
7
+ import { variableNameFromVariableNode } from "../utilities/query";
8
+ import { VARIABLE_RULE_NAME, STATEMENT_RULE_NAME } from "../ruleNames";
9
+
10
+ class SuppositionMatcher extends Matcher {
11
+ matchNonTerminalNode(suppositionNonTerminalNode, nonTerminalNode, substitutions) {
12
+ let nonTerminalNodeMatches = false;
13
+
14
+ const ruleName = nonTerminalNode.getRuleName(),
15
+ suppositionRuleName = suppositionNonTerminalNode.getRuleName(); ///
16
+
17
+ if (ruleName === suppositionRuleName) {
18
+ nonTerminalNodeMatches = super.matchNonTerminalNode(suppositionNonTerminalNode, nonTerminalNode, substitutions);
19
+
20
+ if (!nonTerminalNodeMatches) {
21
+ const ruleNameStatementRuleName = (ruleName === STATEMENT_RULE_NAME);
22
+
23
+ if (ruleNameStatementRuleName) {
24
+ const statementNode = nonTerminalNode, ///
25
+ suppositionStatementNode = suppositionNonTerminalNode, ///
26
+ statementNodeMatches = this.matchStatementNode(suppositionStatementNode, statementNode, substitutions);
27
+
28
+ nonTerminalNodeMatches = statementNodeMatches; ///
29
+ }
30
+ }
31
+ }
32
+
33
+ return nonTerminalNodeMatches;
34
+ }
35
+
36
+ matchStatementNode(suppositionStatementNode, statementNode, substitutions) {
37
+ let statementNodeMatches = false;
38
+
39
+ const suppositionNonTerminalNode = suppositionStatementNode, ///
40
+ suppositionChildNodes = suppositionNonTerminalNode.getChildNodes(),
41
+ suppositionChildNodesLength = suppositionChildNodes.length;
42
+
43
+ if (suppositionChildNodesLength === 1) {
44
+ const firstSuppositionChildNode = first(suppositionChildNodes),
45
+ suppositionChildNode = firstSuppositionChildNode, ///
46
+ suppositionChildNodeNonTerminalNode = suppositionChildNode.isNonTerminalNode();
47
+
48
+ if (suppositionChildNodeNonTerminalNode) {
49
+ const suppositionNonTerminalChildNode = suppositionChildNode, ///
50
+ suppositionNonTerminalChildNodeRuleName = suppositionNonTerminalChildNode.getRuleName(),
51
+ suppositionNonTerminalChildNodeRuleNameVariableRuleName = (suppositionNonTerminalChildNodeRuleName === VARIABLE_RULE_NAME);
52
+
53
+ if (suppositionNonTerminalChildNodeRuleNameVariableRuleName) {
54
+ const suppositionVariableNode = suppositionNonTerminalChildNode, ///
55
+ nonTerminalNode = statementNode, ///
56
+ childNodes = nonTerminalNode.getChildNodes(),
57
+ nodes = childNodes, ///
58
+ variableMatches = this.matchVariable(suppositionVariableNode, nodes, substitutions);
59
+
60
+ statementNodeMatches = variableMatches; ///
61
+ }
62
+ }
63
+ }
64
+
65
+ return statementNodeMatches;
66
+ }
67
+
68
+ matchVariable(suppositionVariableNode, nodes, substitutions) {
69
+ let variableMatches;
70
+
71
+ const suppositionVariableName = variableNameFromVariableNode(suppositionVariableNode),
72
+ substitution = substitutions.find((substitution) => {
73
+ const variableName = substitution.getVariableName();
74
+
75
+ if (variableName === suppositionVariableName) {
76
+ return true;
77
+ }
78
+ }) || null;
79
+
80
+ if (substitution !== null) {
81
+ const substitutionNodesMatch = substitution.matchNodes(nodes);
82
+
83
+ variableMatches = substitutionNodesMatch; ///
84
+ } else {
85
+ const variableName = suppositionVariableName, ///
86
+ substitution = Substitution.fromVariableNameAndNodes(variableName, nodes);
87
+
88
+ substitutions.push(substitution);
89
+
90
+ variableMatches = true;
91
+ }
92
+
93
+ return variableMatches;
94
+ }
95
+ }
96
+
97
+ export const suppositionMatcher = new SuppositionMatcher();
package/src/matcher.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ import matcherMixins from "./mixins/matcher";
4
+
5
+ export default class Matcher {}
6
+
7
+ Object.assign(Matcher.prototype, matcherMixins);
8
+
9
+ export const matcher = new Matcher();
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ import MetaMatcher from "../metaMatcher";
4
+
5
+ import { first } from "../utilities/array";
6
+ import { metavariableNameFromMetavariableNode } from "../utilities/query";
7
+ import { METAVARIABLE_RULE_NAME, METASTATEMENT_RULE_NAME } from "../ruleNames";
8
+
9
+ class ConclusionMetaMatcher extends MetaMatcher {
10
+ matchNonTerminalNode(conclusionNonTerminalNode, nonTerminalNode, metaSubstitutions) {
11
+ let nonTerminalNodeMatches = false;
12
+
13
+ const ruleName = nonTerminalNode.getRuleName(),
14
+ conclusionNonTerminalNodeRuleName = conclusionNonTerminalNode.getRuleName(),
15
+ ruleNameMetastatementRuleName = (ruleName === METASTATEMENT_RULE_NAME),
16
+ conclusionNonTerminalNodeRuleNameMetastatementRuleName = (conclusionNonTerminalNodeRuleName === METASTATEMENT_RULE_NAME);
17
+
18
+ if (ruleNameMetastatementRuleName && conclusionNonTerminalNodeRuleNameMetastatementRuleName) {
19
+ const statementNode = nonTerminalNode, ///
20
+ conclusionMetastatementNode = conclusionNonTerminalNode, ///
21
+ metastatementNodeMatches = this.matchMetastatementNode(conclusionMetastatementNode, statementNode, metaSubstitutions);
22
+
23
+ if (metastatementNodeMatches) {
24
+ nonTerminalNodeMatches = true; ///
25
+ } else {
26
+ nonTerminalNodeMatches = super.matchNonTerminalNode(conclusionNonTerminalNode, nonTerminalNode, metaSubstitutions);
27
+ }
28
+ } else if (ruleName === conclusionNonTerminalNodeRuleName) {
29
+ nonTerminalNodeMatches = super.matchNonTerminalNode(conclusionNonTerminalNode, nonTerminalNode, metaSubstitutions);
30
+ }
31
+
32
+ return nonTerminalNodeMatches;
33
+ }
34
+
35
+ matchMetavariableNode(conclusionMetavariableNode, metastatementNode, metaSubstitutions) {
36
+ let metavariableNodeMatches = true;
37
+
38
+ const conclusionMetavariableName = metavariableNameFromMetavariableNode(conclusionMetavariableNode),
39
+ metaSubstitution = metaSubstitutions.find((metaSubstitution) => {
40
+ const metavariableName = metaSubstitution.getMetavariableName();
41
+
42
+ if (metavariableName === conclusionMetavariableName) {
43
+ return true;
44
+ }
45
+ }) || null;
46
+
47
+ if (metaSubstitution !== null) {
48
+ const metaSubstitutionNodesMatch = metaSubstitution.matchMetastatementNode(metastatementNode);
49
+
50
+ metavariableNodeMatches = metaSubstitutionNodesMatch; ///
51
+ }
52
+
53
+ return metavariableNodeMatches;
54
+ }
55
+
56
+ matchMetastatementNode(conclusionMetastatementNode, metastatementNode, metaSubstitutions) {
57
+ let metastatementNodeMatches = false;
58
+
59
+ const conclusionNonTerminalNode = conclusionMetastatementNode, ///
60
+ conclusionNonTerminalNodeChildNodes = conclusionNonTerminalNode.getChildNodes(),
61
+ conclusionNonTerminalNodeChildNodesLength = conclusionNonTerminalNodeChildNodes.length;
62
+
63
+ if (conclusionNonTerminalNodeChildNodesLength === 1) {
64
+ const firstConclusionChildNode = first(conclusionNonTerminalNodeChildNodes),
65
+ conclusionChildNode = firstConclusionChildNode, ///
66
+ conclusionChildNodeNonTerminalNode = conclusionChildNode.isNonTerminalNode();
67
+
68
+ if (conclusionChildNodeNonTerminalNode) {
69
+ const conclusionNonTerminalChildNode = conclusionChildNode, ///
70
+ conclusionNonTerminalChildNodeRuleName = conclusionNonTerminalChildNode.getRuleName(),
71
+ conclusionNonTerminalChildNodeRuleNameMetavariableRuleName = (conclusionNonTerminalChildNodeRuleName === METAVARIABLE_RULE_NAME);
72
+
73
+ if (conclusionNonTerminalChildNodeRuleNameMetavariableRuleName) {
74
+ const conclusionMetavariableNode = conclusionNonTerminalChildNode, ///
75
+ metavariableNodeMatches = this.matchMetavariableNode(conclusionMetavariableNode, metastatementNode, metaSubstitutions);
76
+
77
+ metastatementNodeMatches = metavariableNodeMatches; ///
78
+ }
79
+ }
80
+ }
81
+
82
+ return metastatementNodeMatches;
83
+ }
84
+ }
85
+
86
+ export const conclusionMetaMatcher = new ConclusionMetaMatcher();
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ import MetaMatcher from "../metaMatcher";
4
+ import MetaSubstitution from "../metaSubstitution";
5
+
6
+ import { first } from "../utilities/array";
7
+ import { metavariableNameFromMetavariableNode } from "../utilities/query";
8
+ import { METAVARIABLE_RULE_NAME, METASTATEMENT_RULE_NAME } from "../ruleNames";
9
+
10
+ class PremiseMetaMatcher extends MetaMatcher {
11
+ matchNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, metaSubstitutions) {
12
+ let nonTerminalNodeMatches = false;
13
+
14
+ const ruleName = nonTerminalNode.getRuleName(),
15
+ premiseNonTerminalNodeRuleName = premiseNonTerminalNode.getRuleName(),
16
+ ruleNameMetastatementRuleName = (ruleName === METASTATEMENT_RULE_NAME),
17
+ premiseNonTerminalNodeRuleNameMetastatementRuleName = (premiseNonTerminalNodeRuleName === METASTATEMENT_RULE_NAME);
18
+
19
+ if (ruleNameMetastatementRuleName && premiseNonTerminalNodeRuleNameMetastatementRuleName) {
20
+ const metastatementNode = nonTerminalNode, ///
21
+ premiseMetastatementNode = premiseNonTerminalNode, ///
22
+ metastatementNodeMatches = this.matchMetastatementNode(premiseMetastatementNode, metastatementNode, metaSubstitutions);
23
+
24
+ if (metastatementNodeMatches) {
25
+ nonTerminalNodeMatches = true;
26
+ } else {
27
+ nonTerminalNodeMatches = super.matchNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, metaSubstitutions);
28
+ }
29
+ } else if (ruleName === premiseNonTerminalNodeRuleName) {
30
+ nonTerminalNodeMatches = super.matchNonTerminalNode(premiseNonTerminalNode, nonTerminalNode, metaSubstitutions);
31
+ }
32
+
33
+ return nonTerminalNodeMatches;
34
+ }
35
+
36
+ matchMetavariableNode(premiseMetavariableNode, metastatementNode, metaSubstitutions) {
37
+ let metavariableNodeMatches;
38
+
39
+ const premiseMetavariableName = metavariableNameFromMetavariableNode(premiseMetavariableNode),
40
+ metaSubstitution = metaSubstitutions.find((metaSubstitution) => {
41
+ const metavariableName = metaSubstitution.getMetavariableName();
42
+
43
+ if (metavariableName === premiseMetavariableName) {
44
+ return true;
45
+ }
46
+ }) || null;
47
+
48
+ if (metaSubstitution !== null) {
49
+ const metaSubstitutionNodesMatch = metaSubstitution.matchMetastatementNode(metastatementNode);
50
+
51
+ metavariableNodeMatches = metaSubstitutionNodesMatch; ///
52
+ } else {
53
+ const metavariableName = premiseMetavariableName, ///
54
+ metaSubstitution = MetaSubstitution.fromMetavariableNameAndMetastatementNode(metavariableName, metastatementNode);
55
+
56
+ metaSubstitutions.push(metaSubstitution);
57
+
58
+ metavariableNodeMatches = true;
59
+ }
60
+
61
+ return metavariableNodeMatches;
62
+ }
63
+
64
+ matchMetastatementNode(premiseMetastatementNode, metastatementNode, metaSubstitutions) {
65
+ let metastatementNodeMatches = false;
66
+
67
+ const premiseNonTerminalNode = premiseMetastatementNode, ///
68
+ premiseNonTerminalNodeChildNodes = premiseNonTerminalNode.getChildNodes(),
69
+ premiseNonTerminalNodeChildNodesLength = premiseNonTerminalNodeChildNodes.length;
70
+
71
+ if (premiseNonTerminalNodeChildNodesLength === 1) {
72
+ const firstPremiseChildNode = first(premiseNonTerminalNodeChildNodes),
73
+ premiseChildNode = firstPremiseChildNode, ///
74
+ premiseChildNodeNonTerminalNode = premiseChildNode.isNonTerminalNode();
75
+
76
+ if (premiseChildNodeNonTerminalNode) {
77
+ const premiseNonTerminalChildNode = premiseChildNode, ///
78
+ premiseNonTerminalChildNodeRuleName = premiseNonTerminalChildNode.getRuleName(),
79
+ premiseNonTerminalChildNodeRuleNameMetavariableRuleName = (premiseNonTerminalChildNodeRuleName === METAVARIABLE_RULE_NAME);
80
+
81
+ if (premiseNonTerminalChildNodeRuleNameMetavariableRuleName) {
82
+ const premiseMetavariableNode = premiseNonTerminalChildNode, ///
83
+ metaVariableNodeMatches = this.matchMetavariableNode(premiseMetavariableNode, metastatementNode, metaSubstitutions);
84
+
85
+ metastatementNodeMatches = metaVariableNodeMatches; ///
86
+ }
87
+ }
88
+ }
89
+
90
+ return metastatementNodeMatches;
91
+ }
92
+ }
93
+
94
+ export const premiseMetaMatcher = new PremiseMetaMatcher();
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ import matcherMixins from "./mixins/matcher";
4
+
5
+ export default class MetaMatcher {}
6
+
7
+ Object.assign(MetaMatcher.prototype, matcherMixins);
8
+
9
+ export const metaMatcher = new MetaMatcher();
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
 
3
+ import { matcher } from "./matcher";
3
4
  import { METASTATEMENT_RULE_NAME } from "./ruleNames";
4
- import { matchNode, bracketedNonTerminalChildNodeFromChildNodes } from "./utilities/node";
5
+ import { bracketedNonTerminalChildNodeFromChildNodes } from "./utilities/substitution";
5
6
 
6
7
  export default class MetaSubstitution {
7
8
  constructor(metavariableName, metastatementNode) {
@@ -22,7 +23,7 @@ export default class MetaSubstitution {
22
23
 
23
24
  const nodeA = this.metastatementNode, ///
24
25
  nodeB = metastatementNode,
25
- nodeMatches = matchNode(nodeA, nodeB);
26
+ nodeMatches = matcher.matchNode(nodeA, nodeB);
26
27
 
27
28
  matchesMetastatementNode = nodeMatches; ///
28
29
 
@@ -36,7 +37,7 @@ export default class MetaSubstitution {
36
37
  if (metastatementNode !== null) {
37
38
  const nodeA = this.metastatementNode, ///
38
39
  nodeB = metastatementNode,
39
- nodeMatches = matchNode(nodeA, nodeB);
40
+ nodeMatches = matcher.matchNode(nodeA, nodeB);
40
41
 
41
42
  matchesMetastatementNode = nodeMatches; ///
42
43
  }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+
3
+ function matchNode(nodeA, nodeB, ...remainingArguments) {
4
+ let nodeMatches = false;
5
+
6
+ const nodeATerminalNode = nodeA.isTerminalNode(),
7
+ nodeBTerminalNode = nodeB.isTerminalNode();
8
+
9
+ if (nodeATerminalNode === nodeBTerminalNode) {
10
+ if (nodeATerminalNode) {
11
+ const terminalNodeA = nodeA, ///
12
+ terminalNodeB = nodeB, ///
13
+ terminalNodeMatches = this.matchTerminalNode(terminalNodeA, terminalNodeB, ...remainingArguments);
14
+
15
+ nodeMatches = terminalNodeMatches; ///
16
+ } else {
17
+ const nonTerminalNodeA = nodeA, ///
18
+ nonTerminalNodeB = nodeB, ///
19
+ nonTerminalNodeMatches = this.matchNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, ...remainingArguments);
20
+
21
+ nodeMatches = nonTerminalNodeMatches; ///
22
+ }
23
+ }
24
+
25
+ return nodeMatches;
26
+ }
27
+
28
+ function matchNodes(nodesA, nodesB, ...remainingArguments) {
29
+ let nodesMatch = false;
30
+
31
+ const nodesALength = nodesA.length,
32
+ nodesBLength = nodesB.length;
33
+
34
+ if (nodesALength === nodesBLength) {
35
+ nodesMatch = nodesA.every((nodeA, index) => {
36
+ const nodeB = nodesB[index],
37
+ nodeMatches = this.matchNode(nodeA, nodeB, ...remainingArguments);
38
+
39
+ if (nodeMatches) {
40
+ return true;
41
+ }
42
+ })
43
+ }
44
+
45
+ return nodesMatch;
46
+ }
47
+
48
+ function matchTerminalNode(terminalNodeA, terminalNodeB, ...remainingArguments) {
49
+ const matches = terminalNodeA.match(terminalNodeB),
50
+ terminalNodeMatches = matches; ///
51
+
52
+ return terminalNodeMatches;
53
+ }
54
+
55
+ function matchNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, ...remainingArguments) {
56
+ let nonTerminalNodeMatches = false;
57
+
58
+ const nonTerminalNodeARuleName = nonTerminalNodeA.getRuleName(), ///
59
+ nonTerminalNodeBRuleName = nonTerminalNodeB.getRuleName(); ///
60
+
61
+ if (nonTerminalNodeARuleName === nonTerminalNodeBRuleName) {
62
+ const nonTerminalNodeAChildNodes = nonTerminalNodeA.getChildNodes(),
63
+ nonTerminalNodeBChildNodes = nonTerminalNodeB.getChildNodes(),
64
+ nodesA = nonTerminalNodeAChildNodes, ///
65
+ nodesB = nonTerminalNodeBChildNodes, ///
66
+ nodesMatch = this.matchNodes(nodesA, nodesB, ...remainingArguments);
67
+
68
+ nonTerminalNodeMatches = nodesMatch; ///
69
+ }
70
+
71
+ return nonTerminalNodeMatches;
72
+ }
73
+
74
+ const matcherMixins = {
75
+ matchNode,
76
+ matchNodes,
77
+ matchTerminalNode,
78
+ matchNonTerminalNode
79
+ };
80
+
81
+ export default matcherMixins;