Skip to content

Commit

Permalink
add static analyzer to engine for no rules warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mauris committed Sep 18, 2018
1 parent ccfa1e2 commit 035cf27
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/engine/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
const lpsRequire = require('../lpsRequire');
const LiteralTreeMap = lpsRequire('engine/LiteralTreeMap');
const FunctorProvider = lpsRequire('engine/FunctorProvider');
const StaticAnalyzer = lpsRequire('engine/StaticAnalyzer');

const processRules = lpsRequire('utility/processRules');
const goalTreeSorter = lpsRequire('utility/goalTreeSorter');
Expand Down Expand Up @@ -704,6 +705,7 @@ function Engine(programArg) {
// we preprocess some of the built-in processors by looking at the facts
// of the _program.
this.on('loaded', () => {
StaticAnalyzer.analyze(_program, _engineEventManager);
settingsProcessor(this, _program);
timableProcessor(this, _program);
initiallyProcessor(this, _program);
Expand Down
26 changes: 26 additions & 0 deletions src/engine/StaticAnalyzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
This file is part of the lps.js project, released open source under
the BSD 3-Clause license. For more info, please see https://github.com/mauris/lps.js
*/

const lpsRequire = require('../lpsRequire');
const stringLiterals = lpsRequire('utility/strings');

const WARNING_EVENT = 'warning';

function StaticAnalyzer() {
}

StaticAnalyzer.analyze = function (program, eventManager) {
const rules = program.getRules();
if (rules.length === 0) {
eventManager.notify(WARNING_EVENT, {
type: 'rule.empty',
message: stringLiterals(
'engine.analyzer.noRules'
)
});
}
};

module.exports = StaticAnalyzer;

0 comments on commit 035cf27

Please sign in to comment.