Skip to content

Commit 870db51

Browse files
committed
Upgrade to latest glyph version.
1 parent 0d93d97 commit 870db51

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

pyro-repl/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77
[dependencies.glyph]
88
git = "https://github.com/YoEight/glyph.git"
9-
branch = "master"
9+
tag = "0.1.0"
1010

1111
[dependencies.pyro-runtime]
1212
path = "../pyro-runtime"

pyro-repl/src/main.rs

+33-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use clap::{Parser, Subcommand};
22
use directories::UserDirs;
3-
use glyph::{Input, Options};
3+
use glyph::{FileBackedInputs, Input, Options, PromptOptions};
44
use pyro_core::annotate::{annotate_decl, annotate_val};
55
use pyro_core::ast::Tag;
66
use pyro_core::parser::ParserState;
77
use pyro_core::sym::Sym;
88
use pyro_core::tokenizer::Tokenizer;
99
use pyro_core::{infer_decl, infer_val, Machine};
1010
use pyro_runtime::{Engine, Env};
11+
use std::io;
1112
use std::path::PathBuf;
1213

1314
#[derive(Parser, Debug)]
14-
#[command(name = ":")]
1515
struct Shell {
1616
#[command(subcommand)]
1717
cmd: Cmd,
@@ -29,19 +29,38 @@ enum Cmd {
2929
Exit,
3030
}
3131

32+
#[derive(Default)]
33+
struct State {
34+
modules: Vec<String>,
35+
}
36+
37+
impl State {
38+
fn next_input(&self, inputs: &mut FileBackedInputs) -> io::Result<Option<Input<Shell>>> {
39+
let prompt = self.modules.join(" ");
40+
let options = if prompt.is_empty() {
41+
PromptOptions::default()
42+
} else {
43+
PromptOptions::default().prompt(prompt)
44+
};
45+
46+
inputs.next_input_with_parser_and_options::<Shell>(&options)
47+
}
48+
}
49+
3250
#[tokio::main]
3351
async fn main() -> eyre::Result<()> {
3452
let user_dirs = UserDirs::new();
3553
let options = Options::default()
36-
.prompt("π")
54+
.prompt(>")
3755
.header(include_str!("header.txt"))
3856
.author("Yo Eight")
3957
.version("master");
4058

4159
let mut inputs = glyph::file_backed_inputs(options, ".pyro-repl")?;
4260
let mut engine = Engine::with_nominal_typing().stdlib(Env::stdio()).build()?;
61+
let mut state = State::default();
4362

44-
while let Some(input) = inputs.next_input_with_parser::<Shell>()? {
63+
while let Some(input) = state.next_input(&mut inputs)? {
4564
match input {
4665
Input::Exit => {
4766
break;
@@ -55,14 +74,14 @@ async fn main() -> eyre::Result<()> {
5574
PathBuf::from(file)
5675
};
5776

58-
if let Err(e) = add_module(&mut engine, path) {
77+
if let Err(e) = add_module(&mut state, &mut engine, path) {
5978
println!("ERR: {}", e);
6079
}
6180
}
6281

6382
Cmd::Type { expr } => {
6483
if let Err(e) = type_expr(&mut engine, expr) {
65-
println!("Err: {}", e);
84+
println!("ERR: {}", e);
6685
}
6786
}
6887

@@ -104,8 +123,12 @@ fn extrapolate_path(dirs: &UserDirs, path: PathBuf) -> PathBuf {
104123
buf
105124
}
106125

107-
fn add_module<M: Machine>(engine: &mut Engine<M>, path: PathBuf) -> eyre::Result<()> {
108-
let source_code = std::fs::read_to_string(path)?;
126+
fn add_module<M: Machine>(
127+
state: &mut State,
128+
engine: &mut Engine<M>,
129+
path: PathBuf,
130+
) -> eyre::Result<()> {
131+
let source_code = std::fs::read_to_string(path.as_path())?;
109132
let tokens = Tokenizer::new(source_code.as_str()).tokenize()?;
110133
let mut parser = ParserState::new(tokens.as_slice());
111134

@@ -129,6 +152,8 @@ fn add_module<M: Machine>(engine: &mut Engine<M>, path: PathBuf) -> eyre::Result
129152
}
130153
}
131154

155+
state.modules.push(format!("{}", path.to_string_lossy()));
156+
132157
Ok(())
133158
}
134159

0 commit comments

Comments
 (0)