Initial library commit.

This commit is contained in:
Myrddin Dundragon 2016-07-15 15:40:16 -04:00
commit 14bd90d88e
9 changed files with 153 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@ -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

4
Cargo.lock generated Normal file
View File

@ -0,0 +1,4 @@
[root]
name = "draconic"
version = "0.1.0"

10
Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "draconic"
version = "0.1.0"
authors = ["Jason Travis Smith <Myrddin@CyberMagesLLC.com>"]
description = "A parser/compiler/interpreter for the Dragonic language."
license = ""
repository = "https://gitlab.com/CyberMages/draconic.git"
documentation = ""
keywords = ["draconic", "parser", "interpreter", "compiler"]

42
examples/parse_test.rs Normal file
View File

@ -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);
}

0
resources/test.pdt Normal file
View File

3
src/compiler.rs Normal file
View File

@ -0,0 +1,3 @@
pub enum Compiler
{
}

3
src/lexer.rs Normal file
View File

@ -0,0 +1,3 @@
pub enum Lexer
{
}

9
src/lib.rs Normal file
View File

@ -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;

65
src/parser.rs Normal file
View File

@ -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<P>(&self, pattern: P) -> bool
where P: AsRef<str>
{
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<F>(&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()
}
}