Fixed where module needs to be placed

This commit is contained in:
2026-06-10 05:54:19 +02:00
parent e7f1072050
commit cb3f1bcde1
3 changed files with 13 additions and 3 deletions
+2 -2
View File
@@ -112,7 +112,7 @@ pub fn transpile_file(path: &Path, output_path: &Path) -> Result<(), String> {
let source = fs::read_to_string(path) let source = fs::read_to_string(path)
.map_err(|e| format!("failed to read file {}: {}", path.display(), e))?; .map_err(|e| format!("failed to read file {}: {}", path.display(), e))?;
let parser_result = mist_parser::parse(&source).map_err(|e| match e { let parser_result = mist_parser::parse(&source, true).map_err(|e| match e {
ParseError::Ast(e) => { ParseError::Ast(e) => {
// Using components carefully to prevent out-of-bounds or zero layout crashes // Using components carefully to prevent out-of-bounds or zero layout crashes
let start_pos = e.span.start_pos().line_col(); let start_pos = e.span.start_pos().line_col();
@@ -149,7 +149,7 @@ pub fn transpile_file(path: &Path, output_path: &Path) -> Result<(), String> {
pub fn transpile_text<'a>(source: &'a str) -> Result<String, ParseError<'a, Vec<TopLevel>>> { pub fn transpile_text<'a>(source: &'a str) -> Result<String, ParseError<'a, Vec<TopLevel>>> {
let mut gc = mist_codegen::RustCodegen::new(); let mut gc = mist_codegen::RustCodegen::new();
Ok(gc.generate(mist_parser::parse(&source)?.1)) Ok(gc.generate(mist_parser::parse(&source, true)?.1))
} }
fn should_skip(source: &Path, output: &Path) -> bool { fn should_skip(source: &Path, output: &Path) -> bool {
+3 -1
View File
@@ -88,7 +88,9 @@ fn transpile_file(path *PathBuf, output_file *PathBuf, mod_decl *str) {
let mut gc = mist_codegen::RustCodegen::new(); let mut gc = mist_codegen::RustCodegen::new();
let [[vis, api], ast] = match (mist_parser::parse(&source)) { let is_master = path.file_name().unwrap().to_str().unwrap() == "main.mist";
let [[vis, api], ast] = match (mist_parser::parse(&source, is_master)) {
Ok[ast] => ast; Ok[ast] => ast;
Err[e] => { Err[e] => {
match (e) { match (e) {
+8
View File
@@ -16,6 +16,7 @@ pub struct MistParser;
pub fn parse<'a>( pub fn parse<'a>(
source: &'a str, source: &'a str,
is_master: bool,
) -> Result<((Visibility, Identifier), Vec<TopLevel>), ParseError<'a, Vec<TopLevel>>> { ) -> Result<((Visibility, Identifier), Vec<TopLevel>), ParseError<'a, Vec<TopLevel>>> {
let mut pairs = MistParser::parse(Rule::program, source)?; let mut pairs = MistParser::parse(Rule::program, source)?;
@@ -29,6 +30,13 @@ pub fn parse<'a>(
} }
} }
if is_master {
return match analyzer.build(statements) {
Ok(v) => Ok(((Visibility::Private, Identifier(String::new())), v)),
Err(e) => Err(ParseError::Ast(e)),
};
}
let m = if let Some(v) = statements.get(0) { let m = if let Some(v) = statements.get(0) {
if let TopLevelKind::DeclareModule(vis, name) = &v.0.item { if let TopLevelKind::DeclareModule(vis, name) = &v.0.item {
(vis.clone(), name.clone()) (vis.clone(), name.clone())