aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/scalam/m/ast/package.scala
blob: 245c6c41e9c9bf7dc3b0ba4a6db4ff9102cb2098 (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
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
  }
}

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