fix(defs): conditional compilation and refactors
This commit is contained in:
parent
8ebc50bea8
commit
b00bf8535d
@ -4,10 +4,10 @@ use crate::{
|
||||
use core::fmt;
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
use alloc::borrow::Cow;
|
||||
use std::prelude::v1::*;
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
use alloc::string::String;
|
||||
use alloc::borrow::Cow;
|
||||
|
||||
#[cfg(not(feature = "no_std"))]
|
||||
use std::borrow::Cow;
|
||||
@ -86,8 +86,14 @@ impl<'e> Definitions<'e> {
|
||||
|
||||
fs::create_dir_all(path)?;
|
||||
|
||||
fs::write(path.join("__builtin__.d.rhai"), include_bytes!("builtin.d.rhai"))?;
|
||||
fs::write(path.join("__builtin-operators__.d.rhai"), include_bytes!("builtin-operators.d.rhai"))?;
|
||||
fs::write(
|
||||
path.join("__builtin__.d.rhai"),
|
||||
include_bytes!("builtin.d.rhai"),
|
||||
)?;
|
||||
fs::write(
|
||||
path.join("__builtin-operators__.d.rhai"),
|
||||
include_bytes!("builtin-operators.d.rhai"),
|
||||
)?;
|
||||
|
||||
fs::write(path.join("__static__.d.rhai"), self.static_module())?;
|
||||
|
||||
@ -95,6 +101,7 @@ impl<'e> Definitions<'e> {
|
||||
fs::write(path.join("__scope__.d.rhai"), self.scope())?;
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
for (name, decl) in self.modules() {
|
||||
fs::write(path.join(format!("{name}.d.rhai")), decl)?;
|
||||
}
|
||||
@ -196,13 +203,15 @@ impl Module {
|
||||
continue;
|
||||
}
|
||||
|
||||
f.write_definition(
|
||||
writer,
|
||||
def,
|
||||
def.engine.custom_keywords.contains_key(&f.metadata.name)
|
||||
|| (!f.metadata.name.contains('$')
|
||||
&& !is_valid_function_name(&f.metadata.name)),
|
||||
)?;
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
let operator = def.engine.custom_keywords.contains_key(&f.metadata.name)
|
||||
|| (!f.metadata.name.contains('$') && !is_valid_function_name(&f.metadata.name));
|
||||
|
||||
#[cfg(feature = "no_custom_syntax")]
|
||||
let operator =
|
||||
!f.metadata.name.contains('$') && !is_valid_function_name(&f.metadata.name);
|
||||
|
||||
f.write_definition(writer, def, operator)?;
|
||||
}
|
||||
|
||||
Ok(())
|
@ -28,6 +28,9 @@ pub mod custom_syntax;
|
||||
|
||||
pub mod deprecated;
|
||||
|
||||
#[cfg(feature = "metadata")]
|
||||
pub mod definitions;
|
||||
|
||||
use crate::{Dynamic, Engine, Identifier};
|
||||
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
|
@ -82,8 +82,6 @@ mod reify;
|
||||
mod tests;
|
||||
mod tokenizer;
|
||||
mod types;
|
||||
#[cfg(feature = "metadata")]
|
||||
mod definitions;
|
||||
|
||||
/// Error encountered when parsing a script.
|
||||
type PERR = ParseErrorType;
|
||||
@ -183,6 +181,10 @@ pub use types::{
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
pub use api::custom_syntax::Expression;
|
||||
|
||||
|
||||
#[cfg(feature = "metadata")]
|
||||
pub use api::definitions::Definitions;
|
||||
|
||||
/// _(debugging)_ Module containing types for debugging.
|
||||
/// Exported under the `debugging` feature only.
|
||||
#[cfg(feature = "debugging")]
|
||||
@ -260,9 +262,6 @@ pub mod serde;
|
||||
#[cfg(not(feature = "no_optimize"))]
|
||||
pub use optimizer::OptimizationLevel;
|
||||
|
||||
#[cfg(feature = "metadata")]
|
||||
pub use definitions::Definitions;
|
||||
|
||||
/// Placeholder for the optimization level.
|
||||
#[cfg(feature = "no_optimize")]
|
||||
pub type OptimizationLevel = ();
|
||||
|
Loading…
Reference in New Issue
Block a user