OCL Parsing
Parse OCL expressions from strings using a Jison-generated parser built for JavaScript.
Parse and evaluate OCL constraints in JavaScript and TypeScript — in the browser or Node.js.
The Object Constraint Language (OCL) is a language for describing rules that apply to MOF-conform modelling languages like UML. It is a text-based language that provides constraint and object query expressions that cannot be expressed by a meta-modelling language.
Since implementations exist in Java (e.g. Eclipse Modelling Framework) but not in JavaScript, OCL.js fills that gap. This library does not claim to be fully compliant with the OMG OCL specification and may have slight differences.
npm install @stekoe/ocl.jsimport { OclEngine } from '@stekoe/ocl.js';
const oclEngine = OclEngine.create();
oclEngine.addOclExpression(`
context Person inv: self.parents->forAll(p | p <> self)
`);
const result = oclEngine.evaluate(new Person());
console.log(result.getResult()); // true