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