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

ool.core.ast.2.6.4.source-code.overtureII.astv2.tostring Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
To String Extensions
// import packages used by external $$ java code
import org.overture.ast.util.Utils;
import org.overture.ast.util.ToStringUtil;


//  Expressions

%exp->apply = [root] "(" + $Utils.listToString($ [args] $)$ + ")"
%exp->narrow = "narrow_(" [test] ", " + $( $ [typeName] $ == null ? $ [basicType] $ : $ [typeName] $)$ + ")"
%exp->boolean_const =  [value] 
%exp->cases = "(cases " [expression] " :\n" +  $Utils.listToString("",$ [cases] $, ",\n", "") + ($ [others] $ == null ? "\n" : "\nothers " + $ [others] + $"\n")$ + " end)" 
%exp->charLiteral =  "'" + $_value.getValue()$ + "'" 
%exp->elseIf =  "elseif " + [elseIf] + "\nthen " + [then]
%exp->exists = "(exists " + $Utils.listToString($[bindList]$)$+ " & " + [predicate] + ")"
%exp->exists1 = "(exists1 " + [bind] + " & " + [predicate] + ")" 
%exp->field =  "(" [object] "." + $($ [memberName] $ == null ? $[field]$.getName() : $[memberName]$.getFullName())$ + ")"
%exp->fieldNumber = "(" + [tuple] + ".#" + [field] + ")"
%exp->forAll = "(forall " + $Utils.listToString($ [bindList] $)$ + " & " [predicate] ")"
%exp->funcInstatiation = "(" [function] ")[" + $Utils.listToString($[actualTypes]$)$ + "]"
%exp->if = "" + $Utils.ifToString($[test]$, $[then]$, $[elseList]$, $[else]$)$
%exp->intLiteral = [value] 
%exp->iota = "(iota " [bind] " & " [predicate] ")"
%exp->is = "is_(" [test] ", " + $( $ [typeName] $ == null ? $ [basicType] $ : $ [typeName] $)$ + ")"
%exp->isOfBaseClass = "isofbaseclass(" [baseClass] "," [exp] ")"
%exp->isOfClass = "isofclass(" [className] "," [exp] ")"
%exp->lambda = "(lambda " + [bindList] + " & " + [expression] + ")"
%exp->letBeSt = "let " [bind] + $($[suchThat]$ == null ? "" : " be st " + $[suchThat]$)$ + " in " + [value]
%exp->letDef = "let " + $Utils.listToString($ [localDefs] $)$ + " in " [expression]
%exp->def = "def " + $Utils.listToString($[localDefs]$)$ + " in\n" + [expression]
%exp->maplet = [left] + " |-> " + [right]
%exp->mkBasic = "mk_" + [type] + "(" + [arg] + ")"
%exp->mkType = "mk_" [typeName] "(" + $Utils.listToString($[args]$)$ + ")"
%exp->mu  = "mu(" [record] ", " + $Utils.listToString($[modifiers]$)$ + ")"
%exp->new = "new " [className] "("+ $Utils.listToString($[args]$)$ + ")"
%exp->nil = "nil"
%exp->notYetSpecified = "is not yet specified"
%exp->postOp = [postexpression]
%exp->pre = "pre_(" [function] + $Utils.listToString($ [args] $)$ + ")"
%exp->preOp = [expression]
%exp->quoteLiteral = [value]
%exp->realLiteral = [value]
%exp->sameBaseClass = "samebaseclass(" + [left] + "," + [right] + ")"
%exp->sameClass = "sameclass(" [left] "," + [right] + ")"
%exp->self = "self"
%exp->stateInit = "init " [state]$.getInitPattern()$ + " == " [state]$.getInitExpression()$
%exp->stringLiteral = [value]
%exp->subclassResponsibility = "is subclass responsibility"
%exp->subseq = "(" [seq] "(" [from] ", ... ," [to] "))"
%exp->threadId = "threadid"
%exp->time = "time"
%exp->tuple = "mk_(" + $Utils.listToString($ [args] $)$ + ")"
%exp->undefined = "(undefined)"
%exp->variable = [original]

//
%alternative->case = [pattern] + " -> "  [result] 

%exp->#Unary->absolute ="(abs "  [exp]+")"
%exp->#Unary->cardinality ="(card "  [exp]+")"
%exp->#Unary->distConcat ="(conc "  [exp]+")"
%exp->#Unary->distIntersect ="(dinter "  [exp]+")"
%exp->#Unary->distMerge ="(merge "  [exp]+")"
%exp->#Unary->distUnion ="(dunion "  [exp]+")"
%exp->#Unary->elements ="(elems "  [exp]+")"
%exp->#Unary->floor ="(floor "  [exp]+")"
%exp->#Unary->head ="(hd "  [exp]+")"
%exp->#Unary->indices ="(inds "  [exp]+")"
%exp->#Unary->len ="(len "  [exp]+")"
%exp->#Unary->mapDomain ="(dom "  [exp]+")"
%exp->#Unary->mapInverse ="(inverse "  [exp]+")"
%exp->#Unary->mapRange ="(rng "  [exp]+")"
%exp->#Unary->not ="(not "  [exp]+")"
%exp->#Unary->powerSet ="(power "  [exp]+")"
%exp->#Unary->reverse ="(reverse "  [exp]+")"
%exp->#Unary->tail ="(tl "  [exp]+")"
%exp->#Unary->unaryMinus ="-"  [exp]+""
%exp->#Unary->unaryPlus ="(+ "  [exp]+")"

%exp->#binary = "(" + [left] " " + [op] + " " [right] + ")"

%exp->#Map->mapComp = "{" [first] " | " + $Utils.listToString($[bindings]$) + ($[predicate]$ == null ? "}" : " & " + $[predicate]$ + "}")$
%exp->#Map->mapEnum = "" + $($[members]$.isEmpty() ? "{|->}" : "{" + Utils.listToString($[members]$) + "}") + ""$
 
%exp->#Seq->seqComp = "[" [first] " | "  [setBind] + $($[predicate]$ == null ? "]" : " & " + $[predicate]$ + "]")$
%exp->#Seq->seqEnum = "" + $Utils.listToString("[", $[members]$, ", ", "]")$

%exp->#Set->setComp = "{" [first] " | " + $Utils.listToString($[bindings]$) + ($[predicate]$ == null ? "}" : " & " + $[predicate]$ + "}")$
%exp->#Set->setEnum = "" + $Utils.listToString("{", $[members]$, ", ", "}")$
%exp->#Set->setRange = "{" [first] ", ... ," + [last] "}"
 
//field
%field->field=[tagname] + $(($[equalityAbstraction]$ ? " :- " : " : "))$ + [type]
 
//  Types
%type->#basic->boolean = "bool"
%type->#basic->char="char"
%type->#basic->token="token"

%type->#basic->#numeric->int ="int"
%type->#basic->#numeric->natOne="nat1"
%type->#basic->#numeric->nat="nat"
%type->#basic->#numeric->rational="rat"
%type->#basic->#numeric->real="real"

