The practical part of my bachelor thesis is a program that takes OCL rules as input and transforms these rules into Schematron; it transforms constraints defined on top of UML models into constraints defined on top of XML data.
At first I wanted to write my own LALR-Parser for OCL, parse the input into one parse tree and then serialize this tree into the corresponding Schematron output. The major problem is that a LALR-Parser for OCL, even a generated one, seems to take up too much time to develop and test; plus the only LALR-Parser Generator for Ruby, racc, does not work for me at the time of this writing.
My new approach looks somewhat different and utilizes the OCL expression definitions as given in the v2.2 standard document.
- Parse EBNF definitions for OCL using the CPAN Parse::EBNF module
- Parse OCL input file; represent each constraint as a (context, expression) pair
- Match all expressions with their corresponding OCL expression definition
- Match all context with their corresponding XPath2 expression
- Serialize all pairs, prepending Schematron header, appending Schematron footers, grouping pairs by context
Given I find a practical way to match the Concrete Syntax of OCL into Schematron rules this approach should work just fine.
I'm currently working on a small prototype which transforms the following OCL rule
context Person inv: self.Age >= 0
into its Schematron equivalent:
<?xml version="1.0" encoding="utf-8"?>
<title>generated Schematron transformation</title>
<assert test="(attribute(age) cast as xs:integer) ge 0">
self.Age >= 0
The OCL definition parsing works great. I'm currently working on extracting the (context, expression) pairs from the input and matching the expressions with a given OCL expression.
There's still plenty of work ahead, and I'm not sure how to handle more complexe OCL expressions yet...