diff --git a/src/protocol/parser/mod.rs b/src/protocol/parser/mod.rs index f79a81c83522d13a3b39043637b73fc234a79a45..3d4bcba9ff7d17d06a067db4fd631bfc28b8e594 100644 --- a/src/protocol/parser/mod.rs +++ b/src/protocol/parser/mod.rs @@ -54,7 +54,8 @@ pub enum ModuleCompilationPhase { pub struct Module { pub source: InputSource, pub tokens: TokenBuffer, - pub is_compiler_file: bool, // TODO: @Hack + pub is_compiler_file: bool, // TODO: @Hack for custom compiler-only types + pub add_to_global_namespace: bool, pub root_id: RootId, pub name: Option<(PragmaId, StringRef<'static>)>, pub version: Option<(PragmaId, i64)>, @@ -193,7 +194,7 @@ impl Parser { /// it internally for later parsing (when all modules are present). Returns /// the index of the new module. pub fn feed(&mut self, mut source: InputSource) -> Result { - return self.feed_internal(source, false); + return self.feed_internal(source, false, false); } pub fn parse(&mut self) -> Result<(), ParseError> { @@ -296,9 +297,10 @@ impl Parser { use std::path::{Path, PathBuf}; use std::fs; - const FILES: [&'static str; 2] = [ - "std.global.pdl", - "std.random.pdl", + // Pair is (name, add_to_global_namespace) + const FILES: [(&'static str, bool); 2] = [ + ("std.global.pdl", true), + ("std.random.pdl", false), ]; // Determine base directory @@ -324,7 +326,7 @@ impl Parser { let mut file_path = PathBuf::new(); let mut first_file = true; - for file in FILES { + for (file, add_to_global_namespace) in FILES { file_path.clear(); file_path.push(path); file_path.push(file); @@ -340,7 +342,7 @@ impl Parser { let source = source.unwrap(); let input_source = InputSource::new(file.to_string(), source); - let module_index = self.feed_internal(input_source, true); + let module_index = self.feed_internal(input_source, true, add_to_global_namespace); if let Err(err) = module_index { // A bit of a hack, but shouldn't really happen anyway: the // compiler should ship with a decent standard library (at some @@ -358,7 +360,7 @@ impl Parser { return Ok(()) } - fn feed_internal(&mut self, mut source: InputSource, is_compiler_file: bool) -> Result { + fn feed_internal(&mut self, mut source: InputSource, is_compiler_file: bool, add_to_global_namespace: bool) -> Result { let mut token_buffer = TokenBuffer::new(); self.pass_tokenizer.tokenize(&mut source, &mut token_buffer)?; @@ -366,6 +368,7 @@ impl Parser { source, tokens: token_buffer, is_compiler_file, + add_to_global_namespace, root_id: RootId::new_invalid(), name: None, version: None,