Skip to content

Commit

Permalink
Write a mock
Browse files Browse the repository at this point in the history
  • Loading branch information
sozysozbot committed Jul 18, 2020
1 parent ba0ac9e commit 5258a8f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

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

46 changes: 44 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
fn main() {
println!("Hello, world!");
#![warn(clippy::pedantic)]
use std::fs::File;
use std::io::prelude::*;

#[derive(Debug)]
enum Statement {
Declare,
Define,
Print,
For,
Function,
If,
Return,
Math,
Assign,
Import,
Object,
Reference,
Array,
Flush,
Break,
Comment,
}

fn compile(input: &str) -> Vec<Statement> {
let mut ans = vec![];

ans
}

fn main() -> std::io::Result<()> {
let mut file = File::open("test001.wy")?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
println!("src: \n----------------------");
println!("{}", contents);
println!("----------------------");
println!("\noutput: \n----------------------");
for st in compile(&contents) {
println!("{:?}", st);
}
println!("----------------------");

Ok(())
}
23 changes: 23 additions & 0 deletions test001.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fn num_to_hanzi(a: i32) -> String {
match a {
3 => "三".to_string(),
0 => "零".to_string(),
_ => unimplemented!()
}
}

fn main() {
let _ans1 = "問天地好在。";
let _ans2 = "";
println!("{} {}", _ans1, _ans2);
let _ans3 = "天地";
println!("{}", _ans3);
let _ans4 = "宇宙";
let _ans5 = "洪荒";
let _ans6 = "";
let _ans7 = "";
println!("{} {} {} {}", _ans4, _ans5, _ans6, _ans7);
let _ans8 = 3;
let _ans9 = 0;
println!("{} {}", num_to_hanzi(_ans8), num_to_hanzi(_ans9));
}
4 changes: 4 additions & 0 deletions test001.wy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
吾有二言。曰「「問天地好在。」」。書之。
吾有一言。曰「「天地」」。曰「「玄黄」」。書之。
吾有四言。曰「「宇宙」」。曰「「洪荒」」。書之。
吾有二數。曰三。書之。

0 comments on commit 5258a8f

Please sign in to comment.