occam-furtle 3.0.378 → 3.0.381

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "occam-furtle",
3
3
  "author": "James Smith",
4
- "version": "3.0.378",
4
+ "version": "3.0.381",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/occam-furtle",
7
7
  "description": "Occam's Furtle language.",
@@ -11,8 +11,8 @@
11
11
  },
12
12
  "dependencies": {
13
13
  "necessary": "^17.5.2",
14
- "occam-grammars": "^1.3.630",
15
- "occam-languages": "^1.0.33",
14
+ "occam-grammars": "^1.3.632",
15
+ "occam-languages": "^1.0.34",
16
16
  "occam-lexers": "^23.2.2",
17
17
  "occam-parsers": "^23.2.4",
18
18
  "occam-query": "^4.1.198"
@@ -28,8 +28,8 @@
28
28
  "juxtapose": "^4.0.143",
29
29
  "lively-cli": "^3.0.3",
30
30
  "occam-grammar-utilities": "^8.1.17",
31
- "occam-model": "^1.0.560",
32
- "occam-server": "^7.0.60",
31
+ "occam-model": "^1.0.561",
32
+ "occam-server": "^7.0.61",
33
33
  "watchful-cli": "^1.7.102"
34
34
  },
35
35
  "scripts": {
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ import { Element } from "occam-languages";
4
+ import { stringUtilities } from "necessary";
5
+
6
+ import Exception from "../exception";
7
+
8
+ import { define } from "../elements";
9
+ import { STRING_TYPE_NAME } from "../typeNames";
10
+ import { valueFromBoolean } from "../utilities/value";
11
+
12
+ const { indexOf } = stringUtilities;
13
+
14
+ export default define(class Contains extends Element {
15
+ constructor(context, string, node, breakPoint, variable, substring) {
16
+ super(context, string, node, breakPoint);
17
+
18
+ this.variable = variable;
19
+ this.substring = substring;
20
+ }
21
+
22
+ getVariable() {
23
+ return this.variable;
24
+ }
25
+
26
+ getSubstring() {
27
+ return this.substring;
28
+ }
29
+
30
+ evaluate(context) {
31
+ let value;
32
+
33
+ const containsString = this.getString(); ///
34
+
35
+ context.trace(`Evaluating the '${containsString}' function...`);
36
+
37
+ value = this.variable.evaluate(context);
38
+
39
+ const valueType = value.getType(),
40
+ valueTypeStringType = valueType.isStringType();
41
+
42
+ if (!valueTypeStringType) {
43
+ const valueString = value.getString(),
44
+ message = `The '${valueString}' value's '${valueType}' type should be '${STRING_TYPE_NAME}'.`,
45
+ exception = Exception.fromMessage(message);
46
+
47
+ throw exception;
48
+ }
49
+
50
+ const string = value.getString(),
51
+ boolean = string.contains(this.substring);
52
+
53
+ value = valueFromBoolean(boolean);
54
+
55
+ const valueString = value.getString();
56
+
57
+ context.debug(`...evaluated the '${containsString}' function as '${valueString}'.`);
58
+
59
+ return value;
60
+ }
61
+
62
+ static name = "Contains";
63
+ });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ import { Element } from "occam-languages";
4
+
5
+ import Exception from "../exception";
6
+
7
+ import { define } from "../elements";
8
+ import { STRING_TYPE_NAME } from "../typeNames";
9
+ import { valueFromBoolean } from "../utilities/value";
10
+
11
+ export default define(class EndsWith extends Element {
12
+ constructor(context, string, node, breakPoint, variable, substring) {
13
+ super(context, string, node, breakPoint);
14
+
15
+ this.variable = variable;
16
+ this.substring = substring;
17
+ }
18
+
19
+ getVariable() {
20
+ return this.variable;
21
+ }
22
+
23
+ getSubstring() {
24
+ return this.substring;
25
+ }
26
+
27
+ evaluate(context) {
28
+ let value;
29
+
30
+ const endsWithString = this.getString(); ///
31
+
32
+ context.trace(`Evaluating the '${endsWithString}' function...`);
33
+
34
+ value = this.variable.evaluate(context);
35
+
36
+ const valueType = value.getType(),
37
+ valueTypeStringType = valueType.isStringType();
38
+
39
+ if (!valueTypeStringType) {
40
+ const valueString = value.getString(),
41
+ message = `The '${valueString}' value's '${valueType}' type should be '${STRING_TYPE_NAME}'.`,
42
+ exception = Exception.fromMessage(message);
43
+
44
+ throw exception;
45
+ }
46
+
47
+ const string = value.getString(),
48
+ boolean = string.endsWith(this.substring);
49
+
50
+ value = valueFromBoolean(boolean);
51
+
52
+ const valueString = value.getString();
53
+
54
+ context.debug(`...evaluated the '${endsWithString}' function as '${valueString}'.`);
55
+
56
+ return value;
57
+ }
58
+
59
+ static name = "EndsWith";
60
+ });
@@ -5,7 +5,7 @@ import { Element } from "occam-languages";
5
5
  import { define } from "../elements";
6
6
 
7
7
  export default define(class Expression extends Element {
8
- constructor(context, string, node, breakPoint, term, some, every, reduce, ternary, nodeQuery, nodesQuery, lengthOf, toInteger, tryInteger, returnBlock, procedureCall) {
8
+ constructor(context, string, node, breakPoint, term, some, every, reduce, ternary, nodeQuery, nodesQuery, lengthOf, toInteger, tryInteger, contains, endsWith, startsWith, returnBlock, procedureCall) {
9
9
  super(context, string, node, breakPoint);
10
10
 
11
11
  this.term = term;
@@ -18,6 +18,9 @@ export default define(class Expression extends Element {
18
18
  this.lengthOf = lengthOf;
19
19
  this.toInteger = toInteger;
20
20
  this.tryInteger = tryInteger;
21
+ this.contains = contains;
22
+ this.endsWith = endsWith;
23
+ this.startsWith = startsWith;
21
24
  this.returnBlock = returnBlock;
22
25
  this.procedureCall = procedureCall;
23
26
  }
@@ -62,6 +65,18 @@ export default define(class Expression extends Element {
62
65
  return this.tryInteger;
63
66
  }
64
67
 
68
+ getContains() {
69
+ return this.contains;
70
+ }
71
+
72
+ getEndsWith() {
73
+ return this.endsWith;
74
+ }
75
+
76
+ getStartsWith() {
77
+ return this.startsWith;
78
+ }
79
+
65
80
  getReturnBlock() {
66
81
  return this.returnBlock;
67
82
  }
@@ -95,6 +110,12 @@ export default define(class Expression extends Element {
95
110
  type = this.toInteger.getType();
96
111
  } else if (this.tryInteger !== null) {
97
112
  type = this.tryInteger.getType();
113
+ } else if (this.contains !== null) {
114
+ type = this.contains.getType();
115
+ } else if (this.endsWith !== null) {
116
+ type = this.endsWith.getType();
117
+ } else if (this.startsWith !== null) {
118
+ type = this.startsWith.getType();
98
119
  } else if (this.returnBlock !== null) {
99
120
  type = this.returnBlock.getType();
100
121
  } else if (this.procedureCall !== null) {
@@ -121,6 +142,12 @@ export default define(class Expression extends Element {
121
142
  value = this.toInteger.evaluate(context);
122
143
  } else if (this.tryInteger !== null) {
123
144
  value = this.tryInteger.evaluate(context);
145
+ } else if (this.contains !== null) {
146
+ value = this.contains.evaluate(context);
147
+ } else if (this.endsWith !== null) {
148
+ value = this.endsWith.evaluate(context);
149
+ } else if (this.startsWith !== null) {
150
+ value = this.startsWith.evaluate(context);
124
151
  } else if (this.some !== null) {
125
152
  value = await this.some.evaluate(context);
126
153
  } else if (this.every !== null) {
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ import { Element } from "occam-languages";
4
+
5
+ import Exception from "../exception";
6
+
7
+ import { define } from "../elements";
8
+ import { STRING_TYPE_NAME } from "../typeNames";
9
+ import { valueFromBoolean } from "../utilities/value";
10
+
11
+ export default define(class StartsWith extends Element {
12
+ constructor(context, string, node, breakPoint, variable, substring) {
13
+ super(context, string, node, breakPoint);
14
+
15
+ this.variable = variable;
16
+ this.substring = substring;
17
+ }
18
+
19
+ getVariable() {
20
+ return this.variable;
21
+ }
22
+
23
+ getSubstring() {
24
+ return this.substring;
25
+ }
26
+
27
+ evaluate(context) {
28
+ let value;
29
+
30
+ const startsWithString = this.getString(); ///
31
+
32
+ context.trace(`Evaluating the '${startsWithString}' function...`);
33
+
34
+ value = this.variable.evaluate(context);
35
+
36
+ const valueType = value.getType(),
37
+ valueTypeStringType = valueType.isStringType();
38
+
39
+ if (!valueTypeStringType) {
40
+ const valueString = value.getString(),
41
+ message = `The '${valueString}' value's '${valueType}' type should be '${STRING_TYPE_NAME}'.`,
42
+ exception = Exception.fromMessage(message);
43
+
44
+ throw exception;
45
+ }
46
+
47
+ const string = value.getString(),
48
+ boolean = string.startsWith(this.substring);
49
+
50
+ value = valueFromBoolean(boolean);
51
+
52
+ const valueString = value.getString();
53
+
54
+ context.debug(`...evaluated the '${startsWithString}' function as '${valueString}'.`);
55
+
56
+ return value;
57
+ }
58
+
59
+ static name = "StartsWith";
60
+ });
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ import { NonTerminalNode } from "occam-languages";
4
+
5
+ import { VARIABLE_RULE_NAME } from "../ruleNames";
6
+ import { stringFromStringLiteral } from "../utilities/stringLiteral";
7
+ import { STRING_LITERAL_TOKEN_TYPE } from "../tokenTypes";
8
+
9
+ export default class ContainsNode extends NonTerminalNode {
10
+ getString() {
11
+ const stringLiteral = this.getStringLiteral(),
12
+ string = stringFromStringLiteral(stringLiteral);
13
+
14
+ return string;
15
+ }
16
+
17
+ getStringLiteral() {
18
+ let stringLiteral;
19
+
20
+ const tokenType = STRING_LITERAL_TOKEN_TYPE;
21
+
22
+ this.someTerminalNode((terminalNode) => {
23
+ const content = terminalNode.getContent();
24
+
25
+ stringLiteral = content; ///
26
+
27
+ return true;
28
+ }, tokenType);
29
+
30
+ return stringLiteral;
31
+ }
32
+
33
+ getVariableNode() {
34
+ const ruleName = VARIABLE_RULE_NAME,
35
+ variableNode = this.getNodeByRuleName(ruleName);
36
+
37
+ return variableNode;
38
+ }
39
+
40
+ static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return NonTerminalNode.fromRuleNameChildNodesOpacityAndPrecedence(ContainsNode, ruleName, childNodes, opacity, precedence); }
41
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ import { NonTerminalNode } from "occam-languages";
4
+
5
+ import { VARIABLE_RULE_NAME } from "../ruleNames";
6
+ import { stringFromStringLiteral } from "../utilities/stringLiteral";
7
+ import { STRING_LITERAL_TOKEN_TYPE } from "../tokenTypes";
8
+
9
+ export default class EndsWithNode extends NonTerminalNode {
10
+ getString() {
11
+ const stringLiteral = this.getStringLiteral(),
12
+ string = stringFromStringLiteral(stringLiteral);
13
+
14
+ return string;
15
+ }
16
+
17
+ getStringLiteral() {
18
+ let stringLiteral;
19
+
20
+ const tokenType = STRING_LITERAL_TOKEN_TYPE;
21
+
22
+ this.someTerminalNode((terminalNode) => {
23
+ const content = terminalNode.getContent();
24
+
25
+ stringLiteral = content; ///
26
+
27
+ return true;
28
+ }, tokenType);
29
+
30
+ return stringLiteral;
31
+ }
32
+
33
+ getVariableNode() {
34
+ const ruleName = VARIABLE_RULE_NAME,
35
+ variableNode = this.getNodeByRuleName(ruleName);
36
+
37
+ return variableNode;
38
+ }
39
+
40
+ static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return NonTerminalNode.fromRuleNameChildNodesOpacityAndPrecedence(EndsWithNode, ruleName, childNodes, opacity, precedence); }
41
+ }
@@ -7,11 +7,14 @@ import { TERM_RULE_NAME,
7
7
  EVERY_RULE_NAME,
8
8
  REDUCE_RULE_NAME,
9
9
  TERNARY_RULE_NAME,
10
+ CONTAINS_RULE_NAME,
10
11
  LENGTH_OF_RULE_NAME,
12
+ ENDS_WITH_RULE_NAME,
11
13
  TO_INTEGER_RULE_NAME,
12
14
  NODE_QUERY_RULE_NAME,
13
15
  TRY_INTEGER_RULE_NAME,
14
16
  NODES_QUERY_RULE_NAME,
17
+ STARTS_WITH_RULE_NAME,
15
18
  RETURN_BLOCK_RULE_NAME,
16
19
  PROCEDURE_CALL_RULE_NAME } from "../ruleNames";
17
20
 
@@ -46,11 +49,25 @@ export default class ExpressionNode extends NonTerminalNode {
46
49
 
47
50
  getTernaryNode() {
48
51
  const ruleName = TERNARY_RULE_NAME,
49
- ternaryNode = this.getNodeByRuleName(ruleName);
52
+ ternaryNode = this.getNodeByRuleName(ruleName);
50
53
 
51
54
  return ternaryNode;
52
55
  }
53
56
 
57
+ getContainsNode() {
58
+ const ruleName = CONTAINS_RULE_NAME,
59
+ containsNode = this.getNodeByRuleName(ruleName);
60
+
61
+ return containsNode;
62
+ }
63
+
64
+ getEndsWithNode() {
65
+ const ruleName = ENDS_WITH_RULE_NAME,
66
+ endsWithNode = this.getNodeByRuleName(ruleName);
67
+
68
+ return endsWithNode;
69
+ }
70
+
54
71
  getLengthOfNode() {
55
72
  const ruleName = LENGTH_OF_RULE_NAME,
56
73
  lengthOfNode = this.getNodeByRuleName(ruleName);
@@ -72,6 +89,13 @@ export default class ExpressionNode extends NonTerminalNode {
72
89
  return toIntegerNode;
73
90
  }
74
91
 
92
+ getStartsWithNode() {
93
+ const ruleName = STARTS_WITH_RULE_NAME,
94
+ startsWithNode = this.getNodeByRuleName(ruleName);
95
+
96
+ return startsWithNode;
97
+ }
98
+
75
99
  getNodesQueryNode() {
76
100
  const ruleName = NODES_QUERY_RULE_NAME,
77
101
  nodeSQueryNode = this.getNodeByRuleName(ruleName);
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ import { NonTerminalNode } from "occam-languages";
4
+
5
+ import { VARIABLE_RULE_NAME } from "../ruleNames";
6
+ import { stringFromStringLiteral } from "../utilities/stringLiteral";
7
+ import { STRING_LITERAL_TOKEN_TYPE } from "../tokenTypes";
8
+
9
+ export default class StartsWithNode extends NonTerminalNode {
10
+ getString() {
11
+ const stringLiteral = this.getStringLiteral(),
12
+ string = stringFromStringLiteral(stringLiteral);
13
+
14
+ return string;
15
+ }
16
+
17
+ getStringLiteral() {
18
+ let stringLiteral;
19
+
20
+ const tokenType = STRING_LITERAL_TOKEN_TYPE;
21
+
22
+ this.someTerminalNode((terminalNode) => {
23
+ const content = terminalNode.getContent();
24
+
25
+ stringLiteral = content; ///
26
+
27
+ return true;
28
+ }, tokenType);
29
+
30
+ return stringLiteral;
31
+ }
32
+
33
+ getVariableNode() {
34
+ const ruleName = VARIABLE_RULE_NAME,
35
+ variableNode = this.getNodeByRuleName(ruleName);
36
+
37
+ return variableNode;
38
+ }
39
+
40
+ static fromRuleNameChildNodesOpacityAndPrecedence(ruleName, childNodes, opacity, precedence) { return NonTerminalNode.fromRuleNameChildNodesOpacityAndPrecedence(StartsWithNode, ruleName, childNodes, opacity, precedence); }
41
+ }
@@ -17,6 +17,8 @@ import DocumentNode from "./node/document";
17
17
  import VariableNode from "./node/variable";
18
18
  import NonsenseNode from "./node/nonsense";
19
19
  import LengthOfNode from "./node/lengthOf";
20
+ import ContainsNode from "./node/contains";
21
+ import EndsWithNode from "./node/endsWith";
20
22
  import PrimitiveNode from "./node/primitive";
21
23
  import ReferenceNode from "./node/reference";
22
24
  import ParameterNode from "./node/parameter";
@@ -24,6 +26,7 @@ import StatementNode from "./node/statement";
24
26
  import NodeQueryNode from "./node/nodeQuery";
25
27
  import ToIntegerNode from "./node/toInteger";
26
28
  import ProcedureNode from "./node/procedure";
29
+ import StartsWithNode from "./node/startsWith";
27
30
  import TryIntegerNode from "./node/tryInteger";
28
31
  import NodesQueryNode from "./node/nodesQuery";
29
32
  import ExpressionNode from "./node/expression";
@@ -59,6 +62,8 @@ import { SOME_RULE_NAME,
59
62
  DOCUMENT_RULE_NAME,
60
63
  VARIABLE_RULE_NAME,
61
64
  NONSENSE_RULE_NAME,
65
+ CONTAINS_RULE_NAME,
66
+ ENDS_WITH_RULE_NAME,
62
67
  LENGTH_OF_RULE_NAME,
63
68
  PRIMITIVE_RULE_NAME,
64
69
  REFERENCE_RULE_NAME,
@@ -71,6 +76,7 @@ import { SOME_RULE_NAME,
71
76
  TO_INTEGER_RULE_NAME,
72
77
  TRY_INTEGER_RULE_NAME,
73
78
  NODES_QUERY_RULE_NAME,
79
+ STARTS_WITH_RULE_NAME,
74
80
  RETURN_BLOCK_RULE_NAME,
75
81
  LOGICAL_TERM_RULE_NAME,
76
82
  NEGATED_TERM_RULE_NAME,
@@ -102,7 +108,9 @@ const NonTerminalNodeMap = {
102
108
  [BINDINGS_RULE_NAME]: BindingsNode,
103
109
  [VARIABLE_RULE_NAME]: VariableNode,
104
110
  [NONSENSE_RULE_NAME]: NonsenseNode,
111
+ [CONTAINS_RULE_NAME]: ContainsNode,
105
112
  [DOCUMENT_RULE_NAME]: DocumentNode,
113
+ [ENDS_WITH_RULE_NAME]: EndsWithNode,
106
114
  [LENGTH_OF_RULE_NAME]: LengthOfNode,
107
115
  [PRIMITIVE_RULE_NAME]: PrimitiveNode,
108
116
  [REFERENCE_RULE_NAME]: ReferenceNode,
@@ -113,6 +121,7 @@ const NonTerminalNodeMap = {
113
121
  [NODE_QUERY_RULE_NAME]: NodeQueryNode,
114
122
  [EXPRESSION_RULE_NAME]: ExpressionNode,
115
123
  [PARAMETERS_RULE_NAME]: ParametersNode,
124
+ [STARTS_WITH_RULE_NAME]: StartsWithNode,
116
125
  [TRY_INTEGER_RULE_NAME]: TryIntegerNode,
117
126
  [NODES_QUERY_RULE_NAME]: NodesQueryNode,
118
127
  [RETURN_BLOCK_RULE_NAME]: ReturnBlockNode,
package/src/preamble.js CHANGED
@@ -15,6 +15,8 @@ import Binding from "./element/binding";
15
15
  import Bindings from "./element/bindings";
16
16
  import Variable from "./element/variable";
17
17
  import LengthOf from "./element/lengthOf";
18
+ import Contains from "./element/contains";
19
+ import EndsWith from "./element/endsWith";
18
20
  import Primitive from "./element/primitive";
19
21
  import Reference from "./element/reference";
20
22
  import Procedure from "./element/procedure";
@@ -22,6 +24,7 @@ import NodeQuery from "./element/nodeQuery";
22
24
  import Parameter from "./element/parameter";
23
25
  import ToInteger from "./element/toInteger";
24
26
  import Statement from "./element/statement";
27
+ import StartsWith from "./element/startsWith";
25
28
  import TryInteger from "./element/tryInteger";
26
29
  import Parameters from "./element/parameters";
27
30
  import NodesQuery from "./element/nodesQuery";
package/src/ruleNames.js CHANGED
@@ -16,16 +16,19 @@ export const VARIABLE_RULE_NAME = "variable";
16
16
  export const NONSENSE_RULE_NAME = "nonsense";
17
17
  export const DOCUMENT_RULE_NAME = "document";
18
18
  export const BINDINGS_RULE_NAME = "bindings";
19
+ export const CONTAINS_RULE_NAME = "contains";
19
20
  export const STATEMENT_RULE_NAME = "statement";
20
21
  export const PROCEDURE_RULE_NAME = "procedure";
21
22
  export const LENGTH_OF_RULE_NAME = "lengthOf";
22
23
  export const PRIMITIVE_RULE_NAME = "primitive";
23
24
  export const REFERENCE_RULE_NAME = "reference";
24
25
  export const PARAMETER_RULE_NAME = "parameter";
26
+ export const ENDS_WITH_RULE_NAME = "endsWith";
25
27
  export const NODE_QUERY_RULE_NAME = "nodeQuery";
26
28
  export const EXPRESSION_RULE_NAME = "expression";
27
29
  export const PARAMETERS_RULE_NAME = "parameters";
28
30
  export const TO_INTEGER_RULE_NAME = "toInteger";
31
+ export const STARTS_WITH_RULE_NAME = "startsWith";
29
32
  export const TRY_INTEGER_RULE_NAME = "tryInteger";
30
33
  export const NODES_QUERY_RULE_NAME = "nodesQuery";
31
34
  export const RETURN_BLOCK_RULE_NAME = "returnBlock";
@@ -42,4 +45,3 @@ export const OBJECT_ASSIGNMENT_RULE_NAME = "objectAssignment";
42
45
  export const VARIABLE_ASSIGNMENT_RULE_NAME = "variableAssignment";
43
46
  export const ANONYMOUS_PROCEDURE_RULE_NAME = "anonymousProcedure";
44
47
  export const VARIABLE_ASSIGNMENTS_RULE_NAME = "variableAssignments";
45
-