draconic/examples/compile.rs

57 lines
1.2 KiB
Rust
Raw Permalink Normal View History

2016-07-15 15:40:16 -04:00
extern crate draconic;
use std::path::PathBuf;
use draconic::Compiler;
2016-07-15 15:40:16 -04:00
///
pub const RESOURCE_DIR: &'static str = "resources";
///
pub const EXAMPLES_DIR: &'static str = "examples";
///
pub const TEST_INPUT_FILENAME: &'static str = "test.drs";
2016-07-15 15:40:16 -04:00
///
pub const TEST_OUTPUT_FILENAME: &'static str = "test.rs";
///
pub fn main()
{
let mut compiler: Compiler;
let mut include: PathBuf;
2016-07-15 15:40:16 -04:00
let mut input: PathBuf;
let mut output: PathBuf;
// Create a new compiler.
compiler = Compiler::new();
// Add the resource directory as an include directory
// for the compiler.
include = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
include.push(RESOURCE_DIR);
compiler.register_include_dir(&include);
2016-07-15 15:40:16 -04:00
// Get the input file to test with. It is in the
// resources directory.
input = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
input.push(RESOURCE_DIR);
input.push(TEST_INPUT_FILENAME);
// The output file created from compiling. It will be
// placed in the examples directory.
output = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
output.push(EXAMPLES_DIR);
output.push(TEST_OUTPUT_FILENAME);
println!("Compiling {:?} to {:?}", input, output);
compiler.compile(input, output);
2016-07-15 15:40:16 -04:00
}