occam-verify-cli 0.0.843 → 0.0.845

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.
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ import NodesVerifier from "../../verifier/nodes";
4
+
5
+ import TermForVariableSubstitution from "../../substitution/termForVariable";
6
+
7
+ import { nodeQuery } from "../../utilities/query";
8
+ import { TERM_RULE_NAME } from "../../ruleNames";
9
+
10
+ const variableNodeQuery = nodeQuery("/term/variable");
11
+
12
+ class SubstitutionNodesVerifier extends NodesVerifier {
13
+ verifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, localContextA, localContextB, verifyAhead) {
14
+ let nonTerminalNodeVerified = false;
15
+
16
+ const nonTerminalNodeARuleName = nonTerminalNodeA.getRuleName(),
17
+ nonTerminalNodeBRuleName = nonTerminalNodeB.getRuleName();
18
+
19
+ if (nonTerminalNodeARuleName === nonTerminalNodeBRuleName) {
20
+ const ruleName = nonTerminalNodeARuleName; ///
21
+
22
+ switch (ruleName) {
23
+ case TERM_RULE_NAME: {
24
+ const termNodeA = nonTerminalNodeA, ///
25
+ termNodeB = nonTerminalNodeB, ///
26
+ termNodeVerified = this.verifyTermNode(termNodeA, termNodeB, substitutions, localContextA, localContextB, verifyAhead);
27
+
28
+ nonTerminalNodeVerified = termNodeVerified; ///
29
+
30
+ break;
31
+ }
32
+
33
+ default: {
34
+ nonTerminalNodeVerified = super.verifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, localContextA, localContextB, verifyAhead);
35
+
36
+ break;
37
+ }
38
+ }
39
+ }
40
+
41
+ return nonTerminalNodeVerified;
42
+ }
43
+
44
+ verifyTermNode(termNodeA, termNodeB, substitutions, localContextA, localContextB, verifyAhead) {
45
+ let termNodeVerified;
46
+
47
+ const variableNodeA = variableNodeQuery(termNodeA);
48
+
49
+ if (variableNodeA !== null) {
50
+ const variableNodeVerified = this.verifyVariableNode(variableNodeA, termNodeB, substitutions, localContextA, localContextB, verifyAhead);
51
+
52
+ termNodeVerified = variableNodeVerified; ///
53
+ } else {
54
+ const nonTerminalNodeA = termNodeA, ///
55
+ nonTerminalNodeB = termNodeB, ///
56
+ nonTerminalNodeVerified = super.verifyNonTerminalNode(nonTerminalNodeA, nonTerminalNodeB, substitutions, localContextA, localContextB, verifyAhead);
57
+
58
+ termNodeVerified = nonTerminalNodeVerified; ///
59
+ }
60
+
61
+ return termNodeVerified;
62
+ }
63
+
64
+ verifyVariableNode(variableNodeA, termNodeB, substitutions, localContextA, localContextB, verifyAhead) {
65
+ let variableNodeVerified = false;
66
+
67
+ const variableNodeB = variableNodeQuery(termNodeB);
68
+
69
+ if (variableNodeB !== null) {
70
+ const variableNodeAMatchedVariableNodeB = variableNodeA.match(variableNodeB);
71
+
72
+ if (variableNodeAMatchedVariableNodeB) {
73
+ const verifiedAhead = verifyAhead();
74
+
75
+ variableNodeVerified = verifiedAhead;
76
+ }
77
+ } else {
78
+ const variableNode = variableNodeA; ///
79
+
80
+ const substitution = substitutions.find((substitution) => {
81
+ const matches = substitution.matchVariableNode(variableNode);
82
+
83
+ if (matches) {
84
+ return true;
85
+ }
86
+ }) || null;
87
+
88
+ if (substitution !== null) {
89
+ const termNode = termNodeB, ///
90
+ termNodeMatches = substitution.matchTermNode(termNode);
91
+
92
+ if (termNodeMatches) {
93
+ const verifiedAhead = verifyAhead();
94
+
95
+ variableNodeVerified = verifiedAhead; ///
96
+ }
97
+ } else {
98
+ let verifiedAhead;
99
+
100
+ const termNode = termNodeB, ///
101
+ termForVariableSubstitution = TermForVariableSubstitution.fromVariableNodeAndTermNode(variableNode, termNode),
102
+ substitution = termForVariableSubstitution; ///
103
+
104
+ substitutions.push(substitution);
105
+
106
+ verifiedAhead = verifyAhead();
107
+
108
+ if (!verifiedAhead) {
109
+ substitutions.pop();
110
+ }
111
+
112
+ variableNodeVerified = verifiedAhead;
113
+ }
114
+ }
115
+
116
+ return variableNodeVerified;
117
+ }
118
+ }
119
+
120
+ const substitutionNodesVerifier = new SubstitutionNodesVerifier();
121
+
122
+ export default substitutionNodesVerifier;
@@ -4,33 +4,59 @@ import { second } from "../utilities/array";
4
4
  import { CONTAINED } from "../constants";
5
5
  import { nodeQuery, nodesQuery } from "../utilities/query";
6
6
 
7
- const variableNodesQuery = nodesQuery("/metaArgument//variable"),
8
- containmentVariableNodeQuery = nodeQuery("/argument/term/variable!");
7
+ const termNodeQuery = nodeQuery("/argument/term!"),
8
+ variableNodeQuery = nodeQuery("/argument/term/variable!"),
9
+ metaArgumentTermNodesQuery = nodesQuery("/metaArgument//term"),
10
+ metaArgumentVariableNodesQuery = nodesQuery("/metaArgument//variable");
9
11
 
