mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Merge branch 'repl' into repl-warnings
Signed-off-by: Richard Feldman <oss@rtfeldman.com>
This commit is contained in:
commit
0657c38bb4
5 changed files with 53 additions and 115 deletions
127
Cargo.lock
generated
127
Cargo.lock
generated
|
@ -129,7 +129,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"hermit-abi",
|
"hermit-abi",
|
||||||
"libc",
|
"libc",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -509,7 +509,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342"
|
checksum = "9fdf5e01086b6be750428ba4a40619f847eb2e95756eee84b18e06e5f0b50342"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy-bytes-cast",
|
"lazy-bytes-cast",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -520,7 +520,7 @@ checksum = "2f3e1238132dc01f081e1cbb9dace14e5ef4c3a51ee244bd982275fb514605db"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"error-code",
|
"error-code",
|
||||||
"str-buf",
|
"str-buf",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -572,7 +572,7 @@ checksum = "b3616f750b84d8f0de8a58bda93e08e2a81ad3f523089b05f1dffecab48c6cbd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -606,7 +606,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"terminal_size",
|
"terminal_size",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -801,7 +801,7 @@ dependencies = [
|
||||||
"stdweb 0.1.3",
|
"stdweb 0.1.3",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1040,7 +1040,7 @@ checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"libloading",
|
"libloading",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1145,7 +1145,7 @@ checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"redox_users",
|
"redox_users",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1156,7 +1156,7 @@ checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"redox_users",
|
"redox_users",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1313,7 +1313,7 @@ checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"errno-dragonfly",
|
"errno-dragonfly",
|
||||||
"libc",
|
"libc",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1913,16 +1913,6 @@ dependencies = [
|
||||||
"rayon",
|
"rayon",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "kernel32-sys"
|
|
||||||
version = "0.2.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
|
||||||
dependencies = [
|
|
||||||
"winapi 0.2.8",
|
|
||||||
"winapi-build",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "khronos-egl"
|
name = "khronos-egl"
|
||||||
version = "4.1.0"
|
version = "4.1.0"
|
||||||
|
@ -1981,7 +1971,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
|
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2403,7 +2393,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"overload",
|
"overload",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2466,12 +2456,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "numtoa"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "objc"
|
name = "objc"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
@ -2601,7 +2585,7 @@ version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
|
checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2648,7 +2632,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd"
|
checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2707,7 +2691,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3146,15 +3130,6 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "redox_termios"
|
|
||||||
version = "0.1.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f"
|
|
||||||
dependencies = [
|
|
||||||
"redox_syscall",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_users"
|
name = "redox_users"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
|
@ -3212,7 +3187,7 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"libc",
|
"libc",
|
||||||
"mach",
|
"mach",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3221,7 +3196,7 @@ version = "0.5.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3234,7 +3209,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"rayon",
|
"rayon",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3338,7 +3313,7 @@ dependencies = [
|
||||||
"roc_unify",
|
"roc_unify",
|
||||||
"snafu",
|
"snafu",
|
||||||
"ven_graph",
|
"ven_graph",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3944,7 +3919,6 @@ dependencies = [
|
||||||
"rustyline",
|
"rustyline",
|
||||||
"rustyline-derive",
|
"rustyline-derive",
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
"termsize",
|
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -4260,7 +4234,7 @@ dependencies = [
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
"utf8parse",
|
"utf8parse",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4557,7 +4531,7 @@ checksum = "31ef6ee280cdefba6d2d0b4b78a84a1c1a3f3a4cec98c2d4231c8bc225de0f25"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"mach",
|
"mach",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4805,7 +4779,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"remove_dir_all 0.5.3",
|
"remove_dir_all 0.5.3",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4824,32 +4798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termion"
|
|
||||||
version = "1.5.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "077185e2eac69c3f8379a4298e1e07cd36beb962290d4a51199acf0fdc10607e"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"numtoa",
|
|
||||||
"redox_syscall",
|
|
||||||
"redox_termios",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "termsize"
|
|
||||||
version = "0.1.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5e86d824a8e90f342ad3ef4bd51ef7119a9b681b0cc9f8ee7b2852f02ccd2517"
|
|
||||||
dependencies = [
|
|
||||||
"atty",
|
|
||||||
"kernel32-sys",
|
|
||||||
"libc",
|
|
||||||
"termion",
|
|
||||||
"winapi 0.2.8",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5009,7 +4958,7 @@ dependencies = [
|
||||||
"stdweb 0.4.20",
|
"stdweb 0.4.20",
|
||||||
"time-macros 0.1.1",
|
"time-macros 0.1.1",
|
||||||
"version_check",
|
"version_check",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5300,7 +5249,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
|
checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"same-file",
|
"same-file",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -5433,7 +5382,7 @@ dependencies = [
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vm",
|
"wasmer-vm",
|
||||||
"wat",
|
"wat",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5584,7 +5533,7 @@ dependencies = [
|
||||||
"wasmer-engine-universal-artifact",
|
"wasmer-engine-universal-artifact",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"wasmer-vm",
|
"wasmer-vm",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5667,7 +5616,7 @@ dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wasmer-artifact",
|
"wasmer-artifact",
|
||||||
"wasmer-types",
|
"wasmer-types",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5686,7 +5635,7 @@ dependencies = [
|
||||||
"wasmer",
|
"wasmer",
|
||||||
"wasmer-vfs",
|
"wasmer-vfs",
|
||||||
"wasmer-wasi-types",
|
"wasmer-wasi-types",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5889,7 +5838,7 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"wgpu-types",
|
"wgpu-types",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -5924,12 +5873,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi"
|
|
||||||
version = "0.2.8"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
|
@ -5940,12 +5883,6 @@ dependencies = [
|
||||||
"winapi-x86_64-pc-windows-gnu",
|
"winapi-x86_64-pc-windows-gnu",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "winapi-build"
|
|
||||||
version = "0.1.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-i686-pc-windows-gnu"
|
name = "winapi-i686-pc-windows-gnu"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
|
@ -5958,7 +5895,7 @@ version = "0.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -6082,7 +6019,7 @@ dependencies = [
|
||||||
"wayland-client",
|
"wayland-client",
|
||||||
"wayland-protocols",
|
"wayland-protocols",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"winapi 0.3.9",
|
"winapi",
|
||||||
"x11-dl",
|
"x11-dl",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ rustyline = {git = "https://github.com/roc-lang/rustyline", rev = "e74333c"}
|
||||||
rustyline-derive = {git = "https://github.com/roc-lang/rustyline", rev = "e74333c"}
|
rustyline-derive = {git = "https://github.com/roc-lang/rustyline", rev = "e74333c"}
|
||||||
target-lexicon = "0.12.2"
|
target-lexicon = "0.12.2"
|
||||||
unicode-segmentation = "1.10.0"
|
unicode-segmentation = "1.10.0"
|
||||||
termsize = "0.1.6"
|
|
||||||
|
|
||||||
roc_build = {path = "../compiler/build"}
|
roc_build = {path = "../compiler/build"}
|
||||||
roc_builtins = {path = "../compiler/builtins"}
|
roc_builtins = {path = "../compiler/builtins"}
|
||||||
|
|
|
@ -22,7 +22,7 @@ pub const WELCOME_MESSAGE: &str = concatcp!(
|
||||||
|
|
||||||
// For when nothing is entered in the repl
|
// For when nothing is entered in the repl
|
||||||
// TODO add link to repl tutorial(does not yet exist).
|
// TODO add link to repl tutorial(does not yet exist).
|
||||||
pub const SHORT_INSTRUCTIONS: &str = "Enter an expression, or :help, or :q to quit.\n";
|
pub const SHORT_INSTRUCTIONS: &str = "Enter an expression, or :help, or :q to quit.\n\n";
|
||||||
|
|
||||||
pub fn main() -> i32 {
|
pub fn main() -> i32 {
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
|
@ -42,9 +42,10 @@ pub fn main() -> i32 {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
editor.add_history_entry(line.trim());
|
editor.add_history_entry(line.trim());
|
||||||
|
|
||||||
|
let dimensions = editor.dimensions();
|
||||||
let repl_helper = editor.helper_mut().expect("Editor helper was not set");
|
let repl_helper = editor.helper_mut().expect("Editor helper was not set");
|
||||||
|
|
||||||
match repl_helper.step(&line) {
|
match repl_helper.step(&line, dimensions) {
|
||||||
Ok(output) => {
|
Ok(output) => {
|
||||||
// If there was no output, don't print a blank line!
|
// If there was no output, don't print a blank line!
|
||||||
// (This happens for something like a type annotation.)
|
// (This happens for something like a type annotation.)
|
||||||
|
|
|
@ -17,9 +17,8 @@ use rustyline::validate::{self, ValidationContext, ValidationResult, Validator};
|
||||||
use rustyline_derive::{Completer, Helper, Hinter};
|
use rustyline_derive::{Completer, Helper, Hinter};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use target_lexicon::Triple;
|
use target_lexicon::Triple;
|
||||||
use termsize::Size;
|
|
||||||
|
|
||||||
pub const PROMPT: &str = concatcp!("\n", BLUE, "»", END_COL, " ");
|
pub const PROMPT: &str = concatcp!(BLUE, "»", END_COL, " ");
|
||||||
pub const CONT_PROMPT: &str = concatcp!(BLUE, "…", END_COL, " ");
|
pub const CONT_PROMPT: &str = concatcp!(BLUE, "…", END_COL, " ");
|
||||||
|
|
||||||
/// The prefix we use for the automatic variable names we assign to each expr,
|
/// The prefix we use for the automatic variable names we assign to each expr,
|
||||||
|
@ -92,7 +91,7 @@ impl ReplState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn step(&mut self, line: &str) -> Result<String, i32> {
|
pub fn step(&mut self, line: &str, dimensions: Option<(usize, usize)>) -> Result<String, i32> {
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
|
|
||||||
match parse_src(&arena, line) {
|
match parse_src(&arena, line) {
|
||||||
|
@ -103,7 +102,7 @@ impl ReplState {
|
||||||
// After two blank lines in a row, give up and try parsing it
|
// After two blank lines in a row, give up and try parsing it
|
||||||
// even though it's going to fail. This way you don't get stuck
|
// even though it's going to fail. This way you don't get stuck
|
||||||
// in a perpetual Incomplete state due to a syntax error.
|
// in a perpetual Incomplete state due to a syntax error.
|
||||||
Ok(self.eval_and_format(line))
|
Ok(self.eval_and_format(line, dimensions))
|
||||||
} else {
|
} else {
|
||||||
// The previous line wasn't blank, but the line isn't empty either.
|
// The previous line wasn't blank, but the line isn't empty either.
|
||||||
// This could mean that, for example, you're writing a multiline `when`
|
// This could mean that, for example, you're writing a multiline `when`
|
||||||
|
@ -119,7 +118,7 @@ impl ReplState {
|
||||||
| ParseOutcome::ValueDef(_)
|
| ParseOutcome::ValueDef(_)
|
||||||
| ParseOutcome::TypeDef(_)
|
| ParseOutcome::TypeDef(_)
|
||||||
| ParseOutcome::SyntaxErr
|
| ParseOutcome::SyntaxErr
|
||||||
| ParseOutcome::Incomplete => Ok(self.eval_and_format(line)),
|
| ParseOutcome::Incomplete => Ok(self.eval_and_format(line, dimensions)),
|
||||||
ParseOutcome::Help => {
|
ParseOutcome::Help => {
|
||||||
// TODO add link to repl tutorial(does not yet exist).
|
// TODO add link to repl tutorial(does not yet exist).
|
||||||
Ok(TIPS.to_string())
|
Ok(TIPS.to_string())
|
||||||
|
@ -128,7 +127,7 @@ impl ReplState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eval_and_format(&mut self, src: &str) -> String {
|
pub fn eval_and_format(&mut self, src: &str, dimensions: Option<(usize, usize)>) -> String {
|
||||||
let arena = Bump::new();
|
let arena = Bump::new();
|
||||||
let pending_past_def;
|
let pending_past_def;
|
||||||
let mut opt_var_name;
|
let mut opt_var_name;
|
||||||
|
@ -281,7 +280,7 @@ impl ReplState {
|
||||||
self.add_past_def(ident, src);
|
self.add_past_def(ident, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
format_output(output, problems, opt_var_name)
|
format_output(output, problems, opt_var_name, dimensions)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_auto_ident(&mut self) -> u64 {
|
fn next_auto_ident(&mut self) -> u64 {
|
||||||
|
@ -550,6 +549,7 @@ fn format_output(
|
||||||
opt_output: Option<ReplOutput>,
|
opt_output: Option<ReplOutput>,
|
||||||
problems: Problems,
|
problems: Problems,
|
||||||
opt_var_name: Option<String>,
|
opt_var_name: Option<String>,
|
||||||
|
dimensions: Option<(usize, usize)>,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
|
|
||||||
|
@ -587,10 +587,10 @@ fn format_output(
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
const VAR_NAME_PREFIX: &str = " # "; // e.g. in " # val1"
|
const VAR_NAME_PREFIX: &str = " # "; // e.g. in " # val1"
|
||||||
const VAR_NAME_COLUMN_MAX: u16 = 80; // Right-align the var_name at this column
|
const VAR_NAME_COLUMN_MAX: usize = 32; // Right-align the var_name at this column
|
||||||
|
|
||||||
let var_name_column = match termsize::get() {
|
let term_width = match dimensions {
|
||||||
Some(Size { cols, rows: _ }) => cols.min(VAR_NAME_COLUMN_MAX) as usize,
|
Some((width, _)) => width.min(VAR_NAME_COLUMN_MAX),
|
||||||
None => VAR_NAME_COLUMN_MAX as usize,
|
None => VAR_NAME_COLUMN_MAX as usize,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -605,11 +605,11 @@ fn format_output(
|
||||||
.count();
|
.count();
|
||||||
let var_name_len =
|
let var_name_len =
|
||||||
var_name.graphemes(true).count() + VAR_NAME_PREFIX.graphemes(true).count();
|
var_name.graphemes(true).count() + VAR_NAME_PREFIX.graphemes(true).count();
|
||||||
let spaces_needed = if last_line_len + var_name_len > var_name_column {
|
let spaces_needed = if last_line_len + var_name_len > term_width {
|
||||||
buf.push('\n');
|
buf.push('\n');
|
||||||
var_name_column - var_name_len
|
term_width - var_name_len
|
||||||
} else {
|
} else {
|
||||||
var_name_column - last_line_len - var_name_len
|
term_width - last_line_len - var_name_len
|
||||||
};
|
};
|
||||||
|
|
||||||
for _ in 0..spaces_needed {
|
for _ in 0..spaces_needed {
|
||||||
|
@ -620,6 +620,7 @@ fn format_output(
|
||||||
buf.push_str(VAR_NAME_PREFIX);
|
buf.push_str(VAR_NAME_PREFIX);
|
||||||
buf.push_str(&var_name);
|
buf.push_str(&var_name);
|
||||||
buf.push_str(END_COL);
|
buf.push_str(END_COL);
|
||||||
|
buf.push('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ fn exhaustiveness_problem() {
|
||||||
#[test]
|
#[test]
|
||||||
fn tips() {
|
fn tips() {
|
||||||
assert!(!is_incomplete(""));
|
assert!(!is_incomplete(""));
|
||||||
assert_eq!(ReplState::new().step(""), Ok(TIPS.to_string()));
|
assert_eq!(ReplState::new().step("", None), Ok(TIPS.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -98,7 +98,7 @@ fn standalone_annotation() {
|
||||||
|
|
||||||
incomplete(&mut input);
|
incomplete(&mut input);
|
||||||
assert!(!is_incomplete(&input));
|
assert!(!is_incomplete(&input));
|
||||||
assert_eq!(state.step(&input), Ok(String::new()));
|
assert_eq!(state.step(&input, None), Ok(String::new()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// validate and step the given input, then check the Result vs the output
|
/// validate and step the given input, then check the Result vs the output
|
||||||
|
@ -106,7 +106,7 @@ fn standalone_annotation() {
|
||||||
fn complete(input: &str, state: &mut ReplState, expected_step_result: Result<(&str, &str), i32>) {
|
fn complete(input: &str, state: &mut ReplState, expected_step_result: Result<(&str, &str), i32>) {
|
||||||
assert!(!is_incomplete(input));
|
assert!(!is_incomplete(input));
|
||||||
|
|
||||||
match state.step(input) {
|
match state.step(input, None) {
|
||||||
Ok(string) => {
|
Ok(string) => {
|
||||||
let escaped =
|
let escaped =
|
||||||
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap())
|
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap())
|
||||||
|
@ -144,7 +144,7 @@ fn incomplete(input: &mut String) {
|
||||||
fn error(input: &str, state: &mut ReplState, expected_step_result: String) {
|
fn error(input: &str, state: &mut ReplState, expected_step_result: String) {
|
||||||
assert!(!is_incomplete(input));
|
assert!(!is_incomplete(input));
|
||||||
|
|
||||||
let escaped = state.step(input).map(|string| {
|
let escaped = state.step(input, None).map(|string| {
|
||||||
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap()).unwrap()
|
std::string::String::from_utf8(strip_ansi_escapes::strip(string.trim()).unwrap()).unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue