Skip to content
Snippets Groups Projects
Commit 5188b017 authored by René Schöne's avatar René Schöne
Browse files

begin with removing tree and list

parent 2e6e5420
No related branches found
No related tags found
3 merge requests!39Version 1.1.0,!35Version 1.0.0,!19Resolve "Make specification langauge more concise"
Pipeline #11774 passed
This commit is part of merge request !19. Comments created here will be created in the context of that merge request.
Showing with 206 additions and 82 deletions
aspect NameResolution { aspect RagConnectNameResolution {
// rel EndpointDefinition.Mapping* -> MappingDefinition
refine RefResolverStubs eq EndpointDefinition.resolveMappingByToken(String id, int position) { refine RefResolverStubs eq EndpointDefinition.resolveMappingByToken(String id, int position) {
// return a MappingDefinition MappingDefinition result = tryResolveMappingByToken(id);
if (result == null) {
System.err.println("Could not resolve MappingDefinition '" + id + "'.");
}
return result;
}
syn MappingDefinition EndpointDefinition.tryResolveMappingByToken(String id) {
for (MappingDefinition mappingDefinition : ragconnect().allMappingDefinitionList()) { for (MappingDefinition mappingDefinition : ragconnect().allMappingDefinitionList()) {
if (mappingDefinition.getID().equals(id)) { if (mappingDefinition.getID().equals(id)) {
return mappingDefinition; return mappingDefinition;
} }
} }
System.err.println("Could not resolve MappingDefinition '" + id + "'.");
return null; return null;
} }
// rel ___ -> TypeComponent
refine RefResolverStubs eq ASTNode.globallyResolveTypeComponentByToken(String id) { refine RefResolverStubs eq ASTNode.globallyResolveTypeComponentByToken(String id) {
// return a TypeComponent. id is of the form 'parent_type_name + "." + child_type_name' TypeComponent result = tryGloballyResolveTypeComponentByToken(id);
if (result == null) {
System.err.println("Could not resolve TypeComponent '" + id + "'.");
}
return result;
}
syn TypeComponent ASTNode.tryGloballyResolveTypeComponentByToken(String id) {
// id is of the form 'parent_type_name + "." + child_type_name'
int dotIndex = id.indexOf("."); int dotIndex = id.indexOf(".");
String parentTypeName = id.substring(0, dotIndex); String parentTypeName = id.substring(0, dotIndex);
String childTypeName = id.substring(dotIndex + 1); String childTypeName = id.substring(dotIndex + 1);
...@@ -23,12 +37,19 @@ aspect NameResolution { ...@@ -23,12 +37,19 @@ aspect NameResolution {
return comp.asTypeComponent(); return comp.asTypeComponent();
} }
} }
System.err.println("Could not resolve TypeComponent '" + id + "'.");
return null; return null;
} }
// rel ___ -> Component
refine RefResolverStubs eq ASTNode.globallyResolveComponentByToken(String id) { refine RefResolverStubs eq ASTNode.globallyResolveComponentByToken(String id) {
// return a Component. id is of the form 'parent_type_name + "." + child_type_name' Component result = tryGloballyResolveComponentByToken(id);
if (result == null) {
System.err.println("Could not resolve Component '" + id + "'.");
}
return result;
}
syn Component ASTNode.tryGloballyResolveComponentByToken(String id) {
// id is of the form 'parent_type_name + "." + child_type_name'
int dotIndex = id.indexOf("."); int dotIndex = id.indexOf(".");
String parentTypeName = id.substring(0, dotIndex); String parentTypeName = id.substring(0, dotIndex);
String childTypeName = id.substring(dotIndex + 1); String childTypeName = id.substring(dotIndex + 1);
...@@ -39,7 +60,30 @@ aspect NameResolution { ...@@ -39,7 +60,30 @@ aspect NameResolution {
return comp; return comp;
} }
} }
System.err.println("Could not resolve Component '" + id + "'."); return null;
}
// rel ___ -> TokenComponent (from relast-preprocessor)
// refine here to have an attribute without writing on stderr if not found
refine NameResolution eq ASTNode.globallyResolveTokenComponentByToken(String id) {
TokenComponent result = tryGloballyResolveTokenComponentByToken(id);
if (result == null) {
System.err.println("Could not resolve TokenComponent '" + id + "'.");
}
return result;
}
syn TokenComponent ASTNode.tryGloballyResolveTokenComponentByToken(String id) {
// id is of the form 'type_name + "." + token_name'
int dotIndex = id.indexOf(".");
String typeName = id.substring(0, dotIndex);
String tokenName = id.substring(dotIndex + 1);
TypeDecl type = program().resolveTypeDecl(typeName);
// iterate over components and find the matching tokenComponent
for (Component comp : type.getComponentList()) {
if (comp.isTokenComponent() && comp.getName().equals(tokenName)) {
return comp.asTokenComponent();
}
}
return null; return null;
} }
......
...@@ -28,3 +28,8 @@ abstract MappingDefinitionType ::= ; ...@@ -28,3 +28,8 @@ abstract MappingDefinitionType ::= ;
JavaMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ; JavaMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
JavaArrayMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ; JavaArrayMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
DefaultMappingDefinition : MappingDefinition ; DefaultMappingDefinition : MappingDefinition ;
// only used by parser
abstract UntypedEndpointDefinition : EndpointDefinition ::= <TokenOrType> <Indexed:boolean> <WithAdd:boolean> ;
ReceiveUntypedEndpointDefinition : UntypedEndpointDefinition;
SendUntypedEndpointDefinition : UntypedEndpointDefinition;
aspect ParserRewrites {
rewrite SendUntypedEndpointDefinition {
when (tryGloballyResolveTypeComponentByToken(getTokenOrType()) != null)
to SendTypeEndpointDefinition {
SendTypeEndpointDefinition result = new SendTypeEndpointDefinition();
result.applyFrom(this);
if (this.getIndexed()) {
result.setUseList(true);
}
return result;
}
}
rewrite ReceiveUntypedEndpointDefinition {
when (tryGloballyResolveTypeComponentByToken(getTokenOrType()) != null)
to ReceiveTypeEndpointDefinition {
ReceiveTypeEndpointDefinition result = new ReceiveTypeEndpointDefinition();
result.applyFrom(this);
if (this.getWithAdd()) {
result.setWithAdd(true);
}
if (this.getIndexed()) {
result.setUseList(true);
}
return result;
}
}
rewrite SendUntypedEndpointDefinition {
when (tryGloballyResolveTokenComponentByToken(getTokenOrType()) != null)
to SendTokenEndpointDefinition {
SendTokenEndpointDefinition result = new SendTokenEndpointDefinition();
result.applyFrom(this);
return result;
}
}
rewrite ReceiveUntypedEndpointDefinition {
when (tryGloballyResolveTokenComponentByToken(getTokenOrType()) != null)
to ReceiveTokenEndpointDefinition {
ReceiveTokenEndpointDefinition result = new ReceiveTokenEndpointDefinition();
result.applyFrom(this);
return result;
}
}
protected void TypeEndpointDefinition.applyFrom(UntypedEndpointDefinition def) {
this.setAlwaysApply(def.getAlwaysApply());
this.setType(TypeComponent.createRef(def.getTokenOrType()));
this.moveMappingsFrom(def);
}
protected void TokenEndpointDefinition.applyFrom(UntypedEndpointDefinition def) {
this.setAlwaysApply(def.getAlwaysApply());
this.setToken(TokenComponent.createRef(def.getTokenOrType()));
this.moveMappingsFrom(def);
}
protected void EndpointDefinition.moveMappingsFrom(UntypedEndpointDefinition def) {
// can safely iterate over list as we get an unmodifyable list
for (MappingDefinition mapping : def.getMappingList().toArray(new MappingDefinition[0])) {
def.removeMapping(mapping);
this.addMapping(mapping);
}
}
private void UntypedEndpointDefinition.clearMappings() {
}
eq UntypedEndpointDefinition.targetTypeName() = "<unknown>";
syn MEndpointDefinition UntypedEndpointDefinition.toMustache() {
throw new RuntimeException("UntypedEndpoint can not be transformed using toMustache!");
}
}
...@@ -43,49 +43,49 @@ EndpointDefinition endpoint_definition ...@@ -43,49 +43,49 @@ EndpointDefinition endpoint_definition
; ;
EndpointDefinition endpoint_definition_type EndpointDefinition endpoint_definition_type
= RECEIVE token_ref {: return new ReceiveTokenEndpointDefinition().setToken(token_ref); :} = SEND ID.type_name DOT ID.child_name
| SEND token_ref {: return new SendTokenEndpointDefinition().setToken(token_ref); :}
| RECEIVE TREE type_ref {: return new ReceiveTypeEndpointDefinition().setType(type_ref); :}
| RECEIVE TREE WITH ADD type_ref
{: {:
ReceiveTypeEndpointDefinition result = new ReceiveTypeEndpointDefinition(); SendUntypedEndpointDefinition result = new SendUntypedEndpointDefinition();
result.setType(type_ref); result.setTokenOrType(type_name + "." + child_name);
result.setWithAdd(true); return result;
:}
| SEND INDEXED ID.type_name DOT ID.child_name
{:
SendUntypedEndpointDefinition result = new SendUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
result.setIndexed(true);
return result;
:}
| RECEIVE ID.type_name DOT ID.child_name
{:
ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setTokenOrType(type_name + "." + child_name);
return result; return result;
:} :}
| SEND TREE type_ref {: return new SendTypeEndpointDefinition().setType(type_ref); :} | RECEIVE INDEXED ID.type_name DOT ID.child_name
| RECEIVE LIST type_ref
{: {:
ReceiveTypeEndpointDefinition result = new ReceiveTypeEndpointDefinition(); ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setType(type_ref); result.setTokenOrType(type_name + "." + child_name);
result.setUseList(true); result.setIndexed(true);
return result; return result;
:} :}
| RECEIVE LIST WITH ADD type_ref | RECEIVE WITH ADD ID.type_name DOT ID.child_name
{: {:
ReceiveTypeEndpointDefinition result = new ReceiveTypeEndpointDefinition(); ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setType(type_ref); result.setTokenOrType(type_name + "." + child_name);
result.setWithAdd(true); result.setWithAdd(true);
result.setUseList(true);
return result; return result;
:} :}
| SEND LIST type_ref | RECEIVE INDEXED WITH ADD ID.type_name DOT ID.child_name
{: {:
SendTypeEndpointDefinition result = new SendTypeEndpointDefinition(); ReceiveUntypedEndpointDefinition result = new ReceiveUntypedEndpointDefinition();
result.setType(type_ref); result.setTokenOrType(type_name + "." + child_name);
result.setUseList(true); result.setIndexed(true);
result.setWithAdd(true);
return result; return result;
:} :}
; ;
TokenComponent token_ref
= ID.type_name DOT ID.token_name {: return TokenComponent.createRef(type_name + "." + token_name); :}
;
TypeComponent type_ref
= ID.parent_type_name DOT ID.child_type_name {: return TypeComponent.createRef(parent_type_name + "." + child_type_name); :}
;
ArrayList string_list ArrayList string_list
= ID = ID
| string_list COMMA ID | string_list COMMA ID
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
"maps" { return sym(Terminals.MAPS); } "maps" { return sym(Terminals.MAPS); }
"to" { return sym(Terminals.TO); } "to" { return sym(Terminals.TO); }
"as" { return sym(Terminals.AS); } "as" { return sym(Terminals.AS); }
"tree" { return sym(Terminals.TREE); } //"tree" { return sym(Terminals.TREE); }
"list" { return sym(Terminals.LIST); } //"list" { return sym(Terminals.LIST); }
"with" { return sym(Terminals.WITH); } "with" { return sym(Terminals.WITH); }
"indexed" { return sym(Terminals.INDEXED); }
"add" { return sym(Terminals.ADD); } "add" { return sym(Terminals.ADD); }
send list SenderRoot.A ; send indexed SenderRoot.A ;
send list SenderRoot.SingleA ; send indexed SenderRoot.SingleA ;
receive list ReceiverRoot.A ; receive indexed ReceiverRoot.A ;
receive list ReceiverRoot.FromSingleA ; receive indexed ReceiverRoot.FromSingleA ;
receive list with add ReceiverRoot.WithAddFromA ; receive indexed with add ReceiverRoot.WithAddFromA ;
receive list with add ReceiverRoot.WithAddFromSingleA ; receive indexed with add ReceiverRoot.WithAddFromSingleA ;
send tree SenderRoot.A1 ; send SenderRoot.A1 ;
send tree SenderRoot.A2 ; send SenderRoot.A2 ;
send tree SenderRoot.A3 ; send SenderRoot.A3 ;
send tree SenderRoot.A4 ; send SenderRoot.A4 ;
send SenderRoot.InOutput using IntToA ; send SenderRoot.InOutput using IntToA ;
receive tree ReceiverRoot.A ; receive ReceiverRoot.A ;
receive tree ReceiverRoot.UsingWildcardA ; receive ReceiverRoot.UsingWildcardA ;
receive tree with add ReceiverRoot.WithAddA ; receive with add ReceiverRoot.WithAddA ;
receive tree with add ReceiverRoot.UsingWildcardWithAddA ; receive with add ReceiverRoot.UsingWildcardWithAddA ;
IntToA maps int i to A {: IntToA maps int i to A {:
return new A().setID(i); return new A().setID(i);
......
send tree SenderRoot.T_Empty ; send SenderRoot.T_Empty ;
send tree SenderRoot.T_Token ; send SenderRoot.T_Token ;
send tree SenderRoot.T_OneChild ; send SenderRoot.T_OneChild ;
send tree SenderRoot.T_OneOpt ; send SenderRoot.T_OneOpt ;
send tree SenderRoot.T_OneList ; send SenderRoot.T_OneList ;
send tree SenderRoot.T_TwoChildren ; send SenderRoot.T_TwoChildren ;
send tree SenderRoot.T_OneOfEach ; send SenderRoot.T_OneOfEach ;
send tree SenderRoot.T_Abstract ; send SenderRoot.T_Abstract ;
receive tree ReceiverRoot.T_Empty ; receive ReceiverRoot.T_Empty ;
receive tree ReceiverRoot.T_Token ; receive ReceiverRoot.T_Token ;
receive tree ReceiverRoot.T_OneChild ; receive ReceiverRoot.T_OneChild ;
receive tree ReceiverRoot.T_OneOpt ; receive ReceiverRoot.T_OneOpt ;
receive tree ReceiverRoot.T_OneList ; receive ReceiverRoot.T_OneList ;
receive tree ReceiverRoot.T_TwoChildren ; receive ReceiverRoot.T_TwoChildren ;
receive tree ReceiverRoot.T_OneOfEach ; receive ReceiverRoot.T_OneOfEach ;
receive tree ReceiverRoot.T_Abstract ; receive ReceiverRoot.T_Abstract ;
receive tree ReceiverRoot.MyEmpty ; receive ReceiverRoot.MyEmpty ;
receive tree with add ReceiverRoot.EmptyWithAdd ; receive with add ReceiverRoot.EmptyWithAdd ;
receive tree with add ReceiverRoot.TokenWithAdd ; receive with add ReceiverRoot.TokenWithAdd ;
receive tree with add ReceiverRoot.OneChildWithAdd ; receive with add ReceiverRoot.OneChildWithAdd ;
receive tree with add ReceiverRoot.OneOptWithAdd ; receive with add ReceiverRoot.OneOptWithAdd ;
receive tree with add ReceiverRoot.OneListWithAdd ; receive with add ReceiverRoot.OneListWithAdd ;
receive tree with add ReceiverRoot.TwoChildrenWithAdd ; receive with add ReceiverRoot.TwoChildrenWithAdd ;
receive tree with add ReceiverRoot.OneOfEachWithAdd ; receive with add ReceiverRoot.OneOfEachWithAdd ;
receive tree with add ReceiverRoot.AbstractWithAdd ; receive with add ReceiverRoot.AbstractWithAdd ;
send tree SenderRoot.Alfa ; send SenderRoot.Alfa ;
receive tree ReceiverRoot.Alfa ; receive ReceiverRoot.Alfa ;
send tree SenderRoot.Alfa ; send SenderRoot.Alfa ;
receive tree ReceiverRoot.Alfa ; receive ReceiverRoot.Alfa ;
receive SenderRoot.Input1WhenFlagIsTrue ; receive SenderRoot.Input1WhenFlagIsTrue ;
receive SenderRoot.Input1WhenFlagIsFalse ; receive SenderRoot.Input1WhenFlagIsFalse ;
receive SenderRoot.Input2 ; receive SenderRoot.Input2 ;
receive SenderRoot.Input3 ; receive SenderRoot.Input3 ;
send tree SenderRoot.AlfaPrimitive using Alfa2String ; send SenderRoot.AlfaPrimitive using Alfa2String ;
receive tree ReceiverRoot.AlfaPrimitive using String2Alfa ; receive ReceiverRoot.AlfaPrimitive using String2Alfa ;
Alfa2String maps Alfa alfa to String {: Alfa2String maps Alfa alfa to String {:
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment