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