topdown-rs 0.3.2

A top-down parsing library
#![feature(box_patterns)]
#![feature(slicing_syntax)]
#![allow(unstable)]
#![feature(box_syntax)]
#[macro_use]
extern crate topdown;
use std::os;
use std::old_io::File;
use parser::*;
use interpreter::*;
use topdown::*;
pub mod parser;
pub mod interpreter;

#[allow(unused_variables)]
fn main() {
    let a = os::args();
    let path = Path::new(a[1].clone());
    let mut file = match File::open(&path) {
        Ok(f) => f,
        Err(w) => panic!("{}", w)
    };
    let content = match file.read_to_string() {
        Ok(f) => f,
        Err(w) => panic!("{}", w)
    };
    let skip = skip(" \t\r\n");
    let mut cs = CharSeq::new(content.as_slice(), path.as_str().unwrap());
    let mut machine = Interpreter::new();
    cs.add_hook(&skip);
    match script(&mut cs) {
        Succ(ast) => {
            if !cs.eof() {
                println!("{}", cs.get_location());
                return;
            }
            let r = machine.toplevel(ast);
            match r {
                Ok(_) => (),
                Err(e) => println!("error: {}", e)
            }
        },
        Fail(m, l) => println!("Parse Error: {} {}", m, l),
        Error(m, l) => println!("Parse Error: {} {}", m, l)
    };
}