Skip to content

Commit

Permalink
feat:
Browse files Browse the repository at this point in the history
- use rustyline
- add eq code
  • Loading branch information
linsyking committed Apr 2, 2023
1 parent 4bab1d1 commit efcefd8
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 5 deletions.
123 changes: 123 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ build = "build.rs"
[dependencies]
lalrpop-util = {version = "0.19.9", features = ["lexer"]}
regex = "1.7.3"
rustyline = "11.0.0"

# Add a build-time dependency on the lalrpop library:
[build-dependencies]
Expand Down
10 changes: 8 additions & 2 deletions examples/syn.meow
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ decode(s) {
rep
}

m(){
var s = "abcd";
test_code() {
var s = "\ab\^^^cd\$$$^$^$^";
var enc = encode(s);
var dec = decode(enc);
dec
}

eq(x,y) {
encode(x) = "F";
encode(y) = "T";
encode(x)
}
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ fn main() {
.expect("unexpected token!");
let context = &mut Box::new(prog::Context::new());
prog::eval_prog(res, context);
let mut rl = rustyline::DefaultEditor::new().unwrap();
loop {
let mut line = String::new();
eprint!("> ");
std::io::stdin().read_line(&mut line).unwrap();
line = line.trim().to_string();
let readline = rl.readline("> ");
match readline {
Ok(l) => line = l.trim().to_string(),
Err(_) => println!("invalid input"),
}
let expr = parse::ExpressionParser::new()
.parse(line.as_str())
.expect("invalid expression!");
Expand Down

0 comments on commit efcefd8

Please sign in to comment.