Commit a652da52 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Added support for parsing of qualified names with arrays(Port arrays, ComponentInstance arrays)

parent 36995b33
......@@ -32,6 +32,19 @@ grammar Tagging extends de.monticore.common.Common {
fragment token Recursion = '{' (~('{' | '}' | '"') | String | Recursion)+ '}';
fragment token TagToken = (~('"' | '{' | '}' | ';'))+;
NameWithArray = (Name ("[" IntLiteral "]")?);
ast NameWithArray =
method public String toString(){
return name + (intLiteral.isPresent() ? "[" + intLiteral.get().getValue() + "]" : "");
};
QualifiedNameWithArray = ( NameWithArray || ".")+;
ast QualifiedNameWithArray =
method public String toString(){
return de.se_rwth.commons.Joiners.DOT.join(getNameWithArrays());
};
interface Scope;
ast Scope =
method public String getQualifiedNameString() {
......@@ -42,19 +55,19 @@ grammar Tagging extends de.monticore.common.Common {
};
// this one is only defined here, to get Parser Tags
NameScope implements Scope = QualifiedName;
NameScope implements Scope = QualifiedNameWithArray;
ast NameScope =
method public String getQualifiedNameString() {
return getQualifiedName().toString();
return getQualifiedNameWithArray().toString();
}
method public String getScopeKind() {
return "NameScope";
};
ConnectorScope extends NameScope = source:QualifiedName "->" QualifiedName;
ConnectorScope extends NameScope = source:QualifiedNameWithArray "->" QualifiedNameWithArray;
ast ConnectorScope =
method public String getQualifiedNameString() {
return getQualifiedName().toString();
return getQualifiedNameWithArray().toString();
}
method public String getScopeKind() {
return "ConnectorScope";
......
......@@ -20,10 +20,22 @@
*/
package de.monticore.lang.montiarc.tagging;
import de.monticore.lang.tagging._ast.ASTScope;
import de.monticore.lang.tagging._ast.ASTTag;
import de.monticore.lang.tagging._ast.ASTTagElement;
import de.monticore.lang.tagging._ast.ASTTaggingUnit;
import de.monticore.lang.tagging._parser.TaggingParser;
import org.junit.Ignore;
import org.junit.Test;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.assertTrue;
/**
* Created by MichaelvonWenckstern on 13.06.2016.
*/
......@@ -56,7 +68,7 @@ public class ParserTagValueTest {
// .forEachOrdered(t -> System.out.println(t.getTagValue().get()));
//// System.out.println(tags.getTags().get(0).getTagValue().length());
// }
@Ignore
@Test
public void testTagschema2() throws Exception {
TaggingParser parser = new TaggingParser();
......@@ -65,4 +77,29 @@ public class ParserTagValueTest {
// System.out.println(tags.getTags().size());
// System.out.println(tags.getTags().get(0).getTagValue().length());
}
@Test
public void testArrayTagging() throws IOException {
TaggingParser parser = new TaggingParser();
ASTTaggingUnit taggingUnit = parser.parse("src/test/resources/array/Array.tag").get();
List<ASTTag> tags = taggingUnit.getTagBody().getTags();
List<ASTScope> taggedElements = tags.stream()
.map(ASTTag::getScopes)
.flatMap(Collection::stream)
.collect(Collectors.toList());
Set<String> nameStrings = taggedElements.stream()
.map(ASTScope::getQualifiedNameString)
.collect(Collectors.toSet());
assertTrue(nameStrings.size() == 5);
assertTrue(nameStrings.contains("InstanceArrayComp.subcomps[1]"));
assertTrue(nameStrings.contains("InstanceArrayComp.subcomps[5]"));
assertTrue(nameStrings.contains("PortArrayComp.arrayIn[1]"));
assertTrue(nameStrings.contains("PortArrayComp.arrayIn[3]"));
assertTrue(nameStrings.contains("Comp.subCompInst[6].portArray[4]"));
}
}
package array;
conforms to nfp.TracebilityTagSchema;
tags Array{
//Tag a Subcomponent array
tag InstanceArrayComp.subcomps[1] with IsTraceable;
tag InstanceArrayComp.subcomps[5] with IsTraceable;
//Tag an array Port
tag PortArrayComp.arrayIn[1] with IsTraceable;
tag PortArrayComp.arrayIn[3] with IsTraceable;
//Combination of both
tag Comp.subCompInst[6].portArray[4] with IsTraceable;
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment