From 3fdacf018e7cdb0e65483db12d3628688c54d81e Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 16 Jul 2015 02:55:03 -0700 Subject: [PATCH] Basic repl --- src/main.rs | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..5ff19dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,62 @@ +use std::io; +use std::io::Write; +use std::io::BufRead; + fn main() { - println!("Hello, world!"); + println!("Unnamed language 0.01"); + repl(); +} + +#[derive(Debug)] +enum Token { + EOF, + NumLiteral(i32), + StrLiteral(String), + Identifier(String) + /* Keyword(Keyword) */ //implement in future + +} + +#[derive(Debug)] +enum ASTNode { + GenericNode +} + + +fn repl() { + let mut stdin = io::stdin(); + let mut stdout = io::stdout(); + let mut buf = String::with_capacity(20); + loop { + print!(">> "); + stdout.flush().ok(); + let line = stdin.lock().read_line(&mut buf); + match line { + Ok(n) => { + let result = tokenize(&buf); + println!("Tokens: {:?}", result); + }, + Err(err) => { + println!("Error: {}", err); + } + } + } +} + + +fn tokenize(input: &str) -> Vec { + let mut tokens = Vec::new(); + let mut buffer = String::with_capacity(20); + let mut iterator = input.chars(); + loop { + + break; + } + + tokens.push(Token::EOF); + tokens +} + +fn parse(_input: Vec) -> ASTNode { + ASTNode::GenericNode }