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
f8eb7ed1
Commit
f8eb7ed1
authored
Jul 06, 2018
by
Bram Kohlen
Browse files
MathPrettyPrinter can print the individual statements of a script now
parent
e690cd97
Pipeline
#61170
passed with stages
in 1 minute and 33 seconds
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/mpp/montimath/MathPrettyPrinter.java
View file @
f8eb7ed1
...
...
@@ -27,18 +27,36 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
protected
final
IndentPrinter
printer
;
protected
boolean
importVisited
;
protected
boolean
inMatrixEnvironment
;
protected
boolean
internal
;
public
MathPrettyPrinter
()
{
public
MathPrettyPrinter
(
boolean
internal
,
int
spacing
)
{
this
.
printer
=
new
IndentPrinter
();
this
.
printer
.
setIndentLength
(
4
);
this
.
printer
.
setIndentLength
(
spacing
);
this
.
importVisited
=
false
;
this
.
inMatrixEnvironment
=
false
;
this
.
internal
=
internal
;
}
public
MathPrettyPrinter
(
boolean
internal
)
{
this
(
internal
,
4
);
}
public
MathPrettyPrinter
()
{
this
(
false
,
4
);
}
@Override
public
String
prettyPrint
(
ASTMathCompilationUnit
node
)
{
this
.
printer
.
clearBuffer
();
if
(
internal
)
{
this
.
printStatements
(
node
);
}
else
{
this
.
handle
(
node
);
}
return
this
.
printer
.
getContent
();
}
...
...
@@ -50,6 +68,16 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
return
this
.
printer
.
getContent
();
}
protected
void
printStatements
(
ASTMathCompilationUnit
node
)
{
List
<
ASTStatement
>
statements
=
node
.
getMathScript
().
getStatementsList
();
for
(
ASTStatement
statement:
statements
)
{
statement
.
accept
(
this
);
}
}
protected
void
printSpace
()
{
this
.
printer
.
print
(
" "
);
}
...
...
src/test/java/de/monticore/lang/monticar/mpp/models/StatementsOnlyTest.java
0 → 100644
View file @
f8eb7ed1
package
de.monticore.lang.monticar.mpp.models
;
import
de.monticore.lang.monticar.mpp.montimath.MathPrettyPrinter
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
java.io.IOException
;
import
static
junit
.
framework
.
TestCase
.
assertEquals
;
public
class
StatementsOnlyTest
extends
AbstractModelTest
{
@Test
@Ignore
public
void
printTest3
()
throws
IOException
{
this
.
printer
=
new
MathPrettyPrinter
(
true
);
System
.
out
.
println
(
printVanillaModel
(
"Nested.m"
));
}
@Test
public
void
testModel3
()
throws
IOException
{
this
.
printer
=
new
MathPrettyPrinter
(
true
);
String
actual
=
printVanillaModel
(
"Nested.m"
);
String
expected
=
"Q sum = 1;\n"
+
"for i = 1:2:9\n"
+
" if i < 2\n"
+
" sum -= sum * i;\n"
+
" elseif i < 4\n"
+
" sum += sum * i;\n"
+
" else\n"
+
" for j = 1:2:6\n"
+
" sum += sum * (i - j);\n"
+
" end\n"
+
" end\n"
+
"end\n"
;
assertEquals
(
expected
,
actual
);
}
}
Write
Preview
Supports
Markdown
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