chore: initialize NexaCore compiler workspace with basic frontend and CLI

Add initial project structure for NexaCore programming language compiler:
- Create Cargo workspace with 4 crates (cli, driver, frontend, runtime)
- Add lexer with indentation-based tokenization and keyword support
- Add parser for modules, functions, structs, and basic expressions
- Implement CLI with build command and placeholder subcommands
- Add driver crate to orchestrate compilation pipeline
- Include .gitignore for Rust build
This commit is contained in:
2026-04-06 16:57:54 +02:00
commit 0da224325a
17 changed files with 1704 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
[package]
name = "nxc-driver"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
[lib]
path = "src/lib.rs"
[dependencies]
nxc-frontend = { path = "../nxc-frontend" }

View File

@@ -0,0 +1,41 @@
use std::fs;
use std::path::Path;
use nxc_frontend::{Lexer, Module, ParseError, Parser, Token};
#[derive(Debug)]
pub struct CompileResult {
pub tokens: Vec<Token>,
pub module: Module,
}
#[derive(Debug)]
pub enum CompileError {
Io(std::io::Error),
Parse(ParseError),
}
impl From<std::io::Error> for CompileError {
fn from(value: std::io::Error) -> Self {
Self::Io(value)
}
}
impl From<ParseError> for CompileError {
fn from(value: ParseError) -> Self {
Self::Parse(value)
}
}
pub fn compile_file(path: impl AsRef<Path>) -> Result<CompileResult, CompileError> {
let source = fs::read_to_string(path)?;
compile_source(&source)
}
pub fn compile_source(source: &str) -> Result<CompileResult, CompileError> {
let tokens = Lexer::new(source).tokenize();
let mut parser = Parser::new(tokens.clone());
let module = parser.parse_module()?;
Ok(CompileResult { tokens, module })
}