/
Sandbox.scala
92 lines (87 loc) · 2.84 KB
/
Sandbox.scala
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package org.polystat.odin.sandbox
import cats.effect.{ExitCode, IO, IOApp}
import org.polystat.odin.interop.java.EOOdinAnalyzer
import cats.syntax.all._
import scala.jdk.CollectionConverters._
object Sandbox extends IOApp {
val examples = Map(
"first" -> """[x y z] > test
| x.div (y.add z) > @
|""".stripMargin,
"second" -> """[] > test
| [] > base
| [self v] > n
| v > @
| [self v] > m
| self.n self v > @
| [] > derived
| base > @
| [self v] > n
| self.m self v > @
|""".stripMargin,
"third" -> """[] > test
| [] > parent
| [self x] > f
| x.sub 5 > y1
| seq > @
| assert (0.less y1)
| x
| [self y] > g
| self.f self y > @
| [self z] > h
| z > @
| [] > child
| test.parent > @
| [self y] > f
| y > @
| [self z] > h
| self.g self z > @
|""".stripMargin,
"fourth" -> """
|1 > non-existent
|[] > a
| non-existent > @
|""".stripMargin,
"fifth" -> """
|[] > b
|[] > a
| ^.^.b > @
|""".stripMargin,
"sixth" -> """
|[] > a
| [self] > f
| self.non-existent self > @
|""".stripMargin,
"seventh" -> """
|[] > a
| [self a b] > f
| a.add b > @
| [self] > g
| self.f self 1 > @
| [self] > h
| self.f self 1 2 3 > @
|""".stripMargin,
"eight" -> """[] > a
| memory > state
| [self new_state] > update_state
| self.state.write new_state > @
|[] > b
| a > @
| [self new_state] > change_state_plus_two
| self.state.write (new_state.add 2) > @
|""".stripMargin,
)
override def run(args: List[String]): IO[ExitCode] = for {
exitCode <- IO.pure(ExitCode.Success)
_ <- examples.toList.traverse { case (name, code) =>
IO.println(s"Example $name:") *>
IO(
new EOOdinAnalyzer.EOOdinSourceCodeAnalyzer()
.analyze(code)
.asScala
.toList
)
.flatMap(IO.println)
}
} yield exitCode
}