@@ -783,8 +783,16 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
783
783
echo(" \n // Detected repl transcript paste: ctrl-D to finish.\n " )
784
784
apply(Iterator (start) ++ readWhile(! isPromptOnly(_)))
785
785
}
786
+
787
+ def unapply (line : String ): Boolean = isPrompted(line)
788
+ }
789
+
790
+ private object invocation {
791
+ def unapply (line : String ): Boolean = Completion .looksLikeInvocation(line)
786
792
}
787
793
794
+ private val lineComment = """ \s*//.*""" .r // all comment
795
+
788
796
/** Interpret expressions starting with the first line.
789
797
* Read lines until a complete compilation unit is available
790
798
* or until a syntax error has been seen. If a full unit is
@@ -795,53 +803,42 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
795
803
// signal completion non-completion input has been received
796
804
in.completion.resetVerbosity()
797
805
798
- def reallyInterpret = {
799
- val reallyResult = intp.interpret(code)
800
- (reallyResult, reallyResult match {
801
- case IR .Error => None
802
- case IR .Success => Some (code)
803
- case IR .Incomplete =>
804
- if (in.interactive && code.endsWith(" \n\n " )) {
805
- echo(" You typed two blank lines. Starting a new command." )
806
+ def reallyInterpret = intp.interpret(code) match {
807
+ case IR .Error => None
808
+ case IR .Success => Some (code)
809
+ case IR .Incomplete if in.interactive && code.endsWith(" \n\n " ) =>
810
+ echo(" You typed two blank lines. Starting a new command." )
811
+ None
812
+ case IR .Incomplete =>
813
+ in.readLine(paste.ContinueString ) match {
814
+ case null =>
815
+ // we know compilation is going to fail since we're at EOF and the
816
+ // parser thinks the input is still incomplete, but since this is
817
+ // a file being read non-interactively we want to fail. So we send
818
+ // it straight to the compiler for the nice error message.
819
+ intp.compileString(code)
806
820
None
807
- }
808
- else in.readLine(paste.ContinueString ) match {
809
- case null =>
810
- // we know compilation is going to fail since we're at EOF and the
811
- // parser thinks the input is still incomplete, but since this is
812
- // a file being read non-interactively we want to fail. So we send
813
- // it straight to the compiler for the nice error message.
814
- intp.compileString(code)
815
- None
816
-
817
- case line => interpretStartingWith(code + " \n " + line)
818
- }
819
- })
821
+
822
+ case line => interpretStartingWith(code + " \n " + line)
823
+ }
820
824
}
821
825
822
- /** Here we place ourselves between the user and the interpreter and examine
823
- * the input they are ostensibly submitting. We intervene in several cases:
826
+ /* Here we place ourselves between the user and the interpreter and examine
827
+ * the input they are ostensibly submitting. We intervene in several cases:
824
828
*
825
- * 1) If the line starts with "scala> " it is assumed to be an interpreter paste.
826
- * 2) If the line starts with "." (but not ".." or "./") it is treated as an invocation
827
- * on the previous result.
828
- * 3) If the Completion object's execute returns Some(_), we inject that value
829
- * and avoid the interpreter, as it's likely not valid scala code.
829
+ * 1) If the line starts with "scala> " it is assumed to be an interpreter paste.
830
+ * 2) If the line starts with "." (but not ".." or "./") it is treated as an invocation
831
+ * on the previous result.
832
+ * 3) If the Completion object's execute returns Some(_), we inject that value
833
+ * and avoid the interpreter, as it's likely not valid scala code.
830
834
*/
831
- if (code == " " ) None
832
- else if (! paste.running && paste.isPrompted(code)) {
833
- paste.transcript(code)
834
- None
835
- }
836
- else if (Completion .looksLikeInvocation(code) && intp.mostRecentVar != " " ) {
837
- interpretStartingWith(intp.mostRecentVar + code)
835
+ code match {
836
+ case " " => None
837
+ case lineComment() => None // line comment, do nothing
838
+ case paste() if ! paste.running => paste.transcript(code) ; None
839
+ case invocation() if intp.mostRecentVar != " " => interpretStartingWith(intp.mostRecentVar + code)
840
+ case _ => reallyInterpret
838
841
}
839
- else if (code.trim startsWith " //" ) {
840
- // line comment, do nothing
841
- None
842
- }
843
- else
844
- reallyInterpret._2
845
842
}
846
843
847
844
// runs :load `file` on any files passed via -i
0 commit comments