Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lf-validator.ometajs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export ometa LFValidator <: SBVRLibs {
| "Name"
):identifier
"Verb":verb
{factType.concat([identifier, verb])}:factType
{factType.push(identifier, verb)}
)*
( ( "Term"
| "Name"
Expand Down
11 changes: 6 additions & 5 deletions sbvr-libs.ometajs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
};
48 changes: 11 additions & 37 deletions sbvr-parser.ometajs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:')
Expand All @@ -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])
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand Down
Loading