From 14bd90d88e2983e8b36bdc4702f17cbe46c83de7 Mon Sep 17 00:00:00 2001 From: Jason Travis Smith Date: Fri, 15 Jul 2016 15:40:16 -0400 Subject: [PATCH] Initial library commit. --- .gitignore | 17 +++++++++++ Cargo.lock | 4 +++ Cargo.toml | 10 +++++++ examples/parse_test.rs | 42 +++++++++++++++++++++++++++ resources/test.pdt | 0 src/compiler.rs | 3 ++ src/lexer.rs | 3 ++ src/lib.rs | 9 ++++++ src/parser.rs | 65 ++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 153 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 examples/parse_test.rs create mode 100644 resources/test.pdt create mode 100644 src/compiler.rs create mode 100644 src/lexer.rs create mode 100644 src/lib.rs create mode 100644 src/parser.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48f68fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,17 @@ +# Ignore swap files from text editors. +*.swp + +# Ignore compiled files. +*.o +*.so +*.rlib +*.dll +*.exe + +# Ignore files/directories generated by Cargo. +/target/ + +# Remove Cargo.lock from gitignore if creating an executable, +# leave it for libraries. +# More information here: http://doc.crates.io/guide.html#cargotoml-vs-cargolock +#Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..18ad8da --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "draconic" +version = "0.1.0" + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a8fda4f --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "draconic" +version = "0.1.0" +authors = ["Jason Travis Smith "] +description = "A parser/compiler/interpreter for the Dragonic language." +license = "" +repository = "https://gitlab.com/CyberMages/draconic.git" +documentation = "" +keywords = ["draconic", "parser", "interpreter", "compiler"] + diff --git a/examples/parse_test.rs b/examples/parse_test.rs new file mode 100644 index 0000000..6585eb1 --- /dev/null +++ b/examples/parse_test.rs @@ -0,0 +1,42 @@ +extern crate draconic; + + + +use std::path::PathBuf; + + + +/// +pub const RESOURCE_DIR: &'static str = "resources"; + +/// +pub const EXAMPLES_DIR: &'static str = "examples"; + +/// +pub const TEST_INPUT_FILENAME: &'static str = "test.tpl"; + +/// +pub const TEST_OUTPUT_FILENAME: &'static str = "test.rs"; + + + +/// +pub fn main() +{ + let mut input: PathBuf; + let mut output: PathBuf; + + // 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); +} diff --git a/resources/test.pdt b/resources/test.pdt new file mode 100644 index 0000000..e69de29 diff --git a/src/compiler.rs b/src/compiler.rs new file mode 100644 index 0000000..288232e --- /dev/null +++ b/src/compiler.rs @@ -0,0 +1,3 @@ +pub enum Compiler +{ +} diff --git a/src/lexer.rs b/src/lexer.rs new file mode 100644 index 0000000..c8c721e --- /dev/null +++ b/src/lexer.rs @@ -0,0 +1,3 @@ +pub enum Lexer +{ +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..879e088 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,9 @@ +mod compiler; +mod lexer; +mod parser; + + + +pub use self::compiler::Compiler; +pub use self::lexer::Lexer; +pub use self::parser::Parser; diff --git a/src/parser.rs b/src/parser.rs new file mode 100644 index 0000000..02d814f --- /dev/null +++ b/src/parser.rs @@ -0,0 +1,65 @@ +/// +pub struct Parser +{ + /// + position: usize, + + /// + input: String +} + + + +impl Parser +{ + /// + pub fn parse(&mut self) + { + } + + /// Get, but don't consume, the current character. + pub fn get_char(&self) -> char + { + 'a' + } + + /// Returns true if the next set of characters starts with + /// the given pattern; Otherwise, false. + pub fn starts_with

(&self, pattern: P) -> bool + where P: AsRef + { + self.position >= self.input.len() + } + + /// Returns true if all the input has been consumed; + /// Otherwise, false. + pub fn end_of_file(&self) -> bool + { + self.position >= self.input.len() + } + + /// Return the current character and advance to the next one. + pub fn consume_char(&mut self) -> char + { + 'a' + } + + /// Consume and discard zero or more whitespace characters. + pub fn consume_whitespace(&mut self) + { + self.consume_while(Parser::is_whitespace); + } + + /// Consume characters until the test returns false. + pub fn consume_while(&mut self, test: F) -> String + where F: Fn(char) -> bool + { + String::new() + } + + /// Determines if a character is whitespace. + fn is_whitespace(c: char) -> bool + { + c.is_whitespace() + } +}