10
12
  export default function verifyContainment(argumentNode, containmentNode, metaArgumentNode, context) {
11
13
  let containmentVerified = false;
12
14
 
13
- const containmentVariableNode = containmentVariableNodeQuery(argumentNode);
15
+ const contained = containedFromContainmentNode(containmentNode),
16
+ termNode = termNodeQuery(argumentNode),
17
+ variableNode = variableNodeQuery(argumentNode);
14
18
 
15
- if (containmentVariableNode !== null) {
16
- const contained = containedFromContainmentNode(containmentNode),
17
- variableNodes = variableNodesQuery(metaArgumentNode),
18
- containmentVariableNodeMatchesStatementVariableNode = variableNodes.some((statementVariableNode) => {
19
- const containmentVariableNodeMatchesStatementVariableNode = containmentVariableNode.match(statementVariableNode);
19
+ if (false) {
20
+ ///
21
+ } else if (variableNode !== null) {
22
+ const metaArgumentVariableNodes = metaArgumentVariableNodesQuery(metaArgumentNode),
23
+ variableNodeMatchesMetaArgumentVariableNode = metaArgumentVariableNodes.some((metaArgumentVariableNode) => {
24
+ const variableNodeMatchesMetaArgumentVariableNode = variableNode.match(metaArgumentVariableNode);
20
25
 
21
- if (containmentVariableNodeMatchesStatementVariableNode) {
26
+ if (variableNodeMatchesMetaArgumentVariableNode) {
22
27
  return true;
23
28
  }
24
29
  });
25
30
 
26
31
  if (contained) {
27
- if (containmentVariableNodeMatchesStatementVariableNode) {
32
+ if (variableNodeMatchesMetaArgumentVariableNode) {
28
33
  containmentVerified = true;
29
34
  }
30
35
  }
31
36
 
32
37
  if (!contained) {
33
- if (!containmentVariableNodeMatchesStatementVariableNode) {
38
+ if (!variableNodeMatchesMetaArgumentVariableNode) {
39
+ containmentVerified = true;
40
+ }
41
+ }
42
+ } else if (termNode !== null) {
43
+ const metaArgumentTermNodes = metaArgumentTermNodesQuery(metaArgumentNode),
44
+ termNodeMatchesMetaArgumentTermNode = metaArgumentTermNodes.some((metaArgumentTermNode) => {
45
+ const termNodeMatchesMetaArgumentTermNode = termNode.match(metaArgumentTermNode);
46
+
47
+ if (termNodeMatchesMetaArgumentTermNode) {
48
+ return true;
49
+ }
50
+ });
51
+
52
+ if (contained) {
53
+ if (termNodeMatchesMetaArgumentTermNode) {
54
+ containmentVerified = true;
55
+ }
56
+ }
57
+
58
+ if (!contained) {
59
+ if (!termNodeMatchesMetaArgumentTermNode) {
34
60
  containmentVerified = true;
35
61
  }
36
62
  }
@@ -1,32 +1,67 @@
1
1
  "use strict";
2
2
 
3
- import { second } from "../utilities/array";
3
+ import verifyTerm from "./term";
4
+
4
5
  import { DEFINED } from "../constants";
5
6
  import { nodeQuery } from "../utilities/query";
7
+ import { first, second } from "../utilities/array";
6
8
 
7
- const definedVariableNodeQuery = nodeQuery("/argument/term/variable!");
9
+ const termNodeQuery = nodeQuery("/argument/term!"),
10
+ variableNodeQuery = nodeQuery("/argument/term/variable!");
8
11
 
9
12
  export default function verifyDefining(argumentNode, definingNode, context) {
10
13
  let definingVerified = false;
11
14
 
12
- const definedVariableNode = definedVariableNodeQuery(argumentNode);
15
+ const defined = definedFromDefiningNode(definingNode),
16
+ termNode = termNodeQuery(argumentNode),
17
+ variableNode = variableNodeQuery(argumentNode);
18
+
19
+ if (false) {
20
+ ///
21
+ } else if (variableNode !== null) {
22
+ const variable = context.findVariableByVariableNode(variableNode);
13
23
 
14
- if (definedVariableNode !== null) {
15
- const defined = definedFromDefiningNode(definingNode),
16
- variableNode = definedVariableNode, ///
17
- variableDefined = context.isVariableDefined(variableNode);
24
+ if (variable !== null) {
25
+ const variableDefined = context.isVariableDefined(variable);
18
26
 
19
- if (defined) {
20
- if (variableDefined) {
21
- definingVerified = true;
27
+ if (defined) {
28
+ if (variableDefined) {
29
+ definingVerified = true;
30
+ }
22
31
  }
23
- }
24
32
 
25
- if (!defined) {
26
- if (!variableDefined) {
27
- definingVerified = true;
33
+ if (!defined) {
34
+ if (!variableDefined) {
35
+ definingVerified = true;
36
+ }
28
37
  }
29
38
  }
39
+ } else if (termNode !== null) {
40
+ const terms = [],
41
+ termVerified = verifyTerm(termNode, terms, context, () => {
42
+ let verifiedAhead;
43
+
44
+ const firstTerm = first(terms),
45
+ term = firstTerm, ///
46
+ termGrounded = context.isTermGrounded(term);
47
+
48
+ if (defined) {
49
+ if (termGrounded) {
50
+ verifiedAhead = true;
51
+ }
52
+ }
53
+
54
+ if (!defined) {
55
+ if (!termGrounded) {
56
+ verifiedAhead = true;
57
+ }
58
+ }
59
+
60
+ return verifiedAhead;
61
+ });
62
+
63
+ definingVerified = termVerified; ///
64
+
30
65
  }
31
66
 
32
67
  return definingVerified;