Skip to content

Commit 44bc7f4

Browse files
Remove use of kiama.Compiler (#1099)
1 parent 98734da commit 44bc7f4

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

effekt/jvm/src/main/scala/effekt/Driver.scala

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,39 @@ package effekt
33
// Adapted from
44
// https://github.com/inkytonik/kiama/blob/master/extras/src/test/scala/org/bitbucket/inkytonik/kiama/example/oberon0/base/Driver.scala
55

6-
import effekt.source.{ ModuleDecl, Tree }
7-
import effekt.symbols.Module
8-
import effekt.context.{ Context, IOModuleDB }
9-
import kiama.output.PrettyPrinterTypes.Document
10-
import kiama.parsing.ParseResult
11-
import kiama.util.{ IO, Source }
12-
import effekt.util.messages.{ BufferedMessaging, CompilerPanic, EffektError, EffektMessaging, FatalPhaseError }
6+
import effekt.context.{Context, IOModuleDB}
7+
import effekt.source.ModuleDecl
8+
import effekt.util.messages.{CompilerPanic, FatalPhaseError}
139
import effekt.util.paths.file
14-
import effekt.util.{ JSONDocumentationGenerator, AnsiColoredMessaging, MarkdownSource, getOrElseAborting }
10+
import effekt.util.{AnsiColoredMessaging, JSONDocumentationGenerator, MarkdownSource}
11+
import kiama.output.PrettyPrinterTypes.Document
12+
import kiama.util.{FileSource, IO, Source, StringSource}
1513

16-
import scala.sys.process.Process
14+
import scala.collection.mutable
1715

1816
/**
19-
* effekt.Compiler <----- compiles code with ------ Driver ------ implements UI with -----> kiama.util.Compiler
17+
* effekt.Compiler <----- compiles code with ------ Driver
2018
*/
21-
trait Driver extends kiama.util.Compiler[EffektConfig, EffektError] { outer =>
19+
trait Driver { outer =>
2220

2321
object messaging extends AnsiColoredMessaging
2422

23+
val sources = mutable.Map[String, Source]()
24+
2525
// Compiler context
2626
// ================
2727
// We always only have one global instance of the compiler
2828
object context extends Context with IOModuleDB { val messaging = outer.messaging }
2929

30-
override def createConfig(args: Seq[String]) =
30+
def createConfig(args: Seq[String]) =
3131
new EffektConfig(args)
3232

3333
/**
3434
* Main entry to the compiler, invoked by Kiama after creating the config
3535
*
3636
* In LSP mode: invoked for each file opened in an editor
3737
*/
38-
override def compileSource(source: Source, config: EffektConfig): Unit = {
38+
def compileSource(source: Source, config: EffektConfig): Unit = {
3939
val src = if (source.name.endsWith(".md")) { MarkdownSource(source) } else { source }
4040
try {
4141
// remember that we have seen this source, this is used by LSP (kiama.util.Server)
@@ -158,4 +158,21 @@ trait Driver extends kiama.util.Compiler[EffektConfig, EffektError] { outer =>
158158
if (config.exitOnError() && C.messaging.hasErrors)
159159
sys.exit(1)
160160
}
161+
162+
def report(source: Source, messages: messaging.Messages, config: EffektConfig): Unit = {
163+
messaging.report(source, messages, config.output())
164+
}
165+
166+
def compileString(name: String, input: String, config: EffektConfig): Unit = {
167+
compileSource(StringSource(input, name), config)
168+
}
169+
170+
def compileFile(filename: String, config: EffektConfig, encoding: String = "UTF-8"): Unit = {
171+
try {
172+
compileSource(FileSource(filename, encoding), config)
173+
} catch {
174+
case e: java.io.FileNotFoundException =>
175+
config.output().emitln(e.getMessage)
176+
}
177+
}
161178
}

0 commit comments

Comments
 (0)