@balena/sbvr-parser 1.2.5 → 1.3.0

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.
@@ -1,3 +1,20 @@
1
+ - commits:
2
+ - subject: Add support for more forms of negation in rules
3
+ hash: 6d6e3690668b6b64deefcde68f3ebe5f731577ce
4
+ body: ''
5
+ footer:
6
+ Change-type: minor
7
+ change-type: minor
8
+ author: Pagan Gazzard
9
+ - subject: Do not check for negated verbs when declaring fact types
10
+ hash: e1fd4b0245993e0704a866f783dfc9bd98743ebb
11
+ body: ''
12
+ footer:
13
+ Change-type: patch
14
+ change-type: patch
15
+ author: Pagan Gazzard
16
+ version: 1.3.0
17
+ date: 2021-12-16T17:05:11.285Z
1
18
  - commits:
2
19
  - subject: Delete CODEOWNERS
3
20
  hash: d26be5bb58b10118fc49c04509ce4e0b0746e962
@@ -11,7 +28,7 @@
11
28
  https://www.flowdock.com/app/rulemotion/pub/threads/trLcZFnSX9fLZn4LiaIv4xuBbah
12
29
  author: Thodoris Greasidis
13
30
  version: 1.2.5
14
- date: 2021-06-30T21:28:08.336Z
31
+ date: 2021-06-30T21:23:54.448Z
15
32
  - commits:
16
33
  - subject: Optimize space matching
17
34
  hash: 59e1232f8da68f98c65739d5c80de11d3f613b55
package/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file
4
4
  automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
5
5
  This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ # v1.3.0
8
+ ## (2021-12-16)
9
+
10
+ * Add support for more forms of negation in rules [Pagan Gazzard]
11
+ * Do not check for negated verbs when declaring fact types [Pagan Gazzard]
12
+
7
13
  # v1.2.5
8
14
  ## (2021-06-30)
9
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@balena/sbvr-parser",
3
- "version": "1.2.5",
3
+ "version": "1.3.0",
4
4
  "description": "SBVR to LF parser.",
5
5
  "main": "sbvr-parser.js",
6
6
  "scripts": {
@@ -20,10 +20,10 @@
20
20
  "ometa-js": "^1.5.4"
21
21
  },
22
22
  "devDependencies": {
23
- "@balena/lint": "^6.1.1",
24
- "@balena/sbvr-types": "^3.4.3",
23
+ "@balena/lint": "^6.2.0",
24
+ "@balena/sbvr-types": "^3.4.6",
25
25
  "chai": "^4.3.4",
26
- "mocha": "^8.4.0",
26
+ "mocha": "^9.1.3",
27
27
  "require-npm4-to-publish": "^1.0.0"
28
28
  },
29
29
  "mocha": {
@@ -32,5 +32,8 @@
32
32
  "bail": true,
33
33
  "timeout": 5000,
34
34
  "_": "test"
35
+ },
36
+ "versionist": {
37
+ "publishedAt": "2021-12-16T17:05:11.351Z"
35
38
  }
36
39
  }
