Compiler for set-theoretic programming language.
git clone git://
Log | Files | Refs | README | LICENSE (1669B)

//! Syntax, parsing and analysis.

/// location manages line and column location of
/// lexical tokens as well as their span.
pub mod location;

/// Provides token classes and methods
pub mod token;

/// Abstract Syntax Tree nodes and methods.
pub mod ast;

/// Dealing with associativity and precedence.
pub mod operators;

/// Lexer splits code up into a token-stream
/// of relevant lexical tokens, making the
/// parsing step a lot easier.
pub mod lexer;

/// Converts a token-stream into a nested AST.
pub mod parser;

/// Tree static analysis.
pub mod analysis;

use std::fs;
use std::collections::HashSet;

use token::ShowStream;

pub fn parse_source(code : &str, filename : &str) -> ast::Root {
    // First lex:
    println!("Code:\n{}\n", code);

    let stream = lexer::lex(&code, filename);

    println!("Stream:\n{}\n", stream.to_string());

    let mut tree = parser::parse(stream, filename);

    let transformations = transformations![

    // No optimisations in debug.
    let transformations = transformations![

    analysis::replace(&mut tree, transformations);

    println!("AST:\n{}\n", tree);



/// Parses a given file, calling various methods from
/// the `syntax` sub-module.
pub fn parse_file(filename : &str) -> ast::Root {
    let code = fs::read_to_string(filename)
        .expect("Could not open file for reading.");
    parse_source(&code, filename)