From 2c4154025ff2e2081a4f58175b050104388151b3 Mon Sep 17 00:00:00 2001 From: able Date: Sun, 11 Apr 2021 17:22:06 -0500 Subject: [PATCH] Tokens added or something --- able-script-test/functio.able | 2 -- src/main.rs | 3 +-- src/parser.rs | 26 ++++++++++--------- src/tokens.rs | 48 +++++++++++++++++++---------------- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/able-script-test/functio.able b/able-script-test/functio.able index f1ad098d..ce690b4d 100644 --- a/able-script-test/functio.able +++ b/able-script-test/functio.able @@ -1,6 +1,4 @@ functio hello(words){ words print; } - - hello("wonk"); diff --git a/src/main.rs b/src/main.rs index ee20b683..87b856c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use clap::{App, Arg}; mod base_55; mod parser; pub mod tokens; + fn main() { let matches = App::new("AbleScript") .version(env!("CARGO_PKG_VERSION")) @@ -18,11 +19,9 @@ fn main() { .takes_value(true), ) .get_matches(); - match matches.value_of("file") { Some(file_path) => { // Start parsing that file - parser::parse(file_path.to_string()); } None => { println!("hi"); diff --git a/src/parser.rs b/src/parser.rs index 8ece020e..f2efb064 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,15 +1,17 @@ -use crate::tokens; +use crate::tokens::{ABOOL, TOKENS}; -pub fn parse(line: String) { - //match the tokens - //This will not work - let iter = line.split_whitespace(); - for x in iter { - match x { - "#" => { - println!("hi"); - } - _ => {} - } +pub fn abool2num(abool: ABOOL) -> i32 { + match abool { + ABOOL::NEVER => -1, + ABOOL::SOMETIMES => 0, + ABOOL::ALWAYS => 1, + } +} +pub fn num2abool(number: i32) -> ABOOL { + match number { + -1 => ABOOL::NEVER, + 0 => ABOOL::SOMETIMES, + 1 => ABOOL::ALWAYS, + _ => ABOOL::SOMETIMES, } } diff --git a/src/tokens.rs b/src/tokens.rs index 00ba2cba..187afa36 100644 --- a/src/tokens.rs +++ b/src/tokens.rs @@ -1,23 +1,27 @@ -pub enum tokens { - LEFT_PARENTHESIS, // ( - RIGHT_PARENTHESIS, // ) - LEFT_BRACKET, // [ - RIGHT_BRACKET, // ] - LEFT_BRACE, // { - RIGHT_BRACE, // } - COMMENT, // # - SUBTRACT, // - - ADDITION, // + - MULTIPLY, // * - DIVIDE, // / - CHAR, // Base52 based character - FUNCTION, // functio - CONSTANT, // constant.e - BF_FUNCTION, // Brain fuck FFI - VARIABLE, // Variable bro - BOOLEAN, // True, False - ABOOLEAN, // Always, Sometimes, Never - PRINT, // Prints the preceding things - MELO, // Ban the following variable from ever being used again - T_DARK, // +pub enum TOKENS { + LEFT_PARENTHESIS, // ( + RIGHT_PARENTHESIS, // ) + LEFT_BRACKET, // [ + RIGHT_BRACKET, // ] + LEFT_BRACE, // { + RIGHT_BRACE, // } + COMMENT { value: String }, // # + SUBTRACT, // - + ADDITION, // + + MULTIPLY, // * + DIVIDE, // / + CHAR, // Base52 based character + FUNCTION, // functio + BF_FUNCTION { name: String, functio: String }, // Brain fuck FFI + VARIABLE, // Variable bro + BOOLEAN { state: bool }, // True, False + ABOOLEAN { state: u8 }, // Always, Sometimes, Never + PRINT, // Prints the preceding things + MELO, // Ban the following variable from ever being used again + T_DARK, +} +pub enum ABOOL { + NEVER = -1, + SOMETIMES = 0, + ALWAYS = 1, }