@@ -3,39 +3,39 @@ package effekt
3
3
// Adapted from
4
4
// https://github.com/inkytonik/kiama/blob/master/extras/src/test/scala/org/bitbucket/inkytonik/kiama/example/oberon0/base/Driver.scala
5
5
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 }
13
9
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 }
15
13
16
- import scala .sys . process . Process
14
+ import scala .collection . mutable
17
15
18
16
/**
19
- * effekt.Compiler <----- compiles code with ------ Driver ------ implements UI with -----> kiama.util.Compiler
17
+ * effekt.Compiler <----- compiles code with ------ Driver
20
18
*/
21
- trait Driver extends kiama.util. Compiler [ EffektConfig , EffektError ] { outer =>
19
+ trait Driver { outer =>
22
20
23
21
object messaging extends AnsiColoredMessaging
24
22
23
+ val sources = mutable.Map [String , Source ]()
24
+
25
25
// Compiler context
26
26
// ================
27
27
// We always only have one global instance of the compiler
28
28
object context extends Context with IOModuleDB { val messaging = outer.messaging }
29
29
30
- override def createConfig (args : Seq [String ]) =
30
+ def createConfig (args : Seq [String ]) =
31
31
new EffektConfig (args)
32
32
33
33
/**
34
34
* Main entry to the compiler, invoked by Kiama after creating the config
35
35
*
36
36
* In LSP mode: invoked for each file opened in an editor
37
37
*/
38
- override def compileSource (source : Source , config : EffektConfig ): Unit = {
38
+ def compileSource (source : Source , config : EffektConfig ): Unit = {
39
39
val src = if (source.name.endsWith(" .md" )) { MarkdownSource (source) } else { source }
40
40
try {
41
41
// 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 =>
158
158
if (config.exitOnError() && C .messaging.hasErrors)
159
159
sys.exit(1 )
160
160
}
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
+ }
161
178
}
0 commit comments