From 9c7ced2b8082bc53b7ffc65d5cd7aa48ba8ce62d Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 27 Dec 2021 22:02:34 +0800 Subject: [PATCH] Move custom syntax to api. --- src/{ => api}/custom_syntax.rs | 0 src/api/mod.rs | 2 ++ src/engine.rs | 2 +- src/lib.rs | 3 +-- src/parser.rs | 31 +++++++++++++------------------ 5 files changed, 17 insertions(+), 21 deletions(-) rename src/{ => api}/custom_syntax.rs (100%) diff --git a/src/custom_syntax.rs b/src/api/custom_syntax.rs similarity index 100% rename from src/custom_syntax.rs rename to src/api/custom_syntax.rs diff --git a/src/api/mod.rs b/src/api/mod.rs index 13c5488a..e42a489a 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -18,6 +18,8 @@ pub mod limits; pub mod events; +pub mod custom_syntax; + pub mod deprecated; use crate::engine::Precedence; diff --git a/src/engine.rs b/src/engine.rs index e4306199..121101fb 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1,7 +1,7 @@ //! Main module defining the script evaluation [`Engine`]. +use crate::api::custom_syntax::CustomSyntax; use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, Stmt, AST_OPTION_FLAGS::*}; -use crate::custom_syntax::CustomSyntax; use crate::func::native::{OnDebugCallback, OnParseTokenCallback, OnPrintCallback, OnVarCallback}; use crate::func::{get_hasher, CallableFunction, IteratorFn}; use crate::module::Namespace; diff --git a/src/lib.rs b/src/lib.rs index 67baf76d..b74cb0d4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,7 +70,6 @@ use std::prelude::v1::*; mod api; mod ast; -mod custom_syntax; mod engine; mod func; mod module; @@ -140,8 +139,8 @@ pub type FLOAT = f32; pub type ExclusiveRange = std::ops::Range; pub type InclusiveRange = std::ops::RangeInclusive; +pub use api::custom_syntax::Expression; pub use ast::{FnAccess, AST}; -pub use custom_syntax::Expression; pub use engine::{ Engine, EvalContext, OP_CONTAINS, OP_EQUALS, OP_EXCLUSIVE_RANGE, OP_INCLUSIVE_RANGE, }; diff --git a/src/parser.rs b/src/parser.rs index a9d1ab8d..a29c65d9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1,11 +1,11 @@ //! Main module defining the lexer and parser. +use crate::api::custom_syntax::{markers::*, CustomSyntax}; use crate::api::options::LanguageOptions; use crate::ast::{ BinaryExpr, CustomExpr, Expr, FnCallExpr, FnCallHashes, Ident, OpAssignment, ScriptFnDef, Stmt, StmtBlock, AST_OPTION_FLAGS::*, }; -use crate::custom_syntax::{markers::*, CustomSyntax}; use crate::engine::{Precedence, KEYWORD_THIS, OP_CONTAINS}; use crate::func::hashing::get_hasher; use crate::module::Namespace; @@ -2190,24 +2190,19 @@ fn parse_custom_syntax( } }, #[cfg(not(feature = "no_float"))] - crate::custom_syntax::markers::CUSTOM_SYNTAX_MARKER_FLOAT => { - match input.next().expect(NEVER_ENDS) { - (Token::FloatConstant(f), pos) => { - inputs.push(Expr::FloatConstant(f, pos)); - segments.push(f.to_string().into()); - tokens.push(state.get_identifier( - "", - crate::custom_syntax::markers::CUSTOM_SYNTAX_MARKER_FLOAT, - )); - } - (_, pos) => { - return Err(PERR::MissingSymbol( - "Expecting a floating-point number".to_string(), - ) - .into_err(pos)) - } + CUSTOM_SYNTAX_MARKER_FLOAT => match input.next().expect(NEVER_ENDS) { + (Token::FloatConstant(f), pos) => { + inputs.push(Expr::FloatConstant(f, pos)); + segments.push(f.to_string().into()); + tokens.push(state.get_identifier("", CUSTOM_SYNTAX_MARKER_FLOAT)); } - } + (_, pos) => { + return Err(PERR::MissingSymbol( + "Expecting a floating-point number".to_string(), + ) + .into_err(pos)) + } + }, CUSTOM_SYNTAX_MARKER_STRING => match input.next().expect(NEVER_ENDS) { (Token::StringConstant(s), pos) => { let s: ImmutableString = state.get_identifier("", s).into();