An object oriented programming language that transcompiles into Mumps / M
Pending Release: 0.1 for GT.m
Overview
Mole is a curly braced object oriented programming language that transcompiles from Mole into M. Mole is based on the simplicity of the M programming language, whilst adding syntactic sugar, class based encapsulation and full OO goodness.
Class Based Development
Mole provides full class based encapsulation with class wrappers, packages, constants, properties, customisable annotations, object methods, static methods, multiple inheritance and more.
class Foo.Bar.Person inherits Object
{
//a constant, baked into the code
const title="Mr"
//properties of an instantiated object
property firstName as string
property lastName as string
//an instance method
method getFullName() as string
{
return ..#title_" "_..firstName_" "_..lastName
}
//a static test method
method test() as void : static
{
set person=Foo.Bar.Person.new()
set person.firstName="James"
set person.lastName="Bond"
write !,person.getFullName()
}
}
>do Foo.Bar.Person.test() Mr James Bond
M Language Extensions
Mole adds a number of additional keywords to the M language such as the while command.
//always check condition first
set x=1
while x=1 do
{
set x=2
}
//always do once, regardless of condition
do while x=1
{
set x=2
}
A new "for in" command for traversing arrays and globals. Compare this old school M example to the new Mole example.
//old school M set name="" for set name=$Order(^names(name)) quit:name="" do .write !,name
//new school Mole
for name in ^names
{
write !,name
}
Mole also extends the "for in" command with filters.
for date in ^pay("date") between 62400 and 62430
{
for id in ^pay("date",date)
{
write !,^pay("date",date,id)
}
}
Error trapping with try catch blocks that can be nested and customised.
method tryCatchExample() as status : static
{
try
{
do Foo.Bar.mightError()
set sc=Foo.Bar.mightFail()
if sc.isError() throw("U1")
}
catch(err)
{
if err.value="U1"
{
write !,"A user defined error found at ",err.location
}
}
return status.OK()
}
Plus other language additions such as a simple types, switch, case, custom macros, custom compilers, multi line comments and more.
Simple Types
Mole provides a simple type system with 10 pre-built types.
The built in types provide comprehensive functionality that have been extensively unit tested.
Example string type methods.
| piece | toUpper | ellipses |
| pieces | capitalise | getBytes |
| count | camalCase | getHash |
| extract | trim | matches |
| length | ltrim | leftJustify |
| get | rtrim | rightJustify |
| find | split | tabsToSpaces |
| replace | encode | append |
| replaceFirst | decode | insert |
| replaceLast | startsWith | equals |
| toLower | endsWith | notEquals |
Mole implements a combination of both weak typing and strong typing that can be optionally controlled by the end developer.
Simple type methods can be chained together to provide compact and efficient code.
>set address=" 21 long close, exeter, devon "
>write !,address.trim().camelCase()
21 Long Close, Exeter, Devon
>write !,address.trim().camelCase().ellipses(24)
21 Long Close, Exeter...
>write !,address.trim().pieces(" ")
5
>write !,address.trim().camelCase().replace("Close","Drive")
21 Long Drive, Exeter, Devon
Core Library
Mole comes with a core development library that includes.
The future roadmap includes XML, SOAP, Web Services, HL7, SQL and more.
Mole Web Development
Mole provides a fast, simple, secure and feature rich web development framework. Developers can write web pages, web fragements or web methods that will suit most styles of web development. In particular Mole is tuned towards AJAX based solutions.
//this is callable from HTTP, by default all
//web methods are private and need a secure session method
method getPerson(personId) as void : static,webmethod,content=json
{
set person=Foo.Bar.Person.open(personId)
do person.outputJson("person")
}
https://127.0.0.1/app/Foo.Bar.Person.getPerson?personId=1
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 59
{"person":
{"firstName":"connelly","lastName":"sean"}
}
The developers of Mole are also ardent users of the EXT JS JavaScript framework and have included specific EXT JS functionality such as Ext.Direct and code generator wizards.
Mole Storage
Mole implements a common storage interface that is currently implemented across three storage solutions.
Mole currently implements an experimental MQL solution that provides a Mole specific query language. A full blown SQL solution is in the roadmap for future development.
Unit Testing
Mole was developed using a test driven methodology. The Mole language currently has over 250 unit tests providing a solid and highly maintainable solution. The 0.1 release of Mole and its libraries will include well over 1000 unit tests. The developers of Mole are commited to constantly increasing the level of unit testing with each release.
Mole comes with its own built in unit testing library which will eventually include its own set of development and reporting tools for all developers to take advantage of.
Mole Compilers
Mole comes with an array of compiler solutions that include customisable annotations (tags), macros, in-line compilers and method compilers. A powerful feature of Mole is being able to develop custom compilers for any type of method content without needing to be a language parsing expert. Mole provides a very simple compiler API for transcompiling from the target method content to any combination of M or other source code file. This opens up numerous ideas for tight integration with other languages or existing Mumps frameworks or compilers, for instance:-
Here is an example of a custom compiler tag / annotation in action. Lets develop a tag that will log the inbound parameters of any other tagged method.
//a tag handler method that will record the inbound
//parameters for a tagged method. Notice it has a tag called tag.
method logParams(value,error) as void: static,tag
{
for p in $$$params()
{
//build up an array of code
set x($i(x))="set ^debug($zh,"""_p_""")="_p
}
//make sure we are at the beginning and then insert
//the code - the main compiler will do the rest
do $$$rewind()
do $$$insertBefore(.x)
}
Now lets apply that tag (the tags method name) to a test method and see it in action
//this method uses the logParams tag handler
method test(firstName,lastName) as string : static,logParams
{
return "Hello Mr "_lastName
}
>write !,Foo.Bar.test("James","Bond")
Hello Mr Bond
>zwr ^debug
^debug(5270.760247,"firstName")="James"
^debug(5272.940257,"lastName")="Bond"
Developer Tools
Mole will be released with a fast and innovative web based IDE and web based administration tools.
Free and Open Source
Mole is a free and open source solution that will be released on a non viral licence. Mole is culmination of many years research into developing an OO compiler for GT.m, and in its first instance will only compile to GT.m. Other M platforms will be considered in the future. Mole is viewed as a long term venture with a serious commitment for long term development and support.