Added a Pass Through compiler.
This just handles the include statement.
This commit is contained in:
parent
0ee91d15c9
commit
280c6605ff
6
Cargo.lock
generated
6
Cargo.lock
generated
@ -3,6 +3,7 @@ name = "draconic"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"scribe 0.1.0 (git+https://gitlab.com/CyberMages/scribe.git)",
|
"scribe 0.1.0 (git+https://gitlab.com/CyberMages/scribe.git)",
|
||||||
|
"spellbook 0.1.0 (git+https://gitlab.com/CyberMages/spellbook.git)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -10,3 +11,8 @@ name = "scribe"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://gitlab.com/CyberMages/scribe.git#c655eca358577795d818bdd07cb71864c0c9b9f2"
|
source = "git+https://gitlab.com/CyberMages/scribe.git#c655eca358577795d818bdd07cb71864c0c9b9f2"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spellbook"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+https://gitlab.com/CyberMages/spellbook.git#0059c4a676ef2243d982ec1ad471a03fc5c79e01"
|
||||||
|
|
||||||
|
@ -8,6 +8,13 @@ repository = "https://gitlab.com/CyberMages/draconic.git"
|
|||||||
documentation = ""
|
documentation = ""
|
||||||
keywords = ["draconic", "parser", "interpreter", "compiler"]
|
keywords = ["draconic", "parser", "interpreter", "compiler"]
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "draconicpt"
|
||||||
|
path = "src/pt_compiler.rs"
|
||||||
|
|
||||||
|
|
||||||
[dependencies.scribe]
|
[dependencies.scribe]
|
||||||
git = "https://gitlab.com/CyberMages/scribe.git"
|
git = "https://gitlab.com/CyberMages/scribe.git"
|
||||||
|
|
||||||
|
[dependencies.spellbook]
|
||||||
|
git = "https://gitlab.com/CyberMages/spellbook.git"
|
||||||
|
@ -136,7 +136,7 @@ impl Compiler
|
|||||||
|
|
||||||
// Create the output string of the compiled file.
|
// Create the output string of the compiled file.
|
||||||
// Start it with the compilation header.
|
// Start it with the compilation header.
|
||||||
output_string = String::from(FILE_HEADER);
|
output_string = String::new();//from(FILE_HEADER);
|
||||||
|
|
||||||
// Turn the input file into a compiled String.
|
// Turn the input file into a compiled String.
|
||||||
output_string.push_str(&read_file(&self.util, input.as_ref()));
|
output_string.push_str(&read_file(&self.util, input.as_ref()));
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate scribe;
|
extern crate scribe;
|
||||||
|
|
||||||
|
extern crate spellbook;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mod compiler;
|
mod compiler;
|
||||||
|
128
src/pt_compiler.rs
Normal file
128
src/pt_compiler.rs
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
#[macro_use]
|
||||||
|
extern crate scribe;
|
||||||
|
|
||||||
|
extern crate spellbook;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
mod compiler;
|
||||||
|
mod lexer;
|
||||||
|
mod parser;
|
||||||
|
mod reader;
|
||||||
|
mod util;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use spellbook::{EMPTY_STRING, ArgParser, ArgOption};
|
||||||
|
|
||||||
|
use ::compiler::Compiler;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const PROGRAM_NAME: &'static str = "Draconic Pass Through Compiler";
|
||||||
|
const PROGRAM_COMMAND_NAME: &'static str = "draconicpt";
|
||||||
|
const PROGRAM_VERSION: &'static str = "0.1.0";
|
||||||
|
const PROGRAM_SUMMARY: &'static str =
|
||||||
|
"Compiles a Draconic template to a file.";
|
||||||
|
const PROGRAM_DESCRIPTION: &'static str =
|
||||||
|
"The Draconic HTML Compiler compiles a Draconic template to a file.";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
fn configure_arguments(parser: &mut ArgParser)
|
||||||
|
{
|
||||||
|
let mut option: ArgOption;
|
||||||
|
|
||||||
|
option = ArgOption::new();
|
||||||
|
option.set_name("version");
|
||||||
|
option.set_short_name('v');
|
||||||
|
option.set_description("Print the programs version information.");
|
||||||
|
option.set_optional(true);
|
||||||
|
parser.add_option(option);
|
||||||
|
|
||||||
|
option = ArgOption::new();
|
||||||
|
option.set_name("input");
|
||||||
|
option.set_short_name('i');
|
||||||
|
option.set_description("The file to use as input.");
|
||||||
|
option.set_arg_description("FILENAME");
|
||||||
|
parser.add_option(option);
|
||||||
|
|
||||||
|
option = ArgOption::new();
|
||||||
|
option.set_name("output");
|
||||||
|
option.set_short_name('o');
|
||||||
|
option.set_description("The file to use as output.");
|
||||||
|
option.set_arg_description("FILENAME");
|
||||||
|
parser.add_option(option);
|
||||||
|
|
||||||
|
option = ArgOption::new();
|
||||||
|
option.set_name("include_dir");
|
||||||
|
option.set_short_name('I');
|
||||||
|
option.set_description("A directory to search when looking for \
|
||||||
|
included files.");
|
||||||
|
option.set_arg_description("DIRECTORY_PATH");
|
||||||
|
option.set_optional(true);
|
||||||
|
parser.add_option(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
fn print_version()
|
||||||
|
{
|
||||||
|
println!("Program name: {}", PROGRAM_NAME);
|
||||||
|
println!("Version: {}", PROGRAM_VERSION);
|
||||||
|
println!("{} {} {} {}", "\u{00A9}", "2016",
|
||||||
|
"CyberMages LLC", "All Rights Reserved");
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
pub fn main()
|
||||||
|
{
|
||||||
|
let version: bool;
|
||||||
|
let input: String;
|
||||||
|
let output: String;
|
||||||
|
let include_dir: String;
|
||||||
|
let mut parser: ArgParser;
|
||||||
|
let mut compiler: Compiler;
|
||||||
|
|
||||||
|
// Create a new argument parser.
|
||||||
|
parser = ArgParser::new();
|
||||||
|
parser.set_name(PROGRAM_COMMAND_NAME);
|
||||||
|
parser.set_summary(PROGRAM_SUMMARY);
|
||||||
|
parser.set_description(PROGRAM_DESCRIPTION);
|
||||||
|
|
||||||
|
// Configure the arguments that this program takes.
|
||||||
|
configure_arguments(&mut parser);
|
||||||
|
|
||||||
|
// Parse the arguments to this program.
|
||||||
|
parser.parse();
|
||||||
|
|
||||||
|
// Get the argument values.
|
||||||
|
version = parser.get_option_value_as("version", false);
|
||||||
|
input = parser.get_option_value_as("input", String::new());
|
||||||
|
output = parser.get_option_value_as("output", String::new());
|
||||||
|
include_dir = parser.get_option_value_as("include_dir", String::new());
|
||||||
|
|
||||||
|
// If the version is desired then print it instead of running the program.
|
||||||
|
if version == true
|
||||||
|
{
|
||||||
|
print_version();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Compile to an HTML file.
|
||||||
|
// Create a new compiler.
|
||||||
|
compiler = Compiler::new();
|
||||||
|
|
||||||
|
// Register the include directory if there is one.
|
||||||
|
if include_dir != EMPTY_STRING
|
||||||
|
{
|
||||||
|
compiler.register_include_dir(&PathBuf::from(include_dir));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile the file.
|
||||||
|
println!("Compiling {} into {}.", input, output);
|
||||||
|
compiler.compile(PathBuf::from(input), PathBuf::from(output));
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user