Skip to content

Commit

Permalink
Migrate from js_sandbox to rustyscript
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed Oct 17, 2023
1 parent 3995fc3 commit 21fe2d5
Show file tree
Hide file tree
Showing 23 changed files with 4,124 additions and 5,273 deletions.
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"

[features]
default = ["extensions", "crypto-functions", "encoding-functions"]
extensions = ["js_playground"]
extensions = ["rustyscript"]
crypto-functions = ["md-5", "sha2"]
encoding-functions = ["base64", "urlencoding"]

Expand All @@ -29,7 +29,7 @@ chrono = "0.4.23"
rand = "0.8.5"

# Feature deps
js_playground = { git = "https://github.com/rscarson/js-playground.git", optional = true }
rustyscript = { version = "0.1.1", optional = true }
md-5 = { version = "0.10.5", optional = true }
sha2 = { version = "0.10.6", optional = true }
base64 = { version = "0.21.0", optional = true }
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ fn main() -> Result<(), Error> {

A number of functions and @decorators are available for expressions to use - add more using the state:
```rust
use lavendeux_parser::{ParserState, Error, DecoratorDefinition, FunctionDefinition, FunctionArgument, Value};
use lavendeux_parser::Error;
use lavendeux_parser::{ParserState, Error, DecoratorDefinition, FunctionDefinition, FunctionArgument, Value, ExpectedTypes};

let mut state : ParserState = ParserState::new();
state.decorators.register(DecoratorDefinition {
Expand Down Expand Up @@ -157,15 +156,15 @@ fn main() -> Result<(), Error> {
let mut state : ParserState = ParserState::new();

// Load one extension
state.extensions.load("example_extensions/colour_utils.js");
state.extensions.load("example_extensions/simple_extension.js");

// Load a whole directory - this will return a vec of Extension/Error results
// Load a whole directory - this will return a vec of Result<Extension, Error>
state.extensions.load_all("./example_extensions");

// Once loaded, functions and @decorators decribed in the extensions
// can be called in expressions being parsed
let token = Token::new("complement(0xFF0000) @colour", &mut state)?;
assert_eq!(token.text(), "#ffff00");
let token = Token::new("add(1, 2) @colour", &mut state)?;
assert_eq!(token.text(), "#300000");
Ok(())
}
```
Expand Down
Loading

0 comments on commit 21fe2d5

Please sign in to comment.