schala/src/rukka_lang/mod.rs

65 lines
1.3 KiB
Rust
Raw Normal View History

use itertools::Itertools;
use schala_lib::{ProgrammingLanguageInterface, EvalOptions, ReplOutput};
2017-11-29 01:45:29 -08:00
use std::iter::Peekable;
use std::str::Chars;
pub struct Rukka { }
impl Rukka {
pub fn new() -> Rukka { Rukka { } }
}
impl ProgrammingLanguageInterface for Rukka {
fn get_language_name(&self) -> String {
"Rukka".to_string()
}
fn get_source_file_suffix(&self) -> String {
format!("rukka")
}
fn evaluate_in_repl(&mut self, input: &str, _eval_options: &EvalOptions) -> ReplOutput {
let mut output = ReplOutput::default();
2017-11-29 01:45:29 -08:00
match parse(input).and_then(|x| eval(x)) {
Ok(s) => output.add_output(s),
Err(e) => output.add_output(format!("Error: {}", e))
};
output
}
}
2017-11-27 00:57:26 -08:00
2017-11-28 03:37:16 -08:00
fn eval(ast: Sexp) -> Result<String, String> {
Ok(format!("Everything is ()"))
}
2017-11-29 01:45:29 -08:00
fn parse(input: &str) -> Result<Sexp, String> {
let mut iter: Peekable<Chars> = input.chars().peekable();
read_sexp(iter)
2017-11-28 03:37:16 -08:00
}
2017-11-27 00:57:26 -08:00
2017-11-29 01:45:29 -08:00
fn read_sexp(mut input: Peekable<Chars>) -> Result<Sexp, String> {
if input.next() != Some('(') {
return Err(format!("Expected '('"));
2017-11-28 03:37:16 -08:00
}
2017-11-29 01:45:29 -08:00
Ok(Sexp::Atom(AtomT::Number(4)))
2017-11-28 03:37:16 -08:00
}
#[derive(Debug)]
enum Sexp {
Atom(AtomT),
List(Vec<Sexp>),
}
#[derive(Debug)]
enum AtomT {
Symbol(String),
Number(u64),
2017-11-27 00:57:26 -08:00
}
#[derive(Debug)]
struct List<'a> {
next: Option<&'a List<'a>>,
2017-11-28 03:37:16 -08:00
data: usize
2017-11-27 00:57:26 -08:00
}
2017-11-28 03:37:16 -08:00