Skip to content

Commit

Permalink
Merge pull request #163 from finger563/feature/check-event-name
Browse files Browse the repository at this point in the history
feat(generator): Update process model to check if event names are valid
  • Loading branch information
finger563 authored May 22, 2024
2 parents 602b640 + 1807fef commit 2f1e706
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/common/checkModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ define([], function() {
'use strict';
return {
stripRegex: /^([^\n]+)/gm,
badProperty: function(obj, prop) {
throw "ERROR: " +obj.path+" has invalid " +prop+": "+obj[prop];
badProperty: function(obj, prop, msg="") {
if (msg.length > 0) {
throw "ERROR: " +obj.path+" has invalid " +prop+": '"+obj[prop] + "'.\n " + msg;
} else {
throw "ERROR: " +obj.path+" has invalid " +prop+": '"+obj[prop] + "'.";
}
},
error: function(obj, str) {
throw "ERROR: " +obj.path+" : "+str;
Expand All @@ -22,6 +26,11 @@ define([], function() {
if ( !self.isValidString( sName ) )
self.badProperty(obj, 'name');
},
checkEvent: function(obj) {
var self = this;
if ( self.hasEvent(obj) && !self.isValidString( obj.Event ) )
self.badProperty(obj, 'Event', 'Event must be a valid C++ Enum name (alphanumeric + underscore, starting with a letter)');
},
hasGuard: function( trans ) {
return trans.Guard && trans.Guard.trim().length > 0;
},
Expand Down Expand Up @@ -64,6 +73,7 @@ define([], function() {
topLevelObject = obj;
}
else if (obj.type == 'External Transition') {
self.checkEvent(obj);
// checks: src, dst, Event, Guard,
var src = model.objects[obj.pointers['src']],
dst = model.objects[obj.pointers['dst']];
Expand All @@ -75,6 +85,7 @@ define([], function() {
eventNames.push(obj.Event);
}
else if (obj.type == 'Local Transition') {
self.checkEvent(obj);
// checks: src, dst, Event, Guard,
var src = model.objects[obj.pointers['src']],
dst = model.objects[obj.pointers['dst']];
Expand All @@ -95,6 +106,7 @@ define([], function() {
eventNames.push(obj.Event);
}
else if (obj.type == 'Internal Transition') {
self.checkEvent(obj);
// checks: event
if ( !self.hasEvent( obj ) ) {
self.error(obj, "INTERNAL TRANSITIONS MUST HAVE EVENTS");
Expand Down

0 comments on commit 2f1e706

Please sign in to comment.