Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI-4684 Repl supports whole-file paste (rebased) #2725

Merged
merged 2 commits into from
Jul 12, 2013

Conversation

som-snytt
Copy link
Contributor

Re-rebased #2719: Rebased #2696

The first test repl-paste4 was failing for an unknown reason, with no diff in the build output.

This version makes that test a SessionTest with no check file. The research question is whether that changes how line endings are handled.

The second test was already a SessionTest but used a private version, but now it can use the class in partest.

Add a file argument to the :paste command which loads the
file's contents as though entered in :paste mode.

The :paste command is replayable.

Samples, including companions defined together:

```
scala> :paste junk.scala
File contains no code: junk.scala

scala> :paste no-file.scala
That file does not exist

scala> :paste obj-repl.scala
Pasting file obj-repl.scala...
<console>:2: error: expected start of definition
         private foo = 7
                 ^

scala> :paste hw-repl.scala
Pasting file hw-repl.scala...
The pasted code is incomplete!

<pastie>:5: error: illegal start of simple expression
}
^

scala> :replay
Replaying: :paste junk.scala
File contains no code: junk.scala

Replaying: :paste obj-repl.scala
Pasting file obj-repl.scala...
defined trait Foo
defined object Foo

Replaying: Foo(new Foo{})
res0: Int = 7
```
By special request, :paste -raw simply compiles the pasted
code to the repl output dir.

The -raw flag means no wrapping; the pasted code must be
ordinary top level Scala code, not script.
@adriaanm
Copy link
Contributor

LGTM

adriaanm added a commit that referenced this pull request Jul 12, 2013
SI-4684 Repl supports whole-file paste (rebased)
@adriaanm adriaanm merged commit 03e4ae5 into scala:master Jul 12, 2013
@reflectionalist
Copy link

Why not just fix :load rather than introduce a command-line-like option -raw to :paste?

@retronym
Copy link
Member

:load has a different meaning. For example, :load can accept REPL commands, such as :help or :power.

@som-snytt
Copy link
Contributor Author

@plmday :load, :paste, :paste -raw are different features.

@som-snytt
Copy link
Contributor Author

Jinx.

@reflectionalist
Copy link

@retronym I don't understand what you mean by :load can accept REPL commands.

scala> :help load

:load <path> (no extended help available.)

scala> :load help
That file does not exist

scala> :load :help
That file does not exist

@reflectionalist
Copy link

@som-snytt What other features does :load have than loading a file?

@som-snytt
Copy link
Contributor Author

I would ask on the ML for an extended discussion, but to illustrate, my scala -i init.script:

apm@mara:~$ cat init.script
:paste /home/apm/funcs.script
:paste /home/apm/imports.script
apm@mara:~$ scalam
Welcome to Scala version 2.11.0-M5 (OpenJDK 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :load init.script
Loading init.script...
Pasting file /home/apm/funcs.script...
defined object Timing
Pasting file /home/apm/imports.script...
import language._
import language.experimental._
import annotation._
import util._
import reflect.io._
import reflect.macros._
import reflect.runtime._
import universe._
import concurrent._
import duration._
import collection.generic.{CanBuildFrom=>CBF}
import collection.mutable
import mutable.{Map=>MMap}
import java.util.regex._
import sys.exit
import System.{currentTimeMillis=>time, nanoTime=>now}
import Timing.timed

scala> 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants