refactor: restructure CLI into library crate and add semantic analysis phase
Restructure nxc-cli crate: - Extract main logic into lib.rs with main_entry() function - Move nexacore binary to separate bin/nexacore.rs file - Keep nxc binary in main.rs as thin wrapper Add semantic analysis to compilation pipeline: - Implement semantic analyzer with type checking and name resolution - Add Type enum with Int, Float, Bool, String, Void, Struct, Function, Error variants - Add typed AST nodes (TypedModule, TypedFunction
This commit is contained in:
@@ -3,7 +3,8 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use nxc_frontend::{
|
||||
has_errors, Diagnostic, Item, LexResult, Lexer, Module, ParseResult, Parser, Token,
|
||||
analyze, has_errors, Diagnostic, Item, LexResult, Lexer, Module, ParseResult, Parser, Token,
|
||||
TypedModule,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -12,6 +13,7 @@ pub struct FrontendOutput {
|
||||
pub source: String,
|
||||
pub tokens: Vec<Token>,
|
||||
pub module: Module,
|
||||
pub typed_module: Option<TypedModule>,
|
||||
pub diagnostics: Vec<Diagnostic>,
|
||||
}
|
||||
|
||||
@@ -86,13 +88,20 @@ pub fn check_source(path: PathBuf, source: String) -> FrontendOutput {
|
||||
} = Parser::new(tokens.clone()).parse_module();
|
||||
|
||||
lexer_diagnostics.extend(parser_diagnostics);
|
||||
let mut typed_module = None;
|
||||
|
||||
if !has_errors(&lexer_diagnostics) {
|
||||
let semantic = analyze(&module);
|
||||
lexer_diagnostics.extend(semantic.diagnostics);
|
||||
typed_module = Some(semantic.module);
|
||||
}
|
||||
|
||||
FrontendOutput {
|
||||
path,
|
||||
source,
|
||||
tokens,
|
||||
module,
|
||||
typed_module,
|
||||
diagnostics: lexer_diagnostics,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user