Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed Oct 17, 2023
1 parent 966be8c commit 7429e2f
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,28 @@ 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, ExpectedTypes};
use lavendeux_parser::{ParserState, Error, define_function, define_decorator, Value, ExpectedTypes};

let mut state : ParserState = ParserState::new();
state.decorators.register(DecoratorDefinition {
name: &["upper", "uppercase"],
description: "Outputs an uppercase version of the input",
argument: ExpectedTypes::Any,
handler: |_, _token, input| Ok(input.as_string().to_uppercase())
});

// Functions take in an array of values, and return a single value
state.functions.register(FunctionDefinition {
name: "echo",
category: None,
description: "Echo back the provided input",
arguments: || vec![
FunctionArgument::new_required("input", ExpectedTypes::String),
],
handler: |_function, _token, _state, args| {
define_function!(
name = echo,
description = "Echo back the provided input",
arguments = [function_arg!("input":String)],
handler = |function, token, state, args| {
Ok(Value::String(args.get("input").required().as_string()))
}
});
);

define_decorator!(
name = upper,
aliases = ["uppercase"],
description = "Outputs an uppercase version of the input",
input = ExpectedTypes::Any,
handler = |decorator, token, input| Ok(input.as_string().to_uppercase())
);

let mut state : ParserState = ParserState::new();
state.decorators.register(upper);
state.functions.register(echo);

// Expressions being parsed can now call new_function(), and use the @new_decorator
```
Expand Down

0 comments on commit 7429e2f

Please sign in to comment.