blob: c4ab291a4daf39b6d02bf9c1290165656a452d3f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
package scalam.m.ast
/** Trait common to all objects having a representation in the matlab programming language. */
trait Mable {
def m: String
}
trait Root {
final def line: String = this match {
case statement: Statement => statement.m + ";"
case expression: Expression => expression.m + ";"
case comment: Comment => comment.m
}
def withComment(comment: Comment) = EOLComment(this, comment)
}
trait Comment extends Mable with Root {
def m = this match {
case SimpleComment(text) => "% " + text
case DoubleComment(text) => "%% " + text
case EOLComment(root, comment) => root.line + " " + comment.m
}
}
case class SimpleComment(text: String) extends Comment
case class DoubleComment(text: String) extends Comment
case class EOLComment(root: Root, comment: Comment) extends Comment
|