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') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//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') {
......@@ -131,7 +131,7 @@ task doublePreprocessRelationTest(type: JavaExec, group: 'verification') {
classpath = sourceSets.main.runtimeClasspath
main = 'org.jastadd.relast.compiler.Compiler'
//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') {
......
......@@ -193,6 +193,7 @@ public class RelastTest extends DefaultTask {
javaExecSpec.setClasspath(runtimeClasspath);
javaExecSpec.setMain("org.jastadd.relast.compiler.Compiler");
List<Object> args = new ArrayList<>(getRelastFiles());
args.add("--quiet");
if (isWriteToFile()) {
args.add("--file");
}
......
......@@ -25,16 +25,18 @@ public class Compiler {
private EnumOption optionSerializer;
private FlagOption optionResolverHelper;
private FlagOption optionUseJastaddNames;
private FlagOption optionQuiet;
private CommandLine commandLine;
public Compiler(String[] args) throws CommandLineException {
System.out.println("Running RelAST " + VERSION);
options = new ArrayList<>();
addOptions();
commandLine = new CommandLine(options);
commandLine.parse(args);
printMessage("Running RelAST " + VERSION);
if (commandLine.getArguments().size() < 1) {
error("specify at least one input file");
}
......@@ -43,7 +45,7 @@ public class Compiler {
Program p = parseProgram(filenames);
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();
}
......@@ -68,7 +70,7 @@ public class Compiler {
} else {
if (optionListClass.isSet()) {
System.out.println("ListClass is set to " + optionListClass.getValue());
printMessage("ListClass is set to " + optionListClass.getValue());
ASTNode.listClass = optionListClass.getValue();
}
......@@ -109,8 +111,8 @@ public class Compiler {
} else if (optionPrintAST.isSet()) {
System.out.println(p.dumpTree());
} else {
System.out.println(p.generateAbstractGrammar());
System.out.println(p.generateAspect());
printMessage(p.generateAbstractGrammar());
printMessage(p.generateAspect());
}
}
}
......@@ -119,11 +121,17 @@ public class Compiler {
try {
new Compiler(args);
} catch (CommandLineException e) {
System.out.println(e.getMessage());
System.err.println(e.getMessage());
System.exit(1);
}
}
private void printMessage(String message) {
if (!optionQuiet.isSet()) {
System.out.println(message);
}
}
private void writeToFile(String filename, String str) {
try {
PrintWriter writer = new PrintWriter(filename);
......@@ -137,14 +145,14 @@ public class Compiler {
private void addOptions() {
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"));
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"));
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."));
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) {
......
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