%type->bracket = [type]
%type->class =[classdef]$.getName().getName()$
%type->function = "(" + $($ [parameters]$.isEmpty() ? "()" : Utils.listToString($[parameters]$, " * ")) + ($[partial]$ ? " -> " : " +> ")$ + [result] + ")"
%type->#invariant->named = [name]$.getExplicit(true).toString()$
%type->#invariant->record = ""+$Utils.recNameToString($[name]$)$
//map
%type->#Map->inMap="inmap (" [from]  ") to ("  [to] ")"
%type->#Map->map="map (" [from]  ") to ("  [to] ")"
%type->operation = "(" + $($[parameters]$.isEmpty() ? "()" : Utils.listToString($[parameters]$, " * ")) + " ==> "$ + [result] + ")"
%type->optional = "[" [type] "]"
%type->parameter = "@" [name]
%type->product = "" +$Utils.listToString("(",$ [types] $, " * ", ")")$
%type->quote = [value] 
%type->#seq->seq = ""+ $($[empty]$ ? "[]" : "seq of (" + $  [seqof] $+ ")" )$ 
%type->#seq->seq1 = "seq1 of (" + [seqof] + ")"
%type->#set->set = ""+ $($[empty]$ ? "{}" : "set of (" +$ [setof]$ + ")")$
%type->#set->set1 = "set1 of (" + [setof] + ")"
%type->undefined = "(undefined)"
%type->union = ""+$($[types]$.size() == 1?$ [types]$.iterator().next().toString() : Utils.setToString($[types]$, " | "))$
%type->unknown = "?"
%type->unresolved = "(unresolved " + $$[name]$.getExplicit(true)$ + ")"
%type->voidReturn = "(return)"
%type->void = "()"       

//  Patterns
%pattern->boolean = [value]
%pattern->character = [value]
%pattern->concatenation = [left] " ^ " [right]
%pattern->expression = "(" [exp] ")"
%pattern->identifier = [name]
%pattern->ignore = "-"
%pattern->integer = [value]
%pattern->nil = "nil"
%pattern->quote = [value]
%pattern->real = [value]
%pattern->record = "mk_" [typename]  "(" + $Utils.listToString($[plist]$)$ + ")"
%pattern->seq = [plist]
%pattern->set = "{" + $Utils.listToString($[plist]$)$ + "}"
%pattern->string = [value]
%pattern->tuple = "mk_"  "(" + $Utils.listToString($[plist]$)$ + ")"
%pattern->union = [left] " union " [right]
%pattern->map = "" + $($[maplets]$.isEmpty() ? "{|->}" : Utils.listToString("{", $[maplets]$, ", ", "}"))$
%pattern->object = "obj_" [classname]  "(" + $Utils.listToString($[fields]$)$ + ")"

%patternBind->def = "pattern=" [pattern] ", bind=" [bind] ", defs=(" + $Utils.listToString($[defs]$)$ + "), type=" [type]

  

//  Definitions
%definition->assignment = [name] ":"  [type] " := " [expression]
%definition->instanceVariable = [name] ":"  [type] " := " [expression]
%definition->#class->bus = "class " [name]$.getFullName()+ ($[supernames]$.isEmpty() ? "" : " is subclass of " +$ [supernames]$) + "\n" + ToStringUtil.getDefinitionListString($[definitions]$)$ +
                "end "  [name]$.getFullName()$ + "\n"
%definition->#class->cpu = "class " [name]$.getFullName()+ ($[supernames]$.isEmpty() ? "" : " is subclass of " +$ [supernames]$) + "\n" + ToStringUtil.getDefinitionListString($[definitions]$)$ +
                "end "  [name]$.getFullName()$ + "\n"
%definition->#class->system = "system " [name]$.getFullName()+ ($[supernames]$.isEmpty() ? "" : " is subclass of " +$ [supernames]$) + "\n" + ToStringUtil.getDefinitionListString($[definitions]$)$ +
                "end "  [name]$.getFullName()$ + "\n"
%definition->#class->class = "class " [name]$.getFullName()+ ($[supernames]$.isEmpty() ? "" : " is subclass of " +$ [supernames]$) + "\n" + ToStringUtil.getDefinitionListString($[definitions]$)$ +
                "end "  [name]$.getFullName()$ + "\n"
