All Downloads are FREE. Search and download functionalities are using the official Maven repository.

maestro.ast.2.4.0.source-code.mabl.astv2.tostring Maven / Gradle / Ivy

To String Extensions
// import packages used by external $$ java code
import org.intocps.maestro.ast.Utils;
import java.util.stream.Collectors;



%document->root = [content]

%framework->config = "@FrameworkConfig(\"" + [name] + "\", \""+ [config] + "\")"

%compilationUnit->importedModule = "imported "+$ $[imports]$.stream().map( s-> "import " + "" + s.toString()).collect(Collectors.joining(";\n","\n",";\n"))$ + [module]
%compilationUnit->simulationSpecification = "simulation "+$ $[imports]$.stream().map( s-> "import " + "" + s.toString()).collect(Collectors.joining(";\n","\n",";\n"))+ ($[framework]$.isEmpty()?"":$[framework]$.stream().map( s->"\""+  s.getText()+"\"").collect(Collectors.joining(",","\n@Framework(",");\n"))) + ($[frameworkConfigs]$.isEmpty()?"":$[frameworkConfigs]$.stream().map( s->  s.toString()).collect(Collectors.joining(";","\n;","\n")))$ + [body]

%declaration->function = [returnType] +$ " "+ $[name]$+"("+ $[formals]$.stream().map(Object::toString).collect(Collectors.joining(", "))$+")"
%declaration->variable = ""+ $ ($[external]$!=null &&$[external]$ ? "external ":"" )  + $[type]$ +" "+ $[name]$ + ""+($[size]$==null || $[size]$.isEmpty()?"":$[size]$.stream().map(s->s.toString()).collect(Collectors.joining("][","[","]")))+ ( $[initializer]$ ==null?"":" = " +$[initializer]$)$
%declaration->module =   [name]+$" {"+ $[functions]$.stream().map(Object::toString).collect(Collectors.joining(";\n","\n","\n"))$ + "}"


%initializer->exp = [exp]
%initializer->array = "{" + $ $[exp]$.stream().map(Object::toString).collect(Collectors.joining(" , ", " ", " "))$ + "}"
%parameter->formal = [type] +" "+[name]

%exp->identifier = [name]
%exp->#literal->string = "\"" + [value] +"\""
%exp->#literal->bool =  [value]
%exp->#literal->real =  [value]
%exp->#literal->int =  [value]
//%exp->#literal->numeric =  [value]
%exp->load = "load("+$ $[args]$.stream().map(Object::toString).collect(Collectors.joining(", "))$+")"
%exp->unload = "unload("+$ $[args]$.stream().map(Object::toString).collect(Collectors.joining(", "))$+")"
%exp->field = [root]+ "." +[field]
%exp->#binary->plus = [left]+ " + " + [right]
%exp->#binary->minus = [left]+ " - " + [right]
%exp->#binary->lessEqual = [left]+ " <= " + [right]
%exp->#binary->greaterEqual = [left]+ " > " + [right]
%exp->#binary->less = [left]+ " < " + [right]
%exp->#binary->greater = [left]+ " > " + [right]
%exp->#binary->equal = [left]+ " == " + [right]
%exp->#binary->notEqual = [left]+ " != " + [right]
%exp->#binary = [left]+ "" + [right]
%exp->#binary = [left]+ "" + [right]
%exp->#binary->or = [left]+ " || " + [right]
%exp->#binary->and = [left]+ " && " + [right]
%exp->#binary->multiply = [left]+ " * " + [right]
%exp->#binary->divide = [left]+ " / " + [right]
%exp->#unary->not = "!" + [exp]
%exp->#unary->minus = "-" + [exp]
%exp->#unary->plus = "+" + [exp]
%exp->call = ""+ $ ($[object]$==null?"":$[object]$+".")+($[expand]$==null?"":$[expand]$.getText()+ " ")+ $[methodName]$ +"(" +$[args]$.stream().map(Object::toString).collect(Collectors.joining(", "))$+")"
%exp->arrayIndex = ""+ $ $[array]$ +"[" +$[indices]$.stream().map(Object::toString).collect(Collectors.joining("]["))$+"]"
%exp->par = "("+ [exp] +")"
%exp->null = "null"
%exp->ref = "ref "+ [exp]

%stm->block->basic = "\n{"+ $$[body]$.stream().map(Object::toString).collect(Collectors.joining(";\n","\n","\n"))$+"}\n"
%stm->block->parallel = "\n||{"+ $$[body]$.stream().map(Object::toString).collect(Collectors.joining(";\n","\n","\n"))$+"}\n"
%stm->assigment = [target] + " = " [exp] +";"
%stm->localVariable = [declaration]
%stm->if = "if( " +$ $[test]$ +" ) \n{\n" + $[then]$+ "\n}"+   ($[else]$!=null ?"\nelse \n{\n" +$[else]$ +"\n}":"")$
%stm->while = "while( "+[test]+" ) " + [body] + ""
%stm->observable = "observable;"
%stm->expression = [exp]
%stm->break = "break"
%stm->instanceMapping = "@mapInstance(" + [identifier]+ " -> \""+[name] + "\")"
%stm->fmuMapping = "@mapFmu(" + [identifier]+ " -> \""+[name] + "\")"
%stm->transfer = "@Transfer("  +$$[names]$.stream().map(Object::toString).collect(Collectors.joining(","))$+   ")"
%stm->transferAs = "@TransferAs("  +$$[names]$.stream().map(Object::toString).collect(Collectors.joining(","))$+   ")"
%stm->config = "@Config(\"" + [config] + "\")"
%stm->error = "error "+ $ ($[exp]$==null?"":$[exp]$)$
%stm->try = "try" + [body] +  "finally"  +[finally]



%stateDesignator->identifier = [name]
%stateDesignator->array = [target] + "[" + [exp] + "]"

%type->name = [name]
%type->array = [type]+ "[]"
%type->void = "void"
%type->module = [name]
%type->unknown = "?"
%type->reference = "ref " + [type]
%type->function = "" +$ $[parameters]$.stream().map(t->t+"").collect(Collectors.joining(",","(",")"))+" => "$ + [result]
%type->null = "null"

%type->#primitive->boolean="bool"
%type->#primitive->string="string"
%type->#primitive->#numeric->real="real"
%type->#primitive->#numeric->int="int"
%type->#primitive->#numeric->uInt="uint"




© 2015 - 2024 Weber Informatics LLC | Privacy Policy