From 99ce5dc95d7922ba906cdbf5a4bed5c8bf0df11b Mon Sep 17 00:00:00 2001 From: Netanel Friedman Date: Sat, 1 Feb 2025 22:45:35 +0200 Subject: [PATCH] Delete code --- .gitignore | 3 - Cargo.lock | 287 -------------------------- tests/basic-syntax.xta | 17 -- xta-analyzer/Cargo.toml | 9 - xta-analyzer/src/analyzer.rs | 27 --- xta-analyzer/src/lib.rs | 2 - xta-analyzer/src/scope.rs | 27 --- xta-lexer/Cargo.lock | 7 - xta-lexer/Cargo.toml | 6 - xta-lexer/src/lib.rs | 2 - xta-lexer/src/scanner.rs | 257 ----------------------- xta-lexer/src/token.rs | 216 ------------------- xta-parser/Cargo.lock | 70 ------- xta-parser/Cargo.toml | 8 - xta-parser/src/ast.rs | 190 ----------------- xta-parser/src/lib.rs | 2 - xta-parser/src/parser.rs | 387 ----------------------------------- xtac/Cargo.lock | 278 ------------------------- xtac/Cargo.toml | 9 - xtac/src/main.rs | 46 ----- 20 files changed, 1850 deletions(-) delete mode 100644 .gitignore delete mode 100644 Cargo.lock delete mode 100644 tests/basic-syntax.xta delete mode 100644 xta-analyzer/Cargo.toml delete mode 100644 xta-analyzer/src/analyzer.rs delete mode 100644 xta-analyzer/src/lib.rs delete mode 100644 xta-analyzer/src/scope.rs delete mode 100644 xta-lexer/Cargo.lock delete mode 100644 xta-lexer/Cargo.toml delete mode 100644 xta-lexer/src/lib.rs delete mode 100644 xta-lexer/src/scanner.rs delete mode 100644 xta-lexer/src/token.rs delete mode 100644 xta-parser/Cargo.lock delete mode 100644 xta-parser/Cargo.toml delete mode 100644 xta-parser/src/ast.rs delete mode 100644 xta-parser/src/lib.rs delete mode 100644 xta-parser/src/parser.rs delete mode 100644 xtac/Cargo.lock delete mode 100644 xtac/Cargo.toml delete mode 100644 xtac/src/main.rs diff --git a/.gitignore b/.gitignore deleted file mode 100644 index a872904..0000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/target - -.codegpt \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index 5c9327b..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,287 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "anstream" -version = "0.6.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" - -[[package]] -name = "anstyle-parse" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" -dependencies = [ - "anstyle", - "once_cell", - "windows-sys", -] - -[[package]] -name = "clap" -version = "4.5.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" - -[[package]] -name = "colorchoice" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - -[[package]] -name = "once_cell" -version = "1.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" - -[[package]] -name = "proc-macro2" -version = "1.0.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "syn" -version = "2.0.96" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "2.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "unicode-ident" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" - -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "xta-analyzer" -version = "0.1.0" -dependencies = [ - "thiserror", - "xta-lexer", - "xta-parser", -] - -[[package]] -name = "xta-lexer" -version = "0.1.0" - -[[package]] -name = "xta-parser" -version = "0.1.0" -dependencies = [ - "thiserror", - "xta-lexer", -] - -[[package]] -name = "xtac" -version = "0.1.0" -dependencies = [ - "clap", - "xta-lexer", - "xta-parser", -] diff --git a/tests/basic-syntax.xta b/tests/basic-syntax.xta deleted file mode 100644 index 406aeac..0000000 --- a/tests/basic-syntax.xta +++ /dev/null @@ -1,17 +0,0 @@ -fn add(a Int, b Int) -> Int { - return a + b; -} - -fn foo(a Int, b Int) -> Int { - if a > b { - return add(-b, a); - } else { - return add(b / 5, a ^ 25); - } -} - -fn main() { - let a = 5; - let b = 10; - foo(a, b); -} \ No newline at end of file diff --git a/xta-analyzer/Cargo.toml b/xta-analyzer/Cargo.toml deleted file mode 100644 index b86fc01..0000000 --- a/xta-analyzer/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "xta-analyzer" -version = "0.1.0" -edition = "2021" - -[dependencies] -xta-lexer = { path = "../xta-lexer" } -xta-parser = { path = "../xta-parser" } -thiserror = "2.0.9" \ No newline at end of file diff --git a/xta-analyzer/src/analyzer.rs b/xta-analyzer/src/analyzer.rs deleted file mode 100644 index f72e065..0000000 --- a/xta-analyzer/src/analyzer.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::collections::HashMap; - -use xta_lexer::token::Loc; -use xta_parser::ast::{FunctionDeclStmt, Stmt}; - -pub struct Analyzer<'ctx> { - functions: HashMap<&'ctx str, FunctionDeclStmt<'ctx>>, - errors: Vec -} - -impl<'ctx> Analyzer<'ctx> { - pub fn new(stmts: Vec>) -> Self { - // TODO: make analyzer run on the given statements, - // create an AST node called file, and give it statements to map - } -} - -#[derive(Debug, Clone, thiserror::Error)] -pub enum Error { - #[error("~ ({loc}) : Unexpected non-function statement")] - UnexpectedNonFunction { loc: Loc }, - // #[error("~ ({loc}) : Expected `{expected}`, found `{found}`")] - // Expected { loc: Loc, expected: Token<'a>, found: Token<'a> }, - - // #[error("~ ({loc}) : Expected an identifier, found `{found}`")] - // ExpectedId {loc: Loc, found: Token<'a> } -} diff --git a/xta-analyzer/src/lib.rs b/xta-analyzer/src/lib.rs deleted file mode 100644 index 0f3991f..0000000 --- a/xta-analyzer/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod scope; -pub mod analyzer; \ No newline at end of file diff --git a/xta-analyzer/src/scope.rs b/xta-analyzer/src/scope.rs deleted file mode 100644 index c480a08..0000000 --- a/xta-analyzer/src/scope.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::collections::HashMap; - -use xta_parser::ast::IdentifierExpr; - -struct Var<'ctx> { - name: IdentifierExpr<'ctx>, -} - -struct Scope<'ctx> { - vars: HashMap<&'ctx str, Var<'ctx>>, -} - -impl<'ctx> Scope<'ctx> { - fn new() -> Self { - Self { - vars: HashMap::new(), - } - } - - fn insert_var(&mut self, name: IdentifierExpr<'ctx>) { - self.vars.insert(name.name, Var { name }); - } - - fn get_var(&self, name: &str) -> Option<&Var<'ctx>> { - self.vars.get(name) - } -} \ No newline at end of file diff --git a/xta-lexer/Cargo.lock b/xta-lexer/Cargo.lock deleted file mode 100644 index eaaf981..0000000 --- a/xta-lexer/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "xta-lexer" -version = "0.1.0" diff --git a/xta-lexer/Cargo.toml b/xta-lexer/Cargo.toml deleted file mode 100644 index 3652b81..0000000 --- a/xta-lexer/Cargo.toml +++ /dev/null @@ -1,6 +0,0 @@ -[package] -name = "xta-lexer" -version = "0.1.0" -edition = "2021" - -[dependencies] diff --git a/xta-lexer/src/lib.rs b/xta-lexer/src/lib.rs deleted file mode 100644 index 8c164c1..0000000 --- a/xta-lexer/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod token; -pub mod scanner; \ No newline at end of file diff --git a/xta-lexer/src/scanner.rs b/xta-lexer/src/scanner.rs deleted file mode 100644 index a6ec4eb..0000000 --- a/xta-lexer/src/scanner.rs +++ /dev/null @@ -1,257 +0,0 @@ -use crate::token::{lookup_keyword, Loc, Token, TokenKind}; - -pub struct Scanner<'a> { - input: &'a str, // input is now a string slice - position: usize, // the position that displays the current char - offset: usize, // a position of which the next char would be - line: usize, - col: usize, - curr: char, -} - -impl<'a> Scanner<'a> { - // returns a new instance, C'tor - pub fn new(input: &'a str) -> Self { - let mut scanner = Self { - input, - position: 0, - line: 0, - offset: 0, - curr: '\0', - col: 0, - }; - scanner.advance(); - scanner - } -} - - -// implementation for private functions -impl<'a> Scanner<'a> { - pub fn next_token(&mut self) -> Token<'a> { - let token: TokenKind; - let loc = self.get_loc(); - let content = ""; - self.ignore_whitespace(); - - match self.curr { - '\0' => { - token = TokenKind::EOF; - } - ',' => { - token = TokenKind::Comma; - } - '+' => { - token = if self.peek() == '+' { - self.advance(); - TokenKind::Inc - } else { - TokenKind::Plus - }; - } - '-' => { - token = if self.peek() == '>' { - self.advance(); - TokenKind::ReturnTypeArrow - } else if self.peek() == '-' { - self.advance(); - TokenKind::Dec - } else { - TokenKind::Min - } - } - '*' => { - token = TokenKind::Mul; - } - '/' => { - token = TokenKind::Div; - } - '(' => { - token = TokenKind::LeftParen; - } - ')' => { - token = TokenKind::RightParen; - } - ';' => { - token = TokenKind::Semicolon; - } - '{' => { - token = TokenKind::LeftBrace; - } - '}' => { - token = TokenKind::RightBrace; - } - '=' => { - if self.peek() == '=' { - self.advance(); - token = TokenKind::Equals; - } else { - token = TokenKind::Assign; - } - } - '!' => { - if self.peek() == '=' { - self.advance(); - token = TokenKind::NotEquals; - } else { - token = TokenKind::Not; - } - } - '~' => { - token = TokenKind::BNot; - } - '^' => { - token = TokenKind::Xor; - } - '|' => { - if self.peek() == '|' { - self.advance(); - token = TokenKind::Or; - } else { - token = TokenKind::BOr; - } - } - '&' => { - if self.peek() == '&' { - self.advance(); - token = TokenKind::And; - } else { - token = TokenKind::BAnd; - } - } - '>' => { - if self.peek() == '>' { - self.advance(); - token = TokenKind::RightSh; - } else if self.peek() == '=' { - self.advance(); - token = TokenKind::GreaterOrEqu; - } else { - token = TokenKind::Greater; - } - } - '<' => { - if self.peek() == '<' { - self.advance(); - token = TokenKind::LeftSh; - } else if self.peek() == '=' { - self.advance(); - token = TokenKind::LowerOrEqu; - } else { - token = TokenKind::Lower; - } - } - '"' => { - return self.get_string(); - } - _ => { - if self.curr.is_alphabetic() { - let id = self.get_identifier(); - - if id == "true" || id == "false" { - return Token::new(TokenKind::Boolean, loc, id); - } else { - return Token::new(lookup_keyword(id), loc, id); - } - } else if self.curr.is_numeric() { - return self.get_number(); - } else { - return Token::new(TokenKind::Illegal, loc, &self.input[self.position..][..1]); - } - } - } - - self.advance(); - Token::new(token, loc, content) - } - - fn get_loc(&mut self) -> Loc { - Loc { - col: self.col as u32, - row: self.line as u32, - } - } - - // eats up white-space - fn ignore_whitespace(&mut self) { - while self.curr.is_whitespace() { - if self.curr == '\n' { - self.line += 1; - self.col = 0; - } - self.advance(); - } - } - - // moves to the next char - fn advance(&mut self) { - self.curr = self.peek(); - - self.position = self.offset; - self.offset += 1; - self.col += 1; - } - - // peek next char - fn peek(&self) -> char { - if self.offset >= self.input.len() { - '\0' - } else { - self.input[self.offset..].chars().next().unwrap_or('\0') - } - } - - fn get_string(&mut self) -> Token<'a> { - let begin_pos = self.position; - let loc = self.get_loc(); - - self.advance(); // remove '"' - - while self.peek() != '"' { - self.advance(); - - if self.peek() == '\0' { - return Token::new(TokenKind::Illegal, loc, &self.input[begin_pos..self.position]); - } - } - - self.advance(); - - Token::new(TokenKind::String, loc, &self.input[begin_pos..self.position]) - } - - fn get_identifier(&mut self) -> &'a str { - let begin_pos = self.position; - while self.peek().is_alphanumeric() || self.peek() == '_' { - self.advance(); - } - - self.advance(); - - &self.input[begin_pos..self.position] - } - - fn get_number(&mut self) -> Token<'a> { - let begin_pos = self.position; - let loc = self.get_loc(); - let mut count = 0; - let mut is_floating = false; - - while self.curr.is_ascii_digit() || self.curr == '.' { - if self.curr == '.' { - if is_floating { - return Token::new(TokenKind::Illegal, loc, &self.input[begin_pos..][..count]); - } - is_floating = true; - } - count += 1; - self.advance(); - } - - if is_floating { - Token::new(TokenKind::Double, loc, &self.input[begin_pos..][..count]) - } else { - Token::new(TokenKind::Integer, loc, &self.input[begin_pos..][..count]) - } - } -} diff --git a/xta-lexer/src/token.rs b/xta-lexer/src/token.rs deleted file mode 100644 index a791c2e..0000000 --- a/xta-lexer/src/token.rs +++ /dev/null @@ -1,216 +0,0 @@ -#[derive(Debug, PartialEq, Clone)] -pub struct Loc { - pub row: u32, - pub col: u32 -} - -impl std::fmt::Display for Loc { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}:{}", self.row, self.col) - } -} - -#[derive(Debug, PartialEq, Clone)] -pub struct Token<'a> { - pub kind: TokenKind, - pub loc: Loc, - pub text: &'a str -} - -impl<'a> Token<'a> { - pub fn new(kind: TokenKind, loc: Loc, text: &'a str) -> Self { - Self { - kind, - loc, - text, - } - } - - pub fn from_kind(kind: TokenKind) -> Self { - Self { - kind, - loc: Loc { row: 0, col: 0 }, - text: "", - } - } - - pub fn is_unary(&self) -> bool { - matches!(self.kind, TokenKind::Not | TokenKind::BNot | TokenKind::Inc | TokenKind::Dec) - } - - pub fn is_binary(&self) -> bool { - matches!(self.kind, TokenKind::Plus | TokenKind::Min | TokenKind::Mul | TokenKind::Div | TokenKind::Assign | TokenKind::And | TokenKind::Or | TokenKind::Equals | TokenKind::NotEquals | TokenKind::Greater | TokenKind::GreaterOrEqu | TokenKind::Lower | TokenKind::LowerOrEqu | TokenKind::BAnd | TokenKind::BOr | TokenKind::Xor | TokenKind::RightSh | TokenKind::LeftSh) - } -} - -#[derive(Debug, PartialEq, Clone)] -pub enum TokenKind { - // seperators - Semicolon, - Comma, - LeftParen, - RightParen, - LeftBrace, - RightBrace, - - Identifier, - - // basic data types - Integer, - Double, - String, - Boolean, - None, - - // points to the return type of a function (.e.g. fn foo() -> int) - ReturnTypeArrow, - - // operators - Plus, - Mul, - Div, - Min, - Inc, - Dec, - Assign, - - And, - Not, - Or, - Equals, - NotEquals, - Greater, - GreaterOrEqu, - Lower, - LowerOrEqu, - - BNot, - BAnd, - BOr, - Xor, - RightSh, - LeftSh, - - // keywords - Const, - Let, - If, - Elif, - Else, - For, - While, - - // do-while stuff - Loop, - Unless, - - // general loop stuff - Break, - Continue, - - // func def - Fn, - Return, - - Illegal, - EOF, -} - -impl std::fmt::Display for Token<'_> { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match self.kind { - // Arithmetic operators - TokenKind::Min => write!(f, "-"), - TokenKind::Plus => write!(f, "+"), - TokenKind::Mul => write!(f, "*"), - TokenKind::Div => write!(f, "/"), - TokenKind::Dec => write!(f, "--"), - TokenKind::Inc => write!(f, "++"), - - // Logical operators - TokenKind::Greater => write!(f, ">"), - TokenKind::GreaterOrEqu => write!(f, ">="), - TokenKind::And => write!(f, "&&"), - TokenKind::Equals => write!(f, "=="), - TokenKind::Lower => write!(f, "<"), - TokenKind::LowerOrEqu => write!(f, "<="), - TokenKind::Not => write!(f, "!"), - TokenKind::NotEquals => write!(f, "!="), - TokenKind::Or => write!(f, "||"), - - TokenKind::Identifier => write!(f, "{}", self.text), - - // punctuation - TokenKind::Assign => write!(f, "="), - TokenKind::LeftBrace => write!(f, "{{"), - TokenKind::RightBrace => write!(f, "}}"), - TokenKind::LeftParen => write!(f, "("), - TokenKind::RightParen => write!(f, ")"), - TokenKind::Semicolon => write!(f, ";"), - TokenKind::ReturnTypeArrow => write!(f, "->"), - TokenKind::Comma => write!(f, ","), - - // bitwise operators - TokenKind::BAnd => write!(f, "&"), - TokenKind::BNot => write!(f, "~"), - TokenKind::BOr => write!(f, "|"), - TokenKind::LeftSh => write!(f, "<<"), - TokenKind::RightSh => write!(f, ">>"), - TokenKind::Xor => write!(f, "^"), - - // data values - TokenKind::Double => write!(f, "{}", self.text), - TokenKind::Integer => write!(f, "{}", self.text), - TokenKind::String => write!(f, "{}", self.text), - TokenKind::Boolean => write!(f, "{}", self.text), - - // keywords - TokenKind::Break => write!(f, "break"), - TokenKind::Continue => write!(f, "continue"), - TokenKind::Const => write!(f, "const"), - TokenKind::Else => write!(f, "else"), - TokenKind::Elif => write!(f, "elif"), - TokenKind::EOF => write!(f, "EOF"), - TokenKind::For => write!(f, "for"), - TokenKind::Fn => write!(f, "fn"), - TokenKind::Return => write!(f, "return"), - TokenKind::If => write!(f, "if"), - TokenKind::Let => write!(f, "let"), - TokenKind::None => write!(f, "None"), - TokenKind::Unless => write!(f, "unless"), - TokenKind::While => write!(f, "while"), - TokenKind::Loop => write!(f, "loop"), - - TokenKind::Illegal => write!(f, "{}", self.text), - - } - } -} - -pub fn lookup_keyword(identifier: &str) -> TokenKind { - match identifier { - "const" => TokenKind::Const, - "let" => TokenKind::Let, - - "if" => TokenKind::If, - "elif" => TokenKind::Elif, - "else" => TokenKind::Else, - - "fn" => TokenKind::Fn, - "return" => TokenKind::Return, - - "for" => TokenKind::For, - - "loop" => TokenKind::Loop, - "unless" => TokenKind::Unless, - - "while" => TokenKind::While, - - "break" => TokenKind::Break, - "continue" => TokenKind::Continue, - - "None" => TokenKind::None, - - _ => TokenKind::Identifier, - } -} diff --git a/xta-parser/Cargo.lock b/xta-parser/Cargo.lock deleted file mode 100644 index 98cc86b..0000000 --- a/xta-parser/Cargo.lock +++ /dev/null @@ -1,70 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "proc-macro2" -version = "1.0.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "syn" -version = "2.0.96" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "2.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "unicode-ident" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" - -[[package]] -name = "xta-lexer" -version = "0.1.0" - -[[package]] -name = "xta-parser" -version = "0.1.0" -dependencies = [ - "thiserror", - "xta-lexer", -] diff --git a/xta-parser/Cargo.toml b/xta-parser/Cargo.toml deleted file mode 100644 index 56e84f2..0000000 --- a/xta-parser/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "xta-parser" -version = "0.1.0" -edition = "2021" - -[dependencies] -xta-lexer = { path = "../xta-lexer" } -thiserror = "2.0.9" \ No newline at end of file diff --git a/xta-parser/src/ast.rs b/xta-parser/src/ast.rs deleted file mode 100644 index 5176dd6..0000000 --- a/xta-parser/src/ast.rs +++ /dev/null @@ -1,190 +0,0 @@ -use xta_lexer::token::Loc; - -pub type Block<'a> = Vec>; - -#[derive(Debug, PartialEq, Clone)] -pub enum UnaryOpType { - Neg, - Not, - Inc, - Dec, - BitNot, -} - - -#[derive(Debug, PartialEq, Clone)] -pub enum BinaryOpType { - Add, - Sub, - Mul, - Div, - - And, - Or, - - Eq, - Neq, - Smaller, - Greater, - SmallerEq, - GreaterEq, - - BitAnd, - BitOr, - BitXor, - LShift, - RShift, - - Assign, -} - -#[derive(Debug, PartialEq, Clone)] -pub enum Stmt<'a> { - VarDecl(VarDeclStmt<'a>), - FunctionDecl(FunctionDeclStmt<'a>), - If(IfStmt<'a>), - Return(ReturnStmt<'a>), - Expr(Expr<'a>), -} - -#[derive(Debug, PartialEq, Clone)] -pub enum Expr<'a> { - Binary(BinaryExpr<'a>), - Unary(UnaryExpr<'a>), - Literal(LiteralExpr<'a>), - Identifier(IdentifierExpr<'a>), - Call(CallExpr<'a>), -} - - -// custom expressions - -#[derive(Debug, PartialEq, Clone)] -pub struct CallExpr<'a> { - pub name: &'a str, - pub args: Vec>, - pub loc: Loc, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct IdentifierExpr<'a> { - pub name: &'a str, - pub loc: Loc -} - -#[derive(Debug, PartialEq, Clone)] -pub struct LiteralExpr<'a> { - pub value: Literal<'a>, - pub loc: Loc, -} - -#[derive(Debug, PartialEq, Clone)] -pub enum Literal<'a> { - Integer(i64), - Double(f64), - String(&'a str), - Boolean(bool), - None, -} - - - -#[derive(Debug, PartialEq, Clone)] -pub struct BinaryExpr<'a> { - pub left: Box>, - pub right: Box>, - pub operator: BinaryOpType, - pub loc: Loc, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct UnaryExpr<'a> { - pub operand: Box>, - pub operator: UnaryOpType, - pub loc: Loc, -} - -// custom statements -#[derive(Debug, PartialEq, Clone)] -pub struct VarDeclStmt<'a> { - pub name: &'a str, - pub value: Option>, - pub is_const: bool, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct ReturnStmt<'a> { - pub value: Option>, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct IfStmt<'a> { - pub condition: Expr<'a>, - pub then: Block<'a>, - pub elif_branch: Vec>, - pub else_branch: Option>, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct ElifStmt<'a> { - pub condition: Expr<'a>, - pub then: Block<'a>, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct FunctionDeclStmt<'a> { - pub name: &'a str, - pub params: Vec>, - pub return_type: Option<&'a str>, - pub body: Block<'a>, -} - -#[derive(Debug, PartialEq, Clone)] -pub struct Param<'a> { - pub name: &'a str, - pub param_type: &'a str, -} - -// Implementations: - -impl BinaryOpType { - pub fn prec(&self) -> u8 { - match self { - BinaryOpType::Assign => 0, - BinaryOpType::Or => 1, - BinaryOpType::And => 2, - BinaryOpType::Smaller | BinaryOpType::Greater | BinaryOpType::SmallerEq | BinaryOpType::GreaterEq => 3, - BinaryOpType::Eq | BinaryOpType::Neq => 4, - BinaryOpType::BitOr => 5, - BinaryOpType::BitXor => 6, - BinaryOpType::BitAnd => 7, - BinaryOpType::LShift | BinaryOpType::RShift => 8, - BinaryOpType::Add | BinaryOpType::Sub => 9, - BinaryOpType::Mul | BinaryOpType::Div => 10, - } - } - - pub fn is_logical(&self) -> bool { - matches!(self, BinaryOpType::Or | BinaryOpType::And) - } - - pub fn is_bitwise(&self) -> bool { - matches!(self, BinaryOpType::BitOr | BinaryOpType::BitXor | BinaryOpType::BitAnd | BinaryOpType::LShift | BinaryOpType::RShift) - } - - pub fn is_comparison(&self) -> bool { - matches!(self, BinaryOpType::Smaller | BinaryOpType::Greater | BinaryOpType::SmallerEq | BinaryOpType::GreaterEq | BinaryOpType::Eq | BinaryOpType::Neq) - } -} - -impl Expr<'_> { - pub fn loc(&self) -> Loc { - match self { - Expr::Binary(expr) => expr.loc.clone(), - Expr::Unary(expr) => expr.loc.clone(), - Expr::Literal(expr) => expr.loc.clone(), - Expr::Identifier(expr) => expr.loc.clone(), - Expr::Call(expr) => expr.loc.clone(), - } - } -} diff --git a/xta-parser/src/lib.rs b/xta-parser/src/lib.rs deleted file mode 100644 index 4c3cef0..0000000 --- a/xta-parser/src/lib.rs +++ /dev/null @@ -1,2 +0,0 @@ -pub mod ast; -pub mod parser; \ No newline at end of file diff --git a/xta-parser/src/parser.rs b/xta-parser/src/parser.rs deleted file mode 100644 index 4f5a58f..0000000 --- a/xta-parser/src/parser.rs +++ /dev/null @@ -1,387 +0,0 @@ -use xta_lexer::{scanner::Scanner, token::{Loc, Token, TokenKind}}; - -use crate::ast::{CallExpr, ReturnStmt}; - -use super::ast::{BinaryExpr, BinaryOpType, Block, ElifStmt, Expr, FunctionDeclStmt, IdentifierExpr, IfStmt, Literal, LiteralExpr, Param, Stmt, UnaryExpr, UnaryOpType, VarDeclStmt}; - -pub struct Parser<'a> { - scanner: Scanner<'a>, - token: Token<'a>, - pub errors: Vec>, -} - -impl<'a> Parser<'a> { - pub fn new(mut scanner: Scanner<'a>) -> Self { - let token = scanner.next_token(); - - Self { - scanner, - token, - errors: Vec::new(), - } - } - - pub fn parse_file(&mut self) -> Vec> { - let mut stmts = Vec::new(); - - while self.peek().kind != TokenKind::EOF { - if let Some(stmt) = self.parse_statement() { - stmts.push(stmt); - } else { - self.consume(); - } - } - - stmts - } - - pub fn parse_statement(&mut self) -> Option> { - let result = match self.peek().kind { - TokenKind::Let => self.parse_variable_declaration(), - TokenKind::Fn => self.parse_function(), - TokenKind::If => self.parse_if(), - TokenKind::Return => self.parse_return(), - _ => Some(Stmt::Expr(self.parse_expression(None)?)), - }; - - // NOTE: add here every other statement that doesnt have a semicolon at the end. - if matches!(result, Some(Stmt::FunctionDecl(_)) | Some(Stmt::If(_))) { - return result; - } - - self.expect(TokenKind::Semicolon)?; - result - } - - // Following the next syntax: - // return ; - pub fn parse_return(&mut self) -> Option> { - self.expect(TokenKind::Return)?; - // expect any kind of void returns - if self.peek().kind == TokenKind::Semicolon { - return Some(Stmt::Return(ReturnStmt { value: None })); - } - - // expect a value to be returned - let value = self.parse_expression(None)?; - Some(Stmt::Return(ReturnStmt { value: Some(value) })) - } - - // Following the next syntax: - // let = ; - pub fn parse_variable_declaration(&mut self) -> Option> { - self.expect(TokenKind::Let)?; - let name = self.expect(TokenKind::Identifier)?; - - self.expect(TokenKind::Assign)?; - - let value = self.parse_expression(None)?; - - Some(Stmt::VarDecl(VarDeclStmt {value: Some(value), name: name.text, is_const: false})) - } - - // Following the next syntax: - // if(a > b) { } (optional) elif (...) { } (optional) else { ... } - pub fn parse_if(&mut self) -> Option> { - self.expect(TokenKind::If)?; - - let condition = self.parse_expression(None)?; - - let mut elif_branch = Vec::new(); - - let mut else_branch : Option> = None; - - let then = self.parse_scope()?; - - while self.peek().kind == TokenKind::Elif { - elif_branch.push(self.parse_elif()?); - } - - // TODO: fix when no else is added. - if self.peek().kind == TokenKind::Else { - self.consume(); - else_branch = Some(self.parse_scope()?); - } - - Some(Stmt::If(IfStmt { condition, then, elif_branch, else_branch})) - } - - pub fn parse_elif(&mut self) -> Option> { - self.expect(TokenKind::Elif)?; - - let condition = self.parse_expression(None)?; - - let then = self.parse_scope()?; - - Some(ElifStmt { condition, then }) - } - - // Following the next syntax: - // fn foo(a int, b int) -> int { } - pub fn parse_function(&mut self) -> Option> { - self.expect(TokenKind::Fn)?; - let name = self.expect(TokenKind::Identifier)?; - - let params = self.parse_function_params().unwrap_or_default(); - - let return_type = if self.peek().kind == TokenKind::ReturnTypeArrow { - self.consume(); - Some(self.expect(TokenKind::Identifier)?.text) - } else { - None - }; - - let body = self.parse_scope()?; - - Some(Stmt::FunctionDecl(FunctionDeclStmt {name: name.text, params, body, return_type})) - } - - pub fn parse_expression(&mut self, prec: Option) -> Option> { - let prec = prec.unwrap_or(-1); - - let mut lhs = self.parse_unary()?; - - if self.peek().kind == TokenKind::Assign && prec < BinaryOpType::Assign.prec() as i8 { - return self.parse_reassign(lhs); - } - - while let Some(op) = self.parse_binary_op() { - let op_prec = op.prec() as i8; - if op_prec <= prec { - break; - } - - self.consume(); - let rhs = self.parse_expression(Some(op_prec))?; - lhs = Expr::Binary(BinaryExpr { - left: Box::new(lhs), - right: Box::new(rhs), - operator: op, - loc: self.peek().loc.clone(), - }) - } - - Some(lhs) - } - - pub fn parse_unary(&mut self) -> Option> { - match self.peek().kind { - TokenKind::Min => { - let loc = self.peek().loc.clone(); - self.consume(); - let op = self.parse_expression(Some(UnaryOpType::Neg as i8)); - Some(Expr::Unary(UnaryExpr { - operand: Box::new(op.unwrap()), - operator: UnaryOpType::Neg, - loc - })) - } - TokenKind::Not => { - let loc = self.peek().loc.clone(); - self.consume(); - let op = self.parse_expression(Some(UnaryOpType::Not as i8)); - Some(Expr::Unary(UnaryExpr { - operand: Box::new(op.unwrap()), - operator: UnaryOpType::Not, - loc - })) - } - _ => self.parse_primary() - } - } -} - -// Private functions -impl <'a> Parser <'a> { - fn consume(&mut self) -> Token<'a> { - std::mem::replace(&mut self.token, self.scanner.next_token()) - } - - fn peek(&self) -> &Token<'a> { - &self.token - } - - fn expect(&mut self, kind: TokenKind) -> Option> { - if self.token.kind == kind { - Some(self.consume()) - } else { - self.errors.push(Error::Expected { - loc: self.token.loc.clone(), - expected: Token::from_kind(kind), - found: self.token.clone(), - }); - - None - } - } - - fn parse_function_params(&mut self) -> Option>> { - - self.expect(TokenKind::LeftParen)?; - - // handle params - let mut params = Vec::new(); - let has_params = self.peek().kind != TokenKind::RightParen; - - if has_params { - loop { - let param_name = self.expect(TokenKind::Identifier)?; - let param_type = self.expect(TokenKind::Identifier)?; - - params.push(Param { name: param_name.text, param_type: param_type.text}); - - if self.peek().kind == TokenKind::RightParen { - break; - } - - if self.peek().kind == TokenKind::Comma { - self.consume(); - continue; - } else { - self.errors.push(Error::Expected { - loc: self.peek().loc.clone(), - expected: Token::from_kind(TokenKind::Comma), - found: self.peek().clone(), - }); - } - - }; - } - - self.expect(TokenKind::RightParen)?; - Some(params) - } - - fn parse_scope(&mut self) -> Option>> { - self.expect(TokenKind::LeftBrace)?; - - let mut stmts = Vec::new(); - while self.peek().kind != TokenKind::RightBrace { - if let Some(stmt) = self.parse_statement() { - stmts.push(stmt); - } else { - self.consume(); - } - } - - self.expect(TokenKind::RightBrace)?; - - Some(stmts) - } - - fn parse_primary(&mut self) -> Option> { - match self.peek().kind { - TokenKind::Integer => self.parse_integer(), - TokenKind::Identifier => self.parse_identifier(), - TokenKind::String => self.parse_string(), - TokenKind::LeftParen => { - self.consume(); - let expr = self.parse_expression(None); - self.expect(TokenKind::RightParen)?; - expr - } - _ => None, - } - } - - fn parse_binary_op(&mut self) -> Option { - match self.peek().kind { - TokenKind::Plus => Some(BinaryOpType::Add), - TokenKind::Min => Some(BinaryOpType::Sub), - TokenKind::Mul => Some(BinaryOpType::Mul), - TokenKind::Div => Some(BinaryOpType::Div), - TokenKind::Assign => Some(BinaryOpType::Assign), - TokenKind::And => Some(BinaryOpType::And), - TokenKind::Or => Some(BinaryOpType::Or), - TokenKind::Equals => Some(BinaryOpType::Eq), - TokenKind::NotEquals => Some(BinaryOpType::Neq), - TokenKind::Greater => Some(BinaryOpType::Greater), - TokenKind::GreaterOrEqu => Some(BinaryOpType::GreaterEq), - TokenKind::Lower => Some(BinaryOpType::Smaller), - TokenKind::LowerOrEqu => Some(BinaryOpType::SmallerEq), - TokenKind::BAnd => Some(BinaryOpType::BitAnd), - TokenKind::BOr => Some(BinaryOpType::BitOr), - TokenKind::Xor => Some(BinaryOpType::BitXor), - TokenKind::RightSh => Some(BinaryOpType::RShift), - TokenKind::LeftSh => Some(BinaryOpType::LShift), - _ => None, - } - } - - fn parse_reassign(&mut self, lhs: Expr<'a>) -> Option> { - self.expect(TokenKind::Assign)?; - if ! matches!(lhs, Expr::Identifier(_)) { - self.errors.push(Error::ExpectedId { loc: lhs.loc(), found: self.peek().clone() }); - None - } else { - let rhs = self.parse_expression(Some(BinaryOpType::Assign.prec() as i8))?; - let result = Some(Expr::Binary(BinaryExpr { - left: Box::new(lhs), - right: Box::new(rhs), - operator: BinaryOpType::Assign, - loc: self.peek().loc.clone(), - })); - - result - } - } - - // primary expression parsing - fn parse_integer(&mut self) -> Option> { - let token = self.expect(TokenKind::Integer)?; - Some(Expr::Literal(LiteralExpr { value: Literal::Integer(token.text.parse().unwrap()), loc: token.loc.clone() })) - } - - fn parse_string(&mut self) -> Option> { - let token = self.expect(TokenKind::String)?; - Some(Expr::Literal(LiteralExpr { value: Literal::String(token.text), loc: token.loc.clone() })) - } - - fn parse_identifier(&mut self) -> Option> { - let token = self.expect(TokenKind::Identifier)?; - - if self.peek().kind == TokenKind::LeftParen { - self.parse_fn_call(token) - } else { - Some(Expr::Identifier(IdentifierExpr { name: token.text, loc: token.loc.clone() })) - } - - } - - // Parses any function call - fn parse_fn_call(&mut self, identifier: Token<'a>) -> Option> { - self.expect(TokenKind::LeftParen)?; - let mut args = Vec::new(); - while self.peek().kind != TokenKind::RightParen { - let arg = self.parse_expression(None)?; - args.push(arg); - - if self.peek().kind == TokenKind::RightParen { - break; - } - - if self.peek().kind == TokenKind::Comma { - self.consume(); - continue; - } else { - self.errors.push(Error::Expected { - loc: self.peek().loc.clone(), - expected: Token::from_kind(TokenKind::Comma), - found: self.peek().clone(), - }); - } - } - - self.expect(TokenKind::RightParen)?; - Some(Expr::Call(CallExpr { name: identifier.text, args, loc: identifier.loc.clone() })) - } -} - -#[derive(Debug, Clone, thiserror::Error)] -pub enum Error<'a> { - #[error("~ ({loc}) : Expected `{expected}`, found `{found}`")] - Expected { loc: Loc, expected: Token<'a>, found: Token<'a> }, - - #[error("~ ({loc}) : Expected an identifier, found `{found}`")] - ExpectedId {loc: Loc, found: Token<'a> } -} diff --git a/xtac/Cargo.lock b/xtac/Cargo.lock deleted file mode 100644 index a03ff3c..0000000 --- a/xtac/Cargo.lock +++ /dev/null @@ -1,278 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "anstream" -version = "0.6.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" - -[[package]] -name = "anstyle-parse" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" -dependencies = [ - "anstyle", - "once_cell", - "windows-sys", -] - -[[package]] -name = "clap" -version = "4.5.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" - -[[package]] -name = "colorchoice" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - -[[package]] -name = "once_cell" -version = "1.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" - -[[package]] -name = "proc-macro2" -version = "1.0.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "syn" -version = "2.0.96" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "thiserror" -version = "2.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "unicode-ident" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" - -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "xta-lexer" -version = "0.1.0" - -[[package]] -name = "xta-parser" -version = "0.1.0" -dependencies = [ - "thiserror", - "xta-lexer", -] - -[[package]] -name = "xtac" -version = "0.1.0" -dependencies = [ - "clap", - "xta-lexer", - "xta-parser", -] diff --git a/xtac/Cargo.toml b/xtac/Cargo.toml deleted file mode 100644 index 04ae81d..0000000 --- a/xtac/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "xtac" -version = "0.1.0" -edition = "2021" - -[dependencies] -clap = { version = "4.3", features = ["derive"] } -xta-lexer = { path = "../xta-lexer" } -xta-parser = { path = "../xta-parser" } \ No newline at end of file diff --git a/xtac/src/main.rs b/xtac/src/main.rs deleted file mode 100644 index e4682db..0000000 --- a/xtac/src/main.rs +++ /dev/null @@ -1,46 +0,0 @@ -use clap::Parser as p; -use std::{fs, path::PathBuf, process::exit, time::Instant}; -use xta_lexer::scanner::Scanner; -use xta_parser::parser::Parser; - - -#[derive(p)] -#[command(name = "Xta", version, about, long_about = None)] -pub enum Cli { - Run { path: PathBuf }, -} - -fn main() { - let cli = Cli::parse(); - - match cli { - Cli::Run { path } => { - if !path.is_file() { - eprintln!("~ Error: Cannot read the specified source file."); - exit(1); - } - match fs::read_to_string(path) { - Ok(content) => { - let scanner = Scanner::new(&content); - let mut parser = Parser::new(scanner); - - let start = Instant::now(); - let stmts = parser.parse_file(); - let elapsed = start.elapsed(); - - println!("parsing: {:?}", elapsed); - for stmt in stmts { - println!("{:?}", stmt); - } - - for error in parser.errors { - eprintln!("{}", error); - } - } - Err(e) => { - println!("Failed to open file: {}", e); - } - } - } - } -}