@@ -459,9 +459,12 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
459
459
pos
460
460
}
461
461
462
- private def requestFromLine (line : String , synthetic : Boolean ): Either [IR .Result , Request ] = {
462
+ private def requestFromLine (line : String , synthetic : Boolean , forPresentationCompile : Boolean = false ): Either [IR .Result , Request ] = {
463
463
val content = indentCode(line)
464
- val trees = parse(content) match {
464
+ if (forPresentationCompile)
465
+ return Right (buildRequest(line, Nil ))
466
+
467
+ val trees : List [global.Tree ] = parse(content) match {
465
468
case parse.Incomplete => return Left (IR .Incomplete )
466
469
case parse.Error => return Left (IR .Error )
467
470
case parse.Success (trees) => trees
@@ -529,7 +532,7 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
529
532
// Rewriting "foo ; bar ; 123"
530
533
// to "foo ; bar ; val resXX = 123"
531
534
requestFromLine(rewrittenLine, synthetic) match {
532
- case Right (req) => return Right (req withOriginalLine line)
535
+ case Right (req) if ! forPresentationCompile => return Right (req withOriginalLine line)
533
536
case x => return x
534
537
}
535
538
case _ =>
@@ -569,6 +572,17 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
569
572
}
570
573
}
571
574
575
+ private [scala] def presentationCompile (line : String , synthetic : Boolean ): Either [IR .Result , Request ] = {
576
+ if (global == null ) Left (IR .Error )
577
+ else requestFromLine(line, synthetic, forPresentationCompile = true ) match {
578
+ case Left (result) => Left (result)
579
+ case Right (req) =>
580
+ // null indicates a disallowed statement type; otherwise compile and
581
+ // fail if false (implying e.g. a type error)
582
+ if (req == null || ! req.presentationCompile) Left (IR .Error ) else Right (req)
583
+ }
584
+ }
585
+
572
586
var code = " "
573
587
var bound = false
574
588
def compiled (script : String ): CompiledScript = {
@@ -994,6 +1008,23 @@ class IMain(@BeanProperty val factory: ScriptEngineFactory, initialSettings: Set
994
1008
}
995
1009
}
996
1010
1011
+ lazy val presentationCompile : Boolean = {
1012
+ reporter.reset()
1013
+ val wrappedCode : String = ObjectSourceCode (handlers)
1014
+ parseAndTypeCheck(wrappedCode)
1015
+ reporter.hasErrors
1016
+ }
1017
+
1018
+ private [this ] def parseAndTypeCheck (code : String ): global.CompilationUnit = {
1019
+ val unit = global.newCompilationUnit(code)
1020
+ val parser = global.newUnitParser(unit)
1021
+ val parserPhase = global.syntaxAnalyzer.newPhase(NoPhase )
1022
+ val run : global.Run = new global.Run ()
1023
+ run.parserPhase.asInstanceOf [GlobalPhase ].applyPhase(unit)
1024
+ println(showCode(unit.body))
1025
+ unit
1026
+ }
1027
+
997
1028
lazy val resultSymbol = lineRep.resolvePathToSymbol(accessPath)
998
1029
def applyToResultMember [T ](name : Name , f : Symbol => T ) = exitingTyper(f(resultSymbol.info.nonPrivateDecl(name)))
999
1030
0 commit comments