greybel-interpreter 2.1.9 → 2.2.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.
@@ -13,6 +13,7 @@ export interface ProcessorHandler {
13
13
  export declare const GenericProcessorHandler: ProcessorHandler;
14
14
  export declare const NumberProcessorHandler: ProcessorHandler;
15
15
  export declare const multiplyString: (a: CustomValue, b: CustomValue) => CustomValue;
16
+ export declare const minusString: (a: CustomValue, b: CustomValue) => CustomValue;
16
17
  export declare const StringProcessorHandler: ProcessorHandler;
17
18
  export declare const multiplyList: (a: CustomList, b: CustomValue) => CustomValue;
18
19
  export declare const divideList: (a: CustomList, b: CustomValue) => CustomValue;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.Evaluate = exports.handle = exports.handleFunction = exports.handleNil = exports.handleInterface = exports.handleMap = exports.handleList = exports.handleString = exports.handleNumber = exports.FunctionProcessorHandler = exports.NilProcessorHandler = exports.InterfaceProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.divideList = exports.multiplyList = exports.StringProcessorHandler = exports.multiplyString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
12
+ exports.Evaluate = exports.handle = exports.handleFunction = exports.handleNil = exports.handleInterface = exports.handleMap = exports.handleList = exports.handleString = exports.handleNumber = exports.FunctionProcessorHandler = exports.NilProcessorHandler = exports.InterfaceProcessorHandler = exports.MapProcessorHandler = exports.ListProcessorHandler = exports.divideList = exports.multiplyList = exports.StringProcessorHandler = exports.minusString = exports.multiplyString = exports.NumberProcessorHandler = exports.GenericProcessorHandler = void 0;
13
13
  const greyscript_core_1 = require("greyscript-core");
14
14
  const boolean_1 = require("../types/boolean");
15
15
  const default_1 = require("../types/default");
@@ -50,14 +50,24 @@ const multiplyString = (a, b) => {
50
50
  return new string_1.CustomString(multiStr);
51
51
  };
52
52
  exports.multiplyString = multiplyString;
53
+ const minusString = (a, b) => {
54
+ const origin = a.toString();
55
+ const toRemove = b.toString();
56
+ if (origin.endsWith(toRemove)) {
57
+ return new string_1.CustomString(origin.substring(0, origin.length - toRemove.length));
58
+ }
59
+ return new string_1.CustomString(origin);
60
+ };
61
+ exports.minusString = minusString;
53
62
  exports.StringProcessorHandler = {
54
63
  [greyscript_core_1.Operator.Plus]: (a, b) => new string_1.CustomString(a.toString() + b.toString()),
64
+ [greyscript_core_1.Operator.Minus]: (a, b) => (0, exports.minusString)(a, b),
55
65
  [greyscript_core_1.Operator.Asterik]: (a, b) => (0, exports.multiplyString)(a, b),
56
- [greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.CustomBoolean(a.toString().length < b.toString().length),
57
- [greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.CustomBoolean(a.toString().length > b.toString().length),
58
- [greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString().length >= b.toString().length),
66
+ [greyscript_core_1.Operator.LessThan]: (a, b) => new boolean_1.CustomBoolean(a.toString() < b.toString()),
67
+ [greyscript_core_1.Operator.GreaterThan]: (a, b) => new boolean_1.CustomBoolean(a.toString() > b.toString()),
68
+ [greyscript_core_1.Operator.GreaterThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() >= b.toString()),
59
69
  [greyscript_core_1.Operator.Equal]: (a, b) => new boolean_1.CustomBoolean(a.toString() === b.toString()),
60
- [greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString().length <= b.toString().length),
70
+ [greyscript_core_1.Operator.LessThanOrEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() <= b.toString()),
61
71
  [greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a.toString() !== b.toString())
62
72
  };
63
73
  const multiplyList = (a, b) => {
@@ -93,36 +103,12 @@ exports.ListProcessorHandler = {
93
103
  }
94
104
  return left;
95
105
  },
96
- [greyscript_core_1.Operator.LessThan]: (left, right) => {
97
- if (right instanceof list_1.CustomList) {
98
- return new boolean_1.CustomBoolean(left.value.length < right.value.length);
99
- }
100
- return default_1.DefaultType.Void;
101
- },
102
- [greyscript_core_1.Operator.GreaterThan]: (left, right) => {
103
- if (right instanceof list_1.CustomList) {
104
- return new boolean_1.CustomBoolean(left.value.length > right.value.length);
105
- }
106
- return default_1.DefaultType.Void;
107
- },
108
- [greyscript_core_1.Operator.GreaterThanOrEqual]: (left, right) => {
109
- if (right instanceof list_1.CustomList) {
110
- return new boolean_1.CustomBoolean(left.value.length >= right.value.length);
111
- }
112
- return default_1.DefaultType.Void;
113
- },
114
106
  [greyscript_core_1.Operator.Equal]: (left, right) => {
115
107
  if (right instanceof list_1.CustomList) {
116
108
  return new boolean_1.CustomBoolean((0, deep_equal_1.deepEqual)(left, right));
117
109
  }
118
110
  return default_1.DefaultType.Void;
119
111
  },
120
- [greyscript_core_1.Operator.LessThanOrEqual]: (left, right) => {
121
- if (right instanceof list_1.CustomList) {
122
- return new boolean_1.CustomBoolean(left.value.length <= right.value.length);
123
- }
124
- return default_1.DefaultType.Void;
125
- },
126
112
  [greyscript_core_1.Operator.NotEqual]: (left, right) => {
127
113
  if (right instanceof list_1.CustomList) {
128
114
  return new boolean_1.CustomBoolean(!(0, deep_equal_1.deepEqual)(left, right));
@@ -139,36 +125,12 @@ exports.MapProcessorHandler = {
139
125
  }
140
126
  return left;
141
127
  },
142
- [greyscript_core_1.Operator.LessThan]: (left, right) => {
143
- if (right instanceof map_1.CustomMap) {
144
- return new boolean_1.CustomBoolean(left.value.size < right.value.size);
145
- }
146
- return default_1.DefaultType.Void;
147
- },
148
- [greyscript_core_1.Operator.GreaterThan]: (left, right) => {
149
- if (right instanceof map_1.CustomMap) {
150
- return new boolean_1.CustomBoolean(left.value.size > right.value.size);
151
- }
152
- return default_1.DefaultType.Void;
153
- },
154
- [greyscript_core_1.Operator.GreaterThanOrEqual]: (left, right) => {
155
- if (right instanceof map_1.CustomMap) {
156
- return new boolean_1.CustomBoolean(left.value.size >= right.value.size);
157
- }
158
- return default_1.DefaultType.Void;
159
- },
160
128
  [greyscript_core_1.Operator.Equal]: (left, right) => {
161
129
  if (right instanceof map_1.CustomMap) {
162
130
  return new boolean_1.CustomBoolean((0, deep_equal_1.deepEqual)(left, right));
163
131
  }
164
132
  return default_1.DefaultType.Void;
165
133
  },
166
- [greyscript_core_1.Operator.LessThanOrEqual]: (left, right) => {
167
- if (right instanceof map_1.CustomMap) {
168
- return new boolean_1.CustomBoolean(left.value.size <= right.value.size);
169
- }
170
- return default_1.DefaultType.Void;
171
- },
172
134
  [greyscript_core_1.Operator.NotEqual]: (left, right) => {
173
135
  if (right instanceof map_1.CustomMap) {
174
136
  return new boolean_1.CustomBoolean(!(0, deep_equal_1.deepEqual)(left, right));
@@ -189,7 +151,10 @@ exports.FunctionProcessorHandler = {
189
151
  [greyscript_core_1.Operator.NotEqual]: (a, b) => new boolean_1.CustomBoolean(a !== b)
190
152
  };
191
153
  const handleNumber = (op, a, b) => {
192
- if (op in exports.NumberProcessorHandler) {
154
+ if (b instanceof nil_1.CustomNil) {
155
+ b = new number_1.CustomNumber(0);
156
+ }
157
+ if (op in exports.NumberProcessorHandler && b instanceof number_1.CustomNumber) {
193
158
  return exports.NumberProcessorHandler[op](a, b);
194
159
  }
195
160
  else if (op in exports.GenericProcessorHandler) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "2.1.9",
3
+ "version": "2.2.1",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",
@@ -48,8 +48,8 @@
48
48
  "typescript": "^5.0.4"
49
49
  },
50
50
  "dependencies": {
51
- "greybel-core": "^0.9.5",
52
- "greyscript-core": "^0.9.7"
51
+ "greybel-core": "^0.9.6",
52
+ "greyscript-core": "^0.9.9"
53
53
  },
54
54
  "keywords": [
55
55
  "greyscript",