commit cc66d0b63a9edcc41225311f8c1c6076d5d639e3 Author: able Date: Thu Apr 8 16:11:20 2021 -0500 AbleLang is coming together boys :) and girls and enby pals diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..769f7f3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "able-lang" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e00d093 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "able-lang" +version = "0.1.0" +authors = ["able "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/able-lang-test/hello_world.able b/able-lang-test/hello_world.able new file mode 100644 index 0000000..e7b775d --- /dev/null +++ b/able-lang-test/hello_world.able @@ -0,0 +1,2 @@ +var hello = "world"; +print hello; diff --git a/src/file_load.rs b/src/file_load.rs new file mode 100644 index 0000000..9df50f3 --- /dev/null +++ b/src/file_load.rs @@ -0,0 +1,3 @@ +pub fn run_file(filepath: &String) { + println!("{}{}", filepath, PI); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d024d28 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,22 @@ +use std::env; +pub use std::f64::consts::{ + PI, // For the heretics among us + TAU, +}; + +mod file_load; +mod prompt; +mod tokens; + +fn main() { + let mut args: Vec = env::args().collect(); + args.remove(0); + if args.len() > 1 { + println!("Usage: alang [script]"); + } else if args.len() == 1 { + let filepath = &args[0]; + file_load::run_file(filepath); + } else { + prompt::prompt(); + } +} diff --git a/src/prompt.rs b/src/prompt.rs new file mode 100644 index 0000000..515ccd5 --- /dev/null +++ b/src/prompt.rs @@ -0,0 +1,20 @@ +use std::io::{stdin, stdout, Write}; + +pub fn prompt() { + loop { + print! {"> "}; + stdout().flush().unwrap(); + let mut input = String::new(); + stdin().read_line(&mut input).unwrap(); + + if input.trim() == "quit" { + break; + } else { + run(input); + } + } +} + +fn run(s: String) { + println!("{}", s); +} diff --git a/src/scanner.rs b/src/scanner.rs new file mode 100644 index 0000000..9d1d942 --- /dev/null +++ b/src/scanner.rs @@ -0,0 +1,15 @@ +mod tokens; +pub struct Scanner { + pub start: u64, + pub current: u64, + pub line: u64, +} + +pub fn scan() { + let tokens: Vec = vec![]; + + scan_token(); + + // +} +fn scan_token() {} diff --git a/src/tokens.rs b/src/tokens.rs new file mode 100644 index 0000000..414c182 --- /dev/null +++ b/src/tokens.rs @@ -0,0 +1,48 @@ +pub enum Token { + // Single-character tokens. + LEFT_PAREN, // + RIGHT_PAREN, + LEFT_BRACE, + RIGHT_BRACE, + COMMA, + DOT, + MINUS, + PLUS, + SEMICOLON, + SLASH, + STAR, + // One or two character tokens. + BANG, + BANG_EQUAL, + EQUAL, + EQUAL_EQUAL, + GREATER, + GREATER_EQUAL, + LESS, + LESS_EQUAL, + + // Literals. + IDENTIFIER, + STRING, + NUMBER, + + // Keywords. + AND, + CLASS, + ELSE, + FALSE, + FUN, + FOR, + IF, + NIL, + OR, + PRINT, + RETURN, + SUPER, + THIS, + TRUE, + VAR, + WHILE, + + EOF, +}