Commit Graph

53 Commits

Author SHA1 Message Date
Sebastian Schmidt
9fc86a934f Change context trait.
Instead of one catchall trait for contexts, there are now several:

 * `Context` is now a "use-only" context, allowing only to retrieve variable names and call functions.
 * `ContextWithMutableVariables` also allows to mutate variables.
 * `ContextWithMutableFunctions` also allows to mutate functions. However this is not used anywhere at the moment. It will come in handy when the evalexpr language gets a function definition feature.
 * `GetFunctionContext` also allows to retrieve functions as `Function` type. This is uncommented at the moment, as it does not have any use in the crate as of now, and likely also not with planned future features.

 Additionally, this commit makes functions generic over the context type, as opposed to having a dynamic reference to a context type.

Relates to #73
2021-05-28 10:27:32 +03:00
Sebastian Schmidt
fd3063fc64 Reduce unwrap()s.
Relates to #14
2021-05-28 09:40:58 +03:00
Sebastian Schmidt
7bc05e0770 Make node cloneable. 2021-05-28 09:09:04 +03:00
Sebastian Schmidt
1316ae63d0 Update code formatting. 2021-05-28 08:56:21 +03:00
Sebastian Schmidt
a36d4d3815 Use mutable contexts in eval methods of Node
This was forgotten when closing #45.

Relates to #45
2019-08-29 18:06:39 +03:00
Sebastian Schmidt
b7233a3337 Implement operator assignments
Implements #34
2019-08-29 13:10:12 +03:00
Sebastian Schmidt
2399df16a1 Run rustfmt 2019-08-29 10:02:05 +03:00
Atul Bhosale
311c70a823
Update crate for Rust 2018 using 'cargo fix --edition' 2019-06-06 23:23:30 +05:30
Sebastian Schmidt
502ec0adce Format code 2019-05-04 13:54:19 +02:00
Sebastian Schmidt
6f533ca925 Merge branch '52_remove_automatic_function_argument_decomposition' 2019-05-04 13:53:47 +02:00
Sebastian Schmidt
2ca7209d22 Remove debug output 2019-05-04 13:43:05 +02:00
Sebastian Schmidt
21b308f3ae Format code 2019-04-26 17:37:59 +02:00
Sebastian Schmidt
6f77471354 Fixed aggregation operator
Manage sequence operators, which currently are `Chain` and `Token` on the stack without ever inserting unfinished sequence operator nodes into another node.

Relates to #44
2019-04-22 19:08:55 +02:00
Sebastian Schmidt
2e929ae0fe Replace manual type_id with builtin function of trait Any
Relates to #44
2019-04-22 16:24:26 +02:00
Sebastian Schmidt
d576cec9b9 Add flattening of operator chains when building operator tree
Relates to #44
2019-04-22 16:20:33 +02:00
Sebastian Schmidt
531b7b72a0 Make Operator::max_argument_amount optional
Relates to #44
2019-04-22 16:17:02 +02:00
Sebastian Schmidt
6c078c49e5 Refactor operators into an enum
(This commit is not formatted properly)

Relates to #46
2019-04-14 16:54:35 +02:00
Sebastian Schmidt
697fbb5d45 Implement iterators over variable and function identifiers
Relates to #37
2019-04-13 20:16:05 +02:00
Sebastian Schmidt
e328adb97b Implement Node::iter_identifiers()
This commit implements an iterator over the identifiers in an expression.
The identifiers are iterated pre-order, meaning that higher nodes in the tree are emitted first.
The identifier iterator is based on a general iterator over all nodes in an operator tree, which can be used for further featues.

Relates to #37
2019-04-12 19:27:34 +02:00
Sebastian Schmidt
67d68cd974 Add string constants
* Implement string parsing in tokenizer
 * Implement escape sequences `\"` and `\\`
 * Document changes
 * Update change log

Relates to #35
2019-03-30 11:54:26 +01:00
Sebastian Schmidt
9d27969eac Implement and test chain operator
Relates to #26
2019-03-28 11:34:54 +01:00
Sebastian Schmidt
83269068a2 Add the assignment operator
Relates to #25
2019-03-28 11:12:47 +01:00
Sebastian Schmidt
5bc4bcb702 Add crate level shortcut evaluations for Value::Empty
Relates to #28
2019-03-28 10:32:42 +01:00
Sebastian Schmidt
7d36ebe8df Add Node shortcut evaluations for Value::Empty
Relates to #28
2019-03-28 10:26:49 +01:00
Sebastian Schmidt
a7b5f602d5 Do not require expressions to have content
* Make parser return implicit toplevel node
 * Make `RootNode` return `Value::Empty` if it has no arguments instead of failing