%definition->classInvariant = "inv" [expression]
%definition->equals = ""+ $($[pattern]$ != null ? $[pattern]$ : $[typebind]$ != null ? $[typebind]$ : $[setbind]$)$ + " = " + [test]
%definition->explicitFunction = ""+$ToStringUtil.getExplicitFunctionString(this)$ 
%definition->external = ""+$($[readOnly]$ ? "ext rd " : "ext wr ")+$  [state]$.getName()$
%definition->implicitFunction = ""+$ToStringUtil.getImplicitFunctionString(this)$
%definition->explicitOperation = ""+$ToStringUtil.getExplicitOperationString(this)$
%definition->implicitOperation = ""+$ToStringUtil.getImplicitOperationString(this)$
%definition->imported = [def]
%definition->inherited = [superdef] 
%definition->local = [name]$.getFullName()$+ " = " [type] 
%definition->multiBindList = "def " + $Utils.listToString($[bindings]$)$
%definition->mutexSync = "mutex(" + $($[operations]$.isEmpty() ? "all)" :
                Utils.listToString("", $[operations]$, ", ", ")"))$
//%definition->namedTrace = [pathname] " = " [terms]
%definition->perSync =  "per " [opname] " => " [guard]
%definition->renamed = [def]  " renamed " [name]
%definition->state = "state " [name] "of\n" [fields]+$
            ($[invPattern]$ == null ? "" : "\n\tinv " + $[invPattern]$ + " == " + $[invExpression]$) +
            ($[initPattern]$ == null ? "" : "\n\tinit " + $[initPattern]$ + " == " + $[initExpression]$)$
%definition->thread = "thread " [statement]
%definition->type = [name]$.getFullName() + " = " + $[type]$/*.toDetailedString()*/ +
                ($[invPattern]$ == null ? "" :
                    "\n\tinv " + $[invPattern]$ + " == " + $[invExpression]$)$
%definition->untyped = "Unknown type definition " [name] 
%definition->value = [pattern] +$($[type]$ == null ? "" : ":" + $[type]$) + " = " +$ [expression]


%modules->module= "module " [name]$.getName()+  "\n definitions\n" + ToStringUtil.getDefinitionListString($[defs]$)$ +
                "end "  [name]$.getName()$ + "\n"
//return (_name!=null?_name.toString():this.getClass().getSimpleName())+ (_imports!=null?_imports.toString():this.getClass().getSimpleName())+ (_exports!=null?_exports.toString():this.getClass().getSimpleName())+ (_defs!=null?_defs.toString():this.getClass().getSimpleName())+ (_files!=null?_files.toString():this.getClass().getSimpleName())+ (_importdefs!=null?_importdefs.toString():this.getClass().getSimpleName())+ (_exportdefs!=null?_exportdefs.toString():this.getClass().getSimpleName())+ (_isFlat!=null?_isFlat.toString():this.getClass().getSimpleName())+ (_typeChecked!=null?_typeChecked.toString():this.getClass().getSimpleName())+ (_isDLModule!=null?_isDLModule.toString():this.getClass().getSimpleName());

//%definition->value = [pattern] " : " [expType] " = " [expression]

//  Statements
%stm->always = "always "  [always]  " in "  [body]
%stm->assignment = [target] " := " [exp]
%stm->atomic = "atomic (" + $Utils.listToString($[assignments]$)$ + ")"
%stm->callObject = [designator]  "." +
            $($[classname]$ != null ? $[classname]$ : $[fieldname]$) + "(" + Utils.listToString($[args]$)$ + ")"
%stm->call = [name]$.getFullName() + "(" + Utils.listToString($[args]$)$ + ")"
%stm->cases = ""+$ToStringUtil.getCasesString(this)$
%stm->classInvariant = "instance invariant " [name]
%stm->cycles = "cycles (" [cycles] ") " [statement]
%stm->duration = "duration (" [duration] ") " [statement]
%stm->elseIf = "elseif " [elseIf] "\nthen\n" [thenStm]
%stm->error = "error"
%stm->exit = "exit" + $($[expression]$ == null ? ";" : " (" + $[expression]$ + ")")$
%stm->forAll = "for all " [pattern] " in set " [set] " do\n" [statement] 
%stm->forIndex = "for " [var] " = " [from] " to " [to] +
                    $($[by]$ == null ? "" : " by " + $[by]$)$+  "\n" [statement]
