Move custom syntax to api.

This commit is contained in:
Stephen Chung 2021-12-27 22:02:34 +08:00
parent 4d226542fa
commit 9c7ced2b80
5 changed files with 17 additions and 21 deletions

View File

@ -18,6 +18,8 @@ pub mod limits;
pub mod events; pub mod events;
pub mod custom_syntax;
pub mod deprecated; pub mod deprecated;
use crate::engine::Precedence; use crate::engine::Precedence;

View File

@ -1,7 +1,7 @@
//! Main module defining the script evaluation [`Engine`]. //! 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::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::native::{OnDebugCallback, OnParseTokenCallback, OnPrintCallback, OnVarCallback};
use crate::func::{get_hasher, CallableFunction, IteratorFn}; use crate::func::{get_hasher, CallableFunction, IteratorFn};
use crate::module::Namespace; use crate::module::Namespace;

View File

@ -70,7 +70,6 @@ use std::prelude::v1::*;
mod api; mod api;
mod ast; mod ast;
mod custom_syntax;
mod engine; mod engine;
mod func; mod func;
mod module; mod module;
@ -140,8 +139,8 @@ pub type FLOAT = f32;
pub type ExclusiveRange = std::ops::Range<INT>; pub type ExclusiveRange = std::ops::Range<INT>;
pub type InclusiveRange = std::ops::RangeInclusive<INT>; pub type InclusiveRange = std::ops::RangeInclusive<INT>;
pub use api::custom_syntax::Expression;
pub use ast::{FnAccess, AST}; pub use ast::{FnAccess, AST};
pub use custom_syntax::Expression;
pub use engine::{ pub use engine::{
Engine, EvalContext, OP_CONTAINS, OP_EQUALS, OP_EXCLUSIVE_RANGE, OP_INCLUSIVE_RANGE, Engine, EvalContext, OP_CONTAINS, OP_EQUALS, OP_EXCLUSIVE_RANGE, OP_INCLUSIVE_RANGE,
}; };

View File

@ -1,11 +1,11 @@
//! Main module defining the lexer and parser. //! Main module defining the lexer and parser.
use crate::api::custom_syntax::{markers::*, CustomSyntax};
use crate::api::options::LanguageOptions; use crate::api::options::LanguageOptions;
use crate::ast::{ use crate::ast::{
BinaryExpr, CustomExpr, Expr, FnCallExpr, FnCallHashes, Ident, OpAssignment, ScriptFnDef, Stmt, BinaryExpr, CustomExpr, Expr, FnCallExpr, FnCallHashes, Ident, OpAssignment, ScriptFnDef, Stmt,
StmtBlock, AST_OPTION_FLAGS::*, StmtBlock, AST_OPTION_FLAGS::*,
}; };
use crate::custom_syntax::{markers::*, CustomSyntax};
use crate::engine::{Precedence, KEYWORD_THIS, OP_CONTAINS}; use crate::engine::{Precedence, KEYWORD_THIS, OP_CONTAINS};
use crate::func::hashing::get_hasher; use crate::func::hashing::get_hasher;
use crate::module::Namespace; use crate::module::Namespace;
@ -2190,15 +2190,11 @@ fn parse_custom_syntax(
} }
}, },
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
crate::custom_syntax::markers::CUSTOM_SYNTAX_MARKER_FLOAT => { CUSTOM_SYNTAX_MARKER_FLOAT => match input.next().expect(NEVER_ENDS) {
match input.next().expect(NEVER_ENDS) {
(Token::FloatConstant(f), pos) => { (Token::FloatConstant(f), pos) => {
inputs.push(Expr::FloatConstant(f, pos)); inputs.push(Expr::FloatConstant(f, pos));
segments.push(f.to_string().into()); segments.push(f.to_string().into());
tokens.push(state.get_identifier( tokens.push(state.get_identifier("", CUSTOM_SYNTAX_MARKER_FLOAT));
"",
crate::custom_syntax::markers::CUSTOM_SYNTAX_MARKER_FLOAT,
));
} }
(_, pos) => { (_, pos) => {
return Err(PERR::MissingSymbol( return Err(PERR::MissingSymbol(
@ -2206,8 +2202,7 @@ fn parse_custom_syntax(
) )
.into_err(pos)) .into_err(pos))
} }
} },
}
CUSTOM_SYNTAX_MARKER_STRING => match input.next().expect(NEVER_ENDS) { CUSTOM_SYNTAX_MARKER_STRING => match input.next().expect(NEVER_ENDS) {
(Token::StringConstant(s), pos) => { (Token::StringConstant(s), pos) => {
let s: ImmutableString = state.get_identifier("", s).into(); let s: ImmutableString = state.get_identifier("", s).into();