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
d06713af
Commit
d06713af
authored
Jul 04, 2018
by
0xJMR
Browse files
Added basic comments support.
parent
54b8677e
Pipeline
#60545
passed with stages
in 1 minute and 5 seconds
Changes
7
Pipelines
1
Show whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/mpp/montimath/HTMLMathPrettyPrinter.java
View file @
d06713af
package
de.monticore.lang.monticar.mpp.montimath
;
import
de.monticore.lang.math._ast.ASTMathCompilationUnit
;
public
class
HTMLMathPrettyPrinter
extends
MathPrettyPrinter
{
protected
String
getWrappedKeyword
(
String
keyword
)
{
return
String
.
format
(
"<span class=\"keyword\">%s</span>"
,
keyword
);
}
protected
String
getWrappedComment
(
String
comment
)
{
return
String
.
format
(
"<span class=\"comment\">%s</span>"
,
comment
);
}
@Override
protected
void
printPackage
()
{
...
...
@@ -47,4 +49,15 @@ public class HTMLMathPrettyPrinter extends MathPrettyPrinter {
protected
void
printElseIf
()
{
this
.
printer
.
print
(
this
.
getWrappedKeyword
(
"elseif"
));
}
@Override
protected
void
printComment
(
String
comment
)
{
String
[]
lines
=
comment
.
split
(
"\n"
);
if
(
lines
.
length
>
0
)
lines
[
0
]
=
lines
[
0
].
trim
();
for
(
String
line
:
lines
)
{
this
.
printer
.
println
(
this
.
getWrappedComment
(
line
));
}
}
}
src/main/java/de/monticore/lang/monticar/mpp/montimath/MathPrettyPrinter.java
View file @
d06713af
package
de.monticore.lang.monticar.mpp.montimath
;
import
de.monticore.ast.
ASTNode
;
import
de.monticore.ast.
Comment
;
import
de.monticore.commonexpressions._ast.*
;
import
de.monticore.expressionsbasis._ast.ASTExpression
;
import
de.monticore.lang.math._ast.*
;
import
de.monticore.lang.matrix._ast.ASTMathMatrixAccessExpression
;
import
de.monticore.lang.matrix._ast.ASTMathMatrixValueExplicitExpression
;
...
...
@@ -19,6 +18,8 @@ import de.monticore.prettyprint.IndentPrinter;
import
de.monticore.types.types._ast.ASTImportStatement
;
import
de.monticore.types.types._ast.ASTQualifiedName
;
import
java.util.List
;
public
class
MathPrettyPrinter
implements
AstPrettyPrinter
<
ASTMathCompilationUnit
>,
MathStructuredVisitor
{
protected
final
IndentPrinter
printer
;
protected
boolean
importVisited
;
...
...
@@ -49,6 +50,24 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this
.
printer
.
print
(
" "
);
}
protected
void
printComments
(
List
<
Comment
>
comments
)
{
for
(
Comment
comment
:
comments
)
{
String
text
=
comment
.
getText
();
this
.
printComment
(
text
);
}
}
protected
void
printComment
(
String
comment
)
{
String
[]
lines
=
comment
.
split
(
"\n"
);
if
(
lines
.
length
>
0
)
lines
[
0
]
=
lines
[
0
].
trim
();
for
(
String
line
:
lines
)
{
this
.
printer
.
print
(
line
);
}
}
/*========================================================
== TOKENS ================================================
========================================================*/
...
...
@@ -129,6 +148,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
========================================================*/
@Override
public
void
visit
(
ASTMathCompilationUnit
node
)
{
this
.
printComments
(
node
.
get_PreCommentList
());
this
.
printPackage
();
this
.
printSpace
();
}
...
...
@@ -147,6 +167,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public
void
visit
(
ASTMathScript
node
)
{
this
.
printer
.
println
();
this
.
printComments
(
node
.
get_PreCommentList
());
this
.
printScript
();
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getName
());
...
...
@@ -181,6 +202,11 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public
void
visit
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
printComments
(
node
.
get_PreCommentList
());
}
@Override
public
void
revisit
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getName
());
}
...
...
@@ -210,12 +236,14 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public
void
visit
(
ASTMathAssignmentStatement
node
)
{
this
.
printComments
(
node
.
get_PreCommentList
());
this
.
printer
.
print
(
node
.
getName
());
}
@Override
public
void
endVisit
(
ASTMathAssignmentStatement
node
)
{
this
.
printSemicolon
();
this
.
printComments
(
node
.
get_PostCommentList
());
this
.
printer
.
println
();
}
...
...
@@ -231,7 +259,6 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
@Override
public
void
visit
(
ASTMathForLoopHead
node
)
{
this
.
printer
.
println
();
this
.
printFor
();
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getName
());
...
...
@@ -240,16 +267,21 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
this
.
printSpace
();
}
@Override
public
void
visit
(
ASTMathForLoopExpression
node
)
{
this
.
printComments
(
node
.
get_PreCommentList
());
}
@Override
public
void
endVisit
(
ASTMathForLoopExpression
node
)
{
this
.
printEnd
();
this
.
printSemicolon
();
this
.
printer
.
println
(
2
);
this
.
printComments
(
node
.
get_PostCommentList
());
this
.
printer
.
println
();
}
@Override
public
void
visit
(
ASTMathIfExpression
node
)
{
this
.
printer
.
println
();
this
.
printIf
();
this
.
printSpace
();
}
...
...
@@ -258,7 +290,7 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
public
void
endVisit
(
ASTMathIfStatement
node
)
{
this
.
printEnd
();
this
.
printSemicolon
();
this
.
printer
.
println
(
2
);
this
.
printer
.
println
();
}
@Override
...
...
@@ -272,10 +304,12 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
public
void
visit
(
ASTMathStatements
node
)
{
this
.
printer
.
println
();
this
.
printer
.
indent
();
this
.
printComments
(
node
.
get_PreCommentList
());
}
@Override
public
void
endVisit
(
ASTMathStatements
node
)
{
this
.
printComments
(
node
.
get_PostCommentList
());
this
.
printer
.
unindent
();
}
...
...
@@ -329,13 +363,9 @@ public class MathPrettyPrinter implements AstPrettyPrinter<ASTMathCompilationUni
}
@Override
public
void
v
isit
(
ASTMathDeclarationStatement
node
)
{
public
void
endV
isit
(
ASTMathDeclarationStatement
node
)
{
this
.
printSpace
();
this
.
printer
.
print
(
node
.
getName
());
}
@Override
public
void
endVisit
(
ASTMathDeclarationStatement
node
)
{
this
.
printSemicolon
();
this
.
printer
.
println
();
}
...
...
src/main/java/de/monticore/lang/monticar/mpp/montimath/MathStructuredVisitor.java
View file @
d06713af
...
...
@@ -51,12 +51,15 @@ public interface MathStructuredVisitor extends MathVisitor {
@Override
default
void
handle
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
getRealThis
().
traversePartOne
(
node
);
this
.
getRealThis
().
visit
(
node
);
this
.
getRealThis
().
traversePartOne
(
node
);
this
.
getRealThis
().
revisit
(
node
);
this
.
getRealThis
().
traversePartTwo
(
node
);
this
.
getRealThis
().
endVisit
(
node
);
}
default
void
revisit
(
ASTMathAssignmentDeclarationStatement
node
)
{}
default
void
traversePartOne
(
ASTMathAssignmentDeclarationStatement
node
)
{
if
(
null
!=
node
.
getType
())
{
node
.
getType
().
accept
(
this
.
getRealThis
());
...
...
@@ -174,8 +177,8 @@ public interface MathStructuredVisitor extends MathVisitor {
@Override
default
void
handle
(
ASTMathDeclarationStatement
node
)
{
this
.
getRealThis
().
traverse
(
node
);
this
.
getRealThis
().
visit
(
node
);
this
.
getRealThis
().
traverse
(
node
);
this
.
getRealThis
().
endVisit
(
node
);
}
...
...
src/main/java/de/monticore/lang/monticar/mpp/montimath/TeXHTMLMathPrettyPrinter.java
View file @
d06713af
...
...
@@ -41,17 +41,13 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
}
@Override
public
void
visit
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
printImageTag
(
node
);
}
@Override
public
void
visit
(
ASTMathDeclarationStatement
node
)
{
public
void
revisit
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
printImageTag
(
node
);
}
@Override
public
void
endVisit
(
ASTMathDeclarationStatement
node
)
{
this
.
printImageTag
(
node
);
this
.
printer
.
println
();
}
...
...
@@ -72,7 +68,6 @@ public class TeXHTMLMathPrettyPrinter extends HTMLMathPrettyPrinter implements T
@Override
public
void
visit
(
ASTMathForLoopHead
node
)
{
this
.
printer
.
println
();
this
.
printFor
();
this
.
printSpace
();
this
.
printImageTag
(
node
);
...
...
src/main/java/de/monticore/lang/monticar/mpp/montimath/TeXMathPrettyPrinter.java
View file @
d06713af
...
...
@@ -55,7 +55,7 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
}
@Override
public
void
visit
(
ASTMathAssignmentDeclarationStatement
node
)
{
public
void
re
visit
(
ASTMathAssignmentDeclarationStatement
node
)
{
this
.
printer
.
print
(
"~"
);
this
.
printer
.
print
(
node
.
getName
());
this
.
printer
.
print
(
"~"
);
...
...
@@ -68,9 +68,11 @@ public class TeXMathPrettyPrinter extends MathPrettyPrinter implements TeXMathSt
}
@Override
public
void
v
isit
(
ASTMathDeclarationStatement
node
)
{
public
void
endV
isit
(
ASTMathDeclarationStatement
node
)
{
this
.
printer
.
print
(
"~"
);
this
.
printer
.
print
(
node
.
getName
());
this
.
printSemicolon
();
this
.
printer
.
println
();
}
@Override
...
...
src/main/resources/templates/script.ftl
View file @
d06713af
...
...
@@ -34,7 +34,11 @@
}
.keyword
{
color
:
#009fff
!important
;
color
:
#569cd6
;
}
.comment
{
color
:
#608b4e
!important
;
}
pre
{
...
...
@@ -48,6 +52,7 @@
padding-right
:
10px
;
-moz-user-select
:
none
;
-webkit-user-select
:
none
;
color
:
#5a5a5a
;
}
img
{
...
...
@@ -107,7 +112,7 @@
}
input
:checked
{
background-color
:
#
009fff
!important
;
background-color
:
#
569cd6
!important
;
}
input
.code
{
...
...
src/test/resources/models/montimath/vanilla/Comments.m
0 → 100644
View file @
d06713af
/*
* (C) SE RWTH 2018
*/
package montimath.vanilla;
/*
* A Dummy Script to show that comments can be shown.
*/
script Comments
/* Vector of the form [1,3,5,7,9] */
Q(0:10)^{1,5} c = 1:2:10;
Q x = 0;
Q y = 0;
// Iterate over all i in c
for i = c
// Iterate over all j in c
for j = c
// y might become very small when the
// entries in c are very large.
y += 1 / (c(x) * j^i);
end;
x += 1;
end;
end
\ No newline at end of file
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