core_external_language_haskell.serialization.pure Maven / Gradle / Ivy
import meta::external::language::haskell::metamodel::*;
function meta::external::language::haskell::format::toString(module:HaskellModule[1]):String[1]
{
'module ' + $module.id + ' where\n\n' +
$module.elements->map(e | $e->meta::external::language::haskell::format::toString())->makeString('','\n','')
}
function meta::external::language::haskell::format::toString(element:meta::external::language::haskell::metamodel::ModuleElement[1]):String[1]
{
$element->cast(@meta::external::language::haskell::metamodel::AnnotatedElement)->meta::external::language::haskell::format::toString() +
$element->match([
d:meta::external::language::haskell::metamodel::DataType[1] | $d->meta::external::language::haskell::format::toString()
])
}
function meta::external::language::haskell::format::toString(dataType:meta::external::language::haskell::metamodel::DataType[1]):String[1]
{
'data ' + $dataType.name +
if($dataType.constructors->size() > 1, | '\n = ', | ' = ') +
$dataType.constructors->map(c |
$c->meta::external::language::haskell::format::toString())->makeString('','\n | ','') +
$dataType.deriving->map(d | ' ' + $d->meta::external::language::haskell::format::toString())->makeString('','','\n')
}
function meta::external::language::haskell::format::toString(c:NamedConstructor[1]):String[1]
{
$c->match([
r:RecordTypeConstructor[1] | $c.name + $r.fields->map(f | $f->meta::external::language::haskell::format::toString())->makeString(' {\n',',\n','\n}'),
n:NamedConstructor[1] | $c.name
]) +
$c->cast(@meta::external::language::haskell::metamodel::AnnotatedElement)->meta::external::language::haskell::format::toString(true, '\n ')
}
function meta::external::language::haskell::format::toString(f:Field[1]):String[1]
{
' ' + $f.name + ' :: ' + $f.type->map(t | $t->meta::external::language::haskell::format::toString())->makeString('',' ', '')
}
function meta::external::language::haskell::format::toString(type:HaskellType[1]):String[1]
{
$type->match([
t:NamedTypeRef[1] | $t.name,
l:ListType[1] | '[' + $l.type->map(t | $t->meta::external::language::haskell::format::toString())->makeString('',' ', '') + ']',
a:Any[1] | $type->type().name->toOne()
])
}
function meta::external::language::haskell::format::toString(deriving:Deriving[1]):String[1]
{
$deriving.types->map(t | $t->meta::external::language::haskell::format::toString())->makeString('deriving (',', ',')');
}
function meta::external::language::haskell::format::toString(annotatedElement:meta::external::language::haskell::metamodel::AnnotatedElement[1]):String[1]
{
$annotatedElement->meta::external::language::haskell::format::toString(false,'');
}
function meta::external::language::haskell::format::toString(annotatedElement:meta::external::language::haskell::metamodel::AnnotatedElement[1],below:Boolean[1],prefix:String[1]):String[1]
{
if($annotatedElement.documentation->isEmpty()
, | ''
, | $prefix + if($below, | '-- ^ ', |'-- | ') + $annotatedElement.documentation->toOne() + '\n');
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy