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

Move grammar2uml to separate repository

- also use mkdocs for pages, include ragdoc
parent b9eff203
Pipeline #12727 failed
......@@ -6,3 +6,4 @@
.idea/
.gradle/
/build/
/public/
......@@ -46,16 +46,52 @@ publish_master:
only:
- master
ragdoc_build:
image:
name: "git-st.inf.tu-dresden.de:4567/jastadd/ragdoc-builder"
entrypoint: [""]
stage: ragdoc_build
needs:
- build
script:
- JAVA_FILES=$(find dumpAstWithPlantuml/src/ -name '*.java')
- /ragdoc-builder/start-builder.sh -excludeGenerated -d data/ $JAVA_FILES
artifacts:
paths:
- "data/"
ragdoc_view:
image:
name: "git-st.inf.tu-dresden.de:4567/jastadd/ragdoc-view:relations"
entrypoint: [""]
stage: ragdoc_view
needs:
- ragdoc_build
script:
- DATA_DIR=$(pwd -P)/data
- mkdir -p pages/docs/ragdoc
- OUTPUT_DIR=$(pwd -P)/pages/docs/ragdoc
- cd /ragdoc-view/src/ && rm -rf data && ln -s $DATA_DIR
- /ragdoc-view/build-view.sh --output-path=$OUTPUT_DIR
only:
- dev
- main
artifacts:
paths:
- "pages/docs/ragdoc"
pages:
image: python:3.7-alpine
image: python:3.10.0-bullseye
stage: publish
needs:
- ragdoc_view
- test
before_script:
- pip install -r pages/requirements.txt
script:
- "pip install -U sphinx sphinx-rtd-theme recommonmark sphinxemoji sphinx-markdown-tables"
- "sphinx-build -b html pages/ public"
- cd pages && mkdocs build
artifacts:
paths:
- public
- public/
only:
- master
- main
build
src/gen-res/
src/gen/
out/
*.class
buildscript {
repositories.mavenLocal()
repositories.mavenCentral()
dependencies {
classpath group: 'org.jastadd', name: 'jastaddgradle', version: '1.13.3'
}
}
plugins {
id 'relast2uml.java-jastadd-conventions'
id 'relast2uml.java-application-conventions'
id 'relast2uml.java-publishing-conventions'
}
apply plugin: 'jastadd'
application.mainClassName = 'de.tudresden.inf.st.jastadd.grammar2uml.compiler.Compiler'
jar {
manifest {
attributes "Main-Class": application.mainClassName
}
}
dependencies {
implementation project(':relast.preprocessor')
implementation group: 'com.github.spullara.mustache.java', name: 'compiler', version: "${mustache_java_version}"
runtime group: 'org.jastadd', name: 'jastadd', version: '2.3.4'
}
File preprocessorGrammar = file('../relast.preprocessor/src/main/jastadd/RelAst.relast')
File grammar2umlGrammar = file('./src/main/jastadd/Grammar2Uml.relast')
File intermediateGrammar = file('./src/main/jastadd/MustacheNodes.relast')
task relast(type: JavaExec) {
group = 'Build'
main = "-jar"
doFirst {
delete "src/gen/jastadd/*.ast"
delete "src/gen/jastadd/Grammar2Uml.jadd"
delete "src/gen/jastadd/Grammar2UmlRefResolver.jadd"
delete "src/gen/jastadd/Grammar2UmlResolverStubs.jrag"
mkdir "src/gen/jastadd/"
}
args = [
"../libs/relast.jar",
preprocessorGrammar,
grammar2umlGrammar,
intermediateGrammar,
"--listClass=java.util.ArrayList",
"--jastAddList=JastAddList",
"--useJastAddNames",
"--file",
"--resolverHelper",
"--grammarName=./src/gen/jastadd/Grammar2Uml"
]
inputs.files(file("../libs/relast.jar"),
preprocessorGrammar,
grammar2umlGrammar,
intermediateGrammar)
outputs.files(file("./src/gen/jastadd/Grammar2Uml.ast"),
file("./src/gen/jastadd/Grammar2Uml.jadd"),
file("./src/gen/jastadd/Grammar2UmlRefResolver.jadd"),
file('./src/gen/jastadd/Grammar2UmlResolverStubs.jrag'))
}
jastadd {
configureModuleBuild()
modules {
//noinspection GroovyAssignabilityCheck
module("Grammar2Uml") {
java {
basedir ".."
include "relast.preprocessor/main/**/*.java"
include "relast.preprocessor/gen/**/*.java"
include "grammar2uml/src/main/**/*.java"
include "grammar2uml/src/gen/**/*.java"
}
jastadd {
basedir ".."
include "relast.preprocessor/src/main/jastadd/**/*.ast"
include "relast.preprocessor/src/main/jastadd/**/*.jadd"
include "relast.preprocessor/src/main/jastadd/**/*.jrag"
include "grammar2uml/src/main/jastadd/**/*.ast"
include "grammar2uml/src/main/jastadd/**/*.jadd"
include "grammar2uml/src/main/jastadd/**/*.jrag"
include "grammar2uml/src/gen/jastadd/**/*.ast"
include "grammar2uml/src/gen/jastadd/**/*.jadd"
include "grammar2uml/src/gen/jastadd/**/*.jrag"
}
scanner {
basedir ".."
include "grammar2uml/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 "grammar2uml/src/main/jastadd/scanner/Macros.flex", [-3]
include "relast.preprocessor/src/main/jastadd/scanner/RulesPreamble.flex", [-2]
include "grammar2uml/src/main/jastadd/scanner/MappingContent.flex", [-1]
include "grammar2uml/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 {
basedir ".."
include "grammar2uml/src/main/jastadd/parser/Preamble.parser"
include "relast.preprocessor/src/main/jastadd/parser/RelAst.parser"
include "grammar2uml/src/main/jastadd/parser/Grammar2Uml.parser"
}
}
}
cleanGen.doFirst {
delete "src/gen/java/de"
delete "src/gen-res/BuildInfo.properties"
}
preprocessParser.doFirst {
args += ["--no-beaver-symbol"]
}
module = "Grammar2Uml"
astPackage = 'de.tudresden.inf.st.jastadd.grammar2uml.ast'
parser.name = 'Grammar2UmlParser'
genDir = 'src/gen/java'
buildInfoDir = 'src/gen-res'
scanner.genDir = "src/gen/java/de/tudresden/inf/st/jastadd/grammar2uml/scanner"
parser.genDir = "src/gen/java/de/tudresden/inf/st/jastadd/grammar2uml/parser"
jastaddOptions = ["--lineColumnNumbers", "--List=JastAddList", "--safeLazy", "--visitCheck=true", "--rewrite=cnta", "--cache=all"]
}
generateAst.dependsOn relast
aspect Analysis {
syn lazy Folder GrammarFile.defaultFolder() {
Folder result = new Folder();
result.setName(new java.io.File(getFileName()).getName().replace(".relast", "").replace(".ast", ""));
for (Declaration decl : getDeclarationList()) {
if (decl.isTypeDecl() && !decl.asTypeDecl().hasSourceFolder()) {
result.addType(decl.asTypeDecl());
}
}
return result;
}
}
import java.util.Set;
import java.util.TreeSet;
import java.util.LinkedList;
aspect Errors {
coll Set<ErrorMessage> Grammar2Uml.errors()
[new TreeSet<ErrorMessage>()]
root Grammar2Uml;
}
aspect ErrorMessage {
public class ErrorMessage implements Comparable<ErrorMessage> {
private final ASTNode node;
private final String filename;
private final int line;
private final int col;
private final String message;
public ErrorMessage(ASTNode node, String message) {
this.node = node;
this.filename = node.containedFileName();
this.line = node.getStartLine();
this.col = node.getStartColumn();
this.message = message;
}
public ASTNode getNode() {
return node;
}
public int getLine() {
return line;
}
public int getCol() {
return col;
}
public String getMessage() {
return message;
}
public String toString() {
return filename + " Line " + line + ", column " + col + ": " + message;
}
@Override
public int compareTo(ErrorMessage err) {
int n = filename.compareTo(err.filename);
if (n != 0) {
return n;
}
n = line - err.line;
if (n != 0) {
return n;
}
n = col-err.col;
if (n != 0) {
return n;
}
return message.compareTo(err.message);
}
}
protected ErrorMessage ASTNode.error(String message) {
return new ErrorMessage(this, message);
}
}
Grammar2Uml ::= Program <FileName> Folder* ;
Folder ::= <Name:String> ;
rel Folder.Type* <-> TypeDecl.SourceFolder?;
MGrammar2Uml ::= Folder:MFolder* OtherType:MTypeDecl* Containment:MContainment* Relation:MRelation* Inheritance:MInheritance* ;
MFolder ::= InnerTypeDecl:MTypeDecl*;
MTypeDecl ::= InnerTokenComponent:MTokenComponent*;
MTokenComponent;
abstract MContainment ::= <Label:String> ;
MSingleContainment : MContainment;
MOptContainment : MContainment;
MListContainment : MContainment;
MRelation ::= <Label> <LeftModifier> <RightModifier> <Bidirectional:boolean>;
MInheritance ;
rel MGrammar2Uml.Grammar2Uml -> Grammar2Uml;
rel MFolder.Folder -> Folder;
rel MTypeDecl.Type -> TypeDecl;
rel MTokenComponent.Token -> TokenComponent;
rel MContainment.Type -> TypeDecl;
rel MContainment.Component -> TypeDecl;
rel MRelation.Left -> TypeDecl;
rel MRelation.Right -> TypeDecl;
rel MInheritance.SuperClass -> TypeDecl;
rel MInheritance.SubClass -> TypeDecl;
aspect NameResolutionExtended {
refine NameResolution eq Program.resolveTypeDecl(String name) {
try {
return refined(name);
} catch (RuntimeException e) {
System.err.println(e.getMessage());
TypeDecl dummy = new TypeDecl();
dummy.setName("(" + name + ")");
return dummy;
}
}
}
aspect Navigation {
// --- program ---
eq Grammar2Uml.getChild().program() = getProgram();
eq MGrammar2Uml.getChild().program() = getGrammar2Uml().program();
// --- grammar2uml ---
inh Grammar2Uml ASTNode.grammar2uml();
eq Grammar2Uml.getChild().grammar2uml() = this;
eq MGrammar2Uml.getChild().grammar2uml() = getGrammar2Uml();
// --- containedFile ---
eq Grammar2Uml.getChild().containedFile() = null;
eq MGrammar2Uml.getChild().containedFile() = null;
// --- containedFileName ---
eq Grammar2Uml.getChild().containedFileName() = getFileName();
eq Program.getChild().containedFileName() = null;
eq Grammar.getChild().containedFileName() = null;
eq MGrammar2Uml.getChild().containedFileName() = null;
}
aspect GenerationUtils {
public static final String ASTNode.aspectIndent = " ";
public String ASTNode.ind(int n) {
StringBuilder s = new StringBuilder();
for (int i = 0; i < n; i++) {
s.append(aspectIndent);
}
return s.toString();
}
// --- prettyPrint ---
syn String JavaTypeUse.prettyPrint() {
StringBuilder sb = new StringBuilder();
generateAbstractGrammar(sb);
return sb.toString();
}
}
aspect AttributesForMustache {
// --- MFolder ---
syn String MFolder.name() = getFolder().getName();
// --- MTypeDecl ---
eq MTypeDecl.getInnerTokenComponent(int i).isFirst() = i == 0;
eq MTypeDecl.getInnerTokenComponent(int i).isLast() = i == getNumInnerTokenComponent() - 1;
syn boolean MTypeDecl.isAbstract() = getType().getAbstract();
syn String MTypeDecl.name() = getType().getName();
// --- MTokenComponent ---
syn String MTokenComponent.name() = getToken().getName();
inh boolean MTokenComponent.isFirst();
inh boolean MTokenComponent.isLast();
// --- MContainment ---
syn String MContainment.typeName() = getType().getName();
syn String MContainment.componentName() = getComponent().getName();
syn String MContainment.modifier();
eq MSingleContainment.modifier() = "\"1\"";
eq MOptContainment.modifier() = "\"0 .. 1\"";
eq MListContainment.modifier() = "\"*\"";
// --- MRelation ---
syn String MRelation.leftName() = getLeft().getName();
syn String MRelation.rightName() = getRight().getName();
syn boolean MRelation.isBidirectional() = getBidirectional();
// syn String MRelation.modifier();
// eq MSingleRelation.modifier() = "\"1\"";
// eq MOptRelation.modifier() = "\"0 .. 1\"";
// eq MListRelation.modifier() = "\"*\"";
// --- MInheritance ---
syn String MInheritance.superClassName() = getSuperClass().getName();
syn String MInheritance.subClassName() = getSubClass().getName();
// --- toMContainment ---
syn MContainment TypeComponent.toMContainment();
eq NormalComponent.toMContainment() = new MSingleContainment();
eq ListComponent.toMContainment() = new MListContainment();
eq OptComponent.toMContainment() = new MOptContainment();
// --- toMRelation ---
syn MRelation Relation.toMRelation();
eq DirectedRelation.toMRelation() {
MRelation result = new MRelation();
result.setRightModifier(getSource().toMRelationModifier());
result.setBidirectional(false);
return result;
}
eq BidirectionalRelation.toMRelation() {
MRelation result = new MRelation();
result.setLeftModifier(getRight().toMRelationModifier());
result.setRightModifier(getLeft().toMRelationModifier());
result.setBidirectional(true);
return result;
}
// --- toMRelationModifier ---
syn String Role.toMRelationModifier();
eq NormalRole.toMRelationModifier() = "\"1\"";
eq ListRole.toMRelationModifier() = "\"0 .. 1\"";
eq OptRole.toMRelationModifier() = "\"*\"";
eq UnnamedRole.toMRelationModifier() {
throw new RuntimeException("UnnamedRole cannot be converted to MRelation");
}
// --- toMustache ---
syn lazy MGrammar2Uml Grammar2Uml.toMustache() {
MGrammar2Uml result = new MGrammar2Uml();
result.setGrammar2Uml(this);
for (Folder folder : getFolderList()) {
result.addFolder(folder.toMustache());
}
for (TypeDecl typeDecl : getProgram().typeDecls()) {
if (!typeDecl.hasSourceFolder()) {
result.addOtherType(typeDecl.toMustache());
}
for (Component component : typeDecl.getComponentList()) {
if (component.isTypeComponent()) {
TypeComponent typeComponent = component.asTypeComponent();
MContainment containment = typeComponent.toMContainment();
containment.setType(typeDecl);
containment.setComponent(component.asTypeComponent().getTypeDecl());
if (!component.getName().isEmpty() && !component.getName().equals(component.asTypeComponent().getTypeDecl().getName())) {
containment.setLabel(component.getName());
}
result.addContainment(containment);
}
}
if (typeDecl.hasSuperType()) {
MInheritance inheritance = new MInheritance();
inheritance.setSuperClass(typeDecl.getSuperType());
inheritance.setSubClass(typeDecl);
result.addInheritance(inheritance);
}
}
for (Relation relation : getProgram().relations()) {
if (relation.isDirectedRelation()) {
DirectedRelation directedRelation = relation.asDirectedRelation();
MRelation mRelation = directedRelation.toMRelation();
mRelation.setLeft(directedRelation.getSource().getType());
mRelation.setRight(directedRelation.getTarget().getType());
mRelation.setLabel(directedRelation.getSource().getName());
result.addRelation(mRelation);
} else {
BidirectionalRelation bidiRelation = relation.asBidirectionalRelation();
MRelation mRelation = bidiRelation.toMRelation();
mRelation.setLeft(bidiRelation.getLeft().getType());
mRelation.setRight(bidiRelation.getRight().getType());
// mRelation.setLabel(bidiRelation.getSource().getName());
result.addRelation(mRelation);
}
}
return result;
}
syn lazy MFolder Folder.toMustache() {
MFolder result = new MFolder();
result.setFolder(this);
for (TypeDecl typeDecl : getTypeList()) {
result.addInnerTypeDecl(typeDecl.toMustache());
}
return result;
}
syn lazy MTypeDecl TypeDecl.toMustache() {
MTypeDecl result = new MTypeDecl();
result.setType(this);
for (Component component : getComponentList()) {
if (component.isTokenComponent()) {
result.addInnerTokenComponent(component.asTokenComponent().toMustache());
}
}
return result;
}
syn lazy MTokenComponent TokenComponent.toMustache() {
MTokenComponent result = new MTokenComponent();
result.setToken(this);
return result;
}
}
aspect AspectGeneration {
syn String Grammar2Uml.generateAspect() = toMustache().generateAspect();
syn String MGrammar2Uml.generateAspect() {
StringBuilder sb = new StringBuilder();
com.github.mustachejava.reflect.ReflectionObjectHandler roh = new com.github.mustachejava.reflect.ReflectionObjectHandler() {
@Override
public com.github.mustachejava.Binding createBinding(String name, final com.github.mustachejava.TemplateContext tc, com.github.mustachejava.Code code) {
return new com.github.mustachejava.reflect.GuardedBinding(this, name, tc, code) {
@Override
protected synchronized com.github.mustachejava.util.Wrapper getWrapper(String name, java.util.List<Object> scopes) {
com.github.mustachejava.util.Wrapper wrapper = super.getWrapper(name, scopes);
if (wrapper instanceof com.github.mustachejava.reflect.MissingWrapper) {
throw new com.github.mustachejava.MustacheException(name + " not found in " + tc);
}
return wrapper;
}
};
}
};
com.github.mustachejava.DefaultMustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory();
// mf.setObjectHandler(roh);
com.github.mustachejava.Mustache m = mf.compile("grammar2uml.mustache");
m.execute(new java.io.PrintWriter(new AppendableWriter(sb)), this);
return sb.toString();
}
public class AppendableWriter extends java.io.Writer {
private final StringBuilder sb;
public AppendableWriter(StringBuilder sb) {
this.sb = sb;
}
@Override
public void write(char[] chars, int off, int len) {
sb.append(chars, off, len);
}
@Override
public void write(String str) {
sb.append(str);
}
@Override
public void flush() {}
@Override
public void close() {}
}
}
Grammar2Uml grammar2uml
= folder.f grammar2uml.r {: r.getFolderList().insertChild(f, 0); return r; :}
| {: return new Grammar2Uml(); :}
;
Folder folder
= FOLDER ID.name COL type_use_list.t
{:
Folder result = new Folder();
result.setName(name);
java.util.List<TypeDecl> typeDecls = ((ArrayList<Object>) t).stream().map(x -> TypeDecl.createRef(((Symbol) x).value.toString())).collect(java.util.stream.Collectors.toList());
java.util.Collections.reverse(typeDecls);
for (TypeDecl typeDecl : typeDecls) {
result.addType(typeDecl);
}
return result;
:}
;
ArrayList type_use_list
= ID
| type_use_list COMMA ID
;
%header {:
package de.tudresden.inf.st.jastadd.grammar2uml.parser;
import de.tudresden.inf.st.jastadd.grammar2uml.ast.*;
:};
%goal goal;
%goal grammar2uml;
package de.tudresden.inf.st.jastadd.grammar2uml.scanner;
import de.tudresden.inf.st.jastadd.grammar2uml.parser.Grammar2UmlParser.Terminals;
%%