Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
MathPrettyPrinter
Commits
fdbd04a3
Commit
fdbd04a3
authored
Jul 07, 2018
by
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
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/mpp/core/generator/GeneratorHelper.java
View file @
fdbd04a3
...
@@ -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
);
}
}
}
src/main/java/de/monticore/lang/monticar/mpp/core/options/OptionsService.java
View file @
fdbd04a3
...
@@ -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
);
...
...
src/main/java/de/monticore/lang/monticar/mpp/montimath/MathPrettyPrinter.java
View file @
fdbd04a3
...
@@ -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
)
...
...
src/test/java/de/monticore/lang/monticar/mpp/models/StatementsOnlyTest.java
View file @
fdbd04a3
...
@@ -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"
+
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment