Skip to content

Commit

Permalink
Make decorators more like functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rscarson committed May 5, 2022
1 parent d4250fe commit cc888e4
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 162 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.6.1
-----
Remove debug output
help() no longer takes just strings

0.6.0
-----
Added (Implied)(Multiplication) 2x, etc
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,16 @@ fn main() -> Result<(), ParserError> {

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

// Decorators take in a single value, and return a string representation
fn new_decorator_handler(arg: &Value) -> Result<String, ParserError> {
Ok(arg.as_string())
}

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

// Functions take in an array of values, and return a single value
state.functions.register(FunctionDefinition {
Expand Down
Loading

0 comments on commit cc888e4

Please sign in to comment.