Skip to content

Commit cd43bc7

Browse files
CedarMatt1BADragon
andauthored
Develop (1BADragon#20)
* Write a custom parser and remove parsel. (1BADragon#16) * Added bench times * Working on custom parser * Working on custom tokenizer * Finished conversion to rdp * Added ast to compile output * Fixed a bunch of warnings * Removed unused import and updated some deps * Make tokenizer a trait, ast tokenizer to come * Removed CelValueInner * Added a TODO for a future time * Fixed has and a bug with turnary * Bump version and README details --------- Co-authored-by: matt <[email protected]> * Working on syntax tree locations (1BADragon#17) * Fixed the bindings (1BADragon#18) * Add a bool function (1BADragon#19) --------- Co-authored-by: 1BADragon <[email protected]>
1 parent 0296092 commit cd43bc7

37 files changed

+2239
-1254
lines changed

Cargo.toml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
[package]
22
name = "rscel"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
edition = "2021"
55

66
[lib]
77
crate-type = ["cdylib", "rlib"]
88

99
[features]
10-
default = ["program_cache"]
10+
default = []
1111
ast_ser = []
12-
program_cache = []
12+
debug_output = []
1313
python = ["dep:pyo3"]
1414
console_error_panic_hook = ["dep:console_error_panic_hook"]
1515
wasm = [
16-
"dep:wasm-bindgen", "dep:serde-wasm-bindgen", "dep:js-sys",
16+
"dep:wasm-bindgen", "dep:serde-wasm-bindgen", "dep:js-sys",
1717
"console_error_panic_hook", "chrono/wasmbind"
1818
]
1919

2020

2121
[dependencies]
22-
parsel = "0.12.0"
2322
test-case = "3.1.0"
24-
regex = "1.9.1"
25-
once_cell = "1.18.0"
26-
serde = { version = "1.0.171", features = ["derive", "rc"] }
23+
regex = "1.9.4"
24+
serde = { version = "1.0.188", features = ["derive", "rc"] }
2725
serde_with = { version = "3.0.0", features = ["chrono"] }
28-
serde_json = { version = "1.0.100", features = ["raw_value"] }
26+
serde_json = { version = "1.0.105", features = ["raw_value"] }
2927
chrono = { version = "0.4.26", features = ["serde"] }
3028
duration-str = "0.5.1"
3129

3230
# Dependencies for python bindings
33-
pyo3 = { version = "0.19.1", optional = true, features = ["extension-module", "chrono"] }
31+
pyo3 = { version = "0.19.2", optional = true, features = ["extension-module", "chrono"] }
3432

3533
# Dependencies for wasm bindings
3634
wasm-bindgen = { version = "0.2.87", optional = true}

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ python-binding-release: .env
2828
wasm-example: wasm-binding
2929
cd examples/wasm && npm start
3030

31+
wasm-example-release: wasm-binding-release
32+
cd examples/wasm && npm start
33+
3134
.PHONY: all
3235
all: wasm-binding python-binding

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ assert!(TryInto::<i64>::try_into(res).unwrap() == 6);
3131
## Current Benchmark Times
3232
| Bench Run | Time |
3333
|--------------------------|----------------|
34-
| Run One No Binding | PT0.000145816S |
35-
| Run Many No Binding | PT0.005347295S |
36-
| Run One With Binding | PT0.000068584S |
37-
| Run Many With Bindings | PT0.006373568S |
38-
| Build Many | PT0.128137803S |
39-
| Build Many With Bindings | PT0.032668507S |
34+
|Run One No Binding: | 0.000310S |
35+
|Run Many No Binding: | 0.003657S |
36+
|Run One With Binding: | 0.000033S |
37+
|Run Many With Bindings: | 0.004281S |
38+
|Build Many: | 0.002312S |
39+
|Build Many With Bindings: | 0.051369S |
4040

4141
Build status: [![Rust](https://github.com/1BADragon/rscel/actions/workflows/rust.yml/badge.svg)](https://github.com/1BADragon/rscel/actions/workflows/rust.yml)

examples/eval.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use rscel::{BindContext, CelContext};
2+
use std::env;
3+
4+
fn main() {
5+
let args: Vec<String> = env::args().collect();
6+
let mut context = CelContext::new();
7+
let mut exec = BindContext::new();
8+
9+
context.add_program_str("prog", &args[1]).unwrap();
10+
11+
if args.len() > 2 {
12+
exec.bind_params_from_json_obj(args[2].parse().unwrap())
13+
.unwrap();
14+
}
15+
16+
let res = context.exec("prog", &exec).unwrap();
17+
println!("{}", res);
18+
}

examples/prog2json.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::env;
22

3-
use rscel::Program;
3+
use rscel::{CelCompiler, StringTokenizer};
44

55
fn main() {
66
let args: Vec<String> = env::args().collect();
@@ -10,6 +10,10 @@ fn main() {
1010
return;
1111
}
1212

13-
let prog = Program::from_source(&args[1]).unwrap();
13+
let mut tokenizer = StringTokenizer::with_input(&args[1]);
14+
let prog = CelCompiler::with_tokenizer(&mut tokenizer)
15+
.compile()
16+
.unwrap();
17+
1418
println!("{}", serde_json::to_string_pretty(&prog).unwrap());
1519
}

examples/wasm/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
"webpack-dev-server": "^4.15.0"
2727
},
2828
"dependencies": {
29-
"@fluentui/react": "^8.109.3",
30-
"@fluentui/react-components": "^9.19.1",
31-
"@fluentui/theme": "^2.6.29",
3229
"react": "^18.2.0",
3330
"react-dom": "^18.2.0",
3431
"rscel": "file:../../pkg"

examples/wasm/src/app.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import CelComponent from "./pages/CelComponent";
2-
import { ThemeProvider } from "@fluentui/react";
32
import { Card } from "@fluentui/react-components";
43
import * as React from "react";
54

65
export default function App() {
76
return (
8-
<ThemeProvider>
9-
<Card style={{ height: "640px", width: "480px", margin: "auto" }}>
10-
<CelComponent />
11-
</Card>
12-
</ThemeProvider>
7+
<Card style={{ height: "640px", width: "480px", margin: "auto" }}>
8+
<CelComponent />
9+
</Card>
1310
);
1411
}

examples/wasm/src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import ReactDOM from "react-dom";
21
import React from "react";
2+
import { createRoot } from 'react-dom/client';
33

44
import App from "./app.tsx";
55

6-
ReactDOM.render(<App />, document.getElementById("app"));
6+
7+
const domNode = document.getElementById("app");
8+
const root = createRoot(domNode);
9+
10+
root.render(<App />);

examples/wasm/src/pages/CelComponent.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as React from "react";
22
import "./CelComponent.css";
33

44
import init, { cel_eval, cel_details, CelFloat } from "rscel";
5-
import { useState } from "react";
5+
import { useState, useEffect } from "react";
66

77
export default function CelComponent() {
88
const [isInit, setIsInit] = useState<boolean>(false);
@@ -11,9 +11,11 @@ export default function CelComponent() {
1111
const [params, setParams] = useState<string[]>([]);
1212
const [paramVals, setParamVals] = useState<any>({});
1313

14-
init().then((_res: any) => {
15-
setIsInit(true);
16-
});
14+
useEffect(() => {
15+
init().then((_res: any) => {
16+
setIsInit(true);
17+
});
18+
}, []);
1719

1820
if (!isInit) {
1921
return <div>Loading...</div>;
@@ -30,7 +32,9 @@ export default function CelComponent() {
3032
setParamVals((old: any) => {
3133
try {
3234
let newObj = { ...old };
33-
newObj[val] = Number(event.target.value);
35+
const floatval = new CelFloat(Number(event.target.value));
36+
37+
newObj[val] = floatval;
3438
setErrorMessage("");
3539
return newObj;
3640
} catch (e) {
@@ -58,21 +62,25 @@ export default function CelComponent() {
5862
<div style={{ display: "flex", rowGap: "10px", justifyContent: "right" }}>
5963
<button
6064
onClick={() => {
61-
const details = cel_details(prog);
65+
const res = cel_details(prog);
6266

63-
if (details.success) {
64-
setParams(details.result.get("params"));
67+
if (res.success) {
68+
console.log(res);
69+
const details = res.result.get("details");
70+
setParams(details.get("params"));
6571
setErrorMessage("");
6672
} else {
67-
setErrorMessage(`${details.error.kind}: ${details.error.msg}`);
73+
setErrorMessage(`${res.error.kind}: ${res.error.msg}`);
6874
}
6975
}}
7076
>
7177
Analyze
7278
</button>
7379
<button
7480
onClick={() => {
81+
console.log(paramVals);
7582
const result = cel_eval(prog, paramVals);
83+
console.log(result);
7684

7785
if (result.success) {
7886
setErrorMessage(`Result: ${result.result.toString()}`);

0 commit comments

Comments
 (0)