Commit fdbd04a3 authored by 0xJMR's avatar 0xJMR
Browse files

Small adjustment in order to make the flag available as CLI option.

parent 4eda01f9
Pipeline #61229 passed with stages
in 1 minute and 35 seconds
......@@ -4,6 +4,7 @@ import com.google.common.eventbus.Subscribe;
import de.monticore.lang.math._ast.ASTMathCompilationUnit;
import de.monticore.lang.math._ast.ASTMathScript;
import de.monticore.lang.monticar.mpp.core.events.EventsService;
import de.monticore.lang.monticar.mpp.core.options.OptionsParsedEvent;
import de.monticore.lang.monticar.mpp.core.options.OptionsService;
import de.monticore.lang.monticar.mpp.core.parser.MathFileParsedEvent;
import de.monticore.lang.monticar.mpp.core.tex.SVGGenerator;
......@@ -32,7 +33,7 @@ public class GeneratorHelper {
this.svggenerator = new SVGGenerator(this.optionsService);
this.htmlPrinter = new HTMLMathPrettyPrinter();
this.texPrinter = new TeXHTMLMathPrettyPrinter(svggenerator);
this.texPrinter = new TeXHTMLMathPrettyPrinter(this.svggenerator);
this.nodes = new ArrayList<>();
......@@ -82,4 +83,12 @@ public class GeneratorHelper {
public void onMathFileParsed(MathFileParsedEvent event) {
this.nodes.add(event.ast);
}
@Subscribe
public void onOptionsParsed(OptionsParsedEvent event) {
boolean isInternal = this.optionsService.isInternal();
this.texPrinter.setInternal(isInternal);
this.htmlPrinter.setInternal(isInternal);
}
}
......@@ -17,6 +17,7 @@ public class OptionsService {
protected Path modelPath;
protected Path outputPath;
protected boolean internal;
public OptionsService(EventsService eventsService) {
this.eventsService = eventsService;
......@@ -31,6 +32,8 @@ public class OptionsService {
"Absolute Path to the package root of the models.");
this.options.addOption("out", "output-path", true,
"Absolute Path to the root directory of the output.");
this.options.addOption("i", "internal", false,
"If set, runs the application in internal mode.");
}
public Path getModelPath() {
......@@ -49,6 +52,9 @@ public class OptionsService {
return this.outputPath.resolve(relativePath);
}
public boolean isInternal() {
return this.internal;
}
@Subscribe
public void onApplicationConfigure(ApplicationConfigureEvent event) throws ParseException {
......@@ -60,6 +66,7 @@ public class OptionsService {
this.modelPath = Paths.get(modelPath);
this.outputPath = Paths.get(outputPath);
this.internal = commandLine.hasOption("i");
OptionsParsedEvent optionsEvent = new OptionsParsedEvent(this.modelPath, this.outputPath);
......
......@@ -29,7 +29,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
protected boolean inMatrixEnvironment;
protected boolean internal;
public MathPrettyPrinter(boolean internal, int spacing) {
public MathPrettyPrinter(int spacing, boolean internal) {
this.printer = new IndentPrinter();
this.printer.setIndentLength(spacing);
this.importVisited = false;
......@@ -37,24 +37,25 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this.internal = internal;
}
public MathPrettyPrinter(boolean internal)
{
this(internal, 4);
public MathPrettyPrinter(int spacing) {
this(spacing, false);
}
public MathPrettyPrinter()
{
this(false,4);
public MathPrettyPrinter() {
this(4,false);
}
public void setInternal(boolean internal) {
this.internal = internal;
}
@Override
public String prettyPrint(ASTMathCompilationUnit node) {
this.printer.clearBuffer();
if(internal) {
if(this.internal) {
this.printStatements(node);
}
else {
} else {
this.handle(node);
}
......@@ -68,8 +69,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
return this.printer.getContent();
}
protected void printStatements(ASTMathCompilationUnit node)
{
protected void printStatements(ASTMathCompilationUnit node) {
List<ASTStatement> statements = node.getMathScript().getStatementsList();
for(ASTStatement statement: statements)
......
......@@ -14,14 +14,14 @@ public class StatementsOnlyTest extends AbstractModelTest {
@Ignore
public void printTest3() throws IOException
{
this.printer = new MathPrettyPrinter(true);
this.printer = new MathPrettyPrinter(4, true);
System.out.println(printVanillaModel("Nested.m"));
}
@Test
public void testModel3() throws IOException
{
this.printer = new MathPrettyPrinter(true);
this.printer = new MathPrettyPrinter(4, true);
String actual = printVanillaModel("Nested.m");
String expected =
"Q sum = 1;\n" +
......
Markdown is supported
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