Relates to #28
2019-03-28 10:10:16 +01:00
Sebastian Schmidt
e266f4fc0d Merge ContextMut with Context and add eval_<type>_with_context_mut methods
Trait objects of `ContextMut` cannot be converted into `Context`, even though `ContextMut` requires `Context`.

Relates to #30
2019-03-28 09:22:48 +01:00
Sebastian Schmidt
0acbcd8958 Format code 2019-03-28 08:44:04 +01:00
Sebastian Schmidt
d77fa15864 Use EvalexprResult<T> everywhere
Relates to #31
2019-03-27 19:09:58 +01:00
Sebastian Schmidt
720b2f90c2 Add Node::eval_number[_with_context] methods
Relates to #20
2019-03-27 18:55:51 +01:00
Sebastian Schmidt
b18521b8aa Format code 2019-03-27 18:35:16 +01:00
Sebastian Schmidt
9283d5412f Rename Context to ContextMut and Configuration to Context
Get rid of two different words for the same concept.

Relates to #22
2019-03-27 18:09:33 +01:00
Sebastian Schmidt
3da6019dae Add Context trait
* Rename `HashMapConfiguration` to `HashMapContext`
 * Rename `EmptyConfiguration` to `EmptyContext`
 * Implement `Context` for both predefined contexts
 * Update tests and doctests

Relates to #22
2019-03-27 17:45:06 +01:00
Sebastian Schmidt
fd879193b6 Rename Error to EvalexprError and add EvalexprResult
Relates to #27
2019-03-27 16:33:46 +01:00
Sebastian Schmidt
8a49bf9c11 Get rid of some unwraps
Relates to #14
2019-03-27 16:16:40 +01:00
Sebastian Schmidt
c980e49014 Add shortcut functions to evaluate Node into value types
+ Add functions `Node::eval_[type]` and `Node::eval_[type]_with_configuration` to evaluate a node directly into a value type

Partially implements #15
2019-03-20 16:57:21 +02:00
Sebastian Schmidt
58e8603194 Rename Node::eval to Node::eval_with_configuration for consistency.
* Rename `Node::eval` to `Node::eval_with_configuration`
 + Add `Node::eval` that calls `Node::eval_with_configuration` with an `EmptyConfiguration`
 + Improve documentation of `Node` and the changed methods

Implements #5
2019-03-20 11:58:08 +02:00
Sebastian Schmidt
e387d3370b Fix a typo 2019-03-20 11:50:09 +02:00
Sebastian Schmidt
38c4c35a0b Document all remaining public members
Implements #6
2019-03-20 11:32:55 +02:00
Sebastian Schmidt
bcfce4aaec Add trailing commas to match arm blocks 2019-03-19 19:06:37 +02:00
Sebastian Schmidt
93e8d867b4 Add exponentation operator
+ Add hat token
 + Add exponentation operator

Implements #3
2019-03-19 18:32:10 +02:00
Sebastian Schmidt
c631171ff0 Add comma operator and display implementations
+ Add comma token
 + Add tuple operator
 + Add tuple value type
 + Implement display for `tree::Node` and all related types
 + Add support for right-to-left chaining of operators with same precedence

The priority of chaining of operators with the same precedence remains left-to-right.
Only if two consecutive operators with the same precedence are right-to-left, they will be ordered right-to-left.

Implements #4.
2019-03-19 18:24:36 +02:00
Sebastian Schmidt
879f1fcd22 Evaluate arbitrary functions 2019-03-18 19:22:44 +02:00
Sebastian Schmidt
406bfe0e05 rustfmt 2019-03-15 19:22:14 +02:00
Sebastian Schmidt
bb74bee382 Implemented boolean expressions 2019-03-15 19:19:59 +02:00
Sebastian Schmidt
a1ba054609 Implemented mod and replaced Braced with RootNode 2019-03-15 18:34:40 +02:00
Sebastian Schmidt
1bc2909c1b Implemented and tested braces 2019-03-15 18:27:10 +02:00
Sebastian Schmidt
0ee4946eaf Implemented separate int and float types 2019-03-15 17:40:38 +02:00
Sebastian Schmidt
3975a17f0b Fixed warnings and removed unused dependencies. 2019-03-15 17:21:34 +02:00
Sebastian Schmidt
b38c102c1d Complete rewrite of crate. Simple tokenizer and treeifyer (Or however the compiler people call these.). 2019-03-15 17:14:27 +02:00
fengcen
0c4413836d fix #2 2018-08-24 09:09:55 +08:00