Commit a81fc24c authored by René Schöne's avatar René Schöne
Browse files

Merge branch 'feature/submodule' into dev/rene

parents ceff6575 4675200b
Pipeline #6526 passed with stage
in 1 minute and 15 seconds
variables:
GIT_SUBMODULE_STRATEGY: none
stages: stages:
- build - build
test: test:
image: openjdk:8 image: openjdk:8
stage: build stage: build
before_script:
- git submodule init
- git submodule sync
- cat .gitmodules
- cat .git/config
- ls -lah *
- rm -rf relast.preprocessor/*
- ls -lah *
- git submodule update --remote
- ls -lah *
script: script:
- ./gradlew --no-daemon build - ./gradlew --no-daemon build
[submodule "relast-preprocessor"]
path = relast.preprocessor
url = ../relast-preprocessor.git
Subproject commit 54af6737685fab0be452f446b70b9842aba89e42
...@@ -66,7 +66,7 @@ task relast(type: JavaExec) { ...@@ -66,7 +66,7 @@ task relast(type: JavaExec) {
args = [ args = [
"../libs/relast.jar", "../libs/relast.jar",
"./src/main/jastadd/RelAst.relast", "../relast.preprocessor/src/main/jastadd/RelAst.relast",
"./src/main/jastadd/Ros2Rag.relast", "./src/main/jastadd/Ros2Rag.relast",
"--listClass=java.util.ArrayList", "--listClass=java.util.ArrayList",
"--jastAddList=JastAddList", "--jastAddList=JastAddList",
...@@ -77,7 +77,7 @@ task relast(type: JavaExec) { ...@@ -77,7 +77,7 @@ task relast(type: JavaExec) {
] ]
inputs.files file("../libs/relast.jar"), inputs.files file("../libs/relast.jar"),
file("src/main/jastadd/RelAST.relast"), file("../relast.preprocessor/src/main/jastadd/RelAST.relast"),
file("src/main/jastadd/Ros2Rag.relast") file("src/main/jastadd/Ros2Rag.relast")
outputs.files file("./src/gen/jastadd/Ros2Rag.ast"), outputs.files file("./src/gen/jastadd/Ros2Rag.ast"),
file("src/gen/jastadd/Ros2Rag.jadd"), file("src/gen/jastadd/Ros2Rag.jadd"),
...@@ -92,29 +92,45 @@ jastadd { ...@@ -92,29 +92,45 @@ jastadd {
module("Ros2Rag") { module("Ros2Rag") {
java { java {
basedir "." basedir ".."
include "src/main/**/*.java" include "relast.preprocessor/main/**/*.java"
include "src/gen/**/*.java" include "relast.preprocessor/gen/**/*.java"
include "ros2rag.base/src/main/**/*.java"
include "ros2rag.base/src/gen/**/*.java"
} }
jastadd { jastadd {
basedir "." basedir ".."
include "src/main/jastadd/**/*.ast" include "relast.preprocessor/src/main/jastadd/**/*.ast"
include "src/main/jastadd/**/*.jadd" include "relast.preprocessor/src/main/jastadd/**/*.jadd"
include "src/main/jastadd/**/*.jrag" include "relast.preprocessor/src/main/jastadd/**/*.jrag"
include "src/gen/jastadd/**/*.ast" include "ros2rag.base/src/main/jastadd/**/*.ast"
include "src/gen/jastadd/**/*.jadd" include "ros2rag.base/src/main/jastadd/**/*.jadd"
include "src/gen/jastadd/**/*.jrag" include "ros2rag.base/src/main/jastadd/**/*.jrag"
include "ros2rag.base/src/gen/jastadd/**/*.ast"
include "ros2rag.base/src/gen/jastadd/**/*.jadd"
include "ros2rag.base/src/gen/jastadd/**/*.jrag"
} }
scanner { scanner {
include "src/main/jastadd/Ros2Rag.flex" basedir ".."
include "ros2rag.base/src/main/jastadd/scanner/Header.flex", [-5]
include "relast.preprocessor/src/main/jastadd/scanner/Preamble.flex", [-4]
include "relast.preprocessor/src/main/jastadd/scanner/Macros.flex", [-3]
include "ros2rag.base/src/main/jastadd/scanner/Macros.flex", [-3]
include "relast.preprocessor/src/main/jastadd/scanner/RulesPreamble.flex", [-2]
include "ros2rag.base/src/main/jastadd/scanner/MappingContent.flex", [-1]
include "ros2rag.base/src/main/jastadd/scanner/Keywords.flex"
include "relast.preprocessor/src/main/jastadd/scanner/Keywords.flex"
include "relast.preprocessor/src/main/jastadd/scanner/Symbols.flex", [1]
include "relast.preprocessor/src/main/jastadd/scanner/RulesPostamble.flex", [2]
} }
parser { parser {
include "src/main/jastadd/Preamble.parser" basedir ".."
include "src/main/jastadd/RelAst.parser" include "ros2rag.base/src/main/jastadd/parser/Preamble.parser"
include "src/main/jastadd/Ros2Rag.parser" include "ros2rag.base/src/main/jastadd/parser/Ros2Rag.parser"
include "relast.preprocessor/src/main/jastadd/parser/RelAst.parser"
} }
} }
} }
......
aspect DumpTree {
private static final String ASTNode.DUMP_TREE_INDENT = " ";
public String ASTNode.dumpTree() {
java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
dumpTree(new java.io.PrintStream(bytes));
return bytes.toString();
}
public void ASTNode.dumpTree(java.io.PrintStream out) {
dumpTree(out, "");
out.flush();
}
public void ASTNode.dumpTree(java.io.PrintStream out, String indent) {
out.print(indent + getClass().getSimpleName());
out.print(getTokens());
String extra = extraDumpInfo();
if (!extra.isEmpty()) {
out.print(" " + extra);
}
out.println();
String childIndent = indent + DUMP_TREE_INDENT;
for (ASTNode<?> child : astChildren()) {
if (child == null) {
out.println(childIndent + "null");
} else {
child.dumpTree(out, childIndent);
}
}
}
public String ASTNode.extraDumpInfo() { return ""; }
public String ASTNode.getTokens() {
java.util.TreeSet<java.lang.reflect.Method> methods = new java.util.TreeSet<>(java.util.Comparator.comparing(java.lang.reflect.Method::getName));
methods.addAll(java.util.Arrays.asList(getClass().getMethods()));
StringBuilder result = new StringBuilder();
for (java.lang.reflect.Method method : methods) {
ASTNodeAnnotation.Token token = method.getAnnotation(ASTNodeAnnotation.Token.class);
if (token != null) {
try {
result.append(String.format(" %s=\"%s\"", token.name(), method.invoke(this)));
} catch (IllegalAccessException ignored) {
} catch (java.lang.reflect.InvocationTargetException ignored) {
}
}
}
return result.toString();
}
}
aspect NameResolution { aspect NameResolution {
refine RefResolverStubs eq ASTNode.globallyResolveTypeDeclByToken(String id) = program().resolveTypeDecl(id);
syn TypeDecl Program.resolveTypeDecl(String name) {
for (TypeDecl decl : typeDecls()) {
if (decl.getName().equals(name)) {
return decl;
}
}
throw new RuntimeException("TypeDecl " + name + " could not be resolved.");
}
refine RefResolverStubs eq ASTNode.globallyResolveTokenComponentByToken(String id) {
// return a TokenComponent. 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();
}
}
System.err.println("Could not resolve TokenComponent '" + id + "'.");
return null;
}
refine RefResolverStubs eq UpdateDefinition.resolveMappingByToken(String id, int position) { refine RefResolverStubs eq UpdateDefinition.resolveMappingByToken(String id, int position) {
// return a MappingDefinition // return a MappingDefinition
for (MappingDefinition mappingDefinition : ros2rag().getMappingDefinitionList()) { for (MappingDefinition mappingDefinition : ros2rag().getMappingDefinitionList()) {
......
aspect Navigation { aspect Navigation {
// --- program --- // --- program ---
inh Program ASTNode.program();
eq Program.getChild().program() = this;
eq Ros2Rag.getChild().program() = getProgram(); eq Ros2Rag.getChild().program() = getProgram();
// --- ros2rag // --- ros2rag
inh Ros2Rag ASTNode.ros2rag(); inh Ros2Rag ASTNode.ros2rag();
eq Ros2Rag.getChild().ros2rag() = this; eq Ros2Rag.getChild().ros2rag() = this;
// --- typeDecls --- // --- containedFile (first equation should be in preprocessor) ---
coll java.util.Set<TypeDecl> Program.typeDecls() [new java.util.HashSet<>()] root Program;
TypeDecl contributes this
to Program.typeDecls()
for program();
// --- relations ---
coll java.util.Set<Relation> Program.relations() [new java.util.HashSet<>()] root Program;
Relation contributes this
to Program.relations()
for program();
// --- containingTypeDecl ---
inh TypeDecl Component.containingTypeDecl();
eq TypeDecl.getChild().containingTypeDecl() = this;
// syn boolean RelationComponent.multiplicityOne() = false;
// eq OneRelationComponent.multiplicityOne() = true;
// syn boolean RelationComponent.multiplicityOpt() = false;
// eq OptionalRelationComponent.multiplicityOpt() = true;
// syn boolean RelationComponent.multiplicityMany() = false;
// eq ManyRelationComponent.multiplicityMany() = true;
// --- containedFile ---
inh GrammarFile ASTNode.containedFile();
eq GrammarFile.getChild().containedFile() = this;
eq Program.getChild().containedFile() = null; eq Program.getChild().containedFile() = null;
eq Ros2Rag.getChild().containedFile() = null; eq Ros2Rag.getChild().containedFile() = null;
// --- isTypeComponent --- // --- isTypeComponent (should be in preprocessor) ---
syn boolean Component.isTypeComponent() = false; syn boolean Component.isTypeComponent() = false;
eq TypeComponent.isTypeComponent() = true; eq TypeComponent.isTypeComponent() = true;
// --- isTokenComponent ---
syn boolean Component.isTokenComponent() = false;
eq TokenComponent.isTokenComponent() = true;
// --- asTokenComponent ---
syn TokenComponent Component.asTokenComponent() = null;
eq TokenComponent.asTokenComponent() = this;
// --- isWriteToMqttDefinition --- // --- isWriteToMqttDefinition ---
syn boolean UpdateDefinition.isWriteToMqttDefinition() = false; syn boolean UpdateDefinition.isWriteToMqttDefinition() = false;
eq WriteToMqttDefinition.isWriteToMqttDefinition() = true; eq WriteToMqttDefinition.isWriteToMqttDefinition() = true;
......
GrammarFile goal
= declaration.d goal.p {: p.getDeclarationList().insertChild(d, 0); return p; :}
| {: return new GrammarFile(); :}
;
Declaration declaration
= type_decl
| relation
| comment
;
Comment comment
= COMMENT {: return new Comment(COMMENT); :};
TypeDecl type_decl
= ID components_opt.c SCOL
{:
TypeDecl result = new TypeDecl();
result.setName(ID);
result.setAbstract(false);
result.setComponentList(c);
return result;
:}
| ID COL ID.s components_opt.c SCOL
{:
TypeDecl result = new TypeDecl();
result.setName(ID);
result.setAbstract(false);
result.setSuperType(TypeDecl.createRef(s));
result.setComponentList(c);
return result;
:}
| ABSTRACT ID components_opt.c SCOL
{:
TypeDecl result = new TypeDecl();
result.setName(ID);
result.setAbstract(true);
result.setComponentList(c);
return result;
:}
| ABSTRACT ID COL ID.s components_opt.c SCOL
{:
TypeDecl result = new TypeDecl();
result.setName(ID);
result.setAbstract(true);
result.setSuperType(TypeDecl.createRef(s));
result.setComponentList(c);
return result;
:}
;
JastAddList components_opt
= /* empty */ {: return new JastAddList(); :}
| ASSIGN components.l {: return l; :}
;
JastAddList components
= /* empty */ {: return new JastAddList(); :}
| components.l component.c {: return l.add(c); :}
;
Component component
= SLASH actual_component.c SLASH
{:
c.setNTA(true);
return c;
:}
| actual_component
;
Component actual_component
= ID.name COL ID.type STAR
{:
ListComponent result = new ListComponent();
result.setName(name);
result.setTypeDecl(TypeDecl.createRef(type));
return result;
:}
| ID.name COL ID.type
{:
NormalComponent result = new NormalComponent();
result.setName(name);
result.setTypeDecl(TypeDecl.createRef(type));
return result;
:}
| ID.type STAR
{:
ListComponent result = new ListComponent();
result.setName(type);
result.setTypeDecl(TypeDecl.createRef(type));
return result;
:}
| ID.type
{:
NormalComponent result = new NormalComponent();
result.setName(type);
result.setTypeDecl(TypeDecl.createRef(type));
return result;
:}
| LBRACKET ID.name COL ID.type RBRACKET
{:
OptComponent result = new OptComponent();
result.setName(name);
result.setTypeDecl(TypeDecl.createRef(type));
return result;
:}
| LBRACKET ID.type RBRACKET
{:
OptComponent result = new OptComponent();
result.setName(type);
result.setTypeDecl(TypeDecl.createRef(type));
return result;
:}
| LT ID.name COL java_type_use.type GT
{:
TokenComponent result = new TokenComponent();
result.setName(name);
result.setJavaTypeUse(type);
return result;
:}
| LT ID.type GT
{:
TokenComponent result = new TokenComponent();
result.setName(type);
result.setJavaTypeUse(new SimpleJavaTypeUse(type));
return result;
:}
;
JavaTypeUse java_type_use
= parameterized_java_type_use
| simple_java_type_use
;
ArrayList qualified_name
= ID
| qualified_name DOT ID
;
JastAddList java_type_use_list
= java_type_use.u {: return new JastAddList().add(u); :}
| java_type_use_list.l COMMA java_type_use.u {: return l.add(u); :}
;
SimpleJavaTypeUse simple_java_type_use
= qualified_name.n
{:
return new SimpleJavaTypeUse((String)n.stream().map( x -> ((Symbol)x).value.toString()).collect(java.util.stream.Collectors.joining(".")));
:}
;
ParameterizedJavaTypeUse parameterized_java_type_use
= simple_java_type_use.i LT java_type_use_list.l GT
{:
return new ParameterizedJavaTypeUse(i.getName(), l);
:}
;
Relation relation
= RELATION unnamed_role.a LEFT navigable_role.b SCOL
{:
LeftDirectedRelation result = new LeftDirectedRelation();
result.setSource(b);
result.setTarget(a);
return result;
:}
| RELATION navigable_role.a RIGHT unnamed_role.b SCOL
{:
RightDirectedRelation result = new RightDirectedRelation();
result.setSource(a);
result.setTarget(b);
return result;
:}
| RELATION navigable_role.a BIDIRECTIONAL navigable_role.b SCOL
{:
BidirectionalRelation result = new BidirectionalRelation();
result.setLeft(a);
result.setRight(b);
return result;
:}
;
UnnamedRole unnamed_role
= ID.type
{:
UnnamedRole result = new UnnamedRole();
result.setType(TypeDecl.createRef(type));
return result;
:}
| navigable_role
;
NavigableRole navigable_role
= ID.type DOT ID.name
{:
NormalRole result = new NormalRole();
result.setName(name);
result.setType(TypeDecl.createRef(type));
return result;
:}
| ID.type DOT ID.name STAR
{:
ListRole result = new ListRole();
result.setName(name);
result.setType(TypeDecl.createRef(type));
return result;
:}
| ID.type DOT ID.name QUESTION_MARK
{:
OptRole result = new OptRole();
result.setName(name);
result.setType(TypeDecl.createRef(type));
return result;
:}
;
Program ::= GrammarFile *;
abstract Grammar ::= Declaration*;
GrammarFile : Grammar ::= <FileName> ;
abstract Declaration;
TypeDecl:Declaration ::= <Name> <Abstract:boolean> Component*;
rel TypeDecl.SuperType? <-> TypeDecl.SubType*;
abstract Component ::= <Name> <NTA:boolean>;
abstract TypeComponent : Component;
rel TypeComponent.TypeDecl <-> TypeDecl.PotentialParent*;
NormalComponent : TypeComponent;
ListComponent : TypeComponent;
OptComponent : TypeComponent;
TokenComponent : Component ::= JavaTypeUse;
abstract JavaTypeUse ::= <Name>;
SimpleJavaTypeUse : JavaTypeUse;
ParameterizedJavaTypeUse : JavaTypeUse ::= JavaTypeUse*;
abstract Relation : Declaration;
// rel Source.Name -> Target;
// rel Target <- Source.Name;
abstract DirectedRelation : Relation ::= Source:NavigableRole Target:UnnamedRole ;
LeftDirectedRelation : DirectedRelation;
RightDirectedRelation : DirectedRelation;
// rel Left.LeftName <-> Right.RightName;
BidirectionalRelation : Relation ::= Left:NavigableRole Right:NavigableRole ;
abstract Role;
abstract NavigableRole : Role ::= <Name>;
NormalRole : NavigableRole;
ListRole : NavigableRole;
OptRole : NavigableRole;
UnnamedRole : Role ;
rel Role.Type <-> TypeDecl.Role*;
// comments
Comment : Declaration ::= <Text>;
package org.jastadd.ros2rag.scanner;
import org.jastadd.ros2rag.parser.Ros2RagParser.Terminals;
%%
%public
%final
%class Ros2RagScanner
%extends beaver.Scanner
%type beaver.Symbol
%function nextToken
%yylexthrow beaver.Scanner.Exception
%scanerror Ros2RagScanner.ScannerError
%line
%column
%{
private StringBuilder stringLitSb = new StringBuilder();
private beaver.Symbol sym(short id) {
return new beaver.Symbol(id, yyline + 1, yycolumn + 1, yylength(), yytext());
}
private beaver.Symbol sym(short id, String text) {
return new beaver.Symbol(id, yyline + 1, yycolumn + 1, yylength(), text);
}
public static class ScannerError extends Error {
public ScannerError(String message) {
super(message);
}
}
%}
WhiteSpace = [ ] | \t | \f | \n | \r | \r\n
TraditionalComment = [/][*][^*]*[*]+([^*/][^*]*[*]+)*[/]
EndOfLineComment = "//" [^\n\r]*
Comment = {TraditionalComment} | {EndOfLineComment}
MappingContent = [{][:][^:]*[:]+([^:}][^:]*[:]+)*[}]
ID = [a-zA-Z$_][a-zA-Z0-9$_]*
%%
{WhiteSpace} { /* ignore */ }
{Comment} { return sym(Terminals.COMMENT); }
{MappingContent} { return sym(Terminals.MAPPING_CONTENT); }
"abstract" { return sym(Terminals.ABSTRACT); }
"rel" { return sym(Terminals.RELATION); }
"read" { return sym(Terminals.READ); }
"write" { return sym(Terminals.WRITE); }
"using" { return sym(Terminals.USING); }
"canDependOn" { return sym(Terminals.CAN_DEPEND_ON); }
"maps" { return sym(Terminals.MAPS); }
"to" { return sym(Terminals.TO); }
"as" { return sym(Terminals.AS); }
";" { return sym(Terminals.SCOL); }
":" { return sym(Terminals.COL); }
"::=" { return sym(Terminals.ASSIGN); }
"*" { return sym(Terminals.STAR); }
"." { return sym(