diff --git a/lf-validator.ometajs b/lf-validator.ometajs index 0c5d47e..eb7360c 100644 --- a/lf-validator.ometajs +++ b/lf-validator.ometajs @@ -37,7 +37,7 @@ export ometa LFValidator <: SBVRLibs { | "Name" ):identifier "Verb":verb - {factType.concat([identifier, verb])}:factType + {factType.push(identifier, verb)} )* ( ( "Term" | "Name" diff --git a/sbvr-libs.ometajs b/sbvr-libs.ometajs index 1209a29..90a25cb 100644 --- a/sbvr-libs.ometajs +++ b/sbvr-libs.ometajs @@ -95,14 +95,15 @@ SBVRLibs.AddFactType = function(factType, realFactType) { SBVRLibs._traverseFactType = function(factType, create) { var self = this, - traverseRecurse = function(currentFactTypePart, remainingFactType, currentLevel) { + traverseRecurse = function(currentFactType, currentLevel) { + var currentFactTypePart = currentFactType[0]; if(currentFactTypePart == null) { if(create) { currentLevel.__valid = create; } return currentLevel; } - var finalLevel, finalLevels = {}; + var finalLevel, finalLevels = {}, remainingFactType = currentFactType.slice(1); switch(currentFactTypePart[0]) { case 'Verb': currentFactTypePart = currentFactTypePart.slice(0, 2); // Make sure we only use the first 2 parts for verbs. @@ -112,7 +113,7 @@ SBVRLibs._traverseFactType = function(factType, create) { } if(currentLevel.hasOwnProperty(currentFactTypePart) || (create && (currentLevel[currentFactTypePart] = {})) ) { - finalLevel = traverseRecurse(remainingFactType[0], remainingFactType.slice(1), currentLevel[currentFactTypePart]); + finalLevel = traverseRecurse(remainingFactType, currentLevel[currentFactTypePart]); if(finalLevel !== false) { Object.assign(finalLevels, finalLevel); } @@ -122,7 +123,7 @@ SBVRLibs._traverseFactType = function(factType, create) { while( (currentFactTypePart = self.FollowConceptType(currentFactTypePart)) !== false ) { if( currentLevel.hasOwnProperty(currentFactTypePart) ) { // We use recursion so here we go down each branch until we find the suitable one, or run out of branches. - finalLevel = traverseRecurse(remainingFactType[0], remainingFactType.slice(1), currentLevel[currentFactTypePart]); + finalLevel = traverseRecurse(remainingFactType, currentLevel[currentFactTypePart]); if(finalLevel !== false) { Object.assign(finalLevels, finalLevel); } @@ -131,5 +132,5 @@ SBVRLibs._traverseFactType = function(factType, create) { } return _.isEmpty(finalLevels) === true ? false : finalLevels; }; - return traverseRecurse(factType[0], factType.slice(1), this.factTypes); + return traverseRecurse(factType, this.factTypes); }; diff --git a/sbvr-parser.ometajs b/sbvr-parser.ometajs index 215fb3b..05940ae 100644 --- a/sbvr-parser.ometajs +++ b/sbvr-parser.ometajs @@ -7,7 +7,7 @@ var SBVRLibs = require('./sbvr-libs').SBVRLibs, inflection = require('inflection'); function isEOL(x) { - return ['\n', '\r'].includes(x) + return x === '\n' || x === '\r'; } function isSpace(x) { return x.charCodeAt(0) <= 32; @@ -494,9 +494,8 @@ export ometa SBVRParser <: SBVRLibs { Modifier:mod Junction('RuleBody', [[], []]):ruleLF EOLTerminator - {_.cloneDeep(mod)}:mod - {mod.length === 2 ? (mod[1][1] = ruleLF) : (mod[1] = ruleLF)} - -> ['Rule', mod, ['StructuredEnglish', ruleText]], + {[mod[0], mod.length === 2 ? [mod[1][0], ruleLF] : ruleLF]}:ruleMod + -> ['Rule', ruleMod, ['StructuredEnglish', ruleText]], StartFactType = seq('F:') @@ -514,14 +513,8 @@ export ometa SBVRParser <: SBVRLibs { $elf.AddFactType(factType, factType); var attributes = ['Attributes']; if(factType.length === 3 && (factType[1][1] === 'has' || factType[1][1] === 'is of')) { - synFactType = _.cloneDeep(factType); - synFactType.reverse() - if(synFactType[1][1] === 'has') { - synFactType[1][1] = 'is of' - } - else { - synFactType[1][1] = 'has' - } + var synVerb = factType[1][1] === 'has' ? 'is of' : 'has', + synFactType = [factType[2], ['Verb', synVerb, factType[1][2]], factType[0]]; $elf.AddFactType(synFactType, factType); attributes.push(['SynonymousForm', synFactType]) } @@ -893,20 +886,8 @@ defaultAllowedAttrLists = { function getValidFactTypeParts(vocabulary, identifierType, factTypeSoFar) { var vocabularies = this.vocabularies; if(factTypeSoFar == null || factTypeSoFar.length === 0) { - var identifiers; - if(vocabulary == null) { - identifiers = vocabularies[this.currentVocabulary][identifierType]; - // identifiers = {}; - // for(vocabulary in vocabularies) { - // if(vocabularies.hasOwnProperty(vocabulary)) { - // _.assign(identifiers, vocabularies[vocabulary][identifierType]); - // } - // } - } - else { - identifiers = vocabularies[vocabulary][identifierType]; - } - return Object.keys(identifiers); + vocabulary = vocabulary == null ? this.currentVocabulary : vocabulary; + return Object.keys(vocabularies[vocabulary][identifierType]); } var factTypePart, currentLevel = this._traverseFactType(factTypeSoFar), @@ -1079,32 +1060,25 @@ SBVRParser.AddCustomAttribute = function(attributeName, attachedTo) { SBVRParser.matchForAny = function(rule, arr, returnIndex) { var self = this, origInput = this.input, - ref = {}, - result = ref; + result; for (var idx = 0; idx < arr.length; idx++) { try { self.input = origInput; - result = self._applyWithArgs.call(self, rule, arr[idx]); + result = self._applyWithArgs(rule, arr[idx]); + return returnIndex ? idx : result; } catch (e) { if (!(e instanceof SyntaxError)) { throw e; } } - - if (result !== ref) { - if (returnIndex) { - return idx; - } - return result; - } } throw this._fail(); }; SBVRParser.matchForAll = function(rule, arr) { for (var idx = 0; idx < arr.length; idx++) { - this._applyWithArgs.call(this, rule, arr[idx]); + this._applyWithArgs(rule, arr[idx]); } }; SBVRParser.matchUntil = function(fn) {