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

Add --quiet option to supress anything on stdout.

parent c4a61a1e
...@@ -119,7 +119,7 @@ task preprocessRelationTest(type: JavaExec, group: 'verification') { ...@@ -119,7 +119,7 @@ task preprocessRelationTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler' main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck //noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/relations/Relations.relast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations' args 'src/test/jastadd/relations/Relations.relast', '--quiet', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations'
} }
task doublePreprocessRelationTest(type: JavaExec, group: 'verification') { task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
...@@ -131,7 +131,7 @@ task doublePreprocessRelationTest(type: JavaExec, group: 'verification') { ...@@ -131,7 +131,7 @@ task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler' main = 'org.jastadd.relast.compiler.Compiler'
//noinspection GroovyAssignabilityCheck //noinspection GroovyAssignabilityCheck
args 'src/test/jastadd/relations/Relations.ast', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations2' args 'src/test/jastadd/relations/Relations.ast', '--quiet', '--useJastAddNames', '--file', '--grammarName=src/test/jastadd/relations/Relations2'
} }
task compileRelationTest(type: JavaExec, group: 'verification') { task compileRelationTest(type: JavaExec, group: 'verification') {
......
...@@ -193,6 +193,7 @@ public class RelastTest extends DefaultTask { ...@@ -193,6 +193,7 @@ public class RelastTest extends DefaultTask {
javaExecSpec.setClasspath(runtimeClasspath); javaExecSpec.setClasspath(runtimeClasspath);
javaExecSpec.setMain("org.jastadd.relast.compiler.Compiler"); javaExecSpec.setMain("org.jastadd.relast.compiler.Compiler");
List<Object> args = new ArrayList<>(getRelastFiles()); List<Object> args = new ArrayList<>(getRelastFiles());
args.add("--quiet");
if (isWriteToFile()) { if (isWriteToFile()) {
args.add("--file"); args.add("--file");
} }
......
...@@ -25,16 +25,18 @@ public class Compiler { ...@@ -25,16 +25,18 @@ public class Compiler {
private EnumOption optionSerializer; private EnumOption optionSerializer;
private FlagOption optionResolverHelper; private FlagOption optionResolverHelper;
private FlagOption optionUseJastaddNames; private FlagOption optionUseJastaddNames;
private FlagOption optionQuiet;
private CommandLine commandLine; private CommandLine commandLine;
public Compiler(String[] args) throws CommandLineException { public Compiler(String[] args) throws CommandLineException {
System.out.println("Running RelAST " + VERSION);
options = new ArrayList<>(); options = new ArrayList<>();
addOptions(); addOptions();
commandLine = new CommandLine(options); commandLine = new CommandLine(options);
commandLine.parse(args); commandLine.parse(args);
printMessage("Running RelAST " + VERSION);
if (commandLine.getArguments().size() < 1) { if (commandLine.getArguments().size() < 1) {
error("specify at least one input file"); error("specify at least one input file");
} }
...@@ -43,7 +45,7 @@ public class Compiler { ...@@ -43,7 +45,7 @@ public class Compiler {
Program p = parseProgram(filenames); Program p = parseProgram(filenames);
if (optionJastAddList.isSet()) { if (optionJastAddList.isSet()) {
System.out.println("JastAdd List type is set to " + optionJastAddList.getValue()); printMessage("JastAdd List type is set to " + optionJastAddList.getValue());
ASTNode.jastAddListType = optionJastAddList.getValue(); ASTNode.jastAddListType = optionJastAddList.getValue();
} }
...@@ -68,7 +70,7 @@ public class Compiler { ...@@ -68,7 +70,7 @@ public class Compiler {
} else { } else {
if (optionListClass.isSet()) { if (optionListClass.isSet()) {
System.out.println("ListClass is set to " + optionListClass.getValue()); printMessage("ListClass is set to " + optionListClass.getValue());
ASTNode.listClass = optionListClass.getValue(); ASTNode.listClass = optionListClass.getValue();
} }
...@@ -109,8 +111,8 @@ public class Compiler { ...@@ -109,8 +111,8 @@ public class Compiler {
} else if (optionPrintAST.isSet()) { } else if (optionPrintAST.isSet()) {
System.out.println(p.dumpTree()); System.out.println(p.dumpTree());
} else { } else {
System.out.println(p.generateAbstractGrammar()); printMessage(p.generateAbstractGrammar());
System.out.println(p.generateAspect()); printMessage(p.generateAspect());
} }
} }
} }
...@@ -119,11 +121,17 @@ public class Compiler { ...@@ -119,11 +121,17 @@ public class Compiler {
try { try {
new Compiler(args); new Compiler(args);
} catch (CommandLineException e) { } catch (CommandLineException e) {
System.out.println(e.getMessage()); System.err.println(e.getMessage());
System.exit(1); System.exit(1);
} }
} }
private void printMessage(String message) {
if (!optionQuiet.isSet()) {
System.out.println(message);
}
}
private void writeToFile(String filename, String str) { private void writeToFile(String filename, String str) {
try { try {
PrintWriter writer = new PrintWriter(filename); PrintWriter writer = new PrintWriter(filename);
...@@ -137,14 +145,14 @@ public class Compiler { ...@@ -137,14 +145,14 @@ public class Compiler {
private void addOptions() { private void addOptions() {
optionWriteToFile = addOption(new FlagOption("file", "write output to files <filename>Gen.ast and <filename>Gen.jadd")); optionWriteToFile = addOption(new FlagOption("file", "write output to files <filename>Gen.ast and <filename>Gen.jadd"));
optionPrintAST = addOption(new FlagOption("ast", "print AST")); optionPrintAST = addOption(new FlagOption("ast", "print AST (ignores quiet option)"));
optionListClass = addOption(new StringOption("listClass", "determine the class name of the nonterminal reference list")); optionListClass = addOption(new StringOption("listClass", "determine the class name of the nonterminal reference list"));
optionGrammarName = addOption(new StringOption("grammarName", "name of the generated grammar and aspect (without file extension)")); optionGrammarName = addOption(new StringOption("grammarName", "name of the generated grammar and aspect (without file extension)"));
optionResolverHelper = addOption(new FlagOption("resolverHelper", "create a subtype for each type containing a string that can be used to resolve the type later")); optionResolverHelper = addOption(new FlagOption("resolverHelper", "create a subtype for each type containing a string that can be used to resolve the type later"));
optionJastAddList = addOption(new StringOption("jastAddList", "set the name of the List type in JastAdd (has to match the option '--List' or its default List)")); optionJastAddList = addOption(new StringOption("jastAddList", "set the name of the List type in JastAdd (has to match the option '--List' or its default List)"));
optionUseJastaddNames = addOption(new FlagOption("useJastAddNames", "generate names in the form of addX, removeX and setX. If omitted, the default, original naming scheme resulting in addToX, removeFromX and setX will be used.")); optionUseJastaddNames = addOption(new FlagOption("useJastAddNames", "generate names in the form of addX, removeX and setX. If omitted, the default, original naming scheme resulting in addToX, removeFromX and setX will be used."));
optionSerializer = addOption(new EnumOption("serializer", "generate a (de-)serializer", Arrays.asList("jackson"), "jackson")); optionSerializer = addOption(new EnumOption("serializer", "generate a (de-)serializer", Arrays.asList("jackson"), "jackson"));
optionQuiet = addOption(new FlagOption("quiet", "do not output anything on stdout"));
} }
private <OptionType extends Option<?>> OptionType addOption(OptionType option) { private <OptionType extends Option<?>> OptionType addOption(OptionType option) {
......
Supports Markdown
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