Change crate name to 'deimos'; make compiler bin subproject.

This commit is contained in:
Jesse Brault 2024-11-29 19:13:59 -06:00
parent 66107b4310
commit 921a7fe834
5 changed files with 26 additions and 7 deletions

4
Cargo.lock generated
View File

@ -1,7 +1,7 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 4
[[package]] [[package]]
name = "deimos-lang" name = "deimos"
version = "0.1.0" version = "0.1.0"

View File

@ -1,6 +1,10 @@
[package] [package]
name = "deimos-lang" name = "deimos"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[[bin]]
name = "dmc"
path = "src/bin/compiler"
[dependencies] [dependencies]

13
src/bin/compiler/main.rs Normal file
View File

@ -0,0 +1,13 @@
use deimos::lexer::tokenize;
use std::process::exit;
fn main() {
let src = String::from("print 'Hello, World!'");
let r = tokenize(&src);
if let Err(e) = r {
eprintln!("{}", e);
exit(1);
}
let tokens = r.unwrap();
println!("{:?}", tokens);
}

View File

@ -31,7 +31,7 @@ pub enum Token {
Abstract, Abstract,
} }
pub fn tokenize(input: &String) -> Result<Vec<Token>, &'static str> { pub fn tokenize(input: &String) -> Result<Vec<Token>, String> {
let mut tokens: Vec<Token> = Vec::new(); let mut tokens: Vec<Token> = Vec::new();
let mut peekable = input.chars().peekable(); let mut peekable = input.chars().peekable();
while let Some(c) = peekable.next() { while let Some(c) = peekable.next() {
@ -72,12 +72,14 @@ pub fn tokenize(input: &String) -> Result<Vec<Token>, &'static str> {
match count { match count {
1 => tokens.push(Token::Dot), 1 => tokens.push(Token::Dot),
3 => tokens.push(Token::Ellipsis), 3 => tokens.push(Token::Ellipsis),
_ => return Err("Unexpected number of tokens after '.'"), _ => return Err(String::from("Unexpected number of tokens after '.'")),
} }
} }
_ => { _ => {
if let Some(token) = match_identifier_or_keyword(c, &mut peekable) { if let Some(token) = match_identifier_or_keyword(c, &mut peekable) {
tokens.push(token); tokens.push(token);
} else {
return Err(String::from(format!("Unexpected token: {}", c)));
} }
} }
} }

View File

@ -1,2 +1,2 @@
mod lexer; pub mod lexer;
mod vm; pub mod vm;