occam-verify-cli 0.0.676 → 0.0.677
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/lib/combinator.js +15 -12
- package/lib/constructor.js +26 -21
- package/lib/context/metaproof.js +7 -7
- package/lib/log.js +3 -3
- package/lib/node/statement/combinator/bracketed.js +8 -4
- package/lib/node/statement/combinator/equality.js +8 -4
- package/lib/ocmbinator/bracketed.js +4 -2
- package/lib/ocmbinator/equality.js +4 -2
- package/lib/tokens/statement/combinator/bracketed.js +17 -0
- package/lib/tokens/statement/combinator/equality.js +17 -0
- package/lib/utilities/lineIndex.js +52 -0
- package/lib/utilities/node.js +121 -15
- package/lib/utilities/string.js +1 -1
- package/lib/utilities/tokens.js +49 -36
- package/lib/verify/assertion/type.js +2 -2
- package/lib/verify/metastatement.js +6 -1
- package/lib/verify/statement.js +11 -2
- package/lib/verify/statementAsCombinator.js +2 -2
- package/lib/verify/term.js +14 -5
- package/lib/verify/termAsConstructor.js +2 -2
- package/package.json +1 -1
- package/src/combinator.js +21 -14
- package/src/constructor.js +33 -23
- package/src/context/metaproof.js +2 -2
- package/src/log.js +1 -1
- package/src/node/statement/combinator/bracketed.js +3 -4
- package/src/node/statement/combinator/equality.js +3 -5
- package/src/ocmbinator/bracketed.js +8 -3
- package/src/ocmbinator/equality.js +8 -3
- package/src/tokens/statement/combinator/bracketed.js +10 -0
- package/src/tokens/statement/combinator/equality.js +10 -0
- package/src/utilities/lineIndex.js +51 -0
- package/src/utilities/node.js +130 -53
- package/src/utilities/string.js +0 -1
- package/src/utilities/tokens.js +44 -32
- package/src/verify/assertion/type.js +1 -1
- package/src/verify/metastatement.js +8 -0
- package/src/verify/statement.js +19 -2
- package/src/verify/statementAsCombinator.js +2 -1
- package/src/verify/term.js +28 -7
- package/src/verify/termAsConstructor.js +2 -1
package/src/constructor.js
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
import Type from "./type";
|
|
4
4
|
|
|
5
5
|
import { nodeAsString } from "./utilities/string";
|
|
6
|
-
import {
|
|
6
|
+
import { termNodeFromConstructorDeclarationTokens } from "./utilities/node";
|
|
7
|
+
import { constructorDeclarationTokensFromTermString } from "./utilities/tokens";
|
|
7
8
|
|
|
8
9
|
export default class Constructor {
|
|
9
|
-
constructor(termNode, type) {
|
|
10
|
+
constructor(termNode, string, type) {
|
|
10
11
|
this.termNode = termNode;
|
|
12
|
+
this.string = string;
|
|
11
13
|
this.type = type;
|
|
12
14
|
}
|
|
13
15
|
|
|
@@ -15,25 +17,12 @@ export default class Constructor {
|
|
|
15
17
|
return this.termNode;
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
return this.
|
|
20
|
+
getString() {
|
|
21
|
+
return this.string;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const termString = nodeAsString(this.termNode, tokens);
|
|
26
|
-
|
|
27
|
-
if (this.type === null) {
|
|
28
|
-
string = `${termString}`;
|
|
29
|
-
} else {
|
|
30
|
-
const noSuperType = true,
|
|
31
|
-
typeString = this.type.asString(tokens, noSuperType);
|
|
32
|
-
|
|
33
|
-
string = `${termString}:${typeString}`;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return string;
|
|
24
|
+
getType() {
|
|
25
|
+
return this.type;
|
|
37
26
|
}
|
|
38
27
|
|
|
39
28
|
toJSON(tokens) {
|
|
@@ -51,8 +40,9 @@ export default class Constructor {
|
|
|
51
40
|
return json;
|
|
52
41
|
}
|
|
53
42
|
|
|
54
|
-
static
|
|
55
|
-
const
|
|
43
|
+
static fromTermNodeTypeAndTokens(termNode, type, tokens) {
|
|
44
|
+
const string = stringFromTermNodeTypeAndTokens(termNode, type, tokens),
|
|
45
|
+
constructor = new Constructor(termNode, string, type);
|
|
56
46
|
|
|
57
47
|
return constructor;
|
|
58
48
|
}
|
|
@@ -62,7 +52,8 @@ export default class Constructor {
|
|
|
62
52
|
termString = term, ///
|
|
63
53
|
lexer = fileContext.getLexer(),
|
|
64
54
|
parser = fileContext.getParser(),
|
|
65
|
-
|
|
55
|
+
constructorDeclarationTokens = constructorDeclarationTokensFromTermString(termString, lexer),
|
|
56
|
+
termNode = termNodeFromConstructorDeclarationTokens(constructorDeclarationTokens, parser);
|
|
66
57
|
|
|
67
58
|
let { type } = json;
|
|
68
59
|
|
|
@@ -78,8 +69,27 @@ export default class Constructor {
|
|
|
78
69
|
type = fileContext.findTypeByTypeName(typeName); ///
|
|
79
70
|
}
|
|
80
71
|
|
|
81
|
-
const
|
|
72
|
+
const tokens = constructorDeclarationTokens, ///
|
|
73
|
+
string = stringFromTermNodeTypeAndTokens(termNode, type, tokens),
|
|
74
|
+
constructor = new Constructor(termNode, string, type);
|
|
82
75
|
|
|
83
76
|
return constructor;
|
|
84
77
|
}
|
|
85
78
|
}
|
|
79
|
+
|
|
80
|
+
function stringFromTermNodeTypeAndTokens(termNode, type, tokens) {
|
|
81
|
+
let string;
|
|
82
|
+
|
|
83
|
+
const termString = nodeAsString(termNode, tokens);
|
|
84
|
+
|
|
85
|
+
if (type === null) {
|
|
86
|
+
string = `${termString}`;
|
|
87
|
+
} else {
|
|
88
|
+
const noSuperType = true,
|
|
89
|
+
typeString = type.asString(tokens, noSuperType);
|
|
90
|
+
|
|
91
|
+
string = `${termString}:${typeString}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return string;
|
|
95
|
+
}
|
package/src/context/metaproof.js
CHANGED
|
@@ -16,8 +16,6 @@ class MetaproofContext {
|
|
|
16
16
|
return this.context;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
getVariables() { return this.context.getVariables(); }
|
|
20
|
-
|
|
21
19
|
getMetavariables() {
|
|
22
20
|
const metavariables = [];
|
|
23
21
|
|
|
@@ -41,6 +39,8 @@ class MetaproofContext {
|
|
|
41
39
|
return metaproofSteps;
|
|
42
40
|
}
|
|
43
41
|
|
|
42
|
+
getVariables() { return this.context.getVariables(); }
|
|
43
|
+
|
|
44
44
|
getLastMetaproofStep() {
|
|
45
45
|
let lastMetaproofStep = null;
|
|
46
46
|
|
package/src/log.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { levels } from "necessary";
|
|
4
4
|
|
|
5
|
-
import { leastLineIndexFromNodeAndTokens, greatestLineIndexFromNodeAndTokens } from "./utilities/
|
|
5
|
+
import { leastLineIndexFromNodeAndTokens, greatestLineIndexFromNodeAndTokens } from "./utilities/lineIndex";
|
|
6
6
|
|
|
7
7
|
const { TRACE_LEVEL, DEBUG_LEVEL, INFO_LEVEL, WARNING_LEVEL, ERROR_LEVEL, FATAL_LEVEL } = levels;
|
|
8
8
|
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { statementNodeFromStatementString } from "../../../utilities/node";
|
|
3
|
+
import unqualifiedBracketedCombinatorStatementTokens from "../../../tokens/statement/combinator/bracketed";
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
import { statementNodeFromUnqualifiedStatementTokens } from "../../../utilities/node";
|
|
7
6
|
|
|
8
|
-
const bracketedCombinatorStatementNode =
|
|
7
|
+
const bracketedCombinatorStatementNode = statementNodeFromUnqualifiedStatementTokens(unqualifiedBracketedCombinatorStatementTokens);
|
|
9
8
|
|
|
10
9
|
export default bracketedCombinatorStatementNode;
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import { statementNodeFromStatementString } from "../../../utilities/node";
|
|
3
|
+
import unqualifiedEqualityCombinatorStatementTokens from "../../../tokens/statement/combinator/equality";
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
import { statementNodeFromUnqualifiedStatementTokens } from "../../../utilities/node";
|
|
7
6
|
|
|
8
|
-
const equalityCombinatorStatementNode =
|
|
7
|
+
const equalityCombinatorStatementNode = statementNodeFromUnqualifiedStatementTokens(unqualifiedEqualityCombinatorStatementTokens);
|
|
9
8
|
|
|
10
9
|
export default equalityCombinatorStatementNode;
|
|
11
|
-
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Combinator from "../combinator";
|
|
4
|
-
|
|
5
4
|
import bracketedCombinatorStatementNode from "../node/statement/combinator/bracketed";
|
|
5
|
+
import unqualifiedBracketedCombinatorStatementTokens from "../tokens/statement/combinator/bracketed";
|
|
6
|
+
|
|
7
|
+
import { nodeAsString } from "../utilities/string";
|
|
6
8
|
|
|
7
9
|
class BracketedCombinator extends Combinator {
|
|
8
10
|
static fromNothing() {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
+
const node = bracketedCombinatorStatementNode, ///
|
|
12
|
+
tokens = unqualifiedBracketedCombinatorStatementTokens, ///
|
|
13
|
+
string = nodeAsString(node, tokens),
|
|
14
|
+
statementNode = node, ///
|
|
15
|
+
bracketedCombinator = new BracketedCombinator(statementNode, string);
|
|
11
16
|
|
|
12
17
|
return bracketedCombinator;
|
|
13
18
|
}
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Combinator from "../combinator";
|
|
4
|
-
|
|
5
4
|
import equalityCombinatorStatementNode from "../node/statement/combinator/equality";
|
|
5
|
+
import unqualifiedEqualityCombinatorStatementTokens from "../tokens/statement/combinator/equality";
|
|
6
|
+
|
|
7
|
+
import { nodeAsString } from "../utilities/string";
|
|
6
8
|
|
|
7
9
|
class EqualityCombinator extends Combinator {
|
|
8
10
|
static fromNothing() {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
+
const node = equalityCombinatorStatementNode, ///
|
|
12
|
+
tokens = unqualifiedEqualityCombinatorStatementTokens, ///
|
|
13
|
+
string = nodeAsString(node, tokens),
|
|
14
|
+
statementNode = node, ///
|
|
15
|
+
equalityCombinator = new EqualityCombinator(statementNode, string);
|
|
11
16
|
|
|
12
17
|
return equalityCombinator;
|
|
13
18
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { STATEMENT_META_TYPE_NAME } from "../../../metaTypeNames";
|
|
4
|
+
import { unqualifiedStatementTokensFromStatementString } from "../../../utilities/tokens";
|
|
5
|
+
|
|
6
|
+
const bracketedCombinatorStatementString = `(${STATEMENT_META_TYPE_NAME})`;
|
|
7
|
+
|
|
8
|
+
const unqualifiedBracketedCombinatorStatementTokens = unqualifiedStatementTokensFromStatementString(bracketedCombinatorStatementString)
|
|
9
|
+
|
|
10
|
+
export default unqualifiedBracketedCombinatorStatementTokens;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { OBJECT_TYPE_NAME } from "../../../typeNames";
|
|
4
|
+
import { unqualifiedStatementTokensFromStatementString } from "../../../utilities/tokens";
|
|
5
|
+
|
|
6
|
+
const equalityCombinatorStatementString = `${OBJECT_TYPE_NAME} = ${OBJECT_TYPE_NAME}`;
|
|
7
|
+
|
|
8
|
+
const unqualifiedEqualityCombinatorStatementTokens = unqualifiedStatementTokensFromStatementString(equalityCombinatorStatementString);
|
|
9
|
+
|
|
10
|
+
export default unqualifiedEqualityCombinatorStatementTokens;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export function leastLineIndexFromNodeAndTokens(node, tokens) {
|
|
4
|
+
let leastLineIndex = undefined; ///
|
|
5
|
+
|
|
6
|
+
const firstSignificantToken = node.getFirstSignificantToken(),
|
|
7
|
+
firstSignificantTokenIndex = tokens.indexOf(firstSignificantToken);
|
|
8
|
+
|
|
9
|
+
let lineIndex = 0;
|
|
10
|
+
|
|
11
|
+
tokens.some((token, tokenIndex) => { ///
|
|
12
|
+
if (tokenIndex === firstSignificantTokenIndex) {
|
|
13
|
+
leastLineIndex = lineIndex; ///
|
|
14
|
+
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const tokenEndOfLineToken = token.isEndOfLineToken();
|
|
19
|
+
|
|
20
|
+
if (tokenEndOfLineToken) {
|
|
21
|
+
lineIndex += 1;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return leastLineIndex;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function greatestLineIndexFromNodeAndTokens(node, tokens) {
|
|
29
|
+
let greatestLineIndex = undefined; ///
|
|
30
|
+
|
|
31
|
+
const lastSignificantToken = node.getLastSignificantToken(),
|
|
32
|
+
lastSignificantTokenIndex = tokens.indexOf(lastSignificantToken);
|
|
33
|
+
|
|
34
|
+
let lineIndex = 0;
|
|
35
|
+
|
|
36
|
+
tokens.some((token, tokenIndex) => { ///
|
|
37
|
+
if (tokenIndex === lastSignificantTokenIndex) {
|
|
38
|
+
greatestLineIndex = lineIndex; ///
|
|
39
|
+
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tokenEndOfLineToken = token.isEndOfLineToken();
|
|
44
|
+
|
|
45
|
+
if (tokenEndOfLineToken) {
|
|
46
|
+
lineIndex += 1;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
return greatestLineIndex;
|
|
51
|
+
}
|
package/src/utilities/node.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { parsersUtilities } from "occam-custom-grammars";
|
|
4
4
|
|
|
5
5
|
import { nodeQuery } from "../utilities/query";
|
|
6
|
+
import { combinedCustomGrammarFromNothing } from "./customGrammar";
|
|
6
7
|
import { TYPE_RULE_NAME,
|
|
7
8
|
LABEL_RULE_NAME,
|
|
8
9
|
VARIABLE_RULE_NAME,
|
|
@@ -11,14 +12,16 @@ import { TYPE_RULE_NAME,
|
|
|
11
12
|
UNQUALIFIED_STATEMENT_RULE_NAME,
|
|
12
13
|
CONSTRUCTOR_DECLARATION_RULE_NAME,
|
|
13
14
|
UNQUALIFIED_METASTATEMENT_RULE_NAME } from "../ruleNames";
|
|
15
|
+
import { labelTokensFromLabelString,
|
|
16
|
+
constructorDeclarationTokensFromTermString,
|
|
17
|
+
variableDeclarationTokensFromVariableString,
|
|
18
|
+
unqualifiedStatementTokensFromStatementString,
|
|
19
|
+
metavariableDeclarationTokensFromMetavariableString,
|
|
20
|
+
unqualifiedMetastatementTokensFromMetastatementString } from "../utilities/tokens";
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const { florenceLexerFromCombinedCustomGrammar } = lexersUtilities,
|
|
18
|
-
{ florenceParserFromCombinedCustomGrammar } = parsersUtilities;
|
|
22
|
+
const { florenceParserFromCombinedCustomGrammar } = parsersUtilities;
|
|
19
23
|
|
|
20
24
|
const combinedCustomGrammar = combinedCustomGrammarFromNothing(),
|
|
21
|
-
florenceLexer = florenceLexerFromCombinedCustomGrammar(combinedCustomGrammar),
|
|
22
25
|
florenceParser = florenceParserFromCombinedCustomGrammar(combinedCustomGrammar);
|
|
23
26
|
|
|
24
27
|
const termNodeQuery = nodeQuery("/constructorDeclaration/term!"),
|
|
@@ -30,95 +33,169 @@ const termNodeQuery = nodeQuery("/constructorDeclaration/term!"),
|
|
|
30
33
|
metastatementNodeQuery = nodeQuery("/unqualifiedMetastatement/metastatement!");
|
|
31
34
|
|
|
32
35
|
export function termNodeFromTermString(termString, lexer, parser) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
`,
|
|
36
|
-
node = nodeFromContentAndRuleName(content, ruleName, lexer, parser),
|
|
37
|
-
constructorDeclarationNode = node, ///
|
|
38
|
-
termNode = termNodeQuery(constructorDeclarationNode);
|
|
36
|
+
const constructorDeclarationTokens = constructorDeclarationTokensFromTermString(termString, parser),
|
|
37
|
+
termNode = termNodeFromConstructorDeclarationTokens(constructorDeclarationTokens, parser);
|
|
39
38
|
|
|
40
39
|
return termNode;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
export function labelNodeFromLabelString(labelString, lexer, parser) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
node = nodeFromContentAndRuleName(content, ruleName, lexer, parser),
|
|
47
|
-
labelNode = node; ///
|
|
43
|
+
const labelTokens = labelTokensFromLabelString(labelString, lexer),
|
|
44
|
+
labelNode = labelNodeFromLabelTokens(labelTokens, parser);
|
|
48
45
|
|
|
49
46
|
return labelNode;
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
export function typeNodeFromVariableString(variableString, lexer, parser) {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
`,
|
|
56
|
-
node = nodeFromContentAndRuleName(content, ruleName, lexer, parser),
|
|
57
|
-
typeDeclarationNode = node, ///
|
|
58
|
-
typeNode = typeNodeQuery(typeDeclarationNode);
|
|
50
|
+
const variableDeclarationTokens = variableDeclarationTokensFromVariableString(variableString, lexer),
|
|
51
|
+
typeNode = typeNodeFromVariableVariableDeclarationTokens(variableDeclarationTokens, parser);
|
|
59
52
|
|
|
60
53
|
return typeNode;
|
|
61
54
|
}
|
|
62
55
|
|
|
63
56
|
export function variableNodeFromVariableString(variableString, lexer, parser) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
`,
|
|
67
|
-
node = nodeFromContentAndRuleName(content, ruleName, lexer, parser),
|
|
68
|
-
variableDeclarationNode = node, ///
|
|
69
|
-
variableNode = variableNodeQuery(variableDeclarationNode);
|
|
57
|
+
const variableTDeclarationTokens = variableDeclarationTokensFromVariableString(variableString, lexer),
|
|
58
|
+
variableNode = variableNodeFromVariableVariableTDeclarationTokens(variableTDeclarationTokens, parser);
|
|
70
59
|
|
|
71
60
|
return variableNode;
|
|
72
61
|
}
|
|
73
62
|
|
|
74
63
|
export function statementNodeFromStatementString(statementString, lexer, parser) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
`,
|
|
78
|
-
node = nodeFromContentAndRuleName(content, ruleName, lexer, parser),
|
|
79
|
-
unqualifiedStatementNode = node, ///
|
|
80
|
-
statementNode = statementNodeQuery(unqualifiedStatementNode);
|
|
64
|
+
const unqualifiedStatementTokens = unqualifiedStatementTokensFromStatementString(statementString, lexer),
|
|
65
|
+
statementNode = statementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser);
|
|
81
66
|
|
|
82
67
|
return statementNode;
|
|
83
68
|
}
|
|
84
69
|
|
|
85
70
|
export function metaTypeNodeFromMetavariableString(metavariableString, lexer, parser) {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
`,
|
|
89
|
-
node = nodeFromContentAndRuleName(content, ruleName, lexer, parser),
|
|
90
|
-
metaTypeDeclarationNode = node, ///
|
|
91
|
-
metaTypeNode = metaTypeNodeQuery(metaTypeDeclarationNode);
|
|
71
|
+
const metavariableDeclarationTokens = metavariableDeclarationTokensFromMetavariableString(metavariableString, lexer),
|
|
72
|
+
metaTypeNode = metaTypeNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser);
|
|
92
73
|
|
|
93
74
|
return metaTypeNode;
|
|
94
75
|
}
|
|
95
76
|
|
|
96
77
|
export function metavariableNodeFromMetavariableString(metavariableString, lexer, parser) {
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
`,
|
|
100
|
-
node = nodeFromContentAndRuleName(content, ruleName, lexer, parser),
|
|
101
|
-
metavariableDeclarationNode = node, ///
|
|
102
|
-
metavariableNode = metavariableNodeQuery(metavariableDeclarationNode);
|
|
78
|
+
const metavariableDeclarationTokens = metavariableDeclarationTokensFromMetavariableString(metavariableString, lexer),
|
|
79
|
+
metavariableNode = metavariableNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser);
|
|
103
80
|
|
|
104
81
|
return metavariableNode;
|
|
105
82
|
}
|
|
106
83
|
|
|
107
84
|
export function metastatementNodeFromMetastatementString(metastatementString, lexer, parser) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
85
|
+
const unqualifiedMetastatementTokens = unqualifiedMetastatementTokensFromMetastatementString(metastatementString, lexer),
|
|
86
|
+
metastatementNode = metastatementNodeFromUnqualifiedMetastatementTokens(unqualifiedMetastatementTokens, parser);
|
|
87
|
+
|
|
88
|
+
return metastatementNode;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function termNodeFromConstructorDeclarationTokens(constructorDeclarationTokens, parser) {
|
|
92
|
+
const constructorDeclarationNode = constructorDeclarationNodeFromConstructorDeclarationTokens(constructorDeclarationTokens, parser),
|
|
93
|
+
termNode = termNodeQuery(constructorDeclarationNode);
|
|
94
|
+
|
|
95
|
+
return termNode;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function statementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser) {
|
|
99
|
+
const unqualifiedStatementNode = unqualifiedStatementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser),
|
|
100
|
+
statementNode = statementNodeQuery(unqualifiedStatementNode);
|
|
101
|
+
|
|
102
|
+
return statementNode;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function typeNodeFromVariableVariableDeclarationTokens(variableDeclarationTokens, parser) {
|
|
106
|
+
const typeDeclarationNode = typeDeclarationNodeFromVariableDeclarationTokens(variableDeclarationTokens, parser),
|
|
107
|
+
typeNode = typeNodeQuery(typeDeclarationNode);
|
|
108
|
+
|
|
109
|
+
return typeNode;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function metaTypeNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser) {
|
|
113
|
+
const metaTypeDeclarationNode = metaTypeDeclarationNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser),
|
|
114
|
+
metaTypeNode = metaTypeNodeQuery(metaTypeDeclarationNode);
|
|
115
|
+
|
|
116
|
+
return metaTypeNode;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function metavariableNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser) {
|
|
120
|
+
const metavariableDeclarationNode = metavariableDeclarationNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser),
|
|
121
|
+
metavariableNode = metavariableNodeQuery(metavariableDeclarationNode);
|
|
122
|
+
|
|
123
|
+
return metavariableNode;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function variableNodeFromVariableVariableTDeclarationTokens(variableTDeclarationTokens, parser) {
|
|
127
|
+
const variableDeclarationNode = variableDeclarationNodeFromVariableTDeclarationTokens(variableTDeclarationTokens, parser),
|
|
128
|
+
variableNode = variableNodeQuery(variableDeclarationNode);
|
|
129
|
+
|
|
130
|
+
return variableNode;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function metastatementNodeFromUnqualifiedMetastatementTokens(unqualifiedMetastatementTokens, parser) {
|
|
134
|
+
const unqualifiedMetastatementNode = unqualifiedMetastatementNodeFromUnqualifiedMetastatementTokens(unqualifiedMetastatementTokens, parser),
|
|
113
135
|
metastatementNode = metastatementNodeQuery(unqualifiedMetastatementNode);
|
|
114
136
|
|
|
115
137
|
return metastatementNode;
|
|
116
138
|
}
|
|
117
139
|
|
|
118
|
-
function
|
|
140
|
+
export function labelNodeFromLabelTokens(labelTokens, parser) {
|
|
141
|
+
const ruleName = LABEL_RULE_NAME,
|
|
142
|
+
labelNode = nodeFromTokensRuleNameAndParser(labelTokens, ruleName, parser);
|
|
143
|
+
|
|
144
|
+
return labelNode;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function typeDeclarationNodeFromVariableDeclarationTokens(variableDeclarationTokens, parser) {
|
|
148
|
+
const ruleName = TYPE_RULE_NAME,
|
|
149
|
+
typeDeclarationNode = nodeFromTokensRuleNameAndParser(variableDeclarationTokens, ruleName, parser);
|
|
150
|
+
|
|
151
|
+
return typeDeclarationNode;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export function variableDeclarationNodeFromVariableTDeclarationTokens(variableTDeclarationTokens, parser) {
|
|
155
|
+
const ruleName = VARIABLE_RULE_NAME,
|
|
156
|
+
variableDeclarationNode = nodeFromTokensRuleNameAndParser(variableTDeclarationTokens, ruleName, parser);
|
|
157
|
+
|
|
158
|
+
return variableDeclarationNode;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function unqualifiedStatementNodeFromUnqualifiedStatementTokens(unqualifiedStatementTokens, parser) {
|
|
162
|
+
const ruleName = UNQUALIFIED_STATEMENT_RULE_NAME,
|
|
163
|
+
unqualifiedStatementNode = nodeFromTokensRuleNameAndParser(unqualifiedStatementTokens, ruleName, parser);
|
|
164
|
+
|
|
165
|
+
return unqualifiedStatementNode;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function metaTypeDeclarationNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser) {
|
|
169
|
+
const ruleName = META_TYPE_RULE_NAME,
|
|
170
|
+
metaTypeDeclarationNode = nodeFromTokensRuleNameAndParser(metavariableDeclarationTokens, ruleName, parser);
|
|
171
|
+
|
|
172
|
+
return metaTypeDeclarationNode;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function constructorDeclarationNodeFromConstructorDeclarationTokens(constructorDeclarationTokens, parser) {
|
|
176
|
+
const ruleName = CONSTRUCTOR_DECLARATION_RULE_NAME,
|
|
177
|
+
constructorDeclarationNode = nodeFromTokensRuleNameAndParser(constructorDeclarationTokens, ruleName, parser);
|
|
178
|
+
|
|
179
|
+
return constructorDeclarationNode;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function metavariableDeclarationNodeFromMetavariableDeclarationTokens(metavariableDeclarationTokens, parser) {
|
|
183
|
+
const ruleName = METAVARIABLE_RULE_NAME,
|
|
184
|
+
metavariableDeclarationNode = nodeFromTokensRuleNameAndParser(metavariableDeclarationTokens, ruleName, parser);
|
|
185
|
+
|
|
186
|
+
return metavariableDeclarationNode;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function unqualifiedMetastatementNodeFromUnqualifiedMetastatementTokens(unqualifiedMetastatementTokens, parser) {
|
|
190
|
+
const ruleName = UNQUALIFIED_METASTATEMENT_RULE_NAME,
|
|
191
|
+
unqualifiedMetastatementNode = nodeFromTokensRuleNameAndParser(unqualifiedMetastatementTokens, ruleName, parser);
|
|
192
|
+
|
|
193
|
+
return unqualifiedMetastatementNode;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function nodeFromTokensRuleNameAndParser(tokens, ruleName, parser = florenceParser) {
|
|
119
197
|
const ruleMap = parser.getRuleMap(),
|
|
120
198
|
rule = ruleMap[ruleName],
|
|
121
|
-
tokens = lexer.tokenise(content),
|
|
122
199
|
node = parser.parse(tokens, rule);
|
|
123
200
|
|
|
124
201
|
return node;
|
package/src/utilities/string.js
CHANGED
package/src/utilities/tokens.js
CHANGED
|
@@ -1,51 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
let leastLineIndex = undefined; ///
|
|
3
|
+
import { lexersUtilities } from "occam-custom-grammars";
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
firstSignificantTokenIndex = tokens.indexOf(firstSignificantToken);
|
|
5
|
+
import { combinedCustomGrammarFromNothing } from "./customGrammar";
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
const { florenceLexerFromCombinedCustomGrammar } = lexersUtilities;
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
leastLineIndex = lineIndex; ///
|
|
9
|
+
const combinedCustomGrammar = combinedCustomGrammarFromNothing(),
|
|
10
|
+
florenceLexer = florenceLexerFromCombinedCustomGrammar(combinedCustomGrammar);
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
export function labelTokensFromLabelString(labelString, lexer) {
|
|
13
|
+
const labelContent = `${labelString}`,
|
|
14
|
+
labelTokens = tokensFromContentAndLexer(labelContent, lexer);
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
return labelTokens;
|
|
17
|
+
}
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export function constructorDeclarationTokensFromTermString(termString, lexer) {
|
|
20
|
+
const constructorDeclarationContent = `Constructor ${termString}
|
|
21
|
+
`,
|
|
22
|
+
constructorDeclarationTokens = tokensFromContentAndLexer(constructorDeclarationContent, lexer);
|
|
24
23
|
|
|
25
|
-
return
|
|
24
|
+
return constructorDeclarationTokens;
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
export function
|
|
29
|
-
|
|
27
|
+
export function variableDeclarationTokensFromVariableString(variableString, lexer) {
|
|
28
|
+
const variableDeclarationContent = `Variable ${variableString}
|
|
29
|
+
`,
|
|
30
|
+
variableDeclarationTokens = tokensFromContentAndLexer(variableDeclarationContent, lexer);
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
return variableDeclarationTokens;
|
|
33
|
+
}
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
export function unqualifiedStatementTokensFromStatementString(statementString, lexer) {
|
|
36
|
+
const unqualifiedStatementContent = `${statementString}
|
|
37
|
+
`,
|
|
38
|
+
unqualifiedStatementTokens = tokensFromContentAndLexer(unqualifiedStatementContent, lexer);
|
|
35
39
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
greatestLineIndex = lineIndex; ///
|
|
40
|
+
return unqualifiedStatementTokens;
|
|
41
|
+
}
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
export function metavariableDeclarationTokensFromMetavariableString(metavariableString, lexer) {
|
|
44
|
+
const metavariableDeclarationContent = `Metavariable ${metavariableString}
|
|
45
|
+
`,
|
|
46
|
+
metavariableDeclarationTokens = tokensFromContentAndLexer(metavariableDeclarationContent, lexer);
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
return metavariableDeclarationTokens;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function unqualifiedMetastatementTokensFromMetastatementString(metastatementString, lexer) {
|
|
52
|
+
const unqualifiedMetastatementContent = `${metastatementString}
|
|
53
|
+
`,
|
|
54
|
+
unqualifiedMetastatementTokens = tokensFromContentAndLexer(unqualifiedMetastatementContent, lexer);
|
|
55
|
+
|
|
56
|
+
return unqualifiedMetastatementTokens;
|
|
57
|
+
}
|
|
44
58
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
});
|
|
59
|
+
function tokensFromContentAndLexer(content, lexer = florenceLexer) {
|
|
60
|
+
const tokens = lexer.tokenise(content);
|
|
49
61
|
|
|
50
|
-
return
|
|
62
|
+
return tokens;
|
|
51
63
|
}
|
|
@@ -22,7 +22,7 @@ export default function verifyTypeAssertion(typeAssertionNode, assignments, deri
|
|
|
22
22
|
typePresent = context.isTypePresentByTypeName(typeName);
|
|
23
23
|
|
|
24
24
|
if (!typePresent) {
|
|
25
|
-
context.error(`The ${typeName} type is not present.`, typeAssertionNode);
|
|
25
|
+
context.error(`The '${typeName}' type is not present.`, typeAssertionNode);
|
|
26
26
|
} else {
|
|
27
27
|
if (!typeAssertionVerified) {
|
|
28
28
|
const variableTypeAssertionVerified = verifyVariableTypeAssertion(typeAssertionNode, assignments, derived, context);
|
|
@@ -60,6 +60,10 @@ export const metastatementVerifier = new MetastatementVerifier();
|
|
|
60
60
|
export default function verifyMetastatement(metastatementNode, derived, metaproofContext) {
|
|
61
61
|
let metastatementVerified = false;
|
|
62
62
|
|
|
63
|
+
const metastatementString = metaproofContext.nodeAsString(metastatementNode);
|
|
64
|
+
|
|
65
|
+
metaproofContext.debug(`Verifying the '${metastatementString}' metastatement...`, metastatementNode);
|
|
66
|
+
|
|
63
67
|
if (!metastatementVerified) {
|
|
64
68
|
const nonTerminalNodeA = metastatementNode, ///
|
|
65
69
|
nonTerminalNodeB = metastatementNode, ///
|
|
@@ -68,5 +72,9 @@ export default function verifyMetastatement(metastatementNode, derived, metaproo
|
|
|
68
72
|
metastatementVerified = nonTerminalNodeVerified; ///
|
|
69
73
|
}
|
|
70
74
|
|
|
75
|
+
if (metastatementVerified) {
|
|
76
|
+
metaproofContext.debug(`Verified the '${metastatementString}' metastatement.`, metastatementNode);
|
|
77
|
+
}
|
|
78
|
+
|
|
71
79
|
return metastatementVerified;
|
|
72
80
|
}
|