%stm->forPatternBind = "for " [patternBind] " in " +
            $($[reverse]$ ? " reverse " : "")$+ [exp]  " do\n" [statement]
%stm->if = ""+$ToStringUtil.getIfString(this)$
%stm->letBeSt = "let " [bind] +
            $($[suchThat]$ == null ? "" : " be st " + $[suchThat]$)$ + " in " [statement]
//%stm->#LetDef = "let " [localDefs]  " in " [statement]
//%stm->#LetDef->def = "def " + $Utils.listToString($[localDefs]$)$ + " in " [statement]
%stm->Let = "let " + $Utils.listToString($[localDefs]$)$ + " in " [statement]
%stm->notYetSpecified = "is not yet specified" 
%stm->return = "return" + $($[expression]$ == null ? "" : " (" + $[expression]$ + ")")$
%stm->#SimpleBlock = ""+$ToStringUtil.getSimpleBlockString(this)$ 
%stm->#SimpleBlock->block = ""+$ToStringUtil.getBlockSimpleBlockString(this)$
%stm->#SimpleBlock->nonDeterministic = ""+$ToStringUtil.getNonDeterministicSimpleBlockString(this)$
%stm->skip = "skip"
%stm->specification = "[" +
            $($[externals]$.isEmpty() ? "" : "\n\text " + $[externals]$) +
            ($[precondition]$ == null ? "" : "\n\tpre " + $[precondition]$) +
            ($[postcondition]$ == null ? "" : "\n\tpost " + $[postcondition]$) +
            ($[errors]$.isEmpty() ? "" : "\n\terrs " + $[errors]$)$ + "]" 
%stm->start = "start (" [obj] ")"
%stm->stop = "stop (" [obj] ")"
%stm->subclassResponsibility = "is subclass responsibility"
%stm->tixe = "tixe {" [traps] "} in " [body]
//%stm->traceVariable = 
%stm->trap = "trap " [patternBind] " with " [with] " in " [body]
%stm->while = "while " [exp]  " do " [statement]
%stm->periodic = "periodic(" + $Utils.listToString($[args]$)$ + ")(" [opname] ")"
%stm->sporadic = "sporadic(" + $Utils.listToString($[args]$)$ + ")(" [opname] ")"


%alternativeStm->case = [pattern] " -> " [result]

//Other

//Access
%accessSpecifier->accessSpecifier = ""+$($[access]$==null?"":$[access]$+" ") +
                                    ($[static]$==null?"":$[static]$+" ") +
                                    ($[async]$==null?"":$[async]$+" ") +
                                    ($[pure]$?"pure ":"")$ 
                                    
%access->public ="public"
%access->protected ="protected"
%access->private ="private"


%pair->patternType = [pattern]  ":" [type]

//Binds
%multipleBind->set = ""+ $Utils.listToString($[plist]$)$ + " in set " [set];
%multipleBind->type = "" + $Utils.listToString($[plist]$)$ + ":" [type]
%bind->set = ""+ [pattern] + " in set " [set];
%bind->type = "" + [pattern] + ":" + [type];
%bind->seq = ""+ [pattern] + " in seq " [seq];

// Modifiers
%modifier->record = [tag] " |-> " [value];

//state designator
%stateDesignator->field = [object] "." [field];
%stateDesignator->mapSeq = [mapseq] "(" + [exp] + ")";
%stateDesignator->identifier = [name];

//object designator
%objectDesignator->identifier = [name];
%objectDesignator->apply = [object] "(" + $Utils.listToString($[args]$)$ + ")"
%objectDesignator->field = [object]+"."+[fieldName]
%objectDesignator->new = "new "+[expression]
%objectDesignator->self = [self]


//traces
%traceDefinition->repeat = [core] "{"[from]","[to]"}"
%traceCoreDefinition->applyExpression = [callStatement]
%traceCoreDefinition->bracketedExpression = "("[terms]")"





© 2015 - 2024 Weber Informatics LLC | Privacy Policy