Add no_custom_syntax.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
//! Module implementing custom syntax for [`Engine`].
|
||||
#![cfg(not(feature = "no_custom_syntax"))]
|
||||
|
||||
use crate::ast::Expr;
|
||||
use crate::func::SendSync;
|
||||
@@ -153,6 +154,8 @@ pub struct CustomSyntax {
|
||||
impl Engine {
|
||||
/// Register a custom syntax with the [`Engine`].
|
||||
///
|
||||
/// Not available under `no_custom_syntax`.
|
||||
///
|
||||
/// * `symbols` holds a slice of strings that define the custom syntax.
|
||||
/// * `scope_may_be_changed` specifies variables _may_ be added/removed by this custom syntax.
|
||||
/// * `func` is the implementation function.
|
||||
@@ -296,6 +299,8 @@ impl Engine {
|
||||
}
|
||||
/// Register a custom syntax with the [`Engine`].
|
||||
///
|
||||
/// Not available under `no_custom_syntax`.
|
||||
///
|
||||
/// # WARNING - Low Level API
|
||||
///
|
||||
/// This function is very low level.
|
||||
|
@@ -1,8 +1,8 @@
|
||||
//! Module containing all deprecated API that will be removed in the next major version.
|
||||
|
||||
use crate::{
|
||||
Dynamic, Engine, EvalAltResult, Expression, FnPtr, ImmutableString, NativeCallContext,
|
||||
Position, RhaiResult, RhaiResultOf, Scope, AST,
|
||||
Dynamic, Engine, EvalAltResult, FnPtr, ImmutableString, NativeCallContext, Position,
|
||||
RhaiResult, RhaiResultOf, Scope, AST,
|
||||
};
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
@@ -312,7 +312,8 @@ impl FnPtr {
|
||||
}
|
||||
}
|
||||
|
||||
impl Expression<'_> {
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
impl crate::Expression<'_> {
|
||||
/// If this expression is a variable name, return it. Otherwise [`None`].
|
||||
///
|
||||
/// # Deprecated
|
||||
|
@@ -28,10 +28,11 @@ pub mod custom_syntax;
|
||||
|
||||
pub mod deprecated;
|
||||
|
||||
use crate::engine::Precedence;
|
||||
use crate::tokenizer::Token;
|
||||
use crate::{Dynamic, Engine, Identifier};
|
||||
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
use crate::{engine::Precedence, tokenizer::Token};
|
||||
|
||||
#[cfg(feature = "no_std")]
|
||||
use std::prelude::v1::*;
|
||||
|
||||
@@ -121,6 +122,8 @@ impl Engine {
|
||||
|
||||
/// Register a custom operator with a precedence into the language.
|
||||
///
|
||||
/// Not available under `no_custom_syntax`.
|
||||
///
|
||||
/// The operator can be a valid identifier, a reserved symbol, a disabled operator or a disabled keyword.
|
||||
///
|
||||
/// The precedence cannot be zero.
|
||||
@@ -147,6 +150,7 @@ impl Engine {
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
pub fn register_custom_operator(
|
||||
&mut self,
|
||||
keyword: impl AsRef<str>,
|
||||
@@ -161,8 +165,11 @@ impl Engine {
|
||||
let keyword = keyword.as_ref();
|
||||
|
||||
match Token::lookup_from_syntax(keyword) {
|
||||
// Standard identifiers, reserved keywords and custom keywords are OK
|
||||
None | Some(Token::Reserved(..)) | Some(Token::Custom(..)) => (),
|
||||
// Standard identifiers and reserved keywords are OK
|
||||
None | Some(Token::Reserved(..)) => (),
|
||||
// custom keywords are OK
|
||||
#[cfg(not(feature = "no_custom_syntax"))]
|
||||
Some(Token::Custom(..)) => (),
|
||||
// Active standard keywords cannot be made custom
|
||||
// Disabled keywords are OK
|
||||
Some(token) if token.is_standard_keyword() => {
|
||||
|
Reference in New Issue
Block a user