diff --git a/settings.gradle b/settings.gradle index cd071807d331316a515c88ce224a76993d8705a8..3e1308bbd4da2aa12cb4b290bb83aa0593b79df5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,7 +4,7 @@ pluginManagement { } } -rootProject.name = 'abstract_type_navigation_generator' +rootProject.name = 'RoleRag' include 'relast.preprocessor' diff --git a/src/main/jastadd/AddEmptyDeclaration.jrag b/src/main/jastadd/AddEmptyDeclaration.jrag new file mode 100644 index 0000000000000000000000000000000000000000..ef477bd61cc82be6019b1ac208b5b6db312e0a81 --- /dev/null +++ b/src/main/jastadd/AddEmptyDeclaration.jrag @@ -0,0 +1,20 @@ +aspect AddEmptyDeclaration { + syn GrammarFile GrammarFile.addEmptyDecl() { + + Declaration emptyDecl = new EmptyDeclaration(); + SingleLineComment slc = new SingleLineComment(); + slc.setText("// DO NOT EDIT. Automatically generated using RoleAST.jar"); + emptyDecl.addComment(slc); + + JastAddList declList = new JastAddList(); + declList.add(emptyDecl); + for (Declaration decl : this.getDeclarationList()) { + declList.add(decl); + } + + this.setDeclarationList(declList); + + //this.addDeclaration(emptyDecl); + return this; + } +} diff --git a/src/main/java/org/jastadd/preprocessor/Main.java b/src/main/java/org/jastadd/preprocessor/Main.java index e3c277ab7755a81184433358ae3451385d4fa163..4830eb12bcfe7bcf94bea7c7efbfec83418b2aeb 100644 --- a/src/main/java/org/jastadd/preprocessor/Main.java +++ b/src/main/java/org/jastadd/preprocessor/Main.java @@ -4,11 +4,13 @@ import org.jastadd.option.BooleanOption; import org.jastadd.option.ValueOption; import org.jastadd.relast.ast.Document; import org.jastadd.relast.ast.Program; +import org.jastadd.relast.ast.GrammarFile; import org.jastadd.relast.compiler.CompilerException; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.nio.file.Path; +import java.nio.file.Paths; import static org.jastadd.relast.compiler.Mustache.javaMustache; @@ -23,7 +25,7 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor { protected BooleanOption optionPrintYaml; public Main() { - super("Abstract Type Navigation Generator", false); + super("RoleRag", false); } public static void main(String[] args) { @@ -101,6 +103,14 @@ public class Main extends org.jastadd.relast.compiler.RelAstProcessor { throw new CompilerException("Unable to expand template", e); } + for (GrammarFile grammarFile : program.getGrammarFileList()) { + printMessage("Writing output file " + grammarFile.getFileName()); + // TODO decide and document what the file name should be, the full path or a simple name? + grammarFile.addEmptyDecl(); + writeToFile(outputBasePath.resolve(inputBasePath.relativize(Paths.get(grammarFile.getFileName()))), grammarFile.generateAbstractGrammar()); + } + + return 0; } } diff --git a/src/test/resources/AddEmptyDeclaration/config.yaml b/src/test/resources/AddEmptyDeclaration/config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..17e4646573e269287c2454fde915728c85f56953 --- /dev/null +++ b/src/test/resources/AddEmptyDeclaration/config.yaml @@ -0,0 +1,8 @@ +- name: "AddEmptyDeclaration (null)" + out: "out" + args: + - "--inputBaseDir=in" + - "--outputBaseDir=out" + - "--errorHandling=null" + - "Example.relast" + - "EmptyDeclaration.relast" diff --git a/src/test/resources/AddEmptyDeclaration/in/EmptyDeclaration.relast b/src/test/resources/AddEmptyDeclaration/in/EmptyDeclaration.relast new file mode 100644 index 0000000000000000000000000000000000000000..c27b6c1fd32de5baccc2cc6692dd7c469123c7dd --- /dev/null +++ b/src/test/resources/AddEmptyDeclaration/in/EmptyDeclaration.relast @@ -0,0 +1 @@ +// DO NOT EDIT. Automatically generated using RoleAST.jar diff --git a/src/test/resources/AddEmptyDeclaration/in/Example.relast b/src/test/resources/AddEmptyDeclaration/in/Example.relast new file mode 100644 index 0000000000000000000000000000000000000000..c288fd84cc8834b71a8190e6b0e708a988997b6b --- /dev/null +++ b/src/test/resources/AddEmptyDeclaration/in/Example.relast @@ -0,0 +1,11 @@ + + +StateMachine ::= Element*; +abstract Element ::= <Label:String>; +State : Element ::=; +Transition : Element ::=; + +rel StateMachine.initial -> State; +rel StateMachine.final* -> State; +rel State.outgoing* <-> Transition.from; +rel State.incoming* <-> Transition.to;