package/sbvr-parser.js CHANGED
@@ -6,7 +6,9 @@ var isEOL = function isEOL(x) {
6
6
  return [ "\n", "\r" ].includes(x);
7
7
  }, isSpace = function isSpace(x) {
8
8
  return x.charCodeAt(0) <= 32;
9
- }, SBVRParser = exports.SBVRParser = SBVRLibs._extend({
9
+ }, negatableVerbs = [ "is", "are", "has", "have", "can", "could", "may", "might", "must", "should", "shall", "will" ], negatedVerbs = negatableVerbs.map(function(verb) {
10
+ return "will" === verb ? "won't" : verb + "n't";
11
+ }), SBVRParser = exports.SBVRParser = SBVRLibs._extend({
10
12
  EOL: function() {
11
13
  var $elf = this, _fromIdx = this.input.idx, x;
12
14
  return this._many1(function() {
@@ -376,15 +378,17 @@ var isEOL = function isEOL(x) {
376
378
  return verb;
377
379
  },
378
380
  FindVerb: function(factTypeSoFar, bracketed, verbSoFar, negated) {
379
- var $elf = this, _fromIdx = this.input.idx, negated, part, verb, verbSoFar;
381
+ var $elf = this, _fromIdx = this.input.idx, index, negated, part, verb, verbSoFar;
380
382
  this._opt(function() {
381
- this._pred(factTypeSoFar && !verbSoFar);
383
+ this._pred(!0 !== factTypeSoFar && !verbSoFar);
382
384
  this._or(function() {
383
- return this._applyWithArgs("Keyword", "isn't");
385
+ return this._applyWithArgs("Keyword", "does not");
384
386
  }, function() {
385
- return this._applyWithArgs("Keyword", "aren't");
387
+ return this._applyWithArgs("Keyword", "doesn't");
388
+ }, function() {
389
+ index = this._applyWithArgs("matchForAny", "Keyword", negatedVerbs, !0);
390
+ return verbSoFar = this._verbForm(negatableVerbs[index]);
386
391
  });
387
- verbSoFar = "is";
388
392
  return negated = !0;
389
393
  });
390
394
  this._apply("spaces");
@@ -403,7 +407,7 @@ var isEOL = function isEOL(x) {
403
407
  return this._verbForm(part);
404
408
  });
405
409
  this._opt(function() {
406
- this._pred(factTypeSoFar && "is" === verbSoFar);
410
+ this._pred(!0 !== factTypeSoFar && negatableVerbs.includes(verbSoFar));
407
411
  this._apply("spaces");
408
412
  this._applyWithArgs("Keyword", "not");
409
413
  return negated = !0;
@@ -1287,7 +1291,7 @@ SBVRParser.AddCustomAttribute = function(attributeName, attachedTo) {
1287
1291
  }
1288
1292
  };
1289
1293
 
1290
- SBVRParser.matchForAny = function(rule, arr) {
1294
+ SBVRParser.matchForAny = function(rule, arr, returnIndex) {
1291
1295
  for (var $elf = this, origInput = this.input, ref = {}, result = ref, idx = 0; idx < arr.length; idx++) {
1292
1296
  try {
1293
1297
  $elf.input = origInput;
@@ -1295,7 +1299,7 @@ SBVRParser.matchForAny = function(rule, arr) {
1295
1299
  } catch (e) {
1296
1300
  if (!(e instanceof SyntaxError)) throw e;
1297
1301
  }
1298
- if (result !== ref) return result;
1302
+ if (result !== ref) return returnIndex ? idx : result;
1299
1303
  }
1300
1304
  throw this._fail();
1301
1305
  };
@@ -13,6 +13,14 @@ function isSpace(x) {
13
13
  return x.charCodeAt(0) <= 32;
14
14
  }
15
15
 
16
+ var negatableVerbs = ['is', 'are', 'has', 'have', 'can', 'could', 'may', 'might', 'must', 'should', 'shall', 'will'];
17
+ var negatedVerbs = negatableVerbs.map(function (verb) {
18
+ if (verb === 'will') {
19
+ return "won't";
20
+ }
21
+ return verb + "n't"
22
+ })
23
+
16
24
  export ometa SBVRParser <: SBVRLibs {
17
25
  EOL =
18
26
  ( anything:x
@@ -219,11 +227,13 @@ export ometa SBVRParser <: SBVRLibs {
219
227
  )
220
228
  -> verb,
221
229
  FindVerb :factTypeSoFar :bracketed :verbSoFar :negated =
222
- ( ?(factTypeSoFar && !verbSoFar)
223
- ( Keyword("isn't")
224
- | Keyword("aren't")
230
+ ( ?(factTypeSoFar !== true && !verbSoFar)
231
+ ( Keyword('does not')
232
+ | Keyword('doesn\'t')
233
+ | matchForAny('Keyword', negatedVerbs, true):index
234
+ // Use the non-negated form for the verb
235
+ {this._verbForm(negatableVerbs[index])}:verbSoFar
225
236
  )
226
- {'is'}:verbSoFar
227
237
  {true}:negated
228
238
  )?
229
239
 
@@ -239,13 +249,13 @@ export ometa SBVRParser <: SBVRLibs {
239
249
  -> (verbSoFar + ' ' + part)
240
250
  | -> this._verbForm(part)
241
251
  ):verbSoFar
242
- ( ?(factTypeSoFar && verbSoFar === 'is')
252
+ ( ?(factTypeSoFar !== true && negatableVerbs.includes(verbSoFar))
243
253
  spaces
244
254
  Keyword('not')
245
255
  {true}:negated
246
256
  )?
247
257
  ( FindVerb(factTypeSoFar, bracketed, verbSoFar, negated)
248
- | ( ?(factTypeSoFar===true)
258
+ | ( ?(factTypeSoFar === true)
249
259
  | IsVerb(factTypeSoFar, verbSoFar)
250
260
  )
251
261
  {['Verb', verbSoFar, negated === true]}:verb
@@ -1061,7 +1071,7 @@ SBVRParser.AddCustomAttribute = function(attributeName, attachedTo) {
1061
1071
  };
1062
1072
 
1063
1073
  /** **/
1064
- SBVRParser.matchForAny = function(rule, arr) {
1074
+ SBVRParser.matchForAny = function(rule, arr, returnIndex) {
1065
1075
  var self = this,
1066
1076
  origInput = this.input,
1067
1077
  ref = {},
@@ -1079,6 +1089,9 @@ SBVRParser.matchForAny = function(rule, arr) {
1079
1089
  }
1080
1090
 
1081
1091
  if (result !== ref) {
1092
+ if (returnIndex) {
1093
+ return idx;
1094
+ }
1082
1095
  return result;
1083
1096
  }
1084
1097
  }
package/test/pilots.js CHANGED
@@ -315,6 +315,24 @@ describe('pilots', function () {
315
315
  ),
316
316
  ),
317
317
  );
318
+
319
+ // Rule: It is necessary that each pilot that is not experienced, can not fly at least 2 planes or does not have a years of experience that is greater than 5
320
+ test(
321
+ rule(
322
+ 'Necessity',
323
+ 'each',
324
+ [pilot, verb('is experienced', true)],
325
+ _or(
326
+ [verb('can fly', true), ['at least', 2], plane],
327
+ [
328
+ verb('has', true),
329
+ 'a',
330
+ [yearsOfExperience, verb('is greater than'), 5],
331
+ ],
332
+ ),
333
+ ),
334
+ );
335
+
318
336
  // Rule: It is necessary that each pilot that is experienced or can fly at least 2 planes, has a years of experience that is greater than 5
319
337
  test(
320
338
  rule(
@@ -101,7 +101,11 @@ const toSE = function (lf, currentVocab) {
101
101
  }
102
102
  case 'Verb':
103
103
  if (lf[2]) {
104
- return lf[1].replace('is', 'is not');
104
+ let verb = lf[1].replace('is', 'is not').replace('can', 'can not');
105
+ if (verb === lf[1]) {
106
+ return `does not ${verb}`;
107
+ }
108
+ return verb;
105
109
  } else {
106
110
  return lf[1];
107
111
  }