From 062ee5df9033e8aaa2aebd3bdef4c00aa58ff6fc Mon Sep 17 00:00:00 2001 From: Ivan Miletic <60513195+ivanmiletic@users.noreply.github.com> Date: Mon, 24 Apr 2023 20:28:27 +0200 Subject: [PATCH] feat: crates restructure (#22) --- .github/workflows/rust.yaml | 7 +- actions/cargo-version-action/dist/index.js | 12 ++-- actions/cargo-version-action/src/cargo.ts | 18 +++-- .../cargo-version-action/src/index.spec.ts | 45 ++++++------ actions/cargo-version-action/src/index.ts | 12 ++-- core/engine/Cargo.toml | 2 +- core/engine/src/handler/table/zen.rs | 2 +- core/{vm => expression}/Cargo.toml | 18 ++++- core/{vm => expression}/README.md | 6 +- core/{vm => expression}/benches/isolate.rs | 2 +- core/{parser => expression}/benches/lexer.rs | 2 +- .../benches/standard.rs | 4 +- core/{parser => expression}/benches/unary.rs | 4 +- core/{parser => expression}/src/ast.rs | 0 core/{vm => expression}/src/compiler.rs | 2 +- core/{vm => expression}/src/helpers.rs | 0 core/{vm => expression}/src/isolate.rs | 8 +-- .../{parser => expression}/src/lexer/codes.rs | 0 .../src/lexer/cursor.rs | 0 .../{parser => expression}/src/lexer/error.rs | 0 .../{parser => expression}/src/lexer/lexer.rs | 0 core/{parser => expression}/src/lexer/mod.rs | 0 .../{parser => expression}/src/lexer/token.rs | 0 core/{vm => expression}/src/lib.rs | 3 + core/{vm => expression}/src/opcodes.rs | 0 .../src/parser/definitions.rs | 0 .../src/parser/error.rs | 0 .../{parser => expression}/src/parser/iter.rs | 0 core/{parser => expression}/src/parser/mod.rs | 0 .../src/parser/standard/constants.rs | 0 .../src/parser/standard/mod.rs | 0 .../src/parser/unary/constants.rs | 0 .../src/parser/unary/mod.rs | 0 core/{vm => expression}/src/vm.rs | 0 core/{vm => expression}/tests/isolate.rs | 4 +- core/{parser => expression}/tests/lexer.rs | 4 +- core/{parser => expression}/tests/standard.rs | 6 +- core/{parser => expression}/tests/unary.rs | 6 +- core/parser/Cargo.toml | 32 --------- core/parser/README.md | 71 ------------------- core/parser/src/lib.rs | 7 -- 41 files changed, 85 insertions(+), 192 deletions(-) rename core/{vm => expression}/Cargo.toml (74%) rename core/{vm => expression}/README.md (93%) rename core/{vm => expression}/benches/isolate.rs (93%) rename core/{parser => expression}/benches/lexer.rs (99%) rename core/{parser => expression}/benches/standard.rs (99%) rename core/{parser => expression}/benches/unary.rs (91%) rename core/{parser => expression}/src/ast.rs (100%) rename core/{vm => expression}/src/compiler.rs (99%) rename core/{vm => expression}/src/helpers.rs (100%) rename core/{vm => expression}/src/isolate.rs (97%) rename core/{parser => expression}/src/lexer/codes.rs (100%) rename core/{parser => expression}/src/lexer/cursor.rs (100%) rename core/{parser => expression}/src/lexer/error.rs (100%) rename core/{parser => expression}/src/lexer/lexer.rs (100%) rename core/{parser => expression}/src/lexer/mod.rs (100%) rename core/{parser => expression}/src/lexer/token.rs (100%) rename core/{vm => expression}/src/lib.rs (78%) rename core/{vm => expression}/src/opcodes.rs (100%) rename core/{parser => expression}/src/parser/definitions.rs (100%) rename core/{parser => expression}/src/parser/error.rs (100%) rename core/{parser => expression}/src/parser/iter.rs (100%) rename core/{parser => expression}/src/parser/mod.rs (100%) rename core/{parser => expression}/src/parser/standard/constants.rs (100%) rename core/{parser => expression}/src/parser/standard/mod.rs (100%) rename core/{parser => expression}/src/parser/unary/constants.rs (100%) rename core/{parser => expression}/src/parser/unary/mod.rs (100%) rename core/{vm => expression}/src/vm.rs (100%) rename core/{vm => expression}/tests/isolate.rs (99%) rename core/{parser => expression}/tests/lexer.rs (99%) rename core/{parser => expression}/tests/standard.rs (98%) rename core/{parser => expression}/tests/unary.rs (97%) delete mode 100644 core/parser/Cargo.toml delete mode 100644 core/parser/README.md delete mode 100644 core/parser/src/lib.rs diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index c455029f..d8166bd4 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -120,11 +120,8 @@ jobs: - name: Login to Crates.IO run: cargo login ${{ secrets.CRATES_TOKEN }} - - name: Publish Parser - run: cd core/parser && cargo publish - - - name: Publish VM - run: cd core/vm && cargo publish + - name: Publish Expression + run: cd core/expression && cargo publish - name: Publish Engine run: cd core/engine && cargo publish diff --git a/actions/cargo-version-action/dist/index.js b/actions/cargo-version-action/dist/index.js index 8e7b9b6b..cb5c99bb 100644 --- a/actions/cargo-version-action/dist/index.js +++ b/actions/cargo-version-action/dist/index.js @@ -11268,14 +11268,12 @@ var semver = __nccwpck_require__(1383); var toml = __nccwpck_require__(4920); ;// CONCATENATED MODULE: ./src/cargo.ts -const versionRegex = /version = "[0-9]+\.[0-9]+\.[0-9]+"$/mi; -const vmDep = /zen-vm =.*$/mi; -const parserDep = /zen-parser =.*$/mi; +const versionRegex = /version = "[0-9]+\.[0-9]+\.[0-9]+"$/im; +const expressionDep = /zen-expression =.*$/im; const updateCargoContents = (contents, { version }) => { return contents .replace(versionRegex, `version = "${version}"`) - .replace(parserDep, `zen-parser = { path = "../parser", version = "${version}" }`) - .replace(vmDep, `zen-vm = { path = "../vm", version = "${version}" }`); + .replace(expressionDep, `zen-expression = { path = "../expression", version = "${version}" }`); }; const getCargoVersion = (contents) => { var _a; @@ -11310,9 +11308,7 @@ function run() { const project = 'engine'; const projectsFolder = 'core'; const directory = yield promises_namespaceObject.readdir(external_path_.join(...[workspace, projectsFolder]), { withFileTypes: true }); - const folders = directory - .filter((dirent) => dirent.isDirectory()) - .map((dirent) => dirent.name); + const folders = directory.filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name); const cargoFilePath = external_path_.join(...[workspace, projectsFolder, project, 'Cargo.toml']); const cargoFile = yield promises_namespaceObject.readFile(cargoFilePath, 'utf-8'); const currentVersion = getCargoVersion(cargoFile); diff --git a/actions/cargo-version-action/src/cargo.ts b/actions/cargo-version-action/src/cargo.ts index 7905a0a2..a397bed0 100644 --- a/actions/cargo-version-action/src/cargo.ts +++ b/actions/cargo-version-action/src/cargo.ts @@ -1,21 +1,19 @@ -import * as toml from "toml"; +import * as toml from 'toml'; type UpdateCargoOptions = { version: string; -} +}; -const versionRegex = /version = "[0-9]+\.[0-9]+\.[0-9]+"$/mi; -const vmDep = /zen-vm =.*$/mi; -const parserDep = /zen-parser =.*$/mi; +const versionRegex = /version = "[0-9]+\.[0-9]+\.[0-9]+"$/im; +const expressionDep = /zen-expression =.*$/im; -export const updateCargoContents = (contents: string, {version}: UpdateCargoOptions): string => { +export const updateCargoContents = (contents: string, { version }: UpdateCargoOptions): string => { return contents .replace(versionRegex, `version = "${version}"`) - .replace(parserDep, `zen-parser = { path = "../parser", version = "${version}" }`) - .replace(vmDep, `zen-vm = { path = "../vm", version = "${version}" }`); -} + .replace(expressionDep, `zen-expression = { path = "../expression", version = "${version}" }`); +}; export const getCargoVersion = (contents: string): string => { const t = toml.parse(contents); return t?.package?.version; -} \ No newline at end of file +}; diff --git a/actions/cargo-version-action/src/index.spec.ts b/actions/cargo-version-action/src/index.spec.ts index 021f966e..359349e5 100644 --- a/actions/cargo-version-action/src/index.spec.ts +++ b/actions/cargo-version-action/src/index.spec.ts @@ -1,12 +1,12 @@ -import {describe} from "node:test"; -import {expect, test} from "@jest/globals"; -import {getCargoVersion, updateCargoContents} from "./cargo"; -import {inc, ReleaseType} from "semver"; -import * as fs from "fs/promises"; -import * as path from "path"; +import { describe } from 'node:test'; +import { expect, test } from '@jest/globals'; +import { getCargoVersion, updateCargoContents } from './cargo'; +import { inc, ReleaseType } from 'semver'; +import * as fs from 'fs/promises'; +import * as path from 'path'; // language=Toml -const makeToml = ({version}): string => ` +const makeToml = ({ version }): string => ` [package] authors = ["GoRules Team "] description = "Business rules engine" @@ -28,37 +28,36 @@ serde_v8 = { version = "0.88.0" } once_cell = { version = "1.17.1" } futures = "0.3.27" v8 = { version = "0.66.0" } -zen-parser = { path = "../parser", version = "${version}" } -zen-vm = { path = "../vm", version = "${version}" } -` +zen-expression = { path = "../expression", version = "${version}" } +`; -describe("GitHub Action", () => { - test("Bumps package", () => { - const version = "0.2.0"; - const initialToml = makeToml({version}); +describe('GitHub Action', () => { + test('Bumps package', () => { + const version = '0.2.0'; + const initialToml = makeToml({ version }); - const releases: ReleaseType[] = ["major", "minor", "patch"]; + const releases: ReleaseType[] = ['major', 'minor', 'patch']; for (const release of releases) { const newVersion = inc(version, release); - const expectedToml = makeToml({version: newVersion}); + const expectedToml = makeToml({ version: newVersion }); - expect(updateCargoContents(initialToml, {version: newVersion})).toEqual(expectedToml); + expect(updateCargoContents(initialToml, { version: newVersion })).toEqual(expectedToml); } }); - test("Extracts package version", () => { - const versions = ["0.1.0", "0.2.0", "0.3.0"]; + test('Extracts package version', () => { + const versions = ['0.1.0', '0.2.0', '0.3.0']; for (const version of versions) { const versionedToml = makeToml({ version }); expect(getCargoVersion(versionedToml)).toEqual(version); } - }) + }); - test("Points to right directory", async () => { + test('Points to right directory', async () => { const escapeDir = (count: number) => '../'.repeat(count); const coreDirectory = path.join(__dirname, escapeDir(3), 'core'); const folders = await fs.readdir(coreDirectory); - expect(folders).toEqual(expect.arrayContaining(["engine", "parser", "vm"])) + expect(folders).toEqual(expect.arrayContaining(['engine', 'expression'])); }); -}); \ No newline at end of file +}); diff --git a/actions/cargo-version-action/src/index.ts b/actions/cargo-version-action/src/index.ts index b9160614..7a062faa 100644 --- a/actions/cargo-version-action/src/index.ts +++ b/actions/cargo-version-action/src/index.ts @@ -3,8 +3,8 @@ import * as exec from '@actions/exec'; import * as fs from 'fs/promises'; import * as path from 'path'; -import {inc, ReleaseType} from 'semver'; -import {getCargoVersion, updateCargoContents} from "./cargo"; +import { inc, ReleaseType } from 'semver'; +import { getCargoVersion, updateCargoContents } from './cargo'; async function run() { try { @@ -16,10 +16,8 @@ async function run() { const project = 'engine'; const projectsFolder = 'core'; - const directory = await fs.readdir(path.join(...[workspace, projectsFolder]), {withFileTypes: true}); - const folders = directory - .filter((dirent) => dirent.isDirectory()) - .map((dirent) => dirent.name); + const directory = await fs.readdir(path.join(...[workspace, projectsFolder]), { withFileTypes: true }); + const folders = directory.filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name); const cargoFilePath = path.join(...[workspace, projectsFolder, project, 'Cargo.toml']); const cargoFile = await fs.readFile(cargoFilePath, 'utf-8'); @@ -33,7 +31,7 @@ async function run() { folders.map(async (folder) => { const cargoFilePath = path.join(...[workspace, projectsFolder, folder, 'Cargo.toml']); const cargoFile = await fs.readFile(cargoFilePath, 'utf-8'); - const updatedCargoFile = updateCargoContents(cargoFile, {version}); + const updatedCargoFile = updateCargoContents(cargoFile, { version }); console.log(`Writing new version to: ${cargoFilePath}`); await fs.writeFile(cargoFilePath, updatedCargoFile); diff --git a/core/engine/Cargo.toml b/core/engine/Cargo.toml index da3f4b3a..0ae4aef0 100644 --- a/core/engine/Cargo.toml +++ b/core/engine/Cargo.toml @@ -22,7 +22,7 @@ serde_v8 = { version = "0.88.0" } once_cell = { version = "1.17.1" } futures = "0.3.27" v8 = { version = "0.66.0" } -zen-vm = { path = "../vm", version = "0.2.1" } +zen-expression = { path = "../expression", version = "0.2.1" } [dev-dependencies] tokio-test = "0.4.2" diff --git a/core/engine/src/handler/table/zen.rs b/core/engine/src/handler/table/zen.rs index 403d649e..eee068bd 100644 --- a/core/engine/src/handler/table/zen.rs +++ b/core/engine/src/handler/table/zen.rs @@ -7,7 +7,7 @@ use serde_json::Value; use crate::handler::node::{NodeRequest, NodeResponse, NodeResult}; use crate::handler::table::{RowOutput, RowOutputKind}; use crate::model::{DecisionNodeKind, DecisionTableContent, DecisionTableHitPolicy}; -use zen_vm::isolate::Isolate; +use zen_expression::isolate::Isolate; #[derive(Debug, Serialize)] struct RowResult { diff --git a/core/vm/Cargo.toml b/core/expression/Cargo.toml similarity index 74% rename from core/vm/Cargo.toml rename to core/expression/Cargo.toml index 19fd1574..ae5ad183 100644 --- a/core/vm/Cargo.toml +++ b/core/expression/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["GoRules Team "] -description = "Zen expression language virtual machine" -name = "zen-vm" +description = "Zen Expression Language" +name = "zen-expression" license = "MIT" version = "0.2.1" edition = "2021" @@ -16,15 +16,27 @@ hashbrown = { workspace = true, features = ["bumpalo"] } humantime = { workspace = true } fastrand = { workspace = true } once_cell = { workspace = true } +phf = { workspace = true, features = ["macros"] } serde_json = { workspace = true, features = ["arbitrary_precision"] } thiserror = { workspace = true } rust_decimal = { workspace = true, features = ["maths-nopanic"] } rust_decimal_macros = { workspace = true } -zen-parser = { path = "../parser", version = "0.2.1" } [dev-dependencies] criterion = { workspace = true } +[[bench]] +harness = false +name = "unary" + +[[bench]] +harness = false +name = "standard" + +[[bench]] +harness = false +name = "lexer" + [[bench]] harness = false name = "isolate" \ No newline at end of file diff --git a/core/vm/README.md b/core/expression/README.md similarity index 93% rename from core/vm/README.md rename to core/expression/README.md index bf6b6091..f5531b14 100644 --- a/core/vm/README.md +++ b/core/expression/README.md @@ -1,7 +1,7 @@ -# ZEN VM +# ZEN Expression -Parser for business-first expression language used in -Zen business rules engine by GoRules. The language is designed +Zen Expression is business-first expression language used in +Zen Business rules engine by GoRules. The language is designed to follow these principles: - Side-effect free diff --git a/core/vm/benches/isolate.rs b/core/expression/benches/isolate.rs similarity index 93% rename from core/vm/benches/isolate.rs rename to core/expression/benches/isolate.rs index 3297a6f0..e117c5a0 100644 --- a/core/vm/benches/isolate.rs +++ b/core/expression/benches/isolate.rs @@ -1,7 +1,7 @@ use criterion::{criterion_group, criterion_main, Bencher, Criterion}; use serde_json::Value; -use zen_vm::isolate::Isolate; +use zen_expression::isolate::Isolate; fn bench_source(b: &mut Bencher, source: &'static str) { let s: Value = serde_json::from_str(r#"{ "$": "ru" }"#).unwrap(); diff --git a/core/parser/benches/lexer.rs b/core/expression/benches/lexer.rs similarity index 99% rename from core/parser/benches/lexer.rs rename to core/expression/benches/lexer.rs index 68133836..e3b60a5f 100644 --- a/core/parser/benches/lexer.rs +++ b/core/expression/benches/lexer.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, Bencher, Criterion}; -use zen_parser::lexer::Lexer; +use zen_expression::lexer::Lexer; fn bench_source(b: &mut Bencher, source: &'static str) { let lexer = Lexer::new(); diff --git a/core/parser/benches/standard.rs b/core/expression/benches/standard.rs similarity index 99% rename from core/parser/benches/standard.rs rename to core/expression/benches/standard.rs index a937ff7f..942df51b 100644 --- a/core/parser/benches/standard.rs +++ b/core/expression/benches/standard.rs @@ -1,8 +1,8 @@ use bumpalo::Bump; use criterion::{criterion_group, criterion_main, Bencher, Criterion}; -use zen_parser::lexer::Lexer; -use zen_parser::parser::StandardParser; +use zen_expression::lexer::Lexer; +use zen_expression::parser::StandardParser; fn bench_source(b: &mut Bencher, src: &'static str) { let lexer = Lexer::new(); diff --git a/core/parser/benches/unary.rs b/core/expression/benches/unary.rs similarity index 91% rename from core/parser/benches/unary.rs rename to core/expression/benches/unary.rs index 0d6ceb78..b6f8621b 100644 --- a/core/parser/benches/unary.rs +++ b/core/expression/benches/unary.rs @@ -1,8 +1,8 @@ use bumpalo::Bump; use criterion::{criterion_group, criterion_main, Bencher, Criterion}; -use zen_parser::lexer::Lexer; -use zen_parser::parser::UnaryParser; +use zen_expression::lexer::Lexer; +use zen_expression::parser::UnaryParser; fn bench_source(b: &mut Bencher, src: &'static str) { let lexer = Lexer::new(); diff --git a/core/parser/src/ast.rs b/core/expression/src/ast.rs similarity index 100% rename from core/parser/src/ast.rs rename to core/expression/src/ast.rs diff --git a/core/vm/src/compiler.rs b/core/expression/src/compiler.rs similarity index 99% rename from core/vm/src/compiler.rs rename to core/expression/src/compiler.rs index 2d525eb6..26479ef0 100644 --- a/core/vm/src/compiler.rs +++ b/core/expression/src/compiler.rs @@ -4,7 +4,7 @@ use std::rc::Rc; use bumpalo::Bump; use thiserror::Error; -use zen_parser::ast::Node; +use crate::ast::Node; use crate::compiler::CompilerError::{ ArgumentNotFound, UnknownBinaryOperator, UnknownBuiltIn, UnknownUnaryOperator, diff --git a/core/vm/src/helpers.rs b/core/expression/src/helpers.rs similarity index 100% rename from core/vm/src/helpers.rs rename to core/expression/src/helpers.rs diff --git a/core/vm/src/isolate.rs b/core/expression/src/isolate.rs similarity index 97% rename from core/vm/src/isolate.rs rename to core/expression/src/isolate.rs index 5682f9af..e7a6a960 100644 --- a/core/vm/src/isolate.rs +++ b/core/expression/src/isolate.rs @@ -10,10 +10,10 @@ use bumpalo::Bump; use serde_json::Value; use thiserror::Error; -use zen_parser::lexer::error::LexerError; -use zen_parser::lexer::Lexer; -use zen_parser::parser::error::ParserError; -use zen_parser::parser::{StandardParser, UnaryParser}; +use crate::lexer::error::LexerError; +use crate::lexer::Lexer; +use crate::parser::error::ParserError; +use crate::parser::{StandardParser, UnaryParser}; use crate::compiler::{Compiler, CompilerError}; use crate::opcodes::{ExecResult, Opcode, Variable}; diff --git a/core/parser/src/lexer/codes.rs b/core/expression/src/lexer/codes.rs similarity index 100% rename from core/parser/src/lexer/codes.rs rename to core/expression/src/lexer/codes.rs diff --git a/core/parser/src/lexer/cursor.rs b/core/expression/src/lexer/cursor.rs similarity index 100% rename from core/parser/src/lexer/cursor.rs rename to core/expression/src/lexer/cursor.rs diff --git a/core/parser/src/lexer/error.rs b/core/expression/src/lexer/error.rs similarity index 100% rename from core/parser/src/lexer/error.rs rename to core/expression/src/lexer/error.rs diff --git a/core/parser/src/lexer/lexer.rs b/core/expression/src/lexer/lexer.rs similarity index 100% rename from core/parser/src/lexer/lexer.rs rename to core/expression/src/lexer/lexer.rs diff --git a/core/parser/src/lexer/mod.rs b/core/expression/src/lexer/mod.rs similarity index 100% rename from core/parser/src/lexer/mod.rs rename to core/expression/src/lexer/mod.rs diff --git a/core/parser/src/lexer/token.rs b/core/expression/src/lexer/token.rs similarity index 100% rename from core/parser/src/lexer/token.rs rename to core/expression/src/lexer/token.rs diff --git a/core/vm/src/lib.rs b/core/expression/src/lib.rs similarity index 78% rename from core/vm/src/lib.rs rename to core/expression/src/lib.rs index 2d00ee8a..91b069e7 100644 --- a/core/vm/src/lib.rs +++ b/core/expression/src/lib.rs @@ -5,7 +5,10 @@ extern crate core; mod helpers; +pub mod ast; pub mod compiler; pub mod isolate; +pub mod lexer; pub mod opcodes; +pub mod parser; pub mod vm; diff --git a/core/vm/src/opcodes.rs b/core/expression/src/opcodes.rs similarity index 100% rename from core/vm/src/opcodes.rs rename to core/expression/src/opcodes.rs diff --git a/core/parser/src/parser/definitions.rs b/core/expression/src/parser/definitions.rs similarity index 100% rename from core/parser/src/parser/definitions.rs rename to core/expression/src/parser/definitions.rs diff --git a/core/parser/src/parser/error.rs b/core/expression/src/parser/error.rs similarity index 100% rename from core/parser/src/parser/error.rs rename to core/expression/src/parser/error.rs diff --git a/core/parser/src/parser/iter.rs b/core/expression/src/parser/iter.rs similarity index 100% rename from core/parser/src/parser/iter.rs rename to core/expression/src/parser/iter.rs diff --git a/core/parser/src/parser/mod.rs b/core/expression/src/parser/mod.rs similarity index 100% rename from core/parser/src/parser/mod.rs rename to core/expression/src/parser/mod.rs diff --git a/core/parser/src/parser/standard/constants.rs b/core/expression/src/parser/standard/constants.rs similarity index 100% rename from core/parser/src/parser/standard/constants.rs rename to core/expression/src/parser/standard/constants.rs diff --git a/core/parser/src/parser/standard/mod.rs b/core/expression/src/parser/standard/mod.rs similarity index 100% rename from core/parser/src/parser/standard/mod.rs rename to core/expression/src/parser/standard/mod.rs diff --git a/core/parser/src/parser/unary/constants.rs b/core/expression/src/parser/unary/constants.rs similarity index 100% rename from core/parser/src/parser/unary/constants.rs rename to core/expression/src/parser/unary/constants.rs diff --git a/core/parser/src/parser/unary/mod.rs b/core/expression/src/parser/unary/mod.rs similarity index 100% rename from core/parser/src/parser/unary/mod.rs rename to core/expression/src/parser/unary/mod.rs diff --git a/core/vm/src/vm.rs b/core/expression/src/vm.rs similarity index 100% rename from core/vm/src/vm.rs rename to core/expression/src/vm.rs diff --git a/core/vm/tests/isolate.rs b/core/expression/tests/isolate.rs similarity index 99% rename from core/vm/tests/isolate.rs rename to core/expression/tests/isolate.rs index 73c0251e..d8833cbc 100644 --- a/core/vm/tests/isolate.rs +++ b/core/expression/tests/isolate.rs @@ -2,8 +2,8 @@ use bumpalo::Bump; use rust_decimal_macros::dec; use serde_json::{json, Value}; -use zen_vm::isolate::Isolate; -use zen_vm::opcodes::{ExecResult, Variable}; +use zen_expression::isolate::Isolate; +use zen_expression::opcodes::{ExecResult, Variable}; struct TestEnv { env: Value, diff --git a/core/parser/tests/lexer.rs b/core/expression/tests/lexer.rs similarity index 99% rename from core/parser/tests/lexer.rs rename to core/expression/tests/lexer.rs index 8e698820..847100fd 100644 --- a/core/parser/tests/lexer.rs +++ b/core/expression/tests/lexer.rs @@ -1,5 +1,5 @@ -use zen_parser::lexer::token::{Token, TokenKind}; -use zen_parser::lexer::Lexer; +use zen_expression::lexer::token::{Token, TokenKind}; +use zen_expression::lexer::Lexer; struct LexerTest { test: &'static str, diff --git a/core/parser/tests/standard.rs b/core/expression/tests/standard.rs similarity index 98% rename from core/parser/tests/standard.rs rename to core/expression/tests/standard.rs index 081091d5..dae2f35b 100644 --- a/core/parser/tests/standard.rs +++ b/core/expression/tests/standard.rs @@ -3,9 +3,9 @@ use rust_decimal::Decimal; use rust_decimal_macros::dec; -use zen_parser::ast::Node; -use zen_parser::lexer::Lexer; -use zen_parser::parser::StandardParser; +use zen_expression::ast::Node; +use zen_expression::lexer::Lexer; +use zen_expression::parser::StandardParser; struct StandardTest { src: &'static str, diff --git a/core/parser/tests/unary.rs b/core/expression/tests/unary.rs similarity index 97% rename from core/parser/tests/unary.rs rename to core/expression/tests/unary.rs index 192535f2..acbfd7b9 100644 --- a/core/parser/tests/unary.rs +++ b/core/expression/tests/unary.rs @@ -2,9 +2,9 @@ use bumpalo::Bump; use rust_decimal::Decimal; use rust_decimal_macros::dec; -use zen_parser::ast::Node; -use zen_parser::lexer::Lexer; -use zen_parser::parser::UnaryParser; +use zen_expression::ast::Node; +use zen_expression::lexer::Lexer; +use zen_expression::parser::UnaryParser; struct UnaryTest { src: &'static str, diff --git a/core/parser/Cargo.toml b/core/parser/Cargo.toml deleted file mode 100644 index f7f24815..00000000 --- a/core/parser/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -authors = ["GoRules Team "] -description = "Zen expression language parser" -name = "zen-parser" -license = "MIT" -version = "0.2.1" -edition = "2021" -repository = "https://github.com/gorules/zen.git" - -[dependencies] -ahash = { workspace = true } -bumpalo = { workspace = true } -once_cell = { workspace = true } -phf = { workspace = true, features = ["macros"] } -thiserror = { workspace = true } -rust_decimal = { workspace = true } -rust_decimal_macros = { workspace = true } - -[dev-dependencies] -criterion = { workspace = true } - -[[bench]] -harness = false -name = "unary" - -[[bench]] -harness = false -name = "standard" - -[[bench]] -harness = false -name = "lexer" \ No newline at end of file diff --git a/core/parser/README.md b/core/parser/README.md deleted file mode 100644 index 0d51c27e..00000000 --- a/core/parser/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# ZEN Parser - -Virtual machine for business-first expression language used in -Zen business rules engine by GoRules. The language is designed -to follow these principles: - -- Side-effect free -- Dynamic types -- Simple syntax for broad audiences - -It's primary objective is to bridge the gap between business analysts and engineers, -while providing outstanding performance and readability. - -## Resources - -[Documentation](https://gorules.io/docs/) - -[Zen Language Playground](https://gorules.io/docs/rules-engine/expression-language#playground) - -[Online Rules Editor](https://editor.gorules.io/) - -## Unary tests -Unary test is a comma-separated list of simple expressions which -evaluate to a boolean value. Each comma separation is treated as -or operator. Inside unary expressions, a special symbol is available -$ which refers to a current column. - -Some examples: -```js -// Given: $ = 1 -1, 2, 3 // true -1 // true ->= 1 // true -< 1 // false -[0..10] // true, (internally this is $ >= 0 and $ <= 10) -> 0 and < 10 // true - -// Given: $ = 'USD' -'GBP', 'USD' // true -'EUR' // false -startsWith($, "US") // true - defaults to expression mode, comma is unavailable -endsWith($, "US") // false - defaults to expression mode -lower($) == "usd" // true - defaults to expression mode -``` - -## Standard tests - -Expressions feature full capability syntax of ZEN language. -They give you access to all functions, and are most useful when -defining columns or outputs. Full syntax is also available in unary -expressions when $ is used (as it forces the expression mode). - -```js -100 + 100 // 200 -10 * 5 // 50 -10 ^ 2 // 100 -1 in [1, 2, 3] // true -5 in (5..10] // false -sum([1, 2, 3]) // 6 -max([1, 2, 3]) // 3 - -"hello" + " " + "world" // "hello world" -len("world") // 5 -weekdayString(date("2022-11-08")) // "Tue" -contains("hello world", "hello") // true -upper('john') // "JOHN" - -some(['admin', 'user'], # == "admin") // true -not all([100, 200, 400, 800], # in (100..800)) // false -filter([100, 200, 400, 800], # >= 200) // [200, 400, 800] -``` \ No newline at end of file diff --git a/core/parser/src/lib.rs b/core/parser/src/lib.rs deleted file mode 100644 index 052fb611..00000000 --- a/core/parser/src/lib.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![deny(clippy::unwrap_used)] -#![deny(clippy::expect_used)] -#![allow(clippy::module_inception)] - -pub mod ast; -pub mod lexer; -pub